REORG+histo
This commit is contained in:
@ -2,13 +2,18 @@ namespace isnd
|
||||
{
|
||||
public static class ApiConfig
|
||||
{
|
||||
public const string BaseApiPath = "/";
|
||||
|
||||
public const string Publish = "put";
|
||||
public const string Base = "index.json";
|
||||
public const string Catalog = "catalog";
|
||||
public const string CatalogPage = "catalog-page";
|
||||
public const string Get = "get";
|
||||
public const string Search = "search";
|
||||
public const string AutoComplete = "autocomplete";
|
||||
public const string CatalogLeaf = "catalog-leaf";
|
||||
public const string CatalogPackageDetail = "package-detail";
|
||||
|
||||
public const string Delete = "delete";
|
||||
|
||||
}
|
||||
}
|
@ -6,11 +6,13 @@ using isnd.Data;
|
||||
namespace isnd.Controllers
|
||||
{
|
||||
|
||||
// TODO Web hook CI
|
||||
public class NewUpdateController : Controller
|
||||
{
|
||||
[Authorize(Policy = Constants.RequireAdminPolicyName)]
|
||||
public IActionResult NewRelease(NewReleaseInfo version)
|
||||
{
|
||||
throw new NotImplementedException("web hook");
|
||||
return View(version);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using isnd.Data;
|
||||
using isnd.ViewModels;
|
||||
|
||||
using isnd.Helpers;
|
||||
namespace isnd
|
||||
{
|
||||
[AllowAnonymous]
|
||||
@ -78,16 +78,11 @@ namespace isnd
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
if (!IsOwner(packageVersion)) return Unauthorized();
|
||||
if (!User.IsOwner(packageVersion)) return Unauthorized();
|
||||
|
||||
return View(packageVersion);
|
||||
}
|
||||
|
||||
bool IsOwner(PackageVersion v)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return v.Package.OwnerId == userId;
|
||||
}
|
||||
|
||||
// POST: PackageVersion/Delete/5
|
||||
[HttpPost, ActionName("Delete")]
|
||||
@ -97,7 +92,7 @@ namespace isnd
|
||||
var packageVersion = await _context.PackageVersions.Include(p => p.Package)
|
||||
.FirstOrDefaultAsync(m => m.PackageId == PackageId && m.FullString == FullString);
|
||||
if (packageVersion == null) return NotFound();
|
||||
if (!IsOwner(packageVersion)) return Unauthorized();
|
||||
if (!User.IsOwner(packageVersion)) return Unauthorized();
|
||||
|
||||
_context.PackageVersions.Remove(packageVersion);
|
||||
await _context.SaveChangesAsync();
|
||||
|
62
src/isnd/Controllers/PackagesController.Catalog.cs
Normal file
62
src/isnd/Controllers/PackagesController.Catalog.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using isnd.Data.Catalog;
|
||||
using isnd.Helpers;
|
||||
using isnd.Services;
|
||||
using isnd.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
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()
|
||||
{
|
||||
return Ok(PackageManager.CurrentCatalogIndex);
|
||||
}
|
||||
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.CatalogPage + "-{id}")]
|
||||
public IActionResult Index(string id)
|
||||
{
|
||||
// https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning
|
||||
return Ok(PackageManager.CurrentCatalogPages[int.Parse(id)]);
|
||||
}
|
||||
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.CatalogLeaf + "/{id}/{*lower}")]
|
||||
public async Task<IActionResult> CatalogLeafAsync(string id, string lower)
|
||||
{
|
||||
string pkgType = ParamHelpers.Optional(ref lower);
|
||||
var pkgVersion = await _dbContext.PackageVersions
|
||||
.Include(v => v.LatestCommit)
|
||||
.Include(v => v.Package)
|
||||
.SingleOrDefaultAsync(
|
||||
v => v.PackageId == id &&
|
||||
v.FullString == lower &&
|
||||
v.Type == pkgType
|
||||
);
|
||||
if (pkgVersion == null) return NotFound();
|
||||
|
||||
var pub = await _dbContext.Commits
|
||||
.Include(c => c.Versions)
|
||||
.OrderBy(c => c.CommitTimeStamp)
|
||||
.SingleOrDefaultAsync
|
||||
(
|
||||
c => c.Action == PackageAction.PublishPackage
|
||||
&& c.Versions.Contains(pkgVersion)
|
||||
);
|
||||
return Ok(new CatalogLeaf
|
||||
{
|
||||
CommitId = id,
|
||||
Id = pkgVersion.PackageId,
|
||||
CommitTimeStamp = pkgVersion.LatestCommit.CommitTimeStamp
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
36
src/isnd/Controllers/PackagesController.Delete.cs
Normal file
36
src/isnd/Controllers/PackagesController.Delete.cs
Normal file
@ -0,0 +1,36 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NuGet.Packaging.Core;
|
||||
using NuGet.Versioning;
|
||||
using isnd.Data;
|
||||
using isnd.Helpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using isnd.Data.Catalog;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace isnd.Controllers
|
||||
{
|
||||
|
||||
public partial class PackagesController
|
||||
{
|
||||
|
||||
[HttpDelete(_pkgRootPrefix + ApiConfig.Delete + "/{id}/{*lower}")]
|
||||
public async Task<IActionResult> Delete(
|
||||
[FromRoute][SafeName][Required] string id,
|
||||
[FromRoute][SafeName][Required] string lower)
|
||||
{
|
||||
string pkgtype = ParamHelpers.Optional(ref lower);
|
||||
var report = await _packageManager.DeletePackageAsync(id, lower, pkgtype);
|
||||
return Ok(report);
|
||||
}
|
||||
}
|
||||
}
|
58
src/isnd/Controllers/PackagesController.Files.cs
Normal file
58
src/isnd/Controllers/PackagesController.Files.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using isnd.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace isnd.Controllers
|
||||
{
|
||||
|
||||
public partial class PackagesController
|
||||
{
|
||||
// TODO GET GET {@id}/{LOWER_ID}/{LOWER_VERSION}/{LOWER_ID}.{LOWER_VERSION}.nupkg
|
||||
// LOWER_ID URL string yes The package ID, lowercase
|
||||
// LOWER_VERSION URL string yes The package version, normalized and lowercased
|
||||
// response 200 : the package
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/{idf}-{lowerf}.nupkg")]
|
||||
public IActionResult GetPackage(
|
||||
[FromRoute][SafeName][Required] string id,
|
||||
[FromRoute][SafeName][Required] string lower,
|
||||
[FromRoute] string idf, [FromRoute] string lowerf)
|
||||
{
|
||||
var pkgpath = Path.Combine(_isndSettings.PackagesRootDir,
|
||||
id, lower, $"{id}-{lower}.nupkg"
|
||||
);
|
||||
|
||||
FileInfo pkgfi = new FileInfo(pkgpath);
|
||||
|
||||
if (!pkgfi.Exists)
|
||||
{
|
||||
return BadRequest("!pkgfi.Exists");
|
||||
}
|
||||
return File(pkgfi.OpenRead(), "application/zip; charset=binary");
|
||||
}
|
||||
|
||||
// TODO GET {@id}/{LOWER_ID}/{LOWER_VERSION}/{LOWER_ID}.nuspec
|
||||
// response 200 : the nuspec
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/{idf}-{lowerf}.nuspec")]
|
||||
public IActionResult GetNuspec(
|
||||
[FromRoute][SafeName][Required] string id,
|
||||
[FromRoute][SafeName][Required] string lower,
|
||||
[FromRoute][SafeName][Required] string idf,
|
||||
[FromRoute][SafeName][Required] string lowerf)
|
||||
{
|
||||
var pkgpath = Path.Combine(_isndSettings.PackagesRootDir,
|
||||
id, lower, $"{id}.nuspec");
|
||||
|
||||
FileInfo pkgfi = new FileInfo(pkgpath);
|
||||
if (!pkgfi.Exists)
|
||||
{
|
||||
return BadRequest("!pkgfi.Exists");
|
||||
}
|
||||
|
||||
return File(pkgfi.OpenRead(), "text/xml; charset=utf-8");
|
||||
}
|
||||
}
|
||||
}
|
@ -142,6 +142,7 @@ namespace isnd.Controllers
|
||||
foreach (var v in pkgvers.ToArray())
|
||||
_dbContext.PackageVersions.Remove(v);
|
||||
}
|
||||
// FIXME default type or null
|
||||
if (types==null || types.Count==0)
|
||||
_dbContext.PackageVersions.Add
|
||||
(new PackageVersion{
|
||||
@ -152,7 +153,7 @@ namespace isnd.Controllers
|
||||
Patch = version.Patch,
|
||||
IsPrerelease = version.IsPrerelease,
|
||||
FullString = version.ToFullString(),
|
||||
Type = "<null-type>",
|
||||
Type = null,
|
||||
LatestCommit = commit
|
||||
});
|
||||
else
|
||||
|
54
src/isnd/Controllers/PackagesController.Views.cs
Normal file
54
src/isnd/Controllers/PackagesController.Views.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using isnd.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace isnd.Controllers
|
||||
{
|
||||
|
||||
public partial class PackagesController
|
||||
{
|
||||
|
||||
// GET: PackageVersion
|
||||
public async Task<IActionResult> Index(PackageIndexViewModel model)
|
||||
{
|
||||
var applicationDbContext = _dbContext.Packages.Include(p => p.Versions).Where(
|
||||
p => ( model.Prerelease || p.Versions.Any(v => !v.IsPrerelease))
|
||||
&& ((model.query == null) || p.Id.StartsWith(model.query)));
|
||||
model.data = await applicationDbContext.ToArrayAsync();
|
||||
return View(model);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Details(string pkgid)
|
||||
{
|
||||
if (pkgid == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var packageVersion = _dbContext.PackageVersions
|
||||
.Include(p => p.Package)
|
||||
.Where(m => m.PackageId == pkgid)
|
||||
.OrderByDescending(p => p)
|
||||
;
|
||||
|
||||
if (packageVersion == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
bool results = await packageVersion.AnyAsync();
|
||||
var latest = await packageVersion.FirstAsync();
|
||||
|
||||
return View("Details", new PackageDetailViewModel
|
||||
{
|
||||
latest = latest,
|
||||
pkgid = pkgid,
|
||||
totalHits = packageVersion.Count(),
|
||||
data = packageVersion.Take(10).ToArray()
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -18,7 +18,6 @@ using isnd.Interfaces;
|
||||
|
||||
namespace isnd.Controllers
|
||||
{
|
||||
|
||||
[AllowAnonymous]
|
||||
public partial class PackagesController : Controller
|
||||
{
|
||||
@ -33,6 +32,7 @@ namespace isnd.Controllers
|
||||
readonly ApplicationDbContext _dbContext;
|
||||
private readonly IPackageManager _packageManager;
|
||||
private readonly IUnleash _unleashĈlient;
|
||||
const string _pkgRootPrefix = "~/";
|
||||
|
||||
public PackagesController(
|
||||
ILoggerFactory loggerFactory,
|
||||
@ -51,72 +51,12 @@ namespace isnd.Controllers
|
||||
_ressources = _packageManager.GetResources(_unleashĈlient).ToArray();
|
||||
}
|
||||
|
||||
// dotnet add . package -s http://localhost:5000/packages isn
|
||||
// packages/FindPackagesById()?id='isn'&semVerLevel=2.0.0
|
||||
|
||||
// Search
|
||||
// GET {@id}?q={QUERY}&skip={SKIP}&take={TAKE}&prerelease={PRERELEASE}&semVerLevel={SEMVERLEVEL}&packageType={PACKAGETYPE}
|
||||
|
||||
|
||||
// GET: PackageVersion
|
||||
public async Task<IActionResult> Index(PackageIndexViewModel model)
|
||||
{
|
||||
var applicationDbContext = _dbContext.Packages.Include(p => p.Versions).Where(
|
||||
p => ( model.Prerelease || p.Versions.Any(v => !v.IsPrerelease))
|
||||
&& ((model.query == null) || p.Id.StartsWith(model.query)));
|
||||
model.data = await applicationDbContext.ToArrayAsync();
|
||||
return View(model);
|
||||
}
|
||||
|
||||
// GET: PackageVersion/Details/5
|
||||
public async Task<IActionResult> Details(string pkgid)
|
||||
{
|
||||
if (pkgid == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var packageVersion = _dbContext.PackageVersions
|
||||
.Include(p => p.Package)
|
||||
.Where(m => m.PackageId == pkgid)
|
||||
.OrderByDescending(p => p)
|
||||
;
|
||||
|
||||
if (packageVersion == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
bool results = await packageVersion.AnyAsync();
|
||||
var latest = await packageVersion.FirstAsync();
|
||||
|
||||
return View("Details", new PackageDetailViewModel { latest = latest, pkgid = pkgid, totalHits = packageVersion.Count(), data = packageVersion.Take(10).ToArray() } );
|
||||
|
||||
}
|
||||
|
||||
const string _pkgRootPrefix = "~/" + ApiConfig.BaseApiPath ;
|
||||
|
||||
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.Base)]
|
||||
public IActionResult ApiIndex()
|
||||
{
|
||||
return Ok(_ressources);
|
||||
}
|
||||
|
||||
//
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.Catalog)]
|
||||
public IActionResult CatalogIndex()
|
||||
{
|
||||
// https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning
|
||||
return Ok(PackageManager.CurrentCatalogIndex);
|
||||
}
|
||||
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.Catalog + "-{id}")]
|
||||
public IActionResult Index(string id)
|
||||
{
|
||||
// https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning
|
||||
return Ok(PackageManager.CurrentCatalogPages[int.Parse(id)]);
|
||||
}
|
||||
|
||||
// GET /autocomplete?id=isn.protocol&prerelease=true
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.AutoComplete)]
|
||||
public IActionResult AutoComplete(
|
||||
@ -170,48 +110,5 @@ namespace isnd.Controllers
|
||||
id, parsedVersion, prerelease, packageType, skip, take)
|
||||
});
|
||||
}
|
||||
|
||||
// TODO GET GET {@id}/{LOWER_ID}/{LOWER_VERSION}/{LOWER_ID}.{LOWER_VERSION}.nupkg
|
||||
// LOWER_ID URL string yes The package ID, lowercase
|
||||
// LOWER_VERSION URL string yes The package version, normalized and lowercased
|
||||
// response 200 : the package
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/{idf}-{lowerf}.nupkg")]
|
||||
public IActionResult GetPackage(
|
||||
[FromRoute] string id, [FromRoute] string lower,
|
||||
[FromRoute] string idf, [FromRoute] string lowerf)
|
||||
{
|
||||
var pkgpath = Path.Combine(_isndSettings.PackagesRootDir,
|
||||
id, lower, $"{id}-{lower}.nupkg"
|
||||
);
|
||||
|
||||
FileInfo pkgfi = new FileInfo(pkgpath);
|
||||
|
||||
if (!pkgfi.Exists)
|
||||
{
|
||||
return BadRequest("!pkgfi.Exists");
|
||||
}
|
||||
return File(pkgfi.OpenRead(), "application/zip; charset=binary");
|
||||
}
|
||||
|
||||
// TODO GET {@id}/{LOWER_ID}/{LOWER_VERSION}/{LOWER_ID}.nuspec
|
||||
// response 200 : the nuspec
|
||||
[HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/{idf}-{lowerf}.nuspec")]
|
||||
public IActionResult GetNuspec(
|
||||
[FromRoute][SafeName][Required] string id,
|
||||
[FromRoute][SafeName][Required] string lower,
|
||||
[FromRoute][SafeName][Required] string idf,
|
||||
[FromRoute][SafeName][Required] string lowerf)
|
||||
{
|
||||
var pkgpath = Path.Combine(_isndSettings.PackagesRootDir,
|
||||
id, lower, $"{id}.nuspec");
|
||||
|
||||
FileInfo pkgfi = new FileInfo(pkgpath);
|
||||
if (!pkgfi.Exists)
|
||||
{
|
||||
return BadRequest("!pkgfi.Exists");
|
||||
}
|
||||
|
||||
return File(pkgfi.OpenRead(), "text/xml; charset=utf-8");
|
||||
}
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using isnd.Data;
|
||||
using isnd.Data.ApiKeys;
|
||||
using isnd.Data.Catalog;
|
||||
using isnd.Data.Historic;
|
||||
|
||||
namespace isnd.Data
|
||||
{
|
||||
@ -25,10 +26,15 @@ namespace isnd.Data
|
||||
v.FullString,
|
||||
v.Type
|
||||
});
|
||||
modelBuilder.Entity<PackageVersionCommit>().HasKey
|
||||
(c => new { c.CommitId, c.PackageId, c.FullString, c.PackageType });
|
||||
|
||||
}
|
||||
public DbSet<ApiKey> ApiKeys { get; set; }
|
||||
public DbSet<Package> Packages { get; set; }
|
||||
public DbSet<PackageVersion> PackageVersions { get; set; }
|
||||
public DbSet<Commit> Commits { get; set; }
|
||||
|
||||
public DbSet<PackageVersionCommit> PackageVersionCommmit { get; set; }
|
||||
}
|
||||
}
|
||||
|
29
src/isnd/Data/Catalog/CatalogLeaf.cs
Normal file
29
src/isnd/Data/Catalog/CatalogLeaf.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace isnd.Data.Catalog
|
||||
{
|
||||
public class CatalogLeaf : IObject
|
||||
{
|
||||
|
||||
[JsonProperty("@type")]
|
||||
public List<string> RefType { get; set; }
|
||||
|
||||
[JsonProperty("commitId")]
|
||||
public string CommitId { get; set; }
|
||||
|
||||
[JsonProperty("commitTimeStamp")]
|
||||
public DateTime CommitTimeStamp { get; set; }
|
||||
|
||||
[JsonProperty("published")]
|
||||
public DateTime Published { get; set; }
|
||||
|
||||
[JsonProperty("id")]
|
||||
public string Id { get; set; }
|
||||
|
||||
[JsonProperty("version")]
|
||||
public string Version { get; set; }
|
||||
|
||||
}
|
||||
}
|
7
src/isnd/Data/Catalog/PackageDetail.cs
Normal file
7
src/isnd/Data/Catalog/PackageDetail.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace isnd.Data.Catalog
|
||||
{
|
||||
public class PackageDetail : CatalogLeaf
|
||||
{
|
||||
|
||||
}
|
||||
}
|
30
src/isnd/Data/Historic/PackageVersionCommit.cs
Normal file
30
src/isnd/Data/Historic/PackageVersionCommit.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using isnd.Data.Catalog;
|
||||
|
||||
namespace isnd.Data.Historic
|
||||
{
|
||||
public class PackageVersionCommit
|
||||
{
|
||||
public long CommitId { get; set; }
|
||||
|
||||
[StringLength(1024)]
|
||||
public string PackageId { get; set; }
|
||||
|
||||
[StringLength(256)]
|
||||
public string FullString { get; set; }
|
||||
|
||||
[StringLength(256)]
|
||||
|
||||
public string PackageType { get; set; }
|
||||
|
||||
[ForeignKey("CommitId")]
|
||||
public virtual Commit Commit { get; set; }
|
||||
|
||||
[ForeignKey("PackageId")]
|
||||
public virtual Package Package { get; set; }
|
||||
|
||||
[ForeignKey("PackageId,FullString,PackageType")]
|
||||
public virtual PackageVersion PackageVersion { get; set; }
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ namespace isnd.Data
|
||||
public class Package : IObject
|
||||
{
|
||||
[Key][Required]
|
||||
[StringLength(1024)]
|
||||
public string Id { get; set; }
|
||||
|
||||
[Required]
|
||||
|
@ -9,6 +9,7 @@ namespace isnd.Data
|
||||
{
|
||||
[Required]
|
||||
[ForeignKey("Package")]
|
||||
[StringLength(1024)]
|
||||
public string PackageId { get; set; }
|
||||
|
||||
[Required]
|
||||
|
@ -12,7 +12,5 @@ namespace isnd.Entities
|
||||
public int MaxUserKeyCount {get; set;}
|
||||
public int CatalogPageLen {get; set;}
|
||||
public TimeSpan DisplayDeletionLen {get; set;}
|
||||
|
||||
|
||||
}
|
||||
}
|
33
src/isnd/Helpers/PackageIdHelpers.cs
Normal file
33
src/isnd/Helpers/PackageIdHelpers.cs
Normal file
@ -0,0 +1,33 @@
|
||||
namespace isnd.Helpers
|
||||
{
|
||||
public static class PackageIdHelpers
|
||||
{
|
||||
|
||||
internal static bool SeparatedByMinusMatch(string id, string q)
|
||||
{
|
||||
foreach (var part in id.Split('-'))
|
||||
{
|
||||
if (part.StartsWith(q, System.StringComparison.OrdinalIgnoreCase)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
internal static bool CamelCaseMatch(string id, string query)
|
||||
{
|
||||
// Assert.False (q==null);
|
||||
if (string.IsNullOrEmpty(query)) return true;
|
||||
|
||||
while (id.Length > 0)
|
||||
{
|
||||
int i = 0;
|
||||
while (id.Length > i && char.IsLower(id[i])) i++;
|
||||
if (i == 0) break;
|
||||
id = id.Substring(i);
|
||||
if (id.StartsWith(query, System.StringComparison.OrdinalIgnoreCase)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
15
src/isnd/Helpers/PackageVersionHelpers.cs
Normal file
15
src/isnd/Helpers/PackageVersionHelpers.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.Security.Claims;
|
||||
using isnd.Data;
|
||||
|
||||
namespace isnd.Helpers
|
||||
{
|
||||
public static class PackageVersionHelpers
|
||||
{
|
||||
|
||||
public static bool IsOwner(this ClaimsPrincipal user, PackageVersion v)
|
||||
{
|
||||
var userId = user.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return v.Package.OwnerId == userId;
|
||||
}
|
||||
}
|
||||
}
|
16
src/isnd/Helpers/ParamHelpers.cs
Normal file
16
src/isnd/Helpers/ParamHelpers.cs
Normal file
@ -0,0 +1,16 @@
|
||||
namespace isnd.Helpers
|
||||
{
|
||||
public static class ParamHelpers
|
||||
{
|
||||
public static string Optional(ref string prm)
|
||||
{
|
||||
int sopt = prm.IndexOf('/');
|
||||
if (sopt>0)
|
||||
{
|
||||
prm = prm.Substring(0,sopt);
|
||||
return prm.Substring(sopt + 1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using isnd.Controllers;
|
||||
using isnd.Data.Catalog;
|
||||
using isnd.Services;
|
||||
@ -17,6 +18,7 @@ namespace isnd.Interfaces
|
||||
PackageIndexViewModel SearchByName(string query, int skip, int take, bool prerelease = false, string packageType = null);
|
||||
IEnumerable<Resource> GetResources(IUnleash unleashĈlient);
|
||||
void ÛpdateCatalogFor(Commit commit);
|
||||
Task<PackageDeletionReport> DeletePackageAsync(string pkgId, string fullVersion, string pkgType);
|
||||
}
|
||||
|
||||
}
|
392
src/isnd/Migrations/20210905144343_pkgVerCom.Designer.cs
generated
Normal file
392
src/isnd/Migrations/20210905144343_pkgVerCom.Designer.cs
generated
Normal file
@ -0,0 +1,392 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using isnd.Data;
|
||||
|
||||
namespace isndhost.Migrations
|
||||
{
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
[Migration("20210905144343_pkgVerCom")]
|
||||
partial class pkgVerCom
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
|
||||
.HasAnnotation("ProductVersion", "2.2.6-servicing-10079")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken();
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(256);
|
||||
|
||||
b.Property<string>("NormalizedName")
|
||||
.HasMaxLength(256);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NormalizedName")
|
||||
.IsUnique()
|
||||
.HasName("RoleNameIndex");
|
||||
|
||||
b.ToTable("AspNetRoles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("ClaimType");
|
||||
|
||||
b.Property<string>("ClaimValue");
|
||||
|
||||
b.Property<string>("RoleId")
|
||||
.IsRequired();
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("AspNetRoleClaims");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("ClaimType");
|
||||
|
||||
b.Property<string>("ClaimValue");
|
||||
|
||||
b.Property<string>("UserId")
|
||||
.IsRequired();
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("AspNetUserClaims");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
|
||||
{
|
||||
b.Property<string>("LoginProvider");
|
||||
|
||||
b.Property<string>("ProviderKey");
|
||||
|
||||
b.Property<string>("ProviderDisplayName");
|
||||
|
||||
b.Property<string>("UserId")
|
||||
.IsRequired();
|
||||
|
||||
b.HasKey("LoginProvider", "ProviderKey");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("AspNetUserLogins");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
|
||||
{
|
||||
b.Property<string>("UserId");
|
||||
|
||||
b.Property<string>("RoleId");
|
||||
|
||||
b.HasKey("UserId", "RoleId");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("AspNetUserRoles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||
{
|
||||
b.Property<string>("UserId");
|
||||
|
||||
b.Property<string>("LoginProvider");
|
||||
|
||||
b.Property<string>("Name");
|
||||
|
||||
b.Property<string>("Value");
|
||||
|
||||
b.HasKey("UserId", "LoginProvider", "Name");
|
||||
|
||||
b.ToTable("AspNetUserTokens");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("isnd.Data.ApiKeys.ApiKey", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<DateTime>("CreationDate");
|
||||
|
||||
b.Property<string>("Name");
|
||||
|
||||
b.Property<string>("UserId")
|
||||
.IsRequired();
|
||||
|
||||
b.Property<int>("ValidityPeriodInDays");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("ApiKeys");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("isnd.Data.ApplicationUser", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int>("AccessFailedCount");
|
||||
|
||||
b.Property<string>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken();
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasMaxLength(256);
|
||||
|
||||
b.Property<bool>("EmailConfirmed");
|
||||
|
||||
b.Property<string>("FullName");
|
||||
|
||||
b.Property<bool>("LockoutEnabled");
|
||||
|
||||
b.Property<DateTimeOffset?>("LockoutEnd");
|
||||
|
||||
b.Property<string>("NormalizedEmail")
|
||||
.HasMaxLength(256);
|
||||
|
||||
b.Property<string>("NormalizedUserName")
|
||||
.HasMaxLength(256);
|
||||
|
||||
b.Property<string>("PasswordHash");
|
||||
|
||||
b.Property<string>("PhoneNumber");
|
||||
|
||||
b.Property<bool>("PhoneNumberConfirmed");
|
||||
|
||||
b.Property<string>("SecurityStamp");
|
||||
|
||||
b.Property<bool>("TwoFactorEnabled");
|
||||
|
||||
b.Property<string>("UserName")
|
||||
.HasMaxLength(256);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NormalizedEmail")
|
||||
.HasName("EmailIndex");
|
||||
|
||||
b.HasIndex("NormalizedUserName")
|
||||
.IsUnique()
|
||||
.HasName("UserNameIndex");
|
||||
|
||||
b.ToTable("AspNetUsers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("isnd.Data.Catalog.Commit", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int>("Action");
|
||||
|
||||
b.Property<DateTime>("TimeStamp");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Commits");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("isnd.Data.Historic.PackageVersionCommit", b =>
|
||||
{
|
||||
b.Property<long>("CommitId");
|
||||
|
||||
b.Property<string>("PackageId")
|
||||
.HasMaxLength(1024);
|
||||
|
||||
b.Property<string>("FullString")
|
||||
.HasMaxLength(256);
|
||||
|
||||
b.Property<string>("PackageType")
|
||||
.HasMaxLength(256);
|
||||
|
||||
b.HasKey("CommitId", "PackageId", "FullString", "PackageType");
|
||||
|
||||
b.HasIndex("PackageId", "FullString", "PackageType");
|
||||
|
||||
b.ToTable("PackageVersionCommmit");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("isnd.Data.Package", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(1024);
|
||||
|
||||
b.Property<long>("CommitNId");
|
||||
|
||||
b.Property<DateTime>("CommitTimeStamp");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(1024);
|
||||
|
||||
b.Property<string>("OwnerId")
|
||||
.IsRequired();
|
||||
|
||||
b.Property<bool>("Public");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CommitNId");
|
||||
|
||||
b.HasIndex("OwnerId");
|
||||
|
||||
b.ToTable("Packages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("isnd.Data.PackageVersion", b =>
|
||||
{
|
||||
b.Property<string>("PackageId")
|
||||
.HasMaxLength(1024);
|
||||
|
||||
b.Property<string>("FullString")
|
||||
.HasMaxLength(256);
|
||||
|
||||
b.Property<string>("Type")
|
||||
.HasMaxLength(256);
|
||||
|
||||
b.Property<long>("CommitNId");
|
||||
|
||||
b.Property<bool>("IsPrerelease");
|
||||
|
||||
b.Property<int>("Major");
|
||||
|
||||
b.Property<int>("Minor");
|
||||
|
||||
b.Property<int>("Patch");
|
||||
|
||||
b.HasKey("PackageId", "FullString", "Type");
|
||||
|
||||
b.HasIndex("CommitNId");
|
||||
|
||||
b.ToTable("PackageVersions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole")
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
|
||||
{
|
||||
b.HasOne("isnd.Data.ApplicationUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
|
||||
{
|
||||
b.HasOne("isnd.Data.ApplicationUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole")
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
b.HasOne("isnd.Data.ApplicationUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||
{
|
||||
b.HasOne("isnd.Data.ApplicationUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("isnd.Data.ApiKeys.ApiKey", b =>
|
||||
{
|
||||
b.HasOne("isnd.Data.ApplicationUser", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("isnd.Data.Historic.PackageVersionCommit", b =>
|
||||
{
|
||||
b.HasOne("isnd.Data.Catalog.Commit", "Commit")
|
||||
.WithMany()
|
||||
.HasForeignKey("CommitId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
b.HasOne("isnd.Data.Package", "Package")
|
||||
.WithMany()
|
||||
.HasForeignKey("PackageId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
b.HasOne("isnd.Data.PackageVersion", "PackageVersion")
|
||||
.WithMany()
|
||||
.HasForeignKey("PackageId", "FullString", "PackageType")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("isnd.Data.Package", b =>
|
||||
{
|
||||
b.HasOne("isnd.Data.Catalog.Commit", "LatestVersion")
|
||||
.WithMany()
|
||||
.HasForeignKey("CommitNId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
b.HasOne("isnd.Data.ApplicationUser", "Owner")
|
||||
.WithMany()
|
||||
.HasForeignKey("OwnerId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("isnd.Data.PackageVersion", b =>
|
||||
{
|
||||
b.HasOne("isnd.Data.Catalog.Commit", "LatestCommit")
|
||||
.WithMany("Versions")
|
||||
.HasForeignKey("CommitNId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
b.HasOne("isnd.Data.Package", "Package")
|
||||
.WithMany("Versions")
|
||||
.HasForeignKey("PackageId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
81
src/isnd/Migrations/20210905144343_pkgVerCom.cs
Normal file
81
src/isnd/Migrations/20210905144343_pkgVerCom.cs
Normal file
@ -0,0 +1,81 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace isndhost.Migrations
|
||||
{
|
||||
public partial class pkgVerCom : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "PackageId",
|
||||
table: "PackageVersions",
|
||||
maxLength: 1024,
|
||||
nullable: false,
|
||||
oldClrType: typeof(string));
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Id",
|
||||
table: "Packages",
|
||||
maxLength: 1024,
|
||||
nullable: false,
|
||||
oldClrType: typeof(string));
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PackageVersionCommmit",
|
||||
columns: table => new
|
||||
{
|
||||
CommitId = table.Column<long>(nullable: false),
|
||||
PackageId = table.Column<string>(maxLength: 1024, nullable: false),
|
||||
FullString = table.Column<string>(maxLength: 256, nullable: false),
|
||||
PackageType = table.Column<string>(maxLength: 256, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PackageVersionCommmit", x => new { x.CommitId, x.PackageId, x.FullString, x.PackageType });
|
||||
table.ForeignKey(
|
||||
name: "FK_PackageVersionCommmit_Commits_CommitId",
|
||||
column: x => x.CommitId,
|
||||
principalTable: "Commits",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_PackageVersionCommmit_Packages_PackageId",
|
||||
column: x => x.PackageId,
|
||||
principalTable: "Packages",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_PackageVersionCommmit_PackageVersions_PackageId_FullString_~",
|
||||
columns: x => new { x.PackageId, x.FullString, x.PackageType },
|
||||
principalTable: "PackageVersions",
|
||||
principalColumns: new[] { "PackageId", "FullString", "Type" },
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PackageVersionCommmit_PackageId_FullString_PackageType",
|
||||
table: "PackageVersionCommmit",
|
||||
columns: new[] { "PackageId", "FullString", "PackageType" });
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "PackageVersionCommmit");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "PackageId",
|
||||
table: "PackageVersions",
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldMaxLength: 1024);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Id",
|
||||
table: "Packages",
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldMaxLength: 1024);
|
||||
}
|
||||
}
|
||||
}
|
@ -213,10 +213,31 @@ namespace isndhost.Migrations
|
||||
b.ToTable("Commits");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("isnd.Data.Historic.PackageVersionCommit", b =>
|
||||
{
|
||||
b.Property<long>("CommitId");
|
||||
|
||||
b.Property<string>("PackageId")
|
||||
.HasMaxLength(1024);
|
||||
|
||||
b.Property<string>("FullString")
|
||||
.HasMaxLength(256);
|
||||
|
||||
b.Property<string>("PackageType")
|
||||
.HasMaxLength(256);
|
||||
|
||||
b.HasKey("CommitId", "PackageId", "FullString", "PackageType");
|
||||
|
||||
b.HasIndex("PackageId", "FullString", "PackageType");
|
||||
|
||||
b.ToTable("PackageVersionCommmit");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("isnd.Data.Package", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(1024);
|
||||
|
||||
b.Property<long>("CommitNId");
|
||||
|
||||
@ -241,7 +262,8 @@ namespace isndhost.Migrations
|
||||
|
||||
modelBuilder.Entity("isnd.Data.PackageVersion", b =>
|
||||
{
|
||||
b.Property<string>("PackageId");
|
||||
b.Property<string>("PackageId")
|
||||
.HasMaxLength(1024);
|
||||
|
||||
b.Property<string>("FullString")
|
||||
.HasMaxLength(256);
|
||||
@ -319,6 +341,24 @@ namespace isndhost.Migrations
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("isnd.Data.Historic.PackageVersionCommit", b =>
|
||||
{
|
||||
b.HasOne("isnd.Data.Catalog.Commit", "Commit")
|
||||
.WithMany()
|
||||
.HasForeignKey("CommitId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
b.HasOne("isnd.Data.Package", "Package")
|
||||
.WithMany()
|
||||
.HasForeignKey("PackageId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
b.HasOne("isnd.Data.PackageVersion", "PackageVersion")
|
||||
.WithMany()
|
||||
.HasForeignKey("PackageId", "FullString", "PackageType")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("isnd.Data.Package", b =>
|
||||
{
|
||||
b.HasOne("isnd.Data.Catalog.Commit", "LatestVersion")
|
||||
|
@ -1,9 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using isnd.Controllers;
|
||||
using isnd.Data;
|
||||
using isnd.Data.Catalog;
|
||||
using isnd.Entities;
|
||||
using isnd.Helpers;
|
||||
using isnd.Interfaces;
|
||||
using isnd.ViewModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@ -68,6 +72,15 @@ namespace isnd.Services
|
||||
type = "SearchQueryService/3.5.0",
|
||||
comment = "Search Query service"
|
||||
});
|
||||
|
||||
if (defaultActivation || unleashClient.IsEnabled("pkg-catalog", false))
|
||||
res.Add(
|
||||
new Resource
|
||||
{
|
||||
id = extUrl + ApiConfig.Catalog,
|
||||
type = "Catalog/3.0.0",
|
||||
comment = "Package Catalog Index"
|
||||
});
|
||||
return res;
|
||||
|
||||
}
|
||||
@ -80,7 +93,7 @@ namespace isnd.Services
|
||||
var scope = dbContext.Packages
|
||||
.Include(p => p.Versions)
|
||||
.Where(
|
||||
p => (CamelCaseMatch(p.Id, query) || SeparatedByMinusMatch(p.Id, query))
|
||||
p => (PackageIdHelpers.CamelCaseMatch(p.Id, query) || PackageIdHelpers.SeparatedByMinusMatch(p.Id, query))
|
||||
&& (prerelease || p.Versions.Any(v => !v.IsPrerelease))
|
||||
&& (packageType == null || p.Versions.Any(v => v.Type == packageType))
|
||||
);
|
||||
@ -146,15 +159,17 @@ namespace isnd.Services
|
||||
}
|
||||
return CurrentCatalogIndex;
|
||||
}
|
||||
public void ÛpdateCatalogFor(Commit last = null)
|
||||
public void ÛpdateCatalogFor(Commit reason = null)
|
||||
{
|
||||
int i = 0;
|
||||
int p = 0;
|
||||
var oldIndex = CurrentCatalogIndex;
|
||||
var oldPages = CurrentCatalogPages;
|
||||
string baseid= extUrl + ApiConfig.Catalog;
|
||||
string basepageid= extUrl + ApiConfig.CatalogPage;
|
||||
CurrentCatalogIndex = new CatalogIndex
|
||||
{
|
||||
Id = extUrl,
|
||||
Id = baseid,
|
||||
Items = new List<PageRef>()
|
||||
};
|
||||
CurrentCatalogPages = new List<Page>();
|
||||
@ -170,16 +185,18 @@ namespace isnd.Services
|
||||
{
|
||||
page = new Page
|
||||
{
|
||||
Parent = isndSettings.ExternalUrl + "/package",
|
||||
Id = basepageid + "-" + p++,
|
||||
Parent = baseid,
|
||||
CommitId = commit.CommitId,
|
||||
CommitTimeStamp = commit.CommitTimeStamp,
|
||||
Id = this.isndSettings.ExternalUrl + "/package/index-" + p++,
|
||||
Items = new List<PackageRef>()
|
||||
};
|
||||
CurrentCatalogPages.Add(page);
|
||||
pageRef = new PageRef
|
||||
{
|
||||
Id = page.Id
|
||||
Id = page.Id,
|
||||
CommitId = commit.CommitId,
|
||||
CommitTimeStamp = commit.CommitTimeStamp
|
||||
};
|
||||
CurrentCatalogIndex.Items.Add(pageRef);
|
||||
i = 0;
|
||||
@ -197,54 +214,61 @@ namespace isnd.Services
|
||||
Where (cv => cv.CommitId == commit.CommitId)
|
||||
.OrderByDescending(vc => vc.CommitNId).First();
|
||||
|
||||
StringBuilder refid = new StringBuilder(extUrl);
|
||||
refid.AppendFormat("{0}/{1}/{2}",ApiConfig.CatalogLeaf, v.PackageId
|
||||
, v.FullString);
|
||||
if (v.Type!=null)
|
||||
refid.AppendFormat("/{0}",v.Type);
|
||||
|
||||
var pkgref = new PackageRef
|
||||
{
|
||||
Version = v.FullString,
|
||||
LastCommit = v.LatestCommit,
|
||||
CommitId = v.LatestCommit.CommitId,
|
||||
CommitTimeStamp = v.LatestCommit.CommitTimeStamp,
|
||||
RefId = isndSettings.ExternalUrl + v.NugetLink,
|
||||
Id = v.PackageId
|
||||
RefId = refid.ToString(),
|
||||
Id = v.PackageId,
|
||||
RefType = v.LatestCommit.Action == PackageAction.PublishPackage
|
||||
? "nuget:PackageDetails" :
|
||||
"nuget:PackageDelete"
|
||||
};
|
||||
page.Items.Add(pkgref);
|
||||
}
|
||||
last = commit;
|
||||
reason = commit;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (last != null)
|
||||
if (reason != null)
|
||||
{
|
||||
CurrentCatalogIndex.CommitId = last.CommitId;
|
||||
CurrentCatalogIndex.CommitId = reason.CommitId;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
// From a fresh db
|
||||
CurrentCatalogIndex.CommitId = "none";
|
||||
}
|
||||
}
|
||||
|
||||
protected static bool CamelCaseMatch(string id, string query)
|
||||
public async Task<PackageDeletionReport> DeletePackageAsync(string pkgId, string fullVersion, string pkgType)
|
||||
{
|
||||
// Assert.False (q==null);
|
||||
if (string.IsNullOrEmpty(query)) return true;
|
||||
|
||||
while (id.Length > 0)
|
||||
// TODO package deletion on disk
|
||||
var commit = new Commit{
|
||||
Action = PackageAction.DeletePackage,
|
||||
TimeStamp = DateTime.Now
|
||||
};
|
||||
var pkg = await dbContext.PackageVersions.SingleOrDefaultAsync(
|
||||
v => v.PackageId == pkgId &&
|
||||
v.FullString == fullVersion &&
|
||||
v.Type == pkgType
|
||||
);
|
||||
if (pkg == null)
|
||||
{
|
||||
int i = 0;
|
||||
while (id.Length > i && char.IsLower(id[i])) i++;
|
||||
if (i == 0) break;
|
||||
id = id.Substring(i);
|
||||
if (id.StartsWith(query, System.StringComparison.OrdinalIgnoreCase)) return true;
|
||||
return new PackageDeletionReport{ Deleted = false };
|
||||
}
|
||||
return false;
|
||||
dbContext.PackageVersions.Remove(pkg);
|
||||
await dbContext.SaveChangesAsync();
|
||||
ÛpdateCatalogFor(commit);
|
||||
return new PackageDeletionReport{ Deleted = true };
|
||||
}
|
||||
protected static bool SeparatedByMinusMatch(string id, string q)
|
||||
{
|
||||
foreach (var part in id.Split('-'))
|
||||
{
|
||||
if (part.StartsWith(q, System.StringComparison.OrdinalIgnoreCase)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
7
src/isnd/ViewModels/DeletePackageReport.cs
Normal file
7
src/isnd/ViewModels/DeletePackageReport.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace isnd.ViewModels
|
||||
{
|
||||
public class PackageDeletionReport
|
||||
{
|
||||
public bool Deleted { get; set; }
|
||||
}
|
||||
}
|
@ -38,7 +38,7 @@
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© 2021 - mvc_ident - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||
© 2021 - isn - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||
</div>
|
||||
</footer>
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
|
@ -1,5 +1,4 @@
|
||||
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
@ -17,24 +16,22 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="NuGet.Packaging.Core" Version="5.9.0"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.1" />
|
||||
|
||||
|
||||
<PackageReference Include="MailKit" Version="2.11.1" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.1" IncludeAssets="All" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.1" IncludeAssets="All" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.1" IncludeAssets="All" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" IncludeAssets="All" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.1" />
|
||||
<PackageReference Include="unleash.client" Version="1.6.1" />
|
||||
<PackageReference Include="bootstrap" Version="5.1.0" />
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.1" />
|
||||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.1.0-preview1-final" />
|
||||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.1.0-preview1-final" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\..\LICENSE" Pack="true" PackagePath="LICENSE"/>
|
||||
</ItemGroup>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Reference in New Issue
Block a user