From afdff4942eecfcb824e405fdd2f32a297fe6b2ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Kleinekath=C3=B6fer?= Date: Sun, 25 Nov 2018 18:07:12 +0100 Subject: [PATCH] Fixed perms in user data --- app/models/viewhelper/UserData.scala | 30 ++++++++++++---------------- build.sbt | 2 +- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/app/models/viewhelper/UserData.scala b/app/models/viewhelper/UserData.scala index c758d80df..42f6fa8a9 100644 --- a/app/models/viewhelper/UserData.scala +++ b/app/models/viewhelper/UserData.scala @@ -64,28 +64,24 @@ object UserData { for { isOrga <- user.toMaybeOrganization.isDefined projectCount <- user.projects.size - t <- perms(request.currentUser) + t <- perms(user) (globalRoles, userPerms, orgaPerms) = t orgas <- service.runDBIO(queryRoles(user).result) } yield UserData(request.headerData, user, isOrga, projectCount, orgas, globalRoles, userPerms, orgaPerms) - def perms(currentUser: Option[User])( - implicit service: ModelService, - cs: ContextShift[IO] + def perms(user: User)( + implicit cs: ContextShift[IO], + service: ModelService ): IO[(Set[Role], Map[Permission, Boolean], Map[Permission, Boolean])] = { - currentUser.fold( - IO.pure((Set.empty[Role], Map.empty[Permission, Boolean], Map.empty[Permission, Boolean])) - ) { user => - ( - user.trustIn(GlobalScope), - user.toMaybeOrganization.semiflatMap(user.trustIn[Organization]).value, - user.globalRoles.allFromParent(user), - ).parMapN { (userTrust, orgTrust, globalRoles) => - val userPerms = user.can.asMap(userTrust, globalRoles.toSet)(ViewActivity, ReviewFlags, ReviewProjects) - val orgaPerms = user.can.asMap(orgTrust, Some(globalRoles.toSet))(EditSettings) - - (globalRoles.map(_.toRole).toSet, userPerms, orgaPerms) - } + ( + user.trustIn(GlobalScope), + user.toMaybeOrganization.semiflatMap(user.trustIn[Organization]).value, + user.globalRoles.allFromParent(user), + ).parMapN { (userTrust, orgTrust, globalRoles) => + val userPerms = user.can.asMap(userTrust, globalRoles.toSet)(ViewActivity, ReviewFlags, ReviewProjects) + val orgaPerms = user.can.asMap(orgTrust, Some(globalRoles.toSet))(EditSettings) + + (globalRoles.map(_.toRole).toSet, userPerms, orgaPerms) } } } diff --git a/build.sbt b/build.sbt index e634a6c33..7de4cd9a4 100755 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,5 @@ name := "ore" -version := "1.6.19" +version := "1.6.20" lazy val `ore` = (project in file(".")).enablePlugins(PlayScala)