fixed Delete Confirm Page not allowing you to delete your own drafts
This commit is contained in:
parent
b79881f98d
commit
37f84da148
|
@ -1,8 +1,7 @@
|
||||||
@page "/article/{id:guid}/delete"
|
@page "/article/{id:guid}/delete"
|
||||||
@using Microsoft.EntityFrameworkCore
|
@using Microsoft.EntityFrameworkCore
|
||||||
@using Wave.Data
|
@using Wave.Data
|
||||||
|
@using Wave.Utilities
|
||||||
@attribute [Authorize(Policy = "ArticleDeletePermissions")]
|
|
||||||
|
|
||||||
@inject IDbContextFactory<ApplicationDbContext> ContextFactory
|
@inject IDbContextFactory<ApplicationDbContext> ContextFactory
|
||||||
@inject NavigationManager Navigation
|
@inject NavigationManager Navigation
|
||||||
|
@ -36,6 +35,8 @@
|
||||||
@code {
|
@code {
|
||||||
[CascadingParameter(Name = "TitlePostfix")]
|
[CascadingParameter(Name = "TitlePostfix")]
|
||||||
private string TitlePostfix { get; set; } = default!;
|
private string TitlePostfix { get; set; } = default!;
|
||||||
|
[CascadingParameter]
|
||||||
|
public HttpContext HttpContext { get; set; } = default!;
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
|
@ -45,15 +46,16 @@
|
||||||
protected override async Task OnInitializedAsync() {
|
protected override async Task OnInitializedAsync() {
|
||||||
await using var context = await ContextFactory.CreateDbContextAsync();
|
await using var context = await ContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
Article = await context.Set<Article>().IgnoreQueryFilters()
|
var article = await context.Set<Article>().IgnoreQueryFilters()
|
||||||
.Where(a => !a.IsDeleted).FirstOrDefaultAsync(a => a.Id == Id);
|
.Where(a => !a.IsDeleted).FirstOrDefaultAsync(a => a.Id == Id);
|
||||||
|
if (article.AllowedToDelete(HttpContext.User)) Article = article;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Delete() {
|
private async Task Delete() {
|
||||||
if (Article is null) return;
|
if (Article.AllowedToDelete(HttpContext.User)) return;
|
||||||
|
|
||||||
var context = await ContextFactory.CreateDbContextAsync();
|
var context = await ContextFactory.CreateDbContextAsync();
|
||||||
Article.IsDeleted = true;
|
Article!.IsDeleted = true;
|
||||||
context.Entry(Article).State = EntityState.Modified;
|
context.Entry(Article).State = EntityState.Modified;
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue