parent
ac0734836f
commit
095dfbda6f
|
@ -77,14 +77,22 @@ final class ForumPost(env: Env) extends LilaController(env) with ForumController
|
|||
}
|
||||
|
||||
def delete(categSlug: String, id: String) =
|
||||
Auth { implicit ctx => me =>
|
||||
AuthBody { implicit ctx => me =>
|
||||
postApi getPost id flatMap {
|
||||
_ ?? { post =>
|
||||
if (me.id == ~post.userId && !post.erased)
|
||||
postApi.erasePost(post) inject Redirect(routes.ForumPost.redirect(id))
|
||||
else
|
||||
isGrantedMod(categSlug) flatMap { granted =>
|
||||
(granted | isGranted(_.ModerateForum)) ?? postApi.delete(categSlug, id, me) map { Ok(_) }
|
||||
(granted | isGranted(_.ModerateForum)) ?? postApi.delete(categSlug, id, me) inject {
|
||||
implicit val req = ctx.body
|
||||
for {
|
||||
userId <- post.userId
|
||||
reasonOpt <- forms.deleteWithReason.bindFromRequest().value
|
||||
reason <- reasonOpt
|
||||
} env.msg.api.systemPost(userId, lila.msg.MsgPreset forumDeletion reason)
|
||||
NoContent
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -167,7 +167,7 @@ object topic {
|
|||
if (topic.isSticky) "Unsticky" else "Sticky"
|
||||
)
|
||||
),
|
||||
deleteDialog
|
||||
deleteModal
|
||||
)
|
||||
)
|
||||
),
|
||||
|
@ -203,15 +203,15 @@ object topic {
|
|||
)
|
||||
}
|
||||
|
||||
private def deleteDialog(implicit ctx: Context) =
|
||||
private def deleteModal(implicit ctx: Context) =
|
||||
div(cls := "forum-delete-modal none")(
|
||||
p("Delete the post"),
|
||||
st.form(method := "dialog", cls := "form3")(
|
||||
st.form(method := "post", cls := "form3")(
|
||||
st.select(
|
||||
name := "reason",
|
||||
cls := "form-control"
|
||||
)(
|
||||
option(value := "")("No message"),
|
||||
option(value := "")("no message"),
|
||||
List(
|
||||
"public shaming",
|
||||
"disrespecting other players",
|
||||
|
|
|
@ -41,6 +41,10 @@ final private[forum] class ForumForm(
|
|||
)(TopicData.apply)(TopicData.unapply)
|
||||
)
|
||||
|
||||
val deleteWithReason = Form(
|
||||
single("reason" -> optional(nonEmptyText))
|
||||
)
|
||||
|
||||
private def userTextMapping(user: User, inOwnTeam: Boolean) =
|
||||
cleanText(minLength = 3)
|
||||
.verifying(
|
||||
|
|
|
@ -37,4 +37,7 @@ To follow new players, you must first unfollow some on https://lichess.org/@/$us
|
|||
|
||||
Thank you for your understanding."""
|
||||
)
|
||||
|
||||
def forumDeletion(reason: String) =
|
||||
s"""A moderator deleted one of your posts for this reason: $reason. Please read our Forum-Etiquette: https://lichess.org/page/forum-etiquette"""
|
||||
}
|
||||
|
|
|
@ -4,11 +4,17 @@ import modal from 'common/modal';
|
|||
lichess.load.then(() => {
|
||||
$('.forum')
|
||||
.on('click', 'a.delete', function (this: HTMLAnchorElement) {
|
||||
console.log(this);
|
||||
const link = this;
|
||||
const $wrap = modal($('.forum-delete-modal'));
|
||||
$wrap.find('form').attr('action', this.href);
|
||||
// xhr.text(this.href, { method: 'post' });
|
||||
// $(this).closest('.forum-post').hide();
|
||||
$wrap
|
||||
.find('form')
|
||||
.attr('action', link.href)
|
||||
.on('submit', function (this: HTMLFormElement, e: Event) {
|
||||
e.preventDefault();
|
||||
xhr.formToXhr(this);
|
||||
modal.close();
|
||||
$(link).closest('.forum-post').hide();
|
||||
});
|
||||
return false;
|
||||
})
|
||||
.on('click', 'form.unsub button', function (this: HTMLButtonElement) {
|
||||
|
|
Loading…
Reference in New Issue