Skip to content

Commit

Permalink
Fixed perms in user data
Browse files Browse the repository at this point in the history
  • Loading branch information
felixoi committed Nov 25, 2018
1 parent bbd67bf commit afdff49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
30 changes: 13 additions & 17 deletions app/models/viewhelper/UserData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name := "ore"
version := "1.6.19"
version := "1.6.20"

lazy val `ore` = (project in file(".")).enablePlugins(PlayScala)

Expand Down

0 comments on commit afdff49

Please sign in to comment.