diff --git a/src/isn.abst/ApiConfig.cs b/src/isn.abst/ApiConfig.cs index 311f3cf..42d9633 100644 --- a/src/isn.abst/ApiConfig.cs +++ b/src/isn.abst/ApiConfig.cs @@ -5,7 +5,8 @@ namespace isnd.Entities public static class ApiConfig { public const string Publish = "put"; - public const string Base = "index.json"; + public const string Index = "index"; + public const string IndexDotJson = Index + ".json"; public const string Catalog = "catalog"; public const string CatalogPage = "catalog-page"; public const string GetPackage = Constants.PaquetFileEstension; diff --git a/src/isn.abst/Constants.cs b/src/isn.abst/Constants.cs index 699bb50..e562734 100644 --- a/src/isn.abst/Constants.cs +++ b/src/isn.abst/Constants.cs @@ -4,5 +4,6 @@ namespace isn.abst { public const string PaquetFileEstension = "nupkg"; public const string SpecFileEstension = "nuspec"; + public const string JsonFileEstension = "json"; } } \ No newline at end of file diff --git a/src/isn.abst/isn.abst.csproj b/src/isn.abst/isn.abst.csproj index 57c6523..35ad668 100644 --- a/src/isn.abst/isn.abst.csproj +++ b/src/isn.abst/isn.abst.csproj @@ -1,12 +1,12 @@  1.0.1 - 0.1.175 + 1.0.5 netcoreapp2.1 NETSDK1138 - 0.1.175.0 - 0.1.175.0 - 0.1.175+Branch.main.Sha.3e09afcbfe0eff74c0b3aa0fb974e0801f4708b6 + 1.0.5.0 + 1.0.5.0 + 1.0.5+Branch.main.Sha.14206ac477d0f07566d5e8125dc52cbd7f474ca2 diff --git a/src/isn/SourceHelpers.cs b/src/isn/SourceHelpers.cs index 3b5dc97..ba8762b 100644 --- a/src/isn/SourceHelpers.cs +++ b/src/isn/SourceHelpers.cs @@ -23,37 +23,5 @@ namespace isn return result; } - - public static async Task GetServerResourcesUsingWebRequestAsync(string url) - { - ApiIndexViewModel viewModel=null; - var uri = new Uri(url); - - HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); - httpWebRequest.Method = "GET"; - httpWebRequest.AllowAutoRedirect = false; - try{ - - using (var resp = await httpWebRequest.GetResponseAsync()) - { - using (var stream = resp.GetResponseStream()) - { - using (var reader = new StreamReader(stream)) - { - var json = await reader.ReadToEndAsync(); - Console.Write("got json : "+json); - viewModel = JsonConvert.DeserializeObject(json); - - } - } - - } - } - catch(Exception ex) - { - Console.Error.WriteLine(ex.Message); - } - return viewModel; - } } } \ No newline at end of file diff --git a/src/isn/isn.csproj b/src/isn/isn.csproj index 92acbdd..03ad2b3 100644 --- a/src/isn/isn.csproj +++ b/src/isn/isn.csproj @@ -4,23 +4,23 @@ netcoreapp2.1 nuget_cli 45b74c62-05bc-4603-95b4-3e80ae2fdf50 - 0.1.175 + 1.0.5 1.0.1 true WTFPL true NETSDK1138 - 0.1.175.0 - 0.1.175.0 - 0.1.175+Branch.main.Sha.3e09afcbfe0eff74c0b3aa0fb974e0801f4708b6 + 1.0.5.0 + 1.0.5.0 + 1.0.5+Branch.main.Sha.14206ac477d0f07566d5e8125dc52cbd7f474ca2 - + diff --git a/src/isnd/Controllers/PackageVersionController.cs b/src/isnd/Controllers/PackageVersionController.cs index fb835b8..94c2fb5 100644 --- a/src/isnd/Controllers/PackageVersionController.cs +++ b/src/isnd/Controllers/PackageVersionController.cs @@ -27,7 +27,10 @@ namespace isnd // GET: PackageVersion public async Task Index(PackageVersionIndexViewModel model) { - var applicationDbContext = _context.PackageVersions.Include(p => p.Package).Where( + var applicationDbContext = _context.PackageVersions.Include(p => p.Package) + .Include(p => p.Package.Owner) + .Include(p => p.Package.Versions) + .Where( p => (model.Prerelease || !p.IsPrerelease) && ((model.PackageId == null) || p.PackageId.StartsWith(model.PackageId))); model.Versions = await applicationDbContext.ToArrayAsync(); diff --git a/src/isnd/Controllers/Packages/ApiIndex.cs b/src/isnd/Controllers/Packages/ApiIndex.cs index 2669c07..009545b 100644 --- a/src/isnd/Controllers/Packages/ApiIndex.cs +++ b/src/isnd/Controllers/Packages/ApiIndex.cs @@ -16,12 +16,13 @@ using isnd.ViewModels; using System.Threading.Tasks; using isnd.Interfaces; using isn.Abstract; +using isn.abst; namespace isnd.Controllers { public partial class PackagesController : Controller { - [HttpGet(_pkgRootPrefix + ApiConfig.Base)] + [HttpGet(_pkgRootPrefix + ApiConfig.IndexDotJson)] public IActionResult ApiIndex() { return Ok(new ApiIndexViewModel{ Version = PackageManager.BASE_API_LEVEL, Resources = resources }); diff --git a/src/isnd/Controllers/Packages/Catalog.cs b/src/isnd/Controllers/Packages/Catalog.cs index 563068f..fc4d9b3 100644 --- a/src/isnd/Controllers/Packages/Catalog.cs +++ b/src/isnd/Controllers/Packages/Catalog.cs @@ -1,18 +1,15 @@ using System.Linq; using System.Threading.Tasks; -using isnd.Helpers; using isnd.Services; using isnd.Entities; using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; using System.Collections.Generic; +using NuGet.Versioning; namespace isnd.Controllers { - public partial class PackagesController { - // https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning [HttpGet(_pkgRootPrefix + ApiConfig.Catalog)] public IActionResult CatalogIndex() @@ -27,40 +24,46 @@ namespace isnd.Controllers return Ok(PackageManager.CurrentCatalogPages[int.Parse(id)]); } - [HttpGet(_pkgRootPrefix + "{apiVersion}/" + ApiConfig.Registration + "/{id}/{*lower}")] + [HttpGet(_pkgRootPrefix + "{apiVersion}/" + ApiConfig.Registration + + "/{id}/index.json")] public async Task CatalogRegistrationAsync(string apiVersion, string id, string lower) { - bool askForindex = lower != null && lower.EndsWith(ApiConfig.Base); + bool askForindex = lower == null; if (askForindex) { - lower = lower.Substring(0, lower.Length - ApiConfig.Base.Length); + string sublower = lower.Substring(0, lower.Length - ApiConfig.IndexDotJson.Length); + + var pkgFromname = packageManager.SearchByName(id, 0, 1); + if (pkgFromname == null) return NotFound(); + foreach (var item in pkgFromname.Items) + { + item.Id = this.Url.Action(); + } + return Ok(pkgFromname); } - string pkgType = ParamHelpers.Optional(ref lower); - var pkgFromname = packageManager.SearchByName(id, 0, 1); - if (pkgFromname == null) return NotFound(); - return Ok(pkgFromname); - } + else + { + if (!NuGetVersion.TryParse(lower, out NuGetVersion version)) + return BadRequest(lower); + var pkgFromname = packageManager.GetVersions(id, version, true); + if (pkgFromname == null) return NotFound(); + return Ok(pkgFromname); + } + } - [HttpGet(_pkgRootPrefix + ApiConfig.CatalogLeaf + "/{id}/{version}/{*lower}")] + [HttpGet(_pkgRootPrefix + ApiConfig.CatalogLeaf + "/{id}/{version}/{lower}/index.json")] public async Task CatalogLeafAsync(string id, string version, string lower) { - var pkgvs = this.packageManager.GetCatalogLeaf(id, version, lower) - .ToArray(); - + var pkgvs = this.packageManager.GetCatalogLeaf(id, version, lower).ToArray(); if (pkgvs.Count() == 0) return NotFound(); - - List types = pkgvs - .Select( + List types = pkgvs.Select( v => v.Type ?? "Dependency" - ) - .Distinct().ToList(); + ).Distinct().ToList(); if (!types.Contains("PackageDelete")) types.Add("PackageDetails"); - var last = pkgvs.Last(); var pub = last.LatestCommit.CommitTimeStamp; - return Ok(new Data.Packages.Catalog.CatalogLeaf { CommitId = last.CommitId, @@ -68,10 +71,8 @@ namespace isnd.Controllers CommitTimeStamp = pub, Version = last.FullString, Published = pub, - RefType = types.ToArray(), - + RefType = types.ToArray() }); } - } } \ No newline at end of file diff --git a/src/isnd/Controllers/Packages/Delete.cs b/src/isnd/Controllers/Packages/Delete.cs index 66a4aaf..dcb3a7d 100644 --- a/src/isnd/Controllers/Packages/Delete.cs +++ b/src/isnd/Controllers/Packages/Delete.cs @@ -4,17 +4,20 @@ using isnd.Helpers; using isnd.Entities; using System.ComponentModel.DataAnnotations; using isnd.Attributes; +using System.Security.Claims; + namespace isnd.Controllers { public partial class PackagesController { - [HttpDelete(_pkgRootPrefix + ApiConfig.Delete + "/{id}/{*lower}")] - public async Task Delete( + [HttpDelete(_pkgRootPrefix + ApiConfig.Delete + "/{id}/{lower?}/{type?}")] + public async Task ApiDelete( [FromRoute][SafeName][Required] string id, - [FromRoute][SafeName][Required] string lower) + [FromRoute][SafeName][Required] string lower, + [FromRoute] string type) { - string pkgtype = ParamHelpers.Optional(ref lower); - var report = await packageManager.DeletePackageAsync(id, lower, pkgtype); + var uid = User.FindFirstValue(ClaimTypes.NameIdentifier); + var report = await packageManager.UserAskForPackageDeletionAsync(uid, id, lower, type); return Ok(report); } } diff --git a/src/isnd/Controllers/Packages/GetVersions.cs b/src/isnd/Controllers/Packages/GetVersions.cs index 8fcd84e..dc66721 100644 --- a/src/isnd/Controllers/Packages/GetVersions.cs +++ b/src/isnd/Controllers/Packages/GetVersions.cs @@ -1,12 +1,13 @@ using Microsoft.AspNetCore.Mvc; using NuGet.Versioning; using isnd.Entities; +using isn.abst; namespace isnd.Controllers { - public partial class PackagesController + public partial class PackagesController { - [HttpGet(_pkgRootPrefix + ApiConfig.GetVersion + "/{id}/{lower}/" + ApiConfig.Base)] + [HttpGet(_pkgRootPrefix + ApiConfig.GetVersion + "/{id}/{lower}/" + ApiConfig.IndexDotJson)] public IActionResult GetVersions( string id, string lower, diff --git a/src/isnd/Controllers/Packages/WebViews.cs b/src/isnd/Controllers/Packages/WebViews.cs index 7b767da..0f6b97c 100644 --- a/src/isnd/Controllers/Packages/WebViews.cs +++ b/src/isnd/Controllers/Packages/WebViews.cs @@ -15,15 +15,9 @@ namespace isnd.Controllers public partial class PackagesController { // Web search - public async Task Index(PackageRegistrationIndexViewModel model) + public async Task Index(PackageRegistrationIndexQuery model) { - var applicationDbContext = dbContext.Packages.Include(p => p.Versions) - .Include(p => p.Owner) - .Where( - p => (model.Prerelease || p.Versions.Any(v => !v.IsPrerelease)) - && ((model.Query == null) || p.Id.StartsWith(model.Query))); - model.Data = await applicationDbContext.Select(p => p.ToLeave()).ToArrayAsync(); - return View(model); + return View(packageManager.GetCatalogIndex()); } public async Task Details(string pkgid) @@ -64,6 +58,7 @@ namespace isnd.Controllers { return NotFound(); } + // var report = await packageManager.DeletePackageAsync(id, lower, type); var packageVersion = await dbContext.PackageVersions.Include(p => p.Package) .FirstOrDefaultAsync(m => m.PackageId == pkgid diff --git a/src/isnd/Data/Catalog/CatalogEntry.cs b/src/isnd/Data/Catalog/CatalogEntry.cs index 0fc0c4f..4e9adce 100644 --- a/src/isnd/Data/Catalog/CatalogEntry.cs +++ b/src/isnd/Data/Catalog/CatalogEntry.cs @@ -9,7 +9,7 @@ namespace isnd.Data.Catalog /// The URL to the document used to produce this object /// /// - [Key][Required] + [Key][Required,JsonRequired] [StringLength(1024)] [JsonProperty("@id")] public string Id { get; set; } @@ -70,7 +70,7 @@ namespace isnd.Data.Catalog /// The full version string after normalization /// /// - [Required] + [Required,JsonRequired] public string version { get; set; } // string yes /// /// The security vulnerabilities of the package diff --git a/src/isnd/Data/Catalog/PackageRegistrationIndexViewModel.cs b/src/isnd/Data/Catalog/PackageRegistrationIndexViewModel.cs index 543d9f0..02df87a 100644 --- a/src/isnd/Data/Catalog/PackageRegistrationIndexViewModel.cs +++ b/src/isnd/Data/Catalog/PackageRegistrationIndexViewModel.cs @@ -2,14 +2,11 @@ using Newtonsoft.Json; namespace isnd.Data.Catalog { - public class PackageRegistrationIndexViewModel + public class PackageRegistrationIndexQuery : RegistrationPageIndex { [JsonProperty("prerelease")] public bool Prerelease { get; set; } - [JsonProperty("data")] - public RegistrationLeaf[] Data {get; set;} - [JsonProperty("query")] public string Query { get; set; } diff --git a/src/isnd/Data/Catalog/PageRef.cs b/src/isnd/Data/Catalog/PageRef.cs index 55ffccd..0fd5e25 100644 --- a/src/isnd/Data/Catalog/PageRef.cs +++ b/src/isnd/Data/Catalog/PageRef.cs @@ -25,6 +25,7 @@ namespace isnd.Data.Catalog [JsonProperty("commitTimeStamp")] public DateTime CommitTimeStamp { get; set; } + } diff --git a/src/isnd/Data/Catalog/RegistrationPage.cs b/src/isnd/Data/Catalog/RegistrationPage.cs new file mode 100644 index 0000000..cce9867 --- /dev/null +++ b/src/isnd/Data/Catalog/RegistrationPage.cs @@ -0,0 +1,51 @@ +using System; +using Newtonsoft.Json; + +namespace isnd.Data.Catalog +{ + public class RegistrationPage + { + + /// + /// The URL to the registration page + /// + /// + [JsonProperty("@id"), JsonRequired] + public string Id { get; set; } + + /// + /// The number of registration leaves in the page + /// + /// + [JsonProperty("count"), JsonRequired] + public int Count { get; set; } + + /// + /// no The array of registration leaves and their associate metadata + /// + /// + [JsonProperty("items")] + + public RegistrationLeaf[] Items { get; set; } + /// + /// The highest SemVer 2.0.0 version in the page (inclusive) + /// + /// + [JsonProperty("upper"), JsonRequired] + public Version Upper { get; set; } + /// + /// The lowest SemVer 2.0.0 version in the page (inclusive) + /// + /// + [JsonProperty("lower"), JsonRequired] + public Version Lower { get; set; } + + /// + /// The URL to the registration index + /// + /// + [JsonProperty("parent")] + public string Parent { get; set; } + + } +} \ No newline at end of file diff --git a/src/isnd/Data/Catalog/RegistrationPageIndex.cs b/src/isnd/Data/Catalog/RegistrationPageIndex.cs new file mode 100644 index 0000000..bce162e --- /dev/null +++ b/src/isnd/Data/Catalog/RegistrationPageIndex.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace isnd.Data.Catalog +{ + public class RegistrationPageIndex + { + [JsonProperty("count")] + public int Count { get => Items?.Length ?? 0; } + + [JsonProperty("items")] + public RegistrationPage[] Items { get; set; } + } +} \ No newline at end of file diff --git a/src/isnd/Data/Catalog/RegistrationPages.cs b/src/isnd/Data/Catalog/RegistrationPages.cs deleted file mode 100644 index b3e945e..0000000 --- a/src/isnd/Data/Catalog/RegistrationPages.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using Newtonsoft.Json; - -namespace isnd.Data.Catalog -{ - public class RegistrationPage - { - /* - @id string yes The URL to the registration page - count integer yes The number of registration leaves in the page - items array of objects no The array of registration leaves and their associate metadata - lower string yes The lowest SemVer 2.0.0 version in the page (inclusive) - parent string no The URL to the registration index - upper string yes The highest SemVer 2.0.0 version in the page (inclusive) */ - [JsonProperty("@id")] - public string Id { get; set; } - [JsonProperty("count")] - public int Count { get; set; } - - [JsonProperty("items")] - - public RegistrationLeaf[] Items { get; set; } - - [JsonProperty("upper")] - public Version Upper { get; set; } - - [JsonProperty("lower")] - public Version Lower { get; set; } - - [JsonProperty("parent")] - public string Parent { get; set; } - - } -} \ No newline at end of file diff --git a/src/isnd/Data/Packages/Package.cs b/src/isnd/Data/Packages/Package.cs index 66f7e02..c3a02e0 100644 --- a/src/isnd/Data/Packages/Package.cs +++ b/src/isnd/Data/Packages/Package.cs @@ -46,17 +46,22 @@ namespace isnd.Data.Packages public virtual Commit LatestVersion{ get; set; } public DateTime CommitTimeStamp { get; set; } - - internal RegistrationLeaf ToLeave() + /// + /// Returns the leaf + /// + /// base url tu use for building the id property + /// + internal RegistrationLeaf ToLeave(string bid) { - if (!(Versions != null && - Versions.Count > 0)) throw new Exception("NO VERSION"); + if (Versions.Count == 0) throw new Exception("NO VERSION"); var v = Versions.First(); RegistrationLeaf leave = new RegistrationLeaf { + Id = bid + Id + ".json", PackageContent = v.NugetLink, Entry = new CatalogEntry { + Id = bid + Id + ".json", idp = Id, version = v.FullString, authors = $"{Owner.FullName} <${Owner.Email}>" diff --git a/src/isnd/Data/Packages/PackageVersion.cs b/src/isnd/Data/Packages/PackageVersion.cs index cff7d47..37a9ce6 100644 --- a/src/isnd/Data/Packages/PackageVersion.cs +++ b/src/isnd/Data/Packages/PackageVersion.cs @@ -43,7 +43,7 @@ namespace isnd.Data public string CommitId { get => CommitNId.ToString(); } - public virtual Commit LatestCommit{ get; set; } + public virtual Commit LatestCommit {get; set; } public string NugetLink => $"/{Constants.PaquetFileEstension}/{PackageId}/{FullString}/{PackageId}-{FullString}." + Constants.PaquetFileEstension; public string NuspecLink => $"/{Constants.SpecFileEstension}/{PackageId}/{FullString}/{PackageId}-{FullString}." diff --git a/src/isnd/Helpers/PackageVersionHelpers.cs b/src/isnd/Helpers/PackageVersionHelpers.cs index b8ad75a..b4845f2 100644 --- a/src/isnd/Helpers/PackageVersionHelpers.cs +++ b/src/isnd/Helpers/PackageVersionHelpers.cs @@ -1,15 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; using System.Security.Claims; +using isn.abst; using isnd.Data; +using isnd.Data.Catalog; +using isnd.Entities; namespace isnd.Helpers { public static class PackageVersionHelpers { - + public static bool IsOwner(this ClaimsPrincipal user, PackageVersion v) { - var userId = user.FindFirstValue(ClaimTypes.NameIdentifier); + var userId = user.FindFirstValue(ClaimTypes.NameIdentifier); return v.Package.OwnerId == userId; } + + public static RegistrationPage[] CreateRegistrationPages(this IEnumerable leaves, + string bid) + { + List pages = new List(); + var ids = leaves.Select(l => l.Entry.Id).Distinct().ToArray(); + foreach (var id in ids) + { + var lbi = leaves.Where(l=>l.Entry.Id == id).OrderBy(l=> + new Version(l.Entry.version)); + var latest = new Version(lbi.Last().Entry.version); + pages.Add(new RegistrationPage + { + Id = bid + id + "/" + latest.Major + "." + + latest.Minor + "." + + latest.Build, + Count = lbi.Count(), + Lower = new Version(lbi.First().Entry.version), + Upper = latest, + Items = lbi.ToArray(), + Parent = bid + id + "/" + ApiConfig.IndexDotJson, + }); + } + return pages.ToArray(); + } } } \ No newline at end of file diff --git a/src/isnd/Helpers/UnleashHelpers.cs b/src/isnd/Helpers/UnleashHelpers.cs index 26af48f..d107bff 100644 --- a/src/isnd/Helpers/UnleashHelpers.cs +++ b/src/isnd/Helpers/UnleashHelpers.cs @@ -10,7 +10,7 @@ namespace isnd.Helpers { public static class UnleashHelpers { - + public static IUnleash CreateUnleahClient(this IHostingEnvironment env, UnleashClientSettings unleashClientSettings) { diff --git a/src/isnd/Interfaces/IPackageManager.cs b/src/isnd/Interfaces/IPackageManager.cs index 8a8249c..ab30b95 100644 --- a/src/isnd/Interfaces/IPackageManager.cs +++ b/src/isnd/Interfaces/IPackageManager.cs @@ -15,14 +15,16 @@ namespace isnd.Interfaces { public interface IPackageManager { + string CatalogBaseUrl { get; } AutoCompleteResult AutoComplete(string pkgid, int skip, int take, bool prerelease = false, string packageType = null); CatalogIndex GetCatalogIndex(); string[] GetVersions(string pkgid, NuGetVersion parsedVersion, bool prerelease = false, string packageType = null, int skip = 0, int take = 25); - PackageRegistrationIndexViewModel SearchByName(string query, int skip, int take, bool prerelease = false, string packageType = null); + RegistrationPageIndex SearchByName(string query, int skip, int take, bool prerelease = false, string packageType = null); IEnumerable GetResources(IUnleash unleashĈlient); void ÛpdateCatalogFor(Commit commit); Task DeletePackageAsync(string pkgid, string version, string type); + Task UserAskForPackageDeletionAsync(string uid, string id, string lower, string type); Task GetPackageAsync(string pkgid, string version, string type); IEnumerable GetCatalogLeaf(string id, string version, string lower); } diff --git a/src/isnd/Services/EmailSender.cs b/src/isnd/Services/EmailSender.cs index c5cbe23..238afda 100644 --- a/src/isnd/Services/EmailSender.cs +++ b/src/isnd/Services/EmailSender.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Identity.UI.Services; using Microsoft.Extensions.Options; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Hosting; using MailKit.Net.Smtp; using MimeKit; @@ -16,13 +15,13 @@ namespace isnd.Services public class EmailSender : IEmailSender, IMailer { public EmailSender(IOptions smtpSettings, - Microsoft.AspNetCore.Hosting.IHostingEnvironment env) + IHostingEnvironment env) { Options = smtpSettings.Value; Env = env; } public SmtpSettings Options { get; } //set only via Secret Manager - public Microsoft.AspNetCore.Hosting.IHostingEnvironment Env { get; } + public IHostingEnvironment Env { get; } public Task SendEmailAsync(string email, string subject, string message) { return Execute(Options.SenderName, subject, message, email); diff --git a/src/isnd/Services/PackageManager.cs b/src/isnd/Services/PackageManager.cs index e276446..59bf859 100644 --- a/src/isnd/Services/PackageManager.cs +++ b/src/isnd/Services/PackageManager.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using isn.Abstract; -using isnd.Controllers; using isnd.Data; using isnd.Data.Catalog; using isnd.Data.Packages; @@ -119,16 +118,17 @@ namespace isnd.Services Type = "RegistrationsBaseUrl/3.6.0", Comment = "Base URL of storage where isn package registration info is stored in GZIP format. This base URL includes SemVer 2.0.0 packages." }); + return res; } - public PackageRegistrationIndexViewModel SearchByName(string query, + public RegistrationPageIndex SearchByName(string query, int skip, int take, bool prerelease = false, string packageType = null) { var scope = dbContext.Packages - .Include(p=>p.Versions) + .Include(p => p.Versions) .Include(p => p.Owner) .Where( p => (PackageIdHelpers.CamelCaseMatch(p.Id, query) || PackageIdHelpers.SeparatedByMinusMatch(p.Id, query)) @@ -137,12 +137,11 @@ namespace isnd.Services ); var total = scope.Count(); var pkgs = scope.Skip(skip).Take(take).ToArray(); - - return new PackageRegistrationIndexViewModel + string bid = $"{extUrl}v3.4.0/{ApiConfig.Registration}/"; + var leaves = pkgs.Select(p => p.ToLeave(bid)); + return new RegistrationPageIndex { - Query = query, - TotalHits = total, - Data = pkgs.Select(p => p.ToLeave()).ToArray() + Items = leaves.CreateRegistrationPages(bid) }; } @@ -187,6 +186,9 @@ namespace isnd.Services public static CatalogIndex CurrentCatalogIndex { get; protected set; } public static List CurrentCatalogPages { get; protected set; } + + public string CatalogBaseUrl => extUrl; + private IsndSettings isndSettings; private string extUrl; @@ -320,7 +322,7 @@ namespace isnd.Services v.Type == type ); } - + public IEnumerable GetCatalogLeaf(string id, string version, string lower) { return dbContext.PackageVersions @@ -329,5 +331,18 @@ namespace isnd.Services .Where(v => v.PackageId == id && v.FullString == version && (lower == null || lower == v.Type)); } + + + + public async Task UserAskForPackageDeletionAsync(string uid, string id, string lower, string type) + { + PackageVersion packageVersion = await dbContext.PackageVersions + .Include(pv => pv.Package) + .FirstOrDefaultAsync(m => m.PackageId == id + && m.FullString == lower && m.Type == type); + if (packageVersion == null) return null; + if (packageVersion.Package.OwnerId != uid) return null; + return new PackageDeletionReport { Deleted = true, DeletedVersion = packageVersion }; + } } } \ No newline at end of file diff --git a/src/isnd/Startup.cs b/src/isnd/Startup.cs index af856bb..7a4189c 100644 --- a/src/isnd/Startup.cs +++ b/src/isnd/Startup.cs @@ -1,11 +1,8 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.UI.Services; -using Microsoft.Extensions.Hosting; using isnd.Data; using isnd.Interfaces; using isnd.Services; @@ -17,8 +14,8 @@ using Unleash; using Microsoft.Extensions.Options; using isnd.Helpers; using Microsoft.IdentityModel.Tokens; -using Microsoft.AspNetCore.HttpOverrides; -using System.Net; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; namespace isnd { @@ -86,7 +83,7 @@ namespace isnd throw new System.Exception("No unleash client ApiUrl"); if (config.Value.ClientApiKey==null) throw new System.Exception("No unleash client ClientApiKey"); - return s.GetRequiredService().CreateUnleahClient(config.Value); + return s.GetRequiredService().CreateUnleahClient(config.Value); }); services.AddAuthentication("Bearer") @@ -106,25 +103,27 @@ namespace isnd // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, - Microsoft.AspNetCore.Hosting.IHostingEnvironment env, + IHostingEnvironment env, ApplicationDbContext dbContext) { - app.UseForwardedHeaders(); - // Not using Apache cert : - // app.UseHttpsRedirection(); + // app.UseForwardedHeaders(); + // app.UseDeveloperExceptionPage(); + // app.UseHttpsRedirection(); if (env.IsDevelopment()) { + app.UseDeveloperExceptionPage(); app.UseMigrationsEndPoint(); - app.UseBrowserLink(); + } else { app.UseExceptionHandler("/Home/Error"); dbContext.Database.Migrate(); } - app + + _ = app .UseStaticFiles() .UseAuthentication() .UseMvc(routes => diff --git a/src/isnd/Entities/CatalogRegistration.cs b/src/isnd/ViewModels/CatalogRegistration.cs similarity index 97% rename from src/isnd/Entities/CatalogRegistration.cs rename to src/isnd/ViewModels/CatalogRegistration.cs index 3985e10..240b456 100644 --- a/src/isnd/Entities/CatalogRegistration.cs +++ b/src/isnd/ViewModels/CatalogRegistration.cs @@ -1,7 +1,7 @@ using System; using Newtonsoft.Json; -namespace isnd.Controllers +namespace isnd.ViewModels { public class CatalogRegistration { diff --git a/src/isnd/ViewModels/PackageRegistrationViewModel.cs b/src/isnd/ViewModels/RegistrationLeaf.cs similarity index 100% rename from src/isnd/ViewModels/PackageRegistrationViewModel.cs rename to src/isnd/ViewModels/RegistrationLeaf.cs diff --git a/src/isnd/Views/Home/Index.cshtml b/src/isnd/Views/Home/Index.cshtml index b46d584..d9b0cbe 100644 --- a/src/isnd/Views/Home/Index.cshtml +++ b/src/isnd/Views/Home/Index.cshtml @@ -4,9 +4,6 @@ }

Bienvenue

-

- - Bienvenue dans isnd -

+

Bienvenue dans isn

@Model.PkgCount identifiant(s) de paquet dans le SI
diff --git a/src/isnd/Views/PackageVersion/Index.cshtml b/src/isnd/Views/PackageVersion/Index.cshtml index 7e90861..b2457d7 100644 --- a/src/isnd/Views/PackageVersion/Index.cshtml +++ b/src/isnd/Views/PackageVersion/Index.cshtml @@ -28,7 +28,7 @@ - @Html.DisplayNameFor(model => model.Versions[0].Package.Id) + @Html.DisplayNameFor(model => model.Versions[0].PackageId) @Html.DisplayNameFor(model => model.Versions[0].FullString) diff --git a/src/isnd/Views/Packages/Index.cshtml b/src/isnd/Views/Packages/Index.cshtml index ee1536d..ae6ced1 100644 --- a/src/isnd/Views/Packages/Index.cshtml +++ b/src/isnd/Views/Packages/Index.cshtml @@ -1,4 +1,4 @@ -@model PackageRegistrationIndexViewModel +@model PackageRegistrationIndexQuery @{ ViewData["Title"] = "Index"; @@ -25,16 +25,17 @@ - @Html.DisplayNameFor(model => model.Data[0].Id) + @Html.DisplayNameFor(model => model.Items[0].Items[0].Id) - @Html.DisplayNameFor(model => model.Data[0].Entry.Description) + @Html.DisplayNameFor(model => model.Items[0].Items[0].Entry.Description) -@foreach (var item in Model.Data) { +@foreach (var page in Model.Items) { +@foreach (var item in page.Items) { @Html.DisplayFor(modelItem => item.Id) @@ -47,6 +48,6 @@ @Html.ActionLink("Details", "Details", new { pkgid = item.Id }) -} +}} diff --git a/src/isnd/Views/Shared/_Layout.cshtml b/src/isnd/Views/Shared/_Layout.cshtml index 7f58efa..925f9ae 100644 --- a/src/isnd/Views/Shared/_Layout.cshtml +++ b/src/isnd/Views/Shared/_Layout.cshtml @@ -3,7 +3,7 @@ - @ViewData["Title"] - isnd + @ViewData["Title"] - isn @@ -12,7 +12,7 @@