Skip to content

Commit

Permalink
spam - fix bug where topic removal and banning failed. Do not show sp…
Browse files Browse the repository at this point in the history
…am button user's own posts, resolves #1694
  • Loading branch information
adelikat committed Sep 9, 2023
1 parent 09e64df commit d96b715
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions TASVideos/Pages/Forum/Models/IForumPostEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public interface IForumPostEntry
public ForumPostMood PosterMood { get; }

// Poster
public int PosterId { get; }
public string PosterName { get; }
public int PosterPostCount { get; }
public string? PosterLocation { get; }
Expand Down
3 changes: 2 additions & 1 deletion TASVideos/Pages/Forum/Posts/Edit.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ public async Task<IActionResult> OnPostSpam()
var oldTopicTitle = post.Topic.Title;
var oldForumShortName = post.Topic.Forum!.ShortName;
post.TopicId = SiteGlobalConstants.SpamTopicId;
var result = await ConcurrentSave(_db, $"Post {Id} deleted", $"Unable to delete post {Id}");

bool topicDeleted = false;
if (postCount == 1)
Expand All @@ -287,6 +286,8 @@ public async Task<IActionResult> OnPostSpam()
topicDeleted = true;
}

var result = await ConcurrentSave(_db, $"Post {Id} deleted", $"Unable to delete post {Id}");

if (result)
{
_forumService.ClearLatestPostCache();
Expand Down
1 change: 1 addition & 0 deletions TASVideos/Pages/Forum/Posts/Models/UserPostsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class UserPagePost : IForumPostEntry
public bool IsDeletable => false;

// Fill with user info
public int PosterId { get; set; }
public string PosterName { get; set; } = "";
public string? Signature { get; set; }
public int PosterPostCount { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion TASVideos/Pages/Forum/Posts/User.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public async Task<IActionResult> OnGet()
TopicTitle = p.Topic!.Title,
ForumId = p.Topic.ForumId,
ForumName = p.Topic!.Forum!.Name,
PosterMood = p.PosterMood
PosterMood = p.PosterMood,
PosterId = p.PosterId
})
.SortedPageOf(Search);

Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/Forum/Topics/_TopicPost.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
class="btn btn-primary btn-sm border border-warning">
<i class="fa fa-pencil"></i> Edit
</a>
<delete-button condition="!Model.Restricted && User.Has(PermissionTo.DeleteForumPosts) && User.Has(PermissionTo.AssignRoles)"
<delete-button condition="!Model.Restricted && User.Has(PermissionTo.DeleteForumPosts) && User.Has(PermissionTo.AssignRoles) && Model.PosterId != User.GetUserId()"
asp-href="@($"/Forum/Posts/Edit/{Model.Id}?handler=Spam")"
warning-message="Are you sure you want to mark this post as spam and ban this user?"
action-name="Spam"
Expand Down

0 comments on commit d96b715

Please sign in to comment.