Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for public mods to display icon in forum/qa #3255

Merged
merged 3 commits into from
Jul 9, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/templating/ForumHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ trait ForumHelper { self: UserHelper with StringHelper =>
def authorLink(
post: Post,
cssClass: Option[String] = None,
withOnline: Boolean = true
withOnline: Boolean = true,
modIcon: Boolean = false
) = post.userId.fold(Html(lila.user.User.anonymous)) { userId =>
userIdLink(userId.some, cssClass = cssClass, withOnline = withOnline)
userIdLink(userId.some, cssClass = cssClass, withOnline = withOnline, modIcon = modIcon)
}
}
15 changes: 10 additions & 5 deletions app/templating/UserHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ trait UserHelper { self: I18nHelper with StringHelper with NumberHelper =>
withOnline: Boolean = true,
withTitle: Boolean = true,
truncate: Option[Int] = None,
params: String = ""
params: String = "",
modIcon: Boolean = false
): Html = Html {
userIdOption.flatMap(lightUser).fold(User.anonymous) { user =>
userIdNameLink(
Expand All @@ -94,7 +95,8 @@ trait UserHelper { self: I18nHelper with StringHelper with NumberHelper =>
withOnline = withOnline,
withTitle = withTitle,
truncate = truncate,
params = params
params = params,
modIcon = modIcon
)
}
}
Expand All @@ -116,7 +118,8 @@ trait UserHelper { self: I18nHelper with StringHelper with NumberHelper =>
withOnline = withOnline,
withTitle = withTitle,
truncate = truncate,
params = params
params = params,
modIcon = false
)
}

Expand All @@ -139,13 +142,14 @@ trait UserHelper { self: I18nHelper with StringHelper with NumberHelper =>
withTitle: Boolean,
truncate: Option[Int],
title: Option[String],
params: String
params: String,
modIcon: Boolean
): String = {
val klass = userClass(userId, cssClass, withOnline)
val href = userHref(username, params = params)
val content = truncate.fold(username)(username.take)
val titleS = if (withTitle) titleTag(title) else ""
val icon = withOnline ?? lineIcon(isPatron)
val icon = withOnline ?? (if (modIcon) moderatorIcon else lineIcon(isPatron))
s"""<a $klass $href>$icon$titleS$content</a>"""
}

Expand Down Expand Up @@ -276,6 +280,7 @@ trait UserHelper { self: I18nHelper with StringHelper with NumberHelper =>

val lineIcon: String = """<i class="line"></i>"""
val patronIcon: String = """<i class="line patron" title="lichess Patron"></i>"""
val moderatorIcon: String = """<i class="line moderator" title="lichess Moderator"></i>"""
private def lineIcon(patron: Boolean): String = if (patron) patronIcon else lineIcon
private def lineIcon(user: Option[LightUser]): String = lineIcon(user.??(_.isPatron))
def lineIcon(user: User): String = lineIcon(user.isPatron)
Expand Down
3 changes: 3 additions & 0 deletions app/views/forum/topic/form.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ <h1 data-icon="!"> Important</h1>
@forum.post.formFields(form("post")("text"), form("post")("author"), None)
@base.captcha(form("post")("move"), form("post")("gameId"), captcha)
@errMsg(form("post"))
@if(isGranted(_.PublicMod)){
<div class="submit"><input type="checkbox" name="post.modIcon" value="true" /> Show moderator icon next to my name</div>
}
<button class="submit button" type="submit" data-icon="E"> @trans.createTheTopic()</button>
<a href="@routes.ForumCateg.show(categ.slug)" style="margin-left:20px">@trans.cancel()</a>
</form>
Expand Down
5 changes: 4 additions & 1 deletion app/views/forum/topic/show.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@posts.currentPageResults.map { post =>
<div class="post" id="@post.number">
<div class="metas clearfix">
@authorLink(post, "author".some)
@authorLink(post=post, cssClass="author".some, modIcon=post.displayModIcon)

@post.updatedAt.map { updatedAt =>
<span class="post-edited">edited</span>
Expand Down Expand Up @@ -104,6 +104,9 @@ <h2 class="postNewTitle" id="reply">@trans.replyToThisTopic()</h2>
@forum.post.formFields(form("text"), form("author"), topic.some)
@base.captcha(form("move"), form("gameId"), captcha)
@globalError(form)
@if(isGranted(_.PublicMod)){
<div class="submit"><input type="checkbox" name="modIcon" value="true" /> Show moderator icon next to my name</div>
}
<button type="submit" class="submit button" data-icon="E"> @trans.reply()</button>
<a href="@routes.ForumCateg.show(categ.slug)" style="margin-left:20px">@trans.cancel()</a>
</form>
Expand Down
2 changes: 1 addition & 1 deletion app/views/qa/answerList.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<div class="content">
<div class="answer">
<div class="meta">
<span class="light">Answered @momentFromNow(a.createdAt) by @userIdLink(a.userId.some)</span>
<span class="light">Answered @momentFromNow(a.createdAt) by @userIdLink(userIdOption=a.userId.some, modIcon=a.displayModIcon)</span>
@if(lila.qa.QaAuth canEdit a) {
<a class="thin button toggle-edit-answer" data-icon="m"> Edit</a>
}
Expand Down
3 changes: 3 additions & 0 deletions app/views/qa/questionShow.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ <h1 class="lichess_title">
<textarea class="answer-body" name="@form("body").name">@form("body").value</textarea>
@errMsg(form("body"))
@base.captcha(form("move"), form("gameId"), captcha)
@if(isGranted(_.PublicMod)){
<div class="submit"><input type="checkbox" name="modIcon" value="true" /> Show moderator icon next to my name</div>
}
<button class="pure submit button" type="submit">Post your answer</button>
</form>
</div>
Expand Down
3 changes: 2 additions & 1 deletion modules/forum/src/main/CategApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ private[forum] final class CategApi(env: Env) {
troll = false,
hidden = topic.hidden,
lang = "en".some,
categId = categ.id
categId = categ.id,
modIcon = None
)
env.categColl.insert(categ).void >>
env.postColl.insert(post).void >>
Expand Down
6 changes: 4 additions & 2 deletions modules/forum/src/main/DataForm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ private[forum] final class DataForm(val captcher: akka.actor.ActorSelection) ext
"text" -> text(minLength = 3),
"author" -> optional(text),
"gameId" -> text,
"move" -> text
"move" -> text,
"modIcon" -> optional(boolean)
)(PostData.apply)(PostData.unapply)
.verifying(captchaFailMessage, validateCaptcha _)

Expand All @@ -33,7 +34,8 @@ object DataForm {
text: String,
author: Option[String],
gameId: String,
move: String
move: String,
modIcon: Option[Boolean]
)

case class TopicData(
Expand Down
11 changes: 8 additions & 3 deletions modules/forum/src/main/Post.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ case class Post(
lang: Option[String],
editHistory: Option[List[OldVersion]] = None,
createdAt: DateTime,
updatedAt: Option[DateTime] = None
updatedAt: Option[DateTime] = None,
modIcon: Option[Boolean]
) {

private val permitEditsFor = 4 hours
Expand Down Expand Up @@ -59,6 +60,8 @@ case class Post(
}

def hasEdits = editHistory.isDefined

def displayModIcon = ~modIcon
}

object Post {
Expand All @@ -77,7 +80,8 @@ object Post {
number: Int,
lang: Option[String],
troll: Boolean,
hidden: Boolean
hidden: Boolean,
modIcon: Option[Boolean]
): Post = {

Post(
Expand All @@ -92,7 +96,8 @@ object Post {
troll = troll,
hidden = hidden,
createdAt = DateTime.now,
categId = categId
categId = categId,
modIcon = modIcon
)
}
}
3 changes: 2 additions & 1 deletion modules/forum/src/main/PostApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ final class PostApi(
lang = lang map (_.language),
troll = ctx.troll,
hidden = topic.hidden,
categId = categ.id
categId = categ.id,
modIcon = (data.modIcon.getOrElse(false) && ctx.me.map(MasterGranter(_.PublicMod)).getOrElse(false)).fold(Some(true), None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

booleanOption.getOrElse(false) == ~booleanOption (twice)
.fold(Some(a), None) == .option(a)

)
PostRepo findDuplicate post flatMap {
case Some(dup) => fuccess(dup)
Expand Down
3 changes: 2 additions & 1 deletion modules/forum/src/main/TopicApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ private[forum] final class TopicApi(
text = lila.security.Spam.replace(data.post.text),
lang = lang map (_.language),
number = 1,
categId = categ.id
categId = categ.id,
modIcon = (data.post.modIcon.getOrElse(false) && ctx.me.map(MasterGranter(_.PublicMod)).getOrElse(false)).fold(Some(true), None)
)
env.postColl.insert(post) >>
env.topicColl.insert(topic withPost post) >>
Expand Down
6 changes: 4 additions & 2 deletions modules/qa/src/main/DataForm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ private[qa] final class DataForm(
"body" -> nonEmptyText(minLength = 30)
.verifying(languageMessage, validateLanguage _),
"gameId" -> text,
"move" -> text
"move" -> text,
"modIcon" -> optional(boolean)
)(AnswerData.apply)(AnswerData.unapply)
.verifying(captchaFailMessage, validateCaptcha _)
)
Expand Down Expand Up @@ -82,7 +83,8 @@ private[qa] case class QuestionData(
private[qa] case class AnswerData(
body: String,
gameId: String,
move: String
move: String,
modIcon: Option[Boolean]
)

private[qa] case class CommentData(body: String)
8 changes: 5 additions & 3 deletions modules/qa/src/main/QaApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import org.joda.time.DateTime
import lila.common.paginator._
import lila.db.dsl._
import lila.db.paginator._
import lila.user.User
import lila.user.{ User, UserContext }
import lila.security.Granter

final class QaApi(
questionColl: Coll,
Expand Down Expand Up @@ -161,7 +162,7 @@ final class QaApi(
private implicit val voteBSONHandler = Macros.handler[Vote]
private implicit val answerBSONHandler = Macros.handler[Answer]

def create(data: AnswerData, q: Question, user: User): Fu[Answer] =
def create(data: AnswerData, q: Question, user: User)(implicit ctx: UserContext): Fu[Answer] =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the context needed here? We already have the user who posts the answer.

lila.db.Util findNextId answerColl flatMap { id =>
val a = Answer(
_id = id,
Expand All @@ -172,7 +173,8 @@ final class QaApi(
comments = Nil,
acceptedAt = None,
createdAt = DateTime.now,
editedAt = None
editedAt = None,
modIcon = (data.modIcon.getOrElse(false) && ctx.me.map(Granter(_.PublicMod)).getOrElse(false)).fold(Some(true), None)
)

(answerColl insert a) >>
Expand Down
5 changes: 4 additions & 1 deletion modules/qa/src/main/model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ case class Answer(
comments: List[Comment],
acceptedAt: Option[DateTime],
createdAt: DateTime,
editedAt: Option[DateTime]
editedAt: Option[DateTime],
modIcon: Option[Boolean]
) {

def id = _id
Expand All @@ -60,6 +61,8 @@ case class Answer(
def editNow = copy(editedAt = Some(DateTime.now))

def userIds = userId :: comments.map(_.userId)

def displayModIcon = ~modIcon
}

case class AnswerWithQuestion(answer: Answer, question: Question)
Expand Down
3 changes: 3 additions & 0 deletions public/stylesheets/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ time {
.user_link .line.patron::before {
content: '';
}
.user_link .line.moderator::before {
content: '';
}

body.blind_mode .is::before,
body.blind_mode .is::after,
Expand Down