Skip to content

Commit

Permalink
mod inquiry WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed May 9, 2017
1 parent 0d7fead commit 40b6502
Show file tree
Hide file tree
Showing 15 changed files with 201 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/controllers/LilaController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private[controllers] trait LilaController
Env.team.api.nbRequests(me.id) zip
Env.challenge.api.countInFor.get(me.id) zip
Env.notifyModule.api.unreadCount(Notifies(me.id)).dmap(_.value) zip
Granter(_.Hunter)(me).??(Env.report.api.inquiries.ofModId(me.id))
Env.mod.inquiryApi.forMod(me)
} else fuccess {
((((OnlineFriends.empty, 0), 0), 0), none)
}
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/Report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ object Report extends LilaController {
Ok(html.report.list(reports, reason, counts))
}

def inquiry(id: String) = Secure(_.SeeReport) { implicit ctx => me =>
api.inquiries.toggle(me, id) inject Redirect(routes.Report.list)
}

def process(id: String) = Secure(_.SeeReport) { implicit ctx => me =>
api.process(id, me) inject Redirect(routes.Report.list)
}
Expand Down
4 changes: 4 additions & 0 deletions app/views/base/layout.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
}
@if(ctx.pref.is3d) { @cssTag("board-3d.css") }
@if(ctx.pref.coords == 1) { @cssTag("board.coords.inner.css") }
@if(ctx.pageData.inquiry.isDefined) { @cssTag("inquiry.css") }
@moreCss
<link id="piece-sprite" href="@staticUrl(s"stylesheets/piece/${ctx.currentPieceSet}.css?v=${ctx.pageData.assetVersion}")" type="text/css" rel="stylesheet"/>
<meta content="@openGraph.fold(trans.freeOnlineChessGamePlayChessNowInACleanInterfaceNoRegistrationNoAdsNoPluginRequiredPlayChessWithComputerFriendsOrRandomOpponents())(o => Html(escapeHtml(o.description)))" name="description">
Expand Down Expand Up @@ -80,6 +81,9 @@
<button type="submit">Accessibility: @ctx.blindMode.fold("Disable", "Enable") blind mode</button>
</form>
<div id="site_description">@trans.freeOnlineChessGamePlayChessNowInACleanInterfaceNoRegistrationNoAdsNoPluginRequiredPlayChessWithComputerFriendsOrRandomOpponents()</div>
@ctx.pageData.inquiry.map { inquiry =>
@mod.inquiry(inquiry)
}
<div id="top" class="@ctx.pref.is3d.fold("is3d", "is2d")">
@topmenu()
<div id="ham-plate" class="link hint--bottom" data-hint="@trans.menu()">
Expand Down
46 changes: 46 additions & 0 deletions app/views/mod/inquiry.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@(in: lila.mod.Inquiry)(implicit ctx: Context)

<div class="inquiry">
<i class="icon"></i>
<div class="meat">
<h2 class="user">
@Html(userLink(in.user, withBestRating = true).body.replace("<a ", "<a data-pt-pos=\"se\" "))
</h2>
<div class="report">
<h3>Reported by @userIdLink(in.report.createdBy.some, withOnline = false) for @in.report.reason.name</h3>
<p>@autoLink(in.report.text.replace("\n", " "))</p>
</div>
</div>
<div class="links">
@if(isGranted(_.MarkTroll)) {
<a href="@routes.Mod.communication(in.user.id)">View Coms</a>
}
<a href="@routes.User.show(in.user.username)?mod">Mod tools</a>
</div>
<div class="actions">
@if(isGranted(_.MarkEngine)) {
<form method="post" action="@routes.Mod.engine(in.user.username)" data-hint="This user is clearly cheating." class="hint--bottom-left">
<input class="fbt@when(in.user.engine, " active")" type="submit" value="Engine" />
</form>
}
@if(isGranted(_.MarkBooster)) {
<form method="post" action="@routes.Mod.booster(in.user.username)" data-hint="Marks the user as a booster or sandbagger." class="hint--bottom-left">
<input class="fbt@when(in.user.booster, " active")" type="submit" value="Booster" />
</form>
}
@if(isGranted(_.MarkTroll)) {
<form method="post" action="@routes.Mod.troll(in.user.username)?set=@(if (in.user.troll){0}else{1})" data-hint="@if(in.user.troll){En}else{Dis}able communication features for this user." class="hint--bottom-left">
<input class="fbt@when(in.user.troll, " active")" type="submit" value="Shadowban" />
</form>
}
</div>
<div class="actions close">
<form action="@routes.Report.process(in.report.id)" method="post" data-hint="Dismiss this report as processed." class="hint--bottom-left">
<button type="submit" data-icon="E" class="fbt"></button>
</form>
<form action="@routes.Report.inquiry(in.report.id)" method="post" data-hint="Cancel the inquiry, re-instore the report" class="hint--bottom-left">
<button type="submit" data-icon="L" class="fbt"></button>
</form>
</div>
</div>
</div>
17 changes: 3 additions & 14 deletions app/views/report/list.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@

@title = @{ "Reports" }

@moreJs = {
<script>
$('#report_list form').submit(function() {
$.post($(this).attr('action'));
$(this).parents('tr').removeClass('new').end().remove();
return false;
});
</script>
}

@tab(reports: List[WithUserAndNotes], reason: lila.report.Reason) = {
<a href="@routes.Report.listWithFilter(reason.key)"
class="@when(counts.contains(reason), "new") @filter.active(reason.key)"
Expand All @@ -23,8 +13,7 @@
@mod.layout(
title = title,
active = "report",
moreCss = cssTag("report.css"),
moreJs = moreJs) {
moreCss = cssTag("report.css")) {

<div id="report_list" class="content_box no_padding">
<div class="header">
Expand Down Expand Up @@ -68,8 +57,8 @@ <h1 data-icon="@icon.mod" class="text">@title</h1>
</td>
<td>@r.processedBy.map { u =>
}.getOrElse {
<form action="@routes.Report.process(r.id)" method="post" data-hint="Dismiss this report as processed." class="hint--bottom-left">
<button type="submit" data-icon="E" class="button"></button>
<form action="@routes.Report.inquiry(r.id)" method="post" data-hint="Start an inquiry" class="hint--bottom-left">
<button type="submit" data-icon="G" class="button"></button>
</form>
}
</td>
Expand Down
1 change: 1 addition & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ POST /report controllers.Report.create
GET /report/thanks controllers.Report.thanks(reported: String)
GET /report/list controllers.Report.list
GET /report/list/:reason controllers.Report.listWithFilter(reason: String)
POST /report/:id/inquiry controllers.Report.inquiry(id: String)
POST /report/:id/process controllers.Report.process(id: String)

# QA
Expand Down
2 changes: 1 addition & 1 deletion modules/api/src/main/Context.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ case class PageData(
blindMode: Boolean,
hasFingerprint: Boolean,
assetVersion: AssetVersion,
inquiry: Option[lila.report.Report]
inquiry: Option[lila.mod.Inquiry]
)

object PageData {
Expand Down
2 changes: 2 additions & 0 deletions modules/mod/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ final class Env(
reportApi = reportApi
)

lazy val inquiryApi = new InquiryApi(reportApi)

// api actor
system.lilaBus.subscribe(system.actorOf(Props(new Actor {
def receive = {
Expand Down
34 changes: 34 additions & 0 deletions modules/mod/src/main/Inquiry.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package lila.mod

import play.api.libs.json._

import lila.common.LightUser
import lila.report.{ Report, ReportApi }
import lila.user.{ User, UserRepo }

case class Inquiry(
mod: LightUser,
report: Report,
user: User
)

final class InquiryApi(reportApi: ReportApi) {

def forMod(mod: User): Fu[Option[Inquiry]] =
lila.security.Granter(_.Hunter)(mod).?? {
reportApi.inquiries.ofModId(mod.id).flatMap {
_ ?? { report =>
UserRepo named report.user map {
_ ?? { user =>
Inquiry(mod.light, report, user).some
}
}
}
}
}

import lila.common.LightUser.lightUserWrites
import lila.report.JsonView.reportWrites
import lila.user.JsonView.modWrites
val inquiryWrites = Json.writes[Inquiry]
}
8 changes: 0 additions & 8 deletions modules/report/src/main/Inquiry.scala

This file was deleted.

2 changes: 1 addition & 1 deletion modules/report/src/main/JsonView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import play.api.libs.json._
object JsonView {

private implicit val reasonWrites = Writes[Reason] { v => JsString(v.key) }
private implicit val inquiryWrites: Writes[Inquiry] = Json.writes[Inquiry]
private implicit val inquiryWrites: Writes[Report.Inquiry] = Json.writes[Report.Inquiry]

implicit val reportWrites: Writes[Report] = Json.writes[Report]
}
4 changes: 3 additions & 1 deletion modules/report/src/main/Report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ case class Report(
user: User.ID, // the reportee
reason: Reason,
text: String,
inquiry: Option[Inquiry],
inquiry: Option[Report.Inquiry],
processedBy: Option[User.ID],
createdAt: DateTime,
createdBy: User.ID
Expand Down Expand Up @@ -48,6 +48,8 @@ case class Report(

object Report {

case class Inquiry(mod: User.ID, seenAt: DateTime)

case class WithUser(report: Report, user: User, isOnline: Boolean) {

def urgency: Int =
Expand Down
20 changes: 16 additions & 4 deletions modules/report/src/main/ReportApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ final class ReportApi(

import lila.db.BSON.BSONJodaDateTimeHandler
private implicit val ReasonBSONHandler = isoHandler[Reason, String, BSONString](Reason.reasonIso)
import Report.Inquiry
private implicit val InquiryBSONHandler = Macros.handler[Inquiry]
private implicit val ReportBSONHandler = Macros.handler[Report]

Expand Down Expand Up @@ -129,8 +130,7 @@ final class ReportApi(
coll.update(
$doc(
"user" -> report.user,
"reason" -> report.reason,
"processedBy" $exists false
"reason" -> report.reason
),
$set("processedBy" -> by.id) ++ $unset("inquiry"),
multi = true
Expand All @@ -148,7 +148,7 @@ final class ReportApi(
"reason" $in List(Reason.Cheat.key, Reason.CheatPrint.key),
"processedBy" $exists false
),
$set("processedBy" -> byModId) ++ $unset("inquiry"),
$set("processedBy" -> byModId),
multi = true
).void >>- {
monitorUnprocessed
Expand All @@ -161,7 +161,7 @@ final class ReportApi(
"reason" $in List(Reason.Insult.key, Reason.Troll.key, Reason.Other.key),
"processedBy" $exists false
),
$set("processedBy" -> byModId) ++ $unset("inquiry"),
$set("processedBy" -> byModId),
multi = true
).void >>- monitorUnprocessed

Expand Down Expand Up @@ -264,6 +264,18 @@ final class ReportApi(
def all: Fu[List[Report]] = coll.list[Report]($doc("inquiry.mod" $exists true))

def ofModId(modId: User.ID): Fu[Option[Report]] = coll.uno[Report]($doc("inquiry.mod" -> modId))

def toggle(mod: User, id: String): Funit =
ofModId(mod.id) flatMap { current =>
current.??(cancel) >>
(!current.exists(_.id == id) ?? coll.updateField(
$id(id),
"inquiry",
Report.Inquiry(mod.id, DateTime.now)
).void)
}

def cancel(report: Report): Funit = coll.unsetField($id(report.id), "inquiry").void
}

private def findRecent(nb: Int, selector: Bdoc) =
Expand Down
1 change: 1 addition & 0 deletions public/images/icons/octopus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions public/stylesheets/inquiry.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
.inquiry {
height: 40px;
background: #444;
color: #f0f0f0!important;
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
border-bottom: 1px solid #666;
margin-bottom: 5px;
box-shadow: 2px 5px 6px rgba(0, 0, 0, 0.3);
}
.inquiry > .icon {
flex: 0 0 160px;
height: 160px;
width: 160px;
margin: -80px 0 0 -80px;
background: #444 no-repeat url(../images/icons/octopus.svg);
background-size: 37% 37%;
background-position: 82% 82%;
border-radius: 0 0 50% 0;
border: 2px solid #666;
box-shadow: 3px 3px 6px rgba(0, 0, 0, 0.3);
}
.inquiry a {
color: #f0f0f0!important;
}
.inquiry .meat {
flex: 1 1 100%;
height: 100%;
display: flex;
flex-flow: row nowrap;
align-items: center;
overflow: hidden;
}
.inquiry h2 .user_link {
font-size: 1.3em;
}
.inquiry .report {
margin: 0 20px;
opacity: 0.8;
}
.inquiry .report h3 {
margin: 0;
}
.inquiry .report p {
white-space: nowrap;
overflow: hidden;
font-style: italic;
}
.inquiry .actions,
.inquiry .links {
margin-right: 10px;
white-space: nowrap;
height: 100%;
display: flex;
flex-flow: row nowrap;
align-items: center;
}
.inquiry .actions:not(.close),
.inquiry .links {
padding-right: 10px;
border-right: 1px solid #666;
}
.inquiry .actions form {
height: 100%;
}
.inquiry .fbt {
height: 100%;
background: #444;
color: #f0f0f0!important;
}
.inquiry .fbt.active {
color: #fff!important;
}
.inquiry .links {
padding: 0 10px;
border-left: 1px solid #666;
}
.inquiry .links a {
padding: 10px 13px;
}
.inquiry .links a:hover {
color: #3893E8!important;
}

0 comments on commit 40b6502

Please sign in to comment.