Skip to content

Instantly share code, notes, and snippets.

@ayax79
Created January 5, 2012 00:26
Show Gist options
  • Select an option

  • Save ayax79/1563032 to your computer and use it in GitHub Desktop.

Select an option

Save ayax79/1563032 to your computer and use it in GitHub Desktop.
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
}
@ayax79
Copy link
Author

ayax79 commented Jan 5, 2012

def admins:Iterable[User] = {
def rg = RoleGrant().userGroup(UserGroup().users(Stream(User().nodes(Stream(this)))))

val query = (Role().name("Manage Administrator") | Role().name("synadmin") | Role().name("admin")).find() match {
  case head #:: Stream.Empty => Option(rg.role(head))
  case head #:: tail => Option(tail.foldLeft(rg.role(head))((b, role) => b | rg.role(role)))
  case _ => Option.empty
}

val roleGrants = query match {
  case Some(q) => q.find()
  case _ => Stream.empty
}

roleGrants.flatMap(_.userGroup().users()).toSet

}

@thowitt
Copy link

thowitt commented Jan 5, 2012

val role = (Role().name("Manage Administrator") | Role().name("synadmin") | Role().name("admin"))
rg.role.q(role).find()

@ayax79
Copy link
Author

ayax79 commented Jan 5, 2012

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment