lila/modules/insight/src/main/Share.scala

27 lines
775 B
Scala
Raw Normal View History

2015-11-26 21:05:59 -07:00
package lila.insight
import lila.pref.Pref
import lila.security.Granter
2015-11-26 21:05:59 -07:00
import lila.user.User
final class Share(
2019-12-03 12:15:15 -07:00
prefApi: lila.pref.PrefApi,
relationApi: lila.relation.RelationApi
)(implicit ec: scala.concurrent.ExecutionContext) {
2015-11-26 21:05:59 -07:00
def getPrefId(insighted: User) = prefApi.getPref(insighted.id, _.insightShare)
2015-11-28 09:04:10 -07:00
def grant(insighted: User, to: Option[User]): Fu[Boolean] =
2018-03-16 17:20:53 -06:00
if (to ?? Granter(_.SeeInsight)) fuTrue
2019-12-13 07:30:20 -07:00
else
getPrefId(insighted) flatMap {
case _ if to.contains(insighted) => fuTrue
case Pref.InsightShare.EVERYBODY => fuTrue
case Pref.InsightShare.FRIENDS =>
to ?? { t =>
relationApi.fetchAreFriends(insighted.id, t.id)
}
case Pref.InsightShare.NOBODY => fuFalse
}
2015-11-26 21:05:59 -07:00
}