lila/app/controllers/ForumPost.scala

53 lines
1.6 KiB
Scala
Raw Normal View History

package controllers
import lila.app._
import views._
object ForumPost extends LilaController with ForumController {
2013-05-06 11:46:12 -06:00
def search(text: String, page: Int) = OpenBody { implicit ctx
text.trim.isEmpty.fold(
Redirect(routes.ForumCateg.index).fuccess,
Env.forumSearch(text, page, isGranted(_.StaffForum), ctx.troll) map { paginator
2013-05-06 11:46:12 -06:00
html.forum.search(text, paginator)
}
)
}
2013-05-06 11:46:12 -06:00
def recent = Open { implicit ctx
Env.forum.recent(ctx.me, teamCache.teamIds.apply) map { posts
html.forum.post.recent(posts)
}
}
2013-05-06 11:46:12 -06:00
def create(categSlug: String, slug: String, page: Int) = OpenBody { implicit ctx
CategGrantWrite(categSlug) {
implicit val req = ctx.body
2013-05-16 21:33:31 -06:00
OptionFuResult(topicApi.show(categSlug, slug, page, ctx.troll)) {
2013-05-16 20:04:26 -06:00
case (categ, topic, posts)
if (topic.closed) fuccess(BadRequest("This topic is closed"))
else forms.post.bindFromRequest.fold(
err forms.anyCaptcha map { captcha
BadRequest(html.forum.topic.show(categ, topic, posts, Some(err -> captcha)))
},
data postApi.makePost(categ, topic, data) map { post
Redirect(routes.ForumPost.redirect(post.id))
2013-05-06 11:46:12 -06:00
}
2013-05-16 20:04:26 -06:00
)
2013-05-06 11:46:12 -06:00
}
}
}
2013-05-06 11:46:12 -06:00
def delete(id: String) = Secure(_.ModerateForum) { implicit ctx
me
postApi.delete(id, me)
}
2013-05-27 09:01:19 -06:00
def redirect(id: String) = Open { implicit ctx
OptionResult(postApi.urlData(id, ctx.troll)) {
case lila.forum.PostUrlData(categ, topic, page, number)
Redirect(routes.ForumTopic.show(categ, topic, page).url + "#" + number)
}
}
}