Ignore msg security for Challenge API messages

pull/9417/head
Benedikt Werner 2021-07-15 13:40:56 +02:00
parent 41d9b6b3e0
commit c533d60673
No known key found for this signature in database
GPG Key ID: 1DBFF0F8E9E121EB
2 changed files with 6 additions and 3 deletions

View File

@ -28,7 +28,7 @@ final class ChallengeMsg(msgApi: lila.msg.MsgApi, lightUserApi: LightUserApi)(im
.replace("{player}", s"@${u1.name}")
.replace("{opponent}", s"@${u2.name}")
.replace("{game}", s"#${gameId}")
msgApi.post(managedById, u1.id, msg, multi = true)
msgApi.post(managedById, u1.id, msg, multi = true, ignoreSecurity = true)
}
.sequenceFu
.void

View File

@ -78,14 +78,17 @@ final class MsgApi(
orig: User.ID,
dest: User.ID,
text: String,
multi: Boolean = false
multi: Boolean = false,
ignoreSecurity: Boolean = false
): Fu[PostResult] =
Msg.make(text, orig).fold[Fu[PostResult]](fuccess(PostResult.Invalid)) { msgPre =>
val threadId = MsgThread.id(orig, dest)
for {
contacts <- userRepo.contacts(orig, dest) orFail s"Missing convo contact user $orig->$dest"
isNew <- !colls.thread.exists($id(threadId))
verdict <- security.can.post(contacts, msgPre.text, isNew, unlimited = multi)
verdict <-
if (ignoreSecurity) fuccess(MsgSecurity.Ok)
else security.can.post(contacts, msgPre.text, isNew, unlimited = multi)
_ = lila.mon.msg.post(verdict.toString, isNew = isNew, multi = multi).increment()
res <- verdict match {
case MsgSecurity.Limit => fuccess(PostResult.Limited)