2013-04-01 07:18:11 -06:00
|
|
|
package controllers
|
2012-05-26 08:20:59 -06:00
|
|
|
|
2017-01-15 05:26:08 -07:00
|
|
|
import play.api.mvc._
|
2013-05-28 07:53:32 -06:00
|
|
|
|
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
|
|
|
|
2019-12-04 16:39:16 -07:00
|
|
|
protected def categApi = env.forum.categApi
|
|
|
|
protected def topicApi = env.forum.topicApi
|
2019-12-13 07:30:20 -07:00
|
|
|
protected def postApi = env.forum.postApi
|
|
|
|
protected def forms = env.forum.forms
|
2013-05-06 08:51:19 -06:00
|
|
|
|
2019-12-04 16:39:16 -07:00
|
|
|
protected def teamCache = env.team.cached
|
2013-05-06 08:51:19 -06:00
|
|
|
|
2017-01-25 03:41:08 -07:00
|
|
|
protected def userBelongsToTeam(teamId: String, userId: String): Fu[Boolean] =
|
2019-12-04 16:39:16 -07:00
|
|
|
env.team.api.belongsTo(teamId, userId)
|
2012-12-13 09:37:46 -07:00
|
|
|
|
2013-05-28 07:53:32 -06:00
|
|
|
protected def userOwnsTeam(teamId: String, userId: String): Fu[Boolean] =
|
2020-04-23 17:47:20 -06:00
|
|
|
env.team.api.leads(teamId, userId)
|
2013-05-28 07:53:32 -06:00
|
|
|
|
2019-12-13 07:30:20 -07:00
|
|
|
protected def CategGrantWrite[A <: Result](
|
|
|
|
categSlug: String
|
|
|
|
)(a: => Fu[A])(implicit ctx: Context): Fu[Result] =
|
2017-01-25 03:41:08 -07:00
|
|
|
isGrantedWrite(categSlug) flatMap { granted =>
|
|
|
|
if (granted) a
|
|
|
|
else fuccess(Forbidden("You cannot post to this category"))
|
|
|
|
}
|
2013-05-28 07:53:32 -06:00
|
|
|
|
2019-12-13 07:30:20 -07:00
|
|
|
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 =>
|
2018-07-20 03:41:46 -06:00
|
|
|
if (granted | isGranted(_.ModerateForum)) a
|
|
|
|
else fuccess(Forbidden("You cannot post to this category"))
|
2013-05-28 07:53:32 -06:00
|
|
|
}
|
2012-05-26 08:20:59 -06:00
|
|
|
}
|