Index: core-providers/src/java/membership.properties
===================================================================
--- core-providers/src/java/membership.properties (revision 306218)
+++ core-providers/src/java/membership.properties (revision 306261)
@@ -3,7 +3,7 @@
membership.view.new = (POST) Add the membership specified by the ID. Alternatively, a POST to the simple "/membership" URL can specify "userId" and "locationReference" request parameters. In either case, optional request parameters are: "memberRole" string (default for joinable site memberships is the default joiner role); "active" Boolean value (default is true). Can do a batch add to the same location using the same role by specifying a "userIds" parameter (an array of user IDs).
membership.view.delete = (DELETE) Delete the membership specified by the ID. Multiple memberships can be deleted from the same location by specifying a "userIds" parameter (an array of user IDs).
membership.view.edit = (POST) Modify the membership specified by the ID. Alternatively, a POST to the "/membership" URL can specify "userId" and "locationReference" request parameters. In either case, optional request parameters are: "memberRole" string; "active" Boolean value. Can do a batch update to the same location using the same role and active setting by specifying a "userIds" parameter (an array of user IDs).
-membership.view.list = By default, retrieves a list of all site memberships for the current user. Optional query parameters: "includeSites=false" filters out site memberships; "includeGroups=true" retrieves group memberships; "_locationReference=LOCATION_REFERENCE" returns all memberships in the specified site or group; "user=USER_ID" (or "userId=USER_ID" or "_userReference=USER_REFERENCE") returns the given user's memberships; "role=ROLE_STRING" (or "roleId=ROLE_STRING") restricts the list to the specified member role.
+membership.view.list = By default, retrieves a list of all site memberships for the current user. Optional query parameters: "includeSites=false" filters out site memberships; "includeGroups=true" retrieves group memberships; "_locationReference=LOCATION_REFERENCE" returns all memberships in the specified site or group; "user=USER_ID" (or "userId=USER_ID" or "_userReference=USER_REFERENCE") returns the given user's memberships; "includeMemberDetails=true" to return member full details of just the role of the user, cannot use this with includeGroups=true; "role=ROLE_STRING" (or "roleId=ROLE_STRING") restricts the list to the specified member role.
membership.action.site = The URL format is "/membership/site/:SITE_ID:".
\
(GET) will return all memberships in the specified site.
\
(POST) will add one or more site memberships via an array of "userSearchValues" request parameters (each of which is a user ID, user EID, or email address), along with a "memberRole" string (default for joinable site memberships is the default joiner role) and "active" Boolean value (default is true). Response headers may include "x-warning-not-found" (for a list of invalid userSearchValues) and "x-warning-already-members" (for a list of userSearchValues which were already site members).
@@ -14,3 +14,4 @@
if remove, remove the list from the existing membership.
membership.action.join = Allows a user without permissions in a site to join it, works with the current user only: /membership/join/site/siteId
membership.action.unjoin = Allows a user without permissions in a site to unjoin from it, works with the current user only: /membership/unjoin/site/siteId
+membership.action.fastroles = Allows for retrieval of current role in site only quickly. Use the format "/membership/fastroles/:userId:" (or userEid) or current user if none specified. A shortcut for includeMemberDetail=false.
Index: core-providers/src/java/org/sakaiproject/entitybroker/providers/MembershipEntityProvider.java
===================================================================
--- core-providers/src/java/org/sakaiproject/entitybroker/providers/MembershipEntityProvider.java (revision 306218)
+++ core-providers/src/java/org/sakaiproject/entitybroker/providers/MembershipEntityProvider.java (revision 306261)
@@ -34,6 +34,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.sakaiproject.authz.api.AuthzGroupService;
import org.sakaiproject.authz.api.Member;
import org.sakaiproject.authz.api.Role;
import org.sakaiproject.email.api.EmailService;
@@ -72,8 +73,13 @@
private static Log log = LogFactory.getLog(MembershipEntityProvider.class);
private SiteService siteService;
+ private AuthzGroupService authzGroupService;
- public void setSiteService(SiteService siteService) {
+ public void setAuthzGroupService(AuthzGroupService authzGroupService) {
+ this.authzGroupService = authzGroupService;
+ }
+
+ public void setSiteService(SiteService siteService) {
this.siteService = siteService;
}
@@ -278,7 +284,20 @@
}
return responseHeaders;
}
-
+
+ @EntityCustomAction(action = "fastroles", viewKey = "")
+ public List getMembershipRoles(EntityView view, Map params) {
+ //Can be ID or EID
+ String userId = view.getPathSegment(2);
+ //Don't include member details
+ Search s = new Search("includeMemberDetails",false);
+ if (userId != null) {
+ s.addRestriction(new Restriction(CollectionResolvable.SEARCH_USER_REFERENCE,userId));
+ }
+ return getEntities(new EntityReference(PREFIX, ""), s);
+
+ }
+
@EntityCustomAction(action = "group", viewKey = "")
public List getGroupMemberships(EntityView view, Map params) {
String groupId = view.getPathSegment(2);
@@ -456,6 +475,8 @@
String roleId = null;
boolean includeSites = true;
boolean includeGroups = false;
+ //Include details about the membership, has a performance impact
+ boolean includeMemberDetails = true;
//SAK-25710 hold a map of each sites type so we can look them up later (entityId, siteType)
Map siteTypes = new HashMap();
@@ -486,6 +507,11 @@
if (incGroups != null) {
includeGroups = incGroups.getBooleanValue();
}
+
+ Restriction incMemberDetails = search.getRestrictionByProperty("includeMemberDetails");
+ if (incMemberDetails != null) {
+ includeMemberDetails = incMemberDetails.getBooleanValue();
+ }
}
if (locationReference == null && userId == null) {
// if these are both null then we default to getting memberships for the current user
@@ -527,37 +553,48 @@
}
// Is there a faster way to do this? I really truly hope so -AZ
+ // Only if you don't care about getMember details -MJ
try {
- if (!userCurrent) {
- developerHelperService.setCurrentUser("/user/" + userId);
- }
- List sites = siteService.getSites(SelectionType.ACCESS, null, null, null,
- null, null);
- for (Site site : sites) {
- Member sm = site.getMember(userId);
- if (sm != null) {
- if (includeSites) {
- EntityMember em = new EntityMember(sm, site.getReference(), null);
- members.add(em);
- siteTypes.put(em.getId(), site.getType());
- }
- // also check the groups
- if (includeGroups) {
- Collection groups = site.getGroups();
- for (Group group : groups) {
- Member gm = group.getMember(userId);
- if (gm != null) {
- members.add(new EntityMember(gm, group.getReference(), null));
- }
- }
- }
- }
- }
- } finally {
- if (!userCurrent) {
- developerHelperService.restoreCurrentUser();
- }
+ if (!userCurrent) {
+ developerHelperService.setCurrentUser("/user/" + userId);
+ }
+ List sites = siteService.getSites(SelectionType.ACCESS, null, null, null,
+ null, null);
+ if (includeMemberDetails) {
+ for (Site site : sites) {
+ Member sm = site.getMember(userId);
+ if (sm != null) {
+ if (includeSites) {
+ EntityMember em = new EntityMember(sm, site.getReference(), null);
+ members.add(em);
+ siteTypes.put(em.getId(), site.getType());
+ }
+ // also check the groups
+ if (includeGroups) {
+ Collection groups = site.getGroups();
+ for (Group group : groups) {
+ Member gm = group.getMember(userId);
+ if (gm != null) {
+ members.add(new EntityMember(gm, group.getReference(), null));
+ }
+ }
+ }
+ }
+ }
+ }
+ else {
+ Map userRoles = authzGroupService.getUserRoles(userId, null);
+ for (Site site : sites) {
+ EntityMember em = new EntityMember(userId, site.getReference(), userRoles.get(site.getReference()), true, null);
+ members.add(em);
+ }
+ }
}
+ finally {
+ if (!userCurrent) {
+ developerHelperService.restoreCurrentUser();
+ }
+ }
}
ArrayList sortedMembers = new ArrayList();
int count = 0;
Index: core-providers/src/webapp/WEB-INF/applicationContext.xml
===================================================================
--- core-providers/src/webapp/WEB-INF/applicationContext.xml (revision 306218)
+++ core-providers/src/webapp/WEB-INF/applicationContext.xml (revision 306261)
@@ -41,6 +41,7 @@
class="org.sakaiproject.entitybroker.providers.MembershipEntityProvider"
init-method="init">
+