fixed Article View buttons
Some checks failed
Build, Tag, Push Docker Image / build (push) Has been cancelled
Create Release / Generate Release (push) Has been cancelled

This commit is contained in:
Mia Rose Winter 2024-03-06 14:22:38 +01:00
parent 4f81a292cf
commit 6c92f3728e
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E
3 changed files with 13 additions and 3 deletions

View file

@ -54,7 +54,10 @@
<Authorized>
<ArticleComponent Article="@GetArticleProtected(context.User)" />
<div class="flex gap-2 mt-3 flex-wrap">
<a class="btn btn-info w-full sm:btn-wide" href="article/@Article.Id/edit" data-enhance-nav="false">@Localizer["Edit"]</a>
@if (CanEdit) {
<a class="btn btn-info w-full sm:btn-wide" href="article/@Article!.Id/edit"
data-enhance-nav="false">@Localizer["Edit"]</a>
}
@if (Article.Status is ArticleStatus.Draft) {
<form @formname="submit-for-review" method="post" @onsubmit="SubmitForReview" class="max-sm:w-full">
<AntiforgeryToken />
@ -124,6 +127,8 @@
[CascadingParameter]
public HttpContext HttpContext { get; set; } = default!;
private bool CanEdit { get; set; }
private Article GetArticlePublic() {
if (Article is null) throw new ApplicationException("Article not found.");
if (Article.Status >= ArticleStatus.Published && Article.PublishDate <= DateTimeOffset.UtcNow) {
@ -138,17 +143,21 @@
// The Article is publicly available
if (Article.Status >= ArticleStatus.Published && Article.PublishDate <= DateTimeOffset.UtcNow) {
if (principal.IsInRole("Admin"))
CanEdit = true;
return Article;
}
// Admins always get access
if (principal.IsInRole("Admin")) {
CanEdit = true;
return Article;
}
// You can only access your own drafts
if (Article.Status is ArticleStatus.Draft) {
if (Article.Author.Id == principal.FindFirst("Id")!.Value) {
CanEdit = true;
return Article;
}
throw new ApplicationException("Cannot access draft article without being author or admin.");
@ -156,6 +165,7 @@
// InReview Articles can only be accessed by reviewers
if (Article.Status is ArticleStatus.InReview) {
if (principal.IsInRole("Reviewer")) {
CanEdit = true;
return Article;
}
throw new ApplicationException("Cannot access in-review article without being a reviewer or admin.");

View file

@ -1,4 +1,4 @@
<label for="narrow-reading-toggle" class="narrow-reading-toggle btn btn-square btn-sm swap" title="@Label" onclick="this.classList.toggle('swap-active')">
<label for="narrow-reading-toggle" class="narrow-reading-toggle btn btn-square btn-sm swap max-lg:hidden" title="@Label" onclick="this.classList.toggle('swap-active')">
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="currentColor" class="swap-on fill-current">
<path fill-rule="evenodd" d="M15 3.75a.75.75 0 0 1 .75-.75h4.5a.75.75 0 0 1 .75.75v4.5a.75.75 0 0 1-1.5 0V5.56l-3.97 3.97a.75.75 0 1 1-1.06-1.06l3.97-3.97h-2.69a.75.75 0 0 1-.75-.75Zm-12 0A.75.75 0 0 1 3.75 3h4.5a.75.75 0 0 1 0 1.5H5.56l3.97 3.97a.75.75 0 0 1-1.06 1.06L4.5 5.56v2.69a.75.75 0 0 1-1.5 0v-4.5Zm11.47 11.78a.75.75 0 1 1 1.06-1.06l3.97 3.97v-2.69a.75.75 0 0 1 1.5 0v4.5a.75.75 0 0 1-.75.75h-4.5a.75.75 0 0 1 0-1.5h2.69l-3.97-3.97Zm-4.94-1.06a.75.75 0 0 1 0 1.06L5.56 19.5h2.69a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1-.75-.75v-4.5a.75.75 0 0 1 1.5 0v2.69l3.97-3.97a.75.75 0 0 1 1.06 0Z" clip-rule="evenodd"/>
</svg>

File diff suppressed because one or more lines are too long