Created
January 5, 2012 00:26
-
-
Save ayax79/1563032 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def admins:Iterable[User] = { | |
| def rg = RoleGrant().userGroup(UserGroup().users(Stream(User().nodes(Stream(this))))) | |
| def findRole(nm: String) = Role().name(nm).lookfor() | |
| val query = List(findRole("Manage Administrator"), findRole("synadmin"), findRole("admin")).filter(_.isDefined).map(_.get) match { | |
| case head :: tail => Option(tail.foldLeft(rg.role(head))((b, role) => b.|(role))) | |
| case head :: Nil => Option(rg.role(head)) | |
| case _ => Option.empty[RoleGrant] | |
| } | |
| val roleGrants = query match { | |
| case Some(q) => q.find() | |
| case _ => Stream.empty | |
| } | |
| roleGrants.flatMap(_.userGroup().users()).toSet | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
RoleGrant().userGroup(UserGroup().users(Stream(User().nodes(Stream(this))))).role((Role().name("Manage Administrator") | Role().name("synadmin") | Role().name("admin"))).find().flatMap(_.userGroup().users()).toSet