forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQaAuth.scala
31 lines (20 loc) · 875 Bytes
/
QaAuth.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package lila.qa
import lila.security.Granter
import lila.user.{ User, UserContext }
import org.joda.time.DateTime
object QaAuth {
def canEdit(q: Question)(implicit ctx: UserContext) = noTroll { u =>
(q ownBy u) || Granter(_.ModerateQa)(u)
}
def canEdit(a: Answer)(implicit ctx: UserContext) = noTroll { u =>
(a ownBy u) || Granter(_.ModerateQa)(u)
}
def canAsk(implicit ctx: UserContext) = noTroll(isNotN00b)
def canAnswer(q: Question)(implicit ctx: UserContext) = noTroll(isNotN00b)
def canVote(implicit ctx: UserContext) = noTroll(isNotN00b)
def canComment(implicit ctx: UserContext) = noTroll(isNotN00b)
private def noTroll(block: User => Boolean)(implicit ctx: UserContext) =
ctx.me.filterNot(_.troll) ?? block
private def isNotN00b(u: User) = !isN00b(u)
def isN00b(u: User) = u.createdAt isAfter DateTime.now.minusWeeks(1)
}