Skip to content

Commit

Permalink
Rename EditForumPosts to EditUsersForumPosts for clarity, add new Edi…
Browse files Browse the repository at this point in the history
…tForumPosts permission, not used but will be used in future commits
  • Loading branch information
adelikat committed Jul 4, 2024
1 parent 2b02bf3 commit ff3814d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
6 changes: 5 additions & 1 deletion TASVideos.Data/Entity/PermissionTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public enum PermissionTo
[Description("The ability to rate publications. By default, all registered users have this permission, unless revoked.")]
RateMovies = 4,

[Group("User")]
[Description("The ability for a user to edit their own created forum posts.")]
EditForumPosts = 9,

[Group("User")]
[Description("The ability to create new topics on the forums. Experienced users have the ability to do this, unless revoked")]
CreateForumTopics = 10,
Expand Down Expand Up @@ -196,7 +200,7 @@ public enum PermissionTo

[Group("Forum Moderation")]
[Description("The ability to edit post created by another user.")]
EditForumPosts = 400,
EditUsersForumPosts = 400,

[Group("Forum Moderation")]
[Description("The ability to delete post created by another user.")]
Expand Down
6 changes: 3 additions & 3 deletions TASVideos/Pages/Forum/Posts/Edit.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace TASVideos.Pages.Forum.Posts;
PermissionTo.SeeRestrictedForums,
PermissionTo.CreateForumPosts,
PermissionTo.DeleteForumPosts,
PermissionTo.EditForumPosts)]
PermissionTo.EditUsersForumPosts)]
public class EditModel(
ApplicationDbContext db,
ExternalMediaPublisher publisher,
Expand Down Expand Up @@ -60,7 +60,7 @@ public async Task<IActionResult> OnGet()

IsFirstPost = Id == firstPostId;

if (!User.Has(PermissionTo.EditForumPosts)
if (!User.Has(PermissionTo.EditUsersForumPosts)
&& Post.PosterId != User.GetUserId())
{
return AccessDenied();
Expand Down Expand Up @@ -112,7 +112,7 @@ public async Task<IActionResult> OnPost()
return NotFound();
}

if (!User.Has(PermissionTo.EditForumPosts)
if (!User.Has(PermissionTo.EditUsersForumPosts)
&& forumPost.PosterId != User.GetUserId())
{
ModelState.AddModelError("", "Unable to edit post.");
Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/Forum/Posts/User.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public async Task<IActionResult> OnGet()

var isOwnPost = post.PosterId == User.GetUserId();
var isOpenTopic = !post.TopicIsLocked;
post.IsEditable = User.Has(PermissionTo.EditForumPosts) || (isOwnPost && isOpenTopic);
post.IsEditable = User.Has(PermissionTo.EditUsersForumPosts) || (isOwnPost && isOpenTopic);

// Note: IsLastPost is always false, because calculating it for every topic is too expensive, so we only check permissions
// The goal here is for moderators to be able to modify posts from this screen, as a convenience
Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/Forum/Topics/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public async Task<IActionResult> OnGet()
{
var isOwnPost = post.PosterId == userId;
var isOpenTopic = !topic.IsLocked;
post.IsEditable = User.Has(PermissionTo.EditForumPosts)
post.IsEditable = User.Has(PermissionTo.EditUsersForumPosts)
|| (isOwnPost && isOpenTopic);
post.IsDeletable = User.Has(PermissionTo.DeleteForumPosts)
|| (isOwnPost && isOpenTopic && post.IsLastPost);
Expand Down
4 changes: 2 additions & 2 deletions TASVideos/Pages/Shared/_UserFileInfo.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<timezone-convert asp-for="@comment.CreationTimeStamp" in-line="true" />
</div>
</div>
<div class="col" condition="User.Has(PermissionTo.EditForumPosts) || User.GetUserId() == comment.UserId">
<div class="col" condition="User.Has(PermissionTo.EditUsersForumPosts) || User.GetUserId() == comment.UserId">
<div class="float-end mb-1 mt-1">
<button type="button" class="btn btn-primary btn-sm" data-edit-btn data-comment-id="@comment.Id" id="[email protected]">
<i class="fa fa-pencil"></i> Edit
Expand All @@ -108,7 +108,7 @@
class="btn-sm"
asp-href="/UserFiles/Index?handler=DeleteComment&[email protected]&[email protected]()"
warning-message="Are you sure you want to delete this comment?"
condition="User.Has(PermissionTo.EditForumPosts) || User.GetUserId() == comment.UserId">
condition="User.Has(PermissionTo.EditUsersForumPosts) || User.GetUserId() == comment.UserId">
<i class="fa fa-remove"></i>
</delete-button>
</div>
Expand Down

0 comments on commit ff3814d

Please sign in to comment.