diff --git a/src/isn/isn.csproj b/src/isn/isn.csproj index 793ae37..92acbdd 100644 --- a/src/isn/isn.csproj +++ b/src/isn/isn.csproj @@ -19,6 +19,7 @@ + diff --git a/src/isnd/Controllers/PackageVersionController.cs b/src/isnd/Controllers/PackageVersionController.cs index a4783b3..fb835b8 100644 --- a/src/isnd/Controllers/PackageVersionController.cs +++ b/src/isnd/Controllers/PackageVersionController.cs @@ -47,60 +47,5 @@ namespace isnd return View("Index", model); } - - // GET: PackageVersion/Details/5 - public async Task Details(string pkgid, string version) - { - if (pkgid == null || version == null) - { - return NotFound(); - } - - var packageVersion = await _context.PackageVersions - .Include(p => p.Package) - .FirstOrDefaultAsync(m => m.PackageId == pkgid && m.FullString == version); - if (packageVersion == null) - { - return NotFound(); - } - - return View(packageVersion); - } - - [Authorize] - public async Task Delete(string pkgid, string version, string pkgtype) - { - if (pkgid == null || version == null) - { - return NotFound(); - } - - var packageVersion = await _context.PackageVersions.Include(p => p.Package) - .FirstOrDefaultAsync(m => m.PackageId == pkgid - && m.FullString == version && m.Type == pkgtype); - if (packageVersion == null) return NotFound(); - if (!User.IsOwner(packageVersion)) return Unauthorized(); - var pkg = await _pm.GetPackageAsync(pkgid, version, pkgtype); - return View(pkg); - } - - - // POST: PackageVersion/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public async Task DeleteConfirmed(string PackageId, string FullString, - string Type) - { - PackageVersion packageVersion = await _context.PackageVersions - .FirstOrDefaultAsync(m => m.PackageId == PackageId - && m.FullString == FullString && m.Type == Type); - if (packageVersion == null) return NotFound(); - if (!User.IsOwner(packageVersion)) return Unauthorized(); - - await _pm.DeletePackageAsync(PackageId, FullString, Type); - return RedirectToAction(nameof(Index)); - } - - } } diff --git a/src/isnd/Controllers/Packages/WebViews.cs b/src/isnd/Controllers/Packages/WebViews.cs index d2f9fc6..1a4ea80 100644 --- a/src/isnd/Controllers/Packages/WebViews.cs +++ b/src/isnd/Controllers/Packages/WebViews.cs @@ -1,7 +1,10 @@ using System; using System.Linq; using System.Threading.Tasks; +using isnd.Data; +using isnd.Helpers; using isnd.ViewModels; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -50,6 +53,40 @@ namespace isnd.Controllers } const int MAX_PKG_VERSION_LIST = 50; + + [Authorize] + public async Task Delete(string pkgid, string version, string pkgtype) + { + if (pkgid == null || version == null) + { + return NotFound(); + } + + var packageVersion = await dbContext.PackageVersions.Include(p => p.Package) + .FirstOrDefaultAsync(m => m.PackageId == pkgid + && m.FullString == version && m.Type == pkgtype); + if (packageVersion == null) return NotFound(); + if (!User.IsOwner(packageVersion)) return Unauthorized(); + var pkg = await packageManager.GetPackageAsync(pkgid, version, pkgtype); + return View(pkg); + } + + // POST: PackageVersion/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(string PackageId, string FullString, + string Type) + { + PackageVersion packageVersion = await dbContext.PackageVersions + .Include(pv => pv.Package) + .FirstOrDefaultAsync(m => m.PackageId == PackageId + && m.FullString == FullString && m.Type == Type); + if (packageVersion == null) return NotFound(); + if (!User.IsOwner(packageVersion)) return Unauthorized(); + + await packageManager.DeletePackageAsync(PackageId, FullString, Type); + return RedirectToAction(nameof(Index)); + } } } \ No newline at end of file diff --git a/src/isnd/Data/PackageVersion.cs b/src/isnd/Data/PackageVersion.cs index 0637acb..2331ca3 100644 --- a/src/isnd/Data/PackageVersion.cs +++ b/src/isnd/Data/PackageVersion.cs @@ -34,7 +34,7 @@ namespace isnd.Data [Required][JsonIgnore] [ForeignKey("LatestCommit")] - public long CommitNId { get; set ; } + public long CommitNId { get; set; } [NotMapped] diff --git a/src/isnd/Program.cs b/src/isnd/Program.cs index 9b0ba1d..d9f5f74 100644 --- a/src/isnd/Program.cs +++ b/src/isnd/Program.cs @@ -14,12 +14,13 @@ namespace isnd { public static void Main(string[] args) { - BuildWebHost(args).Run(); + var builder = CreateBuilder(args); + builder.Build().Run(); } - public static IWebHost BuildWebHost(string[] args) => + public static IWebHostBuilder CreateBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup() - .Build(); + ; } } diff --git a/src/isnd/Startup.cs b/src/isnd/Startup.cs index 00a9d79..40333bc 100644 --- a/src/isnd/Startup.cs +++ b/src/isnd/Startup.cs @@ -17,6 +17,8 @@ using Unleash; using Microsoft.Extensions.Options; using isnd.Helpers; using Microsoft.IdentityModel.Tokens; +using Microsoft.AspNetCore.HttpOverrides; +using System.Net; namespace isnd { @@ -25,7 +27,6 @@ namespace isnd public Startup(IConfiguration config) { Configuration = config; - } public IConfiguration Configuration { get; } @@ -52,7 +53,13 @@ namespace isnd .AddSignInManager() .AddDefaultUI() .AddDefaultTokenProviders(); - +/* + services.Configure(options => + { + options.ForwardedHeaders = + ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; + }); +*/ services.AddMvc(); services.AddDataProtection(); @@ -85,14 +92,11 @@ namespace isnd services.AddAuthentication("Bearer") .AddJwtBearer("Bearer", options => { - options.Authority = "https://localhost:5001"; - options.TokenValidationParameters = new TokenValidationParameters { ValidateAudience = false }; }); - } @@ -105,6 +109,9 @@ namespace isnd Microsoft.AspNetCore.Hosting.IHostingEnvironment env, ApplicationDbContext dbContext) { + // app.UseForwardedHeaders(); + // .UseHttpsRedirection(); + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); @@ -113,12 +120,12 @@ namespace isnd else { app.UseExceptionHandler("/Home/Error"); - app.UseHsts(); dbContext.Database.Migrate(); } - - app.UseHttpsRedirection(); - app.UseStatusCodePages().UseStaticFiles().UseAuthentication().UseMvc(routes => + app + .UseStaticFiles() + .UseAuthentication() + .UseMvc(routes => { routes.MapRoute( name: "default", diff --git a/src/isnd/Views/PackageVersion/Delete.cshtml b/src/isnd/Views/Packages/Delete.cshtml similarity index 100% rename from src/isnd/Views/PackageVersion/Delete.cshtml rename to src/isnd/Views/Packages/Delete.cshtml diff --git a/src/isnd/Views/Packages/Details.cshtml b/src/isnd/Views/Packages/Details.cshtml index 0341901..bbf7931 100644 --- a/src/isnd/Views/Packages/Details.cshtml +++ b/src/isnd/Views/Packages/Details.cshtml @@ -38,7 +38,8 @@
<PackageReference Include="@Model.pkgid" Version="@Model.latest.FullString" />
- @Html.ActionLink("Edit", "Edit", new { pkgid = Model.pkgid, version = Model.latest.FullString }) | + @Html.ActionLink("Edit", "Edit", new { pkgid = Model.pkgid, version = Model.latest.FullString }) | + @Html.ActionLink("Delete", "Delete", new { pkgid = Model.pkgid, version= Model.latest.FullString }) | Back to List
diff --git a/src/isnd/Views/Packages/Index.cshtml b/src/isnd/Views/Packages/Index.cshtml index 8b7d0ee..1b63981 100644 --- a/src/isnd/Views/Packages/Index.cshtml +++ b/src/isnd/Views/Packages/Index.cshtml @@ -44,8 +44,7 @@ @Html.DisplayFor(modelItem => item.Description) - @Html.ActionLink("Details", "Details", new { pkgid = item.Id }) | - @Html.ActionLink("Delete", "Delete", new { pkgid = item.Id }) + @Html.ActionLink("Details", "Details", new { pkgid = item.Id }) } diff --git a/src/isnd/wwwroot/css/site.css b/src/isnd/wwwroot/css/site.css index 8c14d74..85e5ce6 100644 --- a/src/isnd/wwwroot/css/site.css +++ b/src/isnd/wwwroot/css/site.css @@ -7843,7 +7843,8 @@ a.text-dark:hover, a.text-dark:focus { border: 1px solid #333; box-shadow: 8px 8px 5px #444; padding: 8px 12px; - background-image: linear-gradient(180deg, #fff, #ddd 40%, #ccc); } + background-image: linear-gradient(180deg, #fff, #ddd 40%, #ccc); + margin: 1em; } .fa-copy { cursor: copy; } diff --git a/src/isnd/wwwroot/css/site.scss b/src/isnd/wwwroot/css/site.scss index 5fce340..7da0fd0 100644 --- a/src/isnd/wwwroot/css/site.scss +++ b/src/isnd/wwwroot/css/site.scss @@ -105,8 +105,9 @@ background-color: black; box-shadow: 8px 8px 5px #444; padding: 8px 12px; background-image: linear-gradient(180deg, #fff, #ddd 40%, #ccc); + margin: 1em; } .fa-copy { cursor: copy; -} \ No newline at end of file +}