From aa9f24e1d752a9598f9959f4648b2871bc0305f5 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Sat, 19 May 2018 19:05:34 +0100 Subject: [PATCH] Switch permissions around. EmailUnconfirmed's are now visible but cannot post. --- src/forum.nim | 14 ++++++++++++++ src/frontend/user.nim | 9 ++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/forum.nim b/src/forum.nim index 86b95d0..24606a1 100644 --- a/src/forum.nim +++ b/src/forum.nim @@ -1020,6 +1020,13 @@ proc executeReply(c: TForumData, threadId: int, content: string, # TODO: Refactor TForumData. assert c.loggedIn() + if not canPost(c.rank): + case c.rank + of EmailUnconfirmed: + raise newForumError("You need to confirm your email before you can post") + else: + raise newForumError("You are not allowed to post") + if rateLimitCheck(c): raise newForumError("You're posting too fast!") @@ -1097,6 +1104,13 @@ proc executeNewThread(c: TForumData, subject, msg: string): (int64, int64) = assert c.loggedIn() + if not canPost(c.rank): + case c.rank + of EmailUnconfirmed: + raise newForumError("You need to confirm your email before you can post") + else: + raise newForumError("You are not allowed to post") + if subject.len <= 2: raise newForumError("Subject is too short", @["subject"]) if subject.len > 100: diff --git a/src/frontend/user.nim b/src/frontend/user.nim index 7daa27e..4b2d212 100644 --- a/src/frontend/user.nim +++ b/src/frontend/user.nim @@ -5,9 +5,12 @@ type Spammer ## spammer: every post is invisible Troll ## troll: cannot write new posts Banned ## A non-specific ban - EmailUnconfirmed ## member with unconfirmed email address Moderated ## new member: posts manually reviewed before everybody ## can see them + 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, + ## their posts don't disappear. User ## Ordinary user Moderator ## Moderator: can change a user's rank Admin ## Admin: can do everything @@ -24,6 +27,10 @@ proc isOnline*(user: User): bool = proc `==`*(u1, u2: User): bool = u1.name == u2.name +proc canPost*(rank: Rank): bool = + ## Determines whether the specified rank can make new posts. + rank >= Rank.User or rank == Moderated + when defined(js): include karax/prelude import karaxutils