verified users can send more messages (for lichess4545)

This commit is contained in:
Thibault Duplessis 2020-02-17 13:48:25 -06:00
parent ad5371a478
commit 15cfe4f508
3 changed files with 10 additions and 8 deletions

View file

@ -24,14 +24,14 @@ final private class MsgSecurity(
import MsgSecurity._ import MsgSecurity._
private val CreateLimitPerUser = new RateLimit[User.ID]( private val CreateLimitPerUser = new RateLimit[User.ID](
credits = 20, credits = 20 * 5,
duration = 24 hour, duration = 24 hour,
name = "PM creates per user", name = "PM creates per user",
key = "msg_create.user" key = "msg_create.user"
) )
private val ReplyLimitPerUser = new RateLimit[User.ID]( private val ReplyLimitPerUser = new RateLimit[User.ID](
credits = 20, credits = 20 * 5,
duration = 1 minute, duration = 1 minute,
name = "PM replies per user", name = "PM replies per user",
key = "msg_reply.user" key = "msg_reply.user"
@ -69,7 +69,8 @@ final private class MsgSecurity(
if (unlimited) fuccess(none) if (unlimited) fuccess(none)
else { else {
val limiter = if (isNew) CreateLimitPerUser else ReplyLimitPerUser val limiter = if (isNew) CreateLimitPerUser else ReplyLimitPerUser
!limiter(user.id)(true) ?? fuccess(Limit.some) val cost = if (user.isVerified) 1 else 5
!limiter(user.id, cost = cost)(true) ?? fuccess(Limit.some)
} }
private def isSpam(text: String): Fu[Option[Verdict]] = private def isSpam(text: String): Fu[Option[Verdict]] =

View file

@ -176,10 +176,11 @@ object User {
def isTroll = marks.exists(_.troll) def isTroll = marks.exists(_.troll)
} }
case class Contact(_id: ID, kid: Option[Boolean], marks: Option[UserMarks]) { case class Contact(_id: ID, kid: Option[Boolean], marks: Option[UserMarks], roles: Option[List[String]]) {
def id = _id def id = _id
def isKid = ~kid def isKid = ~kid
def isTroll = marks.exists(_.troll) def isTroll = marks.exists(_.troll)
def isVerified = roles.exists(_ contains "ROLE_VERIFIED")
} }
case class Contacts(orig: Contact, dest: Contact) case class Contacts(orig: Contact, dest: Contact)

View file

@ -580,7 +580,7 @@ final class UserRepo(val coll: Coll)(implicit ec: scala.concurrent.ExecutionCont
import User.contactHandler import User.contactHandler
coll.byOrderedIds[User.Contact, User.ID]( coll.byOrderedIds[User.Contact, User.ID](
List(orig, dest), List(orig, dest),
$doc(F.kid -> true, F.marks -> true).some, $doc(F.kid -> true, F.marks -> true, F.roles -> true).some,
ReadPreference.secondaryPreferred ReadPreference.secondaryPreferred
)(_._id) map { )(_._id) map {
case List(o, d) => User.Contacts(o, d).some case List(o, d) => User.Contacts(o, d).some