From 9f9d16467f8866104023ee34866db8d495373e64 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Fri, 20 Jul 2018 14:14:59 +0100 Subject: [PATCH] Fixes #181. --- src/forum.nim | 1 - src/frontend/post.nim | 3 ++- src/frontend/threadlist.nim | 16 +++++++++------- src/frontend/user.nim | 7 +++++-- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/forum.nim b/src/forum.nim index 9d7c7eb..399a64e 100644 --- a/src/forum.nim +++ b/src/forum.nim @@ -769,7 +769,6 @@ routes: from thread t, category c, person u where t.isDeleted = 0 and category = c.id and u.status <> 'Spammer' and u.status <> 'Troll' and - u.status <> 'Banned' and u.id in ( select u.id from post p, person u where p.author = u.id and p.thread = t.id diff --git a/src/frontend/post.nim b/src/frontend/post.nim index c32b490..5ca0d5f 100644 --- a/src/frontend/post.nim +++ b/src/frontend/post.nim @@ -32,7 +32,8 @@ proc lastEdit*(post: Post): PostInfo = post.history[^1] proc isModerated*(post: Post): bool = - ## Determines whether the specified thread is under moderation. + ## Determines whether the specified post is under moderation + ## (i.e. whether the post is invisible to ordinary users). post.author.rank <= Moderated proc isLikedBy*(post: Post, user: Option[User]): bool = diff --git a/src/frontend/threadlist.nim b/src/frontend/threadlist.nim index cceca03..0516d74 100644 --- a/src/frontend/threadlist.nim +++ b/src/frontend/threadlist.nim @@ -22,6 +22,7 @@ type proc isModerated*(thread: Thread): bool = ## Determines whether the specified thread is under moderation. + ## (i.e. whether the specified thread is invisible to ordinary users). thread.author.rank <= Moderated when defined(js): @@ -53,6 +54,8 @@ when defined(js): ## ## The rules for this are determined by the rank of the user, their ## settings (TODO), and whether the thread's creator is moderated or not. + ## + ## The ``user`` argument refers to the currently logged in user. mixin isModerated if user.isNone(): return not thread.isModerated @@ -108,20 +111,19 @@ when defined(js): proc genThread(thread: Thread, isNew: bool, noBorder: bool): VNode = let isOld = (getTime() - thread.creation.fromUnix).weeks > 2 - let isBanned = thread.author.rank < Moderated + let isBanned = thread.author.rank.isBanned() result = buildHtml(): tr(class=class({"no-border": noBorder, "banned": isBanned})): td(class="thread-title"): if thread.isLocked: italic(class="fas fa-lock fa-xs", title="Thread cannot be replied to") + if isBanned: + italic(class="fas fa-ban fa-xs", + title="Thread author is banned") if thread.isModerated: - if isBanned: - italic(class="fas fa-ban fa-xs", - title="Thread author is banned") - else: - italic(class="fas fa-eye-slash fa-xs", - title="Thread is moderated") + italic(class="fas fa-eye-slash fa-xs", + title="Thread is moderated") if thread.isSolved: italic(class="fas fa-check-square fa-xs", title="Thread has a solution") diff --git a/src/frontend/user.nim b/src/frontend/user.nim index bbf5782..ea0624b 100644 --- a/src/frontend/user.nim +++ b/src/frontend/user.nim @@ -4,10 +4,10 @@ type # If you add more "Banned" states, be sure to modify forum's threadsQuery too. Rank* {.pure.} = enum ## serialized as 'status' Spammer ## spammer: every post is invisible - Troll ## troll: cannot write new posts - Banned ## A non-specific ban Moderated ## new member: posts manually reviewed before everybody ## can see them + Troll ## troll: cannot write new posts + Banned ## A non-specific ban EmailUnconfirmed ## member with unconfirmed email address. Their posts ## are visible, but cannot make new posts. This is so that ## when a user with existing posts changes their email, @@ -34,6 +34,9 @@ proc canPost*(rank: Rank): bool = ## Determines whether the specified rank can make new posts. rank >= Rank.User or rank == Moderated +proc isBanned*(rank: Rank): bool = + rank in {Spammer, Troll, Banned} + when defined(js): include karax/prelude import karaxutils