[Building Sakai] Get all roles in a site?

Noah Botimer botimer at umich.edu
Tue Jul 9 14:10:46 PDT 2013


Brian,

This confusion probably comes from the inheritance of Site from AuthzGroup. You can use the straightforward getRoles() call on any AuthzGroup or Site object.

Something like this (though the use of the cover is generally discouraged):

import org.sakaiproject.site.api.*;
import org.sakaiproject.authz.api.*;
import org.sakaiproject.site.cover.SiteService;

Site site = SiteService.getSite("someId");
Set<Role> roles = site.getRoles();
for (Role role : roles) {
	role.getId();
	role.getDescription();
	for (String function : role.getAllowedFunctions()) {
		//
	}
}

If you need to do this for a bunch of sites, there might be a method on AuthzGroupService that does what you need efficiently, but most often the need is to find the places a user can take some specific action. Finding all the roles that have a particular function in all or a set of sites may not have come up as an application need -- sometimes you'll find that with things that are more aligned with administrative or auditing scenarios.

If you are in a one-time audit situation, a couple of queries could get you there. You'll have to explore these tables:

SAKAI_REALM
SAKAI_REALM_ROLE
SAKAI_REALM_FUNCTION
SAKAI_REALM_RL_FN

SAKAI-REALM.REALM_ID will correspond to the site ID and SAKAI_REALM_FUNCTION.FUNCTION_NAME is the permission. You could pull in SAKAI_SITE if you need more details from there.

Thanks,
-Noah

On Jul 9, 2013, at 4:10 PM, Brian Jones wrote:

> Hi,
> 
> I've been looking at the APIs but I can't see anything obvious that would
> help me with this. I'm hoping I can somehow retrieve a List<> of all Roles
> inside a give site (ID).
> 
> Does anyone know anything that can help me with this? Ideally, I'd only like
> to identify all Roles in a site that have a certain permission enabled (but
> not in terms of a single user).
> 
> Thanks in advance,
> 
> Brian Jones
> Applications Development
> Information Technology Services
> Support Services Building, Room 4326
> Western University
> (519) 661-2111 x86969
> bjones86 at uwo.ca
> 
> 
> 
> _______________________________________________
> sakai-dev mailing list
> sakai-dev at collab.sakaiproject.org
> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
> 
> TO UNSUBSCRIBE: send email to sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of "unsubscribe"



More information about the sakai-dev mailing list