Skip to content

Commit

Permalink
simplify boolean logic for edit/delete posts
Browse files Browse the repository at this point in the history
  • Loading branch information
adelikat committed Aug 28, 2023
1 parent 7434eea commit 448cafd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions TASVideos/Pages/Forum/Topics/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,12 @@ public async Task<IActionResult> OnGet()

foreach (var post in Topic.Posts)
{
var isOwnPost = post.PosterId == userId;
var isOpenTopic = !topic.IsLocked;
post.IsEditable = User.Has(PermissionTo.EditForumPosts)
|| (userId.HasValue && post.PosterId == userId.Value && !topic.IsLocked);
|| (isOwnPost && isOpenTopic);
post.IsDeletable = User.Has(PermissionTo.DeleteForumPosts)
|| (userId.HasValue && post.PosterId == userId && post.IsLastPost && !topic.IsLocked);
|| (isOwnPost && isOpenTopic && post.IsLastPost);
}

if (userId.HasValue)
Expand Down

0 comments on commit 448cafd

Please sign in to comment.