Package deletion and types
This commit is contained in:
@ -77,8 +77,8 @@ namespace isnd.Controllers
|
||||
}
|
||||
|
||||
var packageVersion = await dbContext.PackageVersions.Include(p => p.Package)
|
||||
.FirstOrDefaultAsync(m => m.PackageId == pkgid
|
||||
&& m.FullString == version && m.Type == pkgtype);
|
||||
.FirstOrDefaultAsync(m => m.PackageId == pkgid && m.FullString == version
|
||||
&& (pkgtype!=null && m.Type == pkgtype || m.Type != "Delete" ));
|
||||
if (packageVersion == null) return NotFound();
|
||||
if (!User.IsOwner(packageVersion)) return Unauthorized();
|
||||
var pkg = await packageManager.GetPackageAsync(pkgid, version, pkgtype);
|
||||
@ -87,18 +87,18 @@ namespace isnd.Controllers
|
||||
|
||||
// POST: PackageVersion/Delete/5
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> DeleteConfirmed(string PackageId, string FullString,
|
||||
string Type)
|
||||
[ValidateAntiForgeryToken][Authorize]
|
||||
public async Task<IActionResult> DeleteConfirmed(string pkgid, string version,
|
||||
string type)
|
||||
{
|
||||
PackageVersion packageVersion = await dbContext.PackageVersions
|
||||
var 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);
|
||||
.Where(m => m.PackageId == pkgid
|
||||
&& m.FullString == version && (type==null || m.Type == type))
|
||||
.ToArrayAsync();
|
||||
if (packageVersion.Length==0) return NotFound();
|
||||
if (!User.IsOwner(packageVersion.First())) return Unauthorized();
|
||||
await packageManager.DeletePackageAsync(pkgid, version, type);
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user