Skip to content

Commit dfd8b8b

Browse files
committed
Admin ability: Forum vote purge
1 parent d5f0d68 commit dfd8b8b

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

Zero-K.info/Controllers/UsersController.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,45 @@ public ActionResult SetUsername(int accountID, string newUsername)
521521
return Content(string.Format("{0} renamed to {1}", oldName, newUsername));
522522
}
523523

524+
[HttpPost]
525+
[ValidateAntiForgeryToken]
526+
[Auth(Role = AdminLevel.Moderator)]
527+
public ActionResult DeleteAllForumVotes(int accountID)
528+
{
529+
var db = new ZkDataContext();
530+
var acc = db.Accounts.FirstOrDefault(x => x.AccountID == accountID);
531+
var votes = acc.AccountForumVotes;
532+
533+
foreach (var vote in votes)
534+
{
535+
var post = vote.ForumPost;
536+
var author = post.Account;
537+
var oldDelta = vote.Vote;
538+
539+
/*
540+
Console.WriteLine("Purging vote on post " + post.ForumPostID + " by author " + author.Name + ": " + oldDelta);
541+
Console.ReadLine();
542+
*/
543+
544+
// reverse vote effects
545+
if (oldDelta > 0)
546+
{
547+
author.ForumTotalUpvotes = author.ForumTotalUpvotes - oldDelta;
548+
post.Upvotes = post.Upvotes - oldDelta;
549+
}
550+
else if (oldDelta < 0)
551+
{
552+
author.ForumTotalDownvotes = author.ForumTotalDownvotes + oldDelta;
553+
post.Downvotes = post.Downvotes + oldDelta;
554+
}
555+
db.AccountForumVotes.DeleteOnSubmit(vote);
556+
}
557+
db.SaveChanges();
558+
Global.Server.GhostChanSay(GlobalConst.ModeratorChannel, string.Format("Account {0} forum votes deleted by {1}", Url.Action("Detail", "Users", new { id = acc.AccountID }, "http"), Global.Account.Name));
559+
560+
return Content(string.Format("Deleted all forum votes of {0}", acc.Name));
561+
}
562+
524563
[HttpPost]
525564
[ValidateAntiForgeryToken]
526565
[Auth(Role = AdminLevel.Moderator)]

Zero-K.info/Views/Users/AdminUserDetail.cshtml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,14 @@
208208
Enter the target's user name to confirm: @Html.TextBox("accountName")
209209
<input type="submit" value="DELETE" class="js_confirm" />
210210
</form>
211+
212+
<h3>Delete all forum votes</h3>
213+
<form action="@Url.Action("DeleteAllForumVotes", "Forum", new { accountID = Model.AccountID })" method="post">
214+
@Html.AntiForgeryToken()
215+
This will <b>permanently</b> remove <b>all</b> of the user's upvotes/downvotes on forum.<br />
216+
This action <b>cannot</b> be undone!<br />
217+
<br />
218+
Enter the target's user name to confirm: @Html.TextBox("accountName")
219+
<input type="submit" value="DELETE" class="js_confirm" />
220+
</form>
211221
</div>

0 commit comments

Comments
 (0)