Corrige la suppression de paquets

broken/ef
Paul Schneider 2 years ago
parent 97eba2390e
commit a84e1d9750
11 changed files with 66 additions and 73 deletions

@ -19,6 +19,7 @@
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="unleash.client" Version="1.6.1" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="microsoft.codeanalysis.analyzers" Version="1.1.0" />
<Reference Include="System.Net.Http" Version="4.0.0" />
</ItemGroup>
<ItemGroup>

@ -47,60 +47,5 @@ namespace isnd
return View("Index", model);
}
// GET: PackageVersion/Details/5
public async Task<IActionResult> 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<IActionResult> 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<IActionResult> 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));
}
}
}

@ -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<IActionResult> 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<IActionResult> 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));
}
}
}

@ -34,7 +34,7 @@ namespace isnd.Data
[Required][JsonIgnore]
[ForeignKey("LatestCommit")]
public long CommitNId { get; set ; }
public long CommitNId { get; set; }
[NotMapped]

@ -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<Startup>()
.Build();
;
}
}

@ -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<ForwardedHeadersOptions>(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",

@ -38,7 +38,8 @@
<pre><code id="code" >&lt;PackageReference Include="@Model.pkgid" Version="@Model.latest.FullString" /&gt;</code></pre>
</div>
<div>
@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 }) |
<a asp-action="Index">Back to List</a>
</div>
</div>

@ -44,8 +44,7 @@
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
@Html.ActionLink("Details", "Details", new { pkgid = item.Id }) |
@Html.ActionLink("Delete", "Delete", new { pkgid = item.Id })
@Html.ActionLink("Details", "Details", new { pkgid = item.Id })
</td>
</tr>
}

@ -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; }

@ -105,6 +105,7 @@ 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 {

Loading…