show emails in mod user lists

pull/5335/head
Thibault Duplessis 2019-07-22 12:48:52 +02:00
parent 8eaf995f01
commit b491b34547
6 changed files with 45 additions and 18 deletions

View File

@ -4,10 +4,10 @@ import lila.api.{ Context, BodyContext }
import lila.app._
import lila.chat.Chat
import lila.common.{ IpAddress, EmailAddress, HTTPRequest }
import lila.mod.UserSearch
import lila.report.{ Suspect, Mod => AsMod, SuspectId }
import lila.security.Permission
import lila.user.{ UserRepo, User => UserModel, Title }
import lila.mod.UserSearch
import ornicar.scalalib.Zero
import views._
@ -181,15 +181,17 @@ object Mod extends LilaController {
(Env.security userSpy user) zip
Env.user.noteApi.forMod(user.id) zip
Env.mod.logApi.userHistory(user.id) zip
Env.report.api.inquiries.ofModId(me.id) map {
Env.report.api.inquiries.ofModId(me.id) flatMap {
case chats ~ threads ~ publicLines ~ spy ~ notes ~ history ~ inquiry =>
if (priv && !inquiry.??(_.isRecentCommOf(Suspect(user))))
Env.slack.api.commlog(mod = me, user = user, inquiry.map(_.oldestAtom.by.value))
val povWithChats = (povs zip chats) collect {
case (p, Some(c)) if c.nonEmpty => p -> c
} take 15
val filteredNotes = notes.filter(_.from != "irwin")
html.mod.communication(user, povWithChats, threads, publicLines, spy, filteredNotes, history, priv)
lila.security.UserSpy.withMeSortedWithEmails(user, spy.otherUsers) map { othersWithEmail =>
if (priv && !inquiry.??(_.isRecentCommOf(Suspect(user))))
Env.slack.api.commlog(mod = me, user = user, inquiry.map(_.oldestAtom.by.value))
val povWithChats = (povs zip chats) collect {
case (p, Some(c)) if c.nonEmpty => p -> c
} take 15
val filteredNotes = notes.filter(_.from != "irwin")
html.mod.communication(user, povWithChats, threads, publicLines, spy, othersWithEmail, filteredNotes, history, priv)
}
}
}
}

View File

@ -288,8 +288,9 @@ object User extends LilaController {
val others = spyFu flatMap { spy =>
val familyUserIds = user.id :: spy.otherUserIds.toList
Env.user.noteApi.forMod(familyUserIds).logTimeIfGt(s"$username noteApi.forMod", 2 seconds) zip
Env.playban.api.bans(familyUserIds).logTimeIfGt(s"$username playban.bans", 2 seconds) map {
case notes ~ bans => html.user.mod.otherUsers(user, spy, notes, bans).some
Env.playban.api.bans(familyUserIds).logTimeIfGt(s"$username playban.bans", 2 seconds) zip
lila.security.UserSpy.withMeSortedWithEmails(user, spy.otherUsers) map {
case notes ~ bans ~ othersWithEmail => html.user.mod.otherUsers(user, spy, othersWithEmail, notes, bans).some
}
}
val identification = spyFu map { spy =>

View File

@ -16,6 +16,7 @@ object communication {
threads: List[lila.message.Thread],
publicLines: List[lila.shutup.PublicLine],
spy: lila.security.UserSpy,
otherWithEmails: lila.security.UserSpy.WithMeSortedWithEmails,
notes: List[lila.user.Note],
history: List[lila.mod.Modlog],
priv: Boolean
@ -131,6 +132,7 @@ object communication {
thead(
tr(
th(spy.otherUsers.size, " similar user(s)"),
th("Email"),
th("Same"),
th("Games"),
th("Marks"),
@ -140,9 +142,10 @@ object communication {
)
),
tbody(
spy.withMeSorted(u).map {
otherWithEmails.others.map {
case lila.security.UserSpy.OtherUser(o, byIp, byFp) => tr(cls := (o == u).option("same"))(
td(userLink(o, withBestRating = true, params = "?mod")),
td(otherWithEmails emailValueOf o),
td(
if (o == u) " - "
else List(byIp option "IP", byFp option "Print").flatten.mkString(", ")

View File

@ -318,12 +318,13 @@ object mod {
)
)
def otherUsers(u: User, spy: lila.security.UserSpy, notes: List[lila.user.Note], bans: Map[String, Int])(implicit ctx: Context): Frag =
def otherUsers(u: User, spy: lila.security.UserSpy, othersWithEmail: lila.security.UserSpy.WithMeSortedWithEmails, notes: List[lila.user.Note], bans: Map[String, Int])(implicit ctx: Context): Frag =
div(id := "mz_others")(
table(cls := "slist")(
thead(
tr(
th(spy.otherUsers.size, " similar user(s)"),
th("Email"),
th("Same"),
th(attr("data-sort-method") := "number")("Games"),
th("Status"),
@ -332,10 +333,11 @@ object mod {
)
),
tbody(
spy.withMeSorted(u).map {
othersWithEmail.others.map {
case lila.security.UserSpy.OtherUser(o, byIp, byFp) => {
tr((o == u) option (cls := "same"))(
td(attr("data-sort") := o.id)(userLink(o, withBestRating = true, params = "?mod")),
td(othersWithEmail emailValueOf o),
td(
if (o == u) "-"
else List(byIp option "IP", byFp option "Print").flatten.mkString(", ")

View File

@ -4,7 +4,7 @@ import org.joda.time.DateTime
import reactivemongo.api.ReadPreference
import scala.collection.breakOut
import lila.common.IpAddress
import lila.common.{ IpAddress, EmailAddress }
import lila.db.dsl._
import lila.user.{ User, UserRepo }
@ -31,9 +31,6 @@ case class UserSpy(
}
}
def withMeSorted(me: User): List[OtherUser] =
(OtherUser(me, true, true) :: otherUsers.toList).sortBy(-_.user.createdAt.getMillis)
def otherUserIds = otherUsers.map(_.user.id)
}
@ -121,4 +118,18 @@ object UserSpy {
type Value = String
case class IPData(ip: Dated[IpAddress], blocked: Boolean, location: Location)
case class WithMeSortedWithEmails(others: List[OtherUser], emails: Map[User.ID, EmailAddress]) {
def emailValueOf(u: User) = emails.get(u.id).map(_.value)
}
def withMeSortedWithEmails(me: User, others: Set[OtherUser]): Fu[WithMeSortedWithEmails] = {
val othersList = others.toList
lila.user.UserRepo.emailMap(me.id :: othersList.map(_.user.id)) map { emailMap =>
WithMeSortedWithEmails(
(OtherUser(me, true, true) :: othersList).sortBy(-_.user.createdAt.getMillis),
emailMap
)
}
}
}

View File

@ -422,6 +422,14 @@ object UserRepo {
}
}
def emailMap(names: List[String]): Fu[Map[User.ID, EmailAddress]] =
coll.find($inIds(names map normalize), $doc(F.verbatimEmail -> true, F.email -> true))
.list[Bdoc](none, ReadPreference.secondaryPreferred).map { docs =>
docs.flatMap { doc =>
anyEmail(doc) map { ~doc.getAs[User.ID](F.id) -> _ }
}(collection.breakOut)
}
def hasEmail(id: ID): Fu[Boolean] = email(id).map(_.isDefined)
def setBot(user: User): Funit =