Switch permissions around. EmailUnconfirmed's are now visible but cannot post.

This commit is contained in:
Dominik Picheta 2018-05-19 19:05:34 +01:00
commit aa9f24e1d7
2 changed files with 22 additions and 1 deletions

View file

@ -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:

View file

@ -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