fix display of enabled coach

This commit is contained in:
Thibault Duplessis 2016-08-28 14:38:17 +02:00
parent e54e457fb4
commit 17e24e3da7
5 changed files with 16 additions and 10 deletions

View file

@ -41,6 +41,7 @@ final class Env(
getRanks = Env.user.cached.ranking.getAll,
isHostingSimul = Env.simul.isHosting,
isStreamer = Env.tv.isStreamer.apply,
fetchIsCoach = Env.coach.api.isEnabledCoach,
insightShare = Env.insight.share,
getPlayTime = Env.game.playTime.apply,
completionRate = Env.playban.api.completionRate) _

View file

@ -28,6 +28,7 @@ case class UserInfo(
playTime: User.PlayTime,
trophies: Trophies,
isStreamer: Boolean,
isCoach: Boolean,
insightVisible: Boolean,
completionRate: Option[Double]) {
@ -41,7 +42,6 @@ case class UserInfo(
def isPublicMod = lila.security.Granter(_.PublicMod)(user)
def isDeveloper = lila.security.Granter(_.Developer)(user)
def isCoach = lila.security.Granter(_.Coach)(user)
def allTrophies = List(
isPublicMod option Trophy(
@ -76,6 +76,7 @@ object UserInfo {
getRanks: String => Fu[Map[String, Int]],
isHostingSimul: String => Fu[Boolean],
isStreamer: String => Boolean,
fetchIsCoach: User => Fu[Boolean],
insightShare: lila.insight.Share,
getPlayTime: User => Fu[User.PlayTime],
completionRate: User.ID => Fu[Option[Double]])(user: User, ctx: Context): Fu[UserInfo] =
@ -89,11 +90,12 @@ object UserInfo {
postApi.nbByUser(user.id) zip
studyRepo.countByOwner(user.id) zip
trophyApi.findByUser(user) zip
fetchIsCoach(user) zip
(user.count.rated >= 10).??(insightShare.grant(user, ctx.me)) zip
getPlayTime(user) zip
completionRate(user.id) zip
bookmarkApi.countByUser(user) flatMap {
case (((((((((((((ranks, nbPlaying), nbImported), crosstable), ratingChart), nbFollowers), nbBlockers), nbPosts), nbStudies), trophies), insightVisible), playTime), completionRate), nbBookmarks) =>
case ((((((((((((((ranks, nbPlaying), nbImported), crosstable), ratingChart), nbFollowers), nbBlockers), nbPosts), nbStudies), trophies), isCoach), insightVisible), playTime), completionRate), nbBookmarks) =>
(nbPlaying > 0) ?? isHostingSimul(user.id) map { hasSimul =>
new UserInfo(
user = user,
@ -111,6 +113,7 @@ object UserInfo {
playTime = playTime,
trophies = trophies,
isStreamer = isStreamer(user.id),
isCoach = isCoach,
insightVisible = insightVisible,
completionRate = completionRate)
}

View file

@ -21,7 +21,7 @@ case class Coach(
def hasPicture = picturePath.isDefined
def fullyEnabled = enabledByUser.value && enabledByMod.value
def isFullyEnabled = enabledByUser.value && enabledByMod.value
}
object Coach {

View file

@ -5,6 +5,7 @@ import scala.concurrent.duration._
import lila.db.dsl._
import lila.memo.AsyncCache
import lila.security.Granter
import lila.user.{ User, UserRepo }
final class CoachApi(
@ -31,8 +32,13 @@ final class CoachApi(
fuccess(Coach.WithUser(Coach make user, user).some)
}
def isEnabledCoach(user: User): Fu[Boolean] =
Granter(_.Coach)(user) ?? all.map(_.exists { c =>
c.is(user) && c.isFullyEnabled
})
def enabledWithUserList: Fu[List[Coach.WithUser]] =
all.map(_.filter(_.fullyEnabled)) flatMap { coaches =>
all.map(_.filter(_.isFullyEnabled)) flatMap { coaches =>
UserRepo.byIds(coaches.map(_.id.value)) map { users =>
coaches.flatMap { coach =>
users find coach.is map { Coach.WithUser(coach, _) }
@ -52,12 +58,8 @@ final class CoachApi(
) >> cache.clear inject "Done!"
}
private val pictureMaxMb = 3
private val pictureMaxBytes = pictureMaxMb * 1024 * 1024
private def pictureId(id: Coach.Id) = s"coach:${id.value}:picture"
def uploadPicture(c: Coach.WithUser, picture: Photographer.Uploaded): Funit =
photographer(c.coach.id, picture) flatMap { pic =>
photographer(c.coach.id, picture).flatMap { pic =>
coll.update($id(c.coach.id), $set("picturePath" -> pic.path))
} >> cache.clear

View file

@ -90,7 +90,7 @@ object ApplicationBuild extends Build {
)
lazy val coach = project("coach", Seq(
common, hub, db, user)).settings(
common, hub, db, user, security)).settings(
libraryDependencies ++= provided(play.api, RM, scrimage)
)