Index: kernel-impl/src/test/java/org/sakai/memory/impl/test/MockAuthzGroupService.java =================================================================== --- kernel-impl/src/test/java/org/sakai/memory/impl/test/MockAuthzGroupService.java (revision 99202) +++ kernel-impl/src/test/java/org/sakai/memory/impl/test/MockAuthzGroupService.java (working copy) @@ -254,4 +254,9 @@ return false; } + public Collection getAuthzUsersInGroups(Set groupIds) { + // TODO Auto-generated method stub + return null; + } + } Index: kernel-impl/src/main/java/org/sakaiproject/authz/impl/DbAuthzGroupService.java =================================================================== --- kernel-impl/src/main/java/org/sakaiproject/authz/impl/DbAuthzGroupService.java (revision 99202) +++ kernel-impl/src/main/java/org/sakaiproject/authz/impl/DbAuthzGroupService.java (working copy) @@ -736,6 +736,24 @@ return rv; } + /** + * {@inheritDoc} + */ + public Collection getAuthzUsersInGroups(Set groupIds) + { + if (groupIds == null || groupIds.isEmpty()) { + return new ArrayList(); // empty list + } + + // make a big where condition for groupIds with ORs + String inClause = orInClause( groupIds.size(), "SR.REALM_ID" ); + String statement = dbAuthzGroupSql.getSelectRealmUsersInGroupsSql(inClause); + Object[] fields = groupIds.toArray(); + @SuppressWarnings("unchecked") + List results = sqlService().dbRead(statement, fields, null); + return results; + } + /** * {@inheritDoc} */ Index: kernel-impl/src/main/java/org/sakaiproject/authz/impl/DbAuthzGroupSqlDefault.java =================================================================== --- kernel-impl/src/main/java/org/sakaiproject/authz/impl/DbAuthzGroupSqlDefault.java (revision 99202) +++ kernel-impl/src/main/java/org/sakaiproject/authz/impl/DbAuthzGroupSqlDefault.java (working copy) @@ -506,4 +506,10 @@ + "inner join SAKAI_REALM_ROLE SRR on SRRG.ROLE_KEY = SRR.ROLE_KEY " + "where SR.REALM_ID = ? and " + inClause + " and SRRG.ACTIVE = '1'"; } + + public String getSelectRealmUsersInGroupsSql( String inClause) + { + return "select SRRG.USER_ID from SAKAI_REALM_RL_GR SRRG inner join SAKAI_REALM SR ON SRRG.REALM_KEY = SR.REALM_KEY where SRRG.ACTIVE = '1' and " + inClause; + } + } Index: kernel-impl/src/main/java/org/sakaiproject/authz/impl/BaseAuthzGroupService.java =================================================================== --- kernel-impl/src/main/java/org/sakaiproject/authz/impl/BaseAuthzGroupService.java (revision 99202) +++ kernel-impl/src/main/java/org/sakaiproject/authz/impl/BaseAuthzGroupService.java (working copy) @@ -329,6 +329,14 @@ /** * {@inheritDoc} */ + public Collection getAuthzUsersInGroups(Set groupIds) + { + return m_storage.getAuthzUsersInGroups(groupIds); + } + + /** + * {@inheritDoc} + */ public int countAuthzGroups(String criteria) { return m_storage.countAuthzGroups(criteria); @@ -1260,6 +1268,14 @@ List getAuthzUserGroupIds(ArrayList authzGroupIds, String user_id); /** + * Return a list of users in the specified group list + * + * @param groupIds set of authz group ids + * @return collection of user ids + */ + Collection getAuthzUsersInGroups(Set groupIds); + + /** * Count the AuthzGroup objets that meet specified criteria. * * @param criteria Index: kernel-impl/src/main/java/org/sakaiproject/authz/impl/DbAuthzGroupSql.java =================================================================== --- kernel-impl/src/main/java/org/sakaiproject/authz/impl/DbAuthzGroupSql.java (revision 99202) +++ kernel-impl/src/main/java/org/sakaiproject/authz/impl/DbAuthzGroupSql.java (working copy) @@ -148,4 +148,6 @@ String getSelectRealmUpdate(); String getSelectRealmUserRoleSql(String inClause); + + String getSelectRealmUsersInGroupsSql( String inClause); } Index: kernel-impl/src/main/java/org/sakaiproject/site/impl/BaseSite.java =================================================================== --- kernel-impl/src/main/java/org/sakaiproject/site/impl/BaseSite.java (revision 99202) +++ kernel-impl/src/main/java/org/sakaiproject/site/impl/BaseSite.java (working copy) @@ -24,6 +24,8 @@ import java.util.Collection; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -856,6 +858,23 @@ /** * {@inheritDoc} */ + public Collection getMembersInGroups(Set groupIds) { + @SuppressWarnings("unchecked") + Collection siteGroups = getGroups(); + HashSet siteGroupRefs = new HashSet(siteGroups.size()); + for (Group group : siteGroups) { + if (groupIds == null || // null groupIds includes all groups in the site + groupIds.contains(group.getId())) { + siteGroupRefs.add(group.getReference()); + } + } + Collection membersInGroups = AuthzGroupService.getAuthzUsersInGroups(siteGroupRefs); + return membersInGroups; + } + + /** + * {@inheritDoc} + */ public Collection getGroupsWithMember(String userId) { Collection siteGroups = getGroups(); Index: api/src/main/java/org/sakaiproject/authz/api/AuthzGroupService.java =================================================================== --- api/src/main/java/org/sakaiproject/authz/api/AuthzGroupService.java (revision 99202) +++ api/src/main/java/org/sakaiproject/authz/api/AuthzGroupService.java (working copy) @@ -453,4 +453,13 @@ * must not be "compound IDs", as defined by the GroupProvider's String[] unpackId(String id) method. */ public Set getProviderIds(String authzGroupId); + + /** + * Get list of users who are in a set of groups + * + * @param groupIds IDs of authZ groups (AuthzGroup selection criteria) + * @return list of user IDs who are in a set of groups + */ + public Collection getAuthzUsersInGroups(Set groupIds); + } Index: api/src/main/java/org/sakaiproject/authz/cover/AuthzGroupService.java =================================================================== --- api/src/main/java/org/sakaiproject/authz/cover/AuthzGroupService.java (revision 99202) +++ api/src/main/java/org/sakaiproject/authz/cover/AuthzGroupService.java (working copy) @@ -21,6 +21,7 @@ package org.sakaiproject.authz.cover; +import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -345,4 +346,13 @@ return service.getUsersRole(param0, param1); } + + public static Collection getAuthzUsersInGroups(Set groupIds) + { + org.sakaiproject.authz.api.AuthzGroupService service = getInstance(); + if (service == null) return null; + + return service.getAuthzUsersInGroups(groupIds); + } + } Index: api/src/main/java/org/sakaiproject/site/api/Site.java =================================================================== --- api/src/main/java/org/sakaiproject/site/api/Site.java (revision 99202) +++ api/src/main/java/org/sakaiproject/site/api/Site.java (working copy) @@ -25,8 +25,10 @@ import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.Set; import org.sakaiproject.authz.api.AuthzGroup; +import org.sakaiproject.authz.api.Member; import org.sakaiproject.entity.api.Edit; import org.sakaiproject.time.api.Time; import org.sakaiproject.user.api.User; @@ -230,6 +232,15 @@ */ Collection getGroupsWithMemberHasRole(String userId, String role); + /** + * Get user IDs of members of a set of groups in this site + * + * @param groupIds IDs of authZ groups (AuthzGroup selection criteria), + * a null groupIds includes all groups in the site, an empty set includes none of them + * @return collection of user IDs who are in (members of) a set of site groups + */ + Collection getMembersInGroups(Set groupIds); + /** * Does the site have any groups defined? *