lila/app/controllers/ForumController.scala

41 lines
1.4 KiB
Scala
Raw Normal View History

2013-04-01 07:18:11 -06:00
package controllers
2012-05-26 08:20:59 -06:00
import play.api.mvc._, Results._
2014-04-18 03:51:19 -06:00
import lila.api.Context
2013-04-01 07:18:11 -06:00
import lila.app._
import lila.forum
2012-05-26 08:20:59 -06:00
2014-02-17 02:12:19 -07:00
private[controllers] trait ForumController extends forum.Granter { self: LilaController =>
2012-05-26 16:27:53 -06:00
protected def categApi = Env.forum.categApi
protected def topicApi = Env.forum.topicApi
protected def postApi = Env.forum.postApi
protected def forms = Env.forum.forms
protected def teamCache = Env.team.cached
2014-04-18 03:51:19 -06:00
protected def userBelongsToTeam(teamId: String, userId: String): Boolean =
2013-04-10 04:17:58 -06:00
Env.team.api.belongsTo(teamId, userId)
2012-12-13 09:37:46 -07:00
protected def userOwnsTeam(teamId: String, userId: String): Fu[Boolean] =
Env.team.api.owns(teamId, userId)
protected def CategGrantRead[A <: Result](categSlug: String)(a: => Fu[A])(implicit ctx: Context): Fu[Result] =
2012-12-13 09:37:46 -07:00
isGrantedRead(categSlug).fold(a,
fuccess(Forbidden("You cannot access to this category"))
2012-05-26 16:27:53 -06:00
)
protected def CategGrantWrite[A <: Result](categSlug: String)(a: => Fu[A])(implicit ctx: Context): Fu[Result] =
2014-04-18 03:51:19 -06:00
if (isGrantedWrite(categSlug)) a
else fuccess(Forbidden("You cannot post to this category"))
protected def CategGrantMod[A <: Result](categSlug: String)(a: => Fu[A])(implicit ctx: Context): Fu[Result] =
2014-02-17 02:12:19 -07:00
isGrantedMod(categSlug) flatMap { granted =>
(granted | isGranted(_.ModerateForum)) fold (
a,
fuccess(Forbidden("You cannot post to this category"))
)
}
2012-05-26 08:20:59 -06:00
}