Search in sources :

Example 6 with SiteMemberInfo

use of org.alfresco.service.cmr.site.SiteMemberInfo in project alfresco-repository by Alfresco.

the class SiteServiceImpl method listMembersInfoImpl.

protected List<SiteMemberInfo> listMembersInfoImpl(String shortName, String nameFilter, String roleFilter, int size, boolean expandGroups) {
    NodeRef siteNodeRef = getSiteNodeRef(shortName);
    if (siteNodeRef == null) {
        throw new SiteDoesNotExistException(shortName);
    }
    // max size limit
    if (size <= 0) {
        size = Integer.MAX_VALUE;
    }
    String[] nameFilters = tokenizeFilterLowercase(nameFilter);
    String nameFilterLower = nameFilters.length > 0 ? nameFilter.toLowerCase() : null;
    List<SiteMemberInfo> members = new ArrayList<SiteMemberInfo>(32);
    QName siteType = directNodeService.getType(siteNodeRef);
    Set<String> permissions = this.permissionService.getSettablePermissions(siteType);
    Map<String, String> groupsToExpand = new HashMap<String, String>(32);
    AUTHORITY_FIND: for (String permission : permissions) {
        if (roleFilter == null || roleFilter.length() == 0 || roleFilter.equals(permission)) {
            String groupName = getSiteRoleGroup(shortName, permission, true);
            Set<String> authorities = this.authorityService.getContainedAuthorities(null, groupName, true);
            for (String authority : authorities) {
                switch(AuthorityType.getAuthorityType(authority)) {
                    case USER:
                        boolean addUser = true;
                        if (nameFilter != null && nameFilter.length() != 0 && !nameFilter.equals(authority)) {
                            // found a filter - does it match person first/last name?
                            addUser = matchPerson(nameFilters, authority);
                        }
                        if (addUser) {
                            // Add the user and their permission to the returned map
                            members.add(new SiteMemberInfoImpl(authority, permission, false));
                            // break on max size limit reached
                            if (members.size() >= size) {
                                break AUTHORITY_FIND;
                            }
                        }
                        break;
                    case GROUP:
                        if (expandGroups) {
                            if (!groupsToExpand.containsKey(authority)) {
                                groupsToExpand.put(authority, permission);
                            }
                        } else {
                            if (nameFilter != null && nameFilter.length() != 0) {
                                // found a filter - does it match Group name part?
                                if (matchByFilter(authority.substring(GROUP_PREFIX_LENGTH).toLowerCase(), nameFilterLower)) {
                                    members.add(new SiteMemberInfoImpl(authority, permission, false));
                                } else {
                                    // Does it match on the Group Display Name part instead?
                                    String displayName = authorityService.getAuthorityDisplayName(authority);
                                    if (displayName != null && matchByFilter(displayName.toLowerCase(), nameFilterLower)) {
                                        members.add(new SiteMemberInfoImpl(authority, permission, false));
                                    }
                                }
                            } else {
                                // No name filter add this group
                                members.add(new SiteMemberInfoImpl(authority, permission, false));
                            }
                            // break on max size limit reached
                            if (members.size() >= size) {
                                break AUTHORITY_FIND;
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
        }
    }
    if ((expandGroups) && (members.size() < size)) {
        GROUP_EXPAND: for (Map.Entry<String, String> entry : groupsToExpand.entrySet()) {
            Set<String> subUsers = this.authorityService.getContainedAuthorities(AuthorityType.USER, entry.getKey(), false);
            for (String subUser : subUsers) {
                if (isAcceptedName(nameFilter, subUser)) {
                    SiteMemberInfo memberInfo = new SiteMemberInfoImpl(subUser, entry.getValue(), true);
                    // Add the collapsed user into the members list if they do not already appear in the list
                    if (members.contains(memberInfo) == false) {
                        members.add(memberInfo);
                    } else {
                        int index = members.indexOf(memberInfo);
                        int priority = roleComparator.compare(members.get(index).getMemberRole(), memberInfo.getMemberRole());
                        if (priority > 0) {
                            members.set(index, memberInfo);
                        }
                    }
                    // break on max size limit reached
                    if (members.size() >= size) {
                        break GROUP_EXPAND;
                    }
                }
            }
        }
    }
    return members;
}
Also used : ResultSet(org.alfresco.service.cmr.search.ResultSet) Set(java.util.Set) TreeSet(java.util.TreeSet) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) FilterTypeString(org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteMemberInfo(org.alfresco.service.cmr.site.SiteMemberInfo)

Example 7 with SiteMemberInfo

use of org.alfresco.service.cmr.site.SiteMemberInfo in project alfresco-repository by Alfresco.

the class SiteServiceImplTest method testUserRoleInGroups.

/**
 * See https://issues.alfresco.com/jira/browse/MNT-2229
 */
@Test
public void testUserRoleInGroups() {
    String sitName = "testMembership2" + UUID.randomUUID();
    // Create a site as user one
    this.siteService.createSite(TEST_SITE_PRESET, sitName, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
    /**
     *  Add a group (GROUP_ONE) with role COLLABORATOR
     */
    this.siteService.setMembership(sitName, this.groupOne, SiteModel.SITE_COLLABORATOR);
    /**
     *  Add a group (GROUP_TWO) with role CONSUMER
     */
    this.siteService.setMembership(sitName, this.groupTwo, SiteModel.SITE_CONSUMER);
    List<SiteMemberInfo> roles = this.siteService.listMembersInfo(sitName, USER_TWO, null, 0, true);
    assertEquals(roles.get(0).getMemberRole(), SiteModel.SITE_COLLABORATOR);
}
Also used : SiteMemberInfo(org.alfresco.service.cmr.site.SiteMemberInfo) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test)

Example 8 with SiteMemberInfo

use of org.alfresco.service.cmr.site.SiteMemberInfo in project alfresco-repository by Alfresco.

the class SiteServiceImplTest method testListMembersInfo.

@Test
public void testListMembersInfo() {
    String siteShortName = "testMemberInfo";
    // Create a site as user one
    this.siteService.createSite(TEST_SITE_PRESET, siteShortName, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE);
    // Get the members of the site and check that user one is a manager
    List<SiteMemberInfo> members = this.siteService.listMembersInfo(siteShortName, null, null, 0, false);
    assertNotNull(members);
    assertEquals(1, members.size());
    SiteMemberInfo user = members.get(0);
    assertNotNull(user);
    assertTrue(user.getMemberName().equals(USER_ONE));
    assertEquals(SiteModel.SITE_MANAGER, user.getMemberRole());
    assertFalse("USER_ONE is NOT member of any group", user.isMemberOfGroup());
    // GROUP_TWO - USER_TWO, USER_THREE
    this.siteService.setMembership(siteShortName, this.groupTwo, SiteModel.SITE_COLLABORATOR);
    this.siteService.setMembership(siteShortName, USER_FOUR, SiteModel.SITE_CONSUMER);
    // Get the members of the site in expanded list
    members = this.siteService.listMembersInfo(siteShortName, null, null, 0, true);
    assertNotNull(members);
    assertEquals(4, members.size());
    // Get USER_TWO who is a member of group two
    user = lookupMemberInfoByUserName(members, USER_TWO);
    assertNotNull(user);
    assertEquals(SiteModel.SITE_COLLABORATOR, user.getMemberRole());
    assertTrue("USER_TWO is member of group two", user.isMemberOfGroup());
    // Get USER_THREE who is a member of group two
    user = lookupMemberInfoByUserName(members, USER_THREE);
    assertNotNull(user);
    assertEquals(SiteModel.SITE_COLLABORATOR, user.getMemberRole());
    assertTrue("USER_THREE is member of group two", user.isMemberOfGroup());
    // Get USER_FOUR
    user = lookupMemberInfoByUserName(members, USER_FOUR);
    assertNotNull(user);
    assertEquals(SiteModel.SITE_CONSUMER, user.getMemberRole());
    assertFalse("USER_FOUR is NOT member of any group", user.isMemberOfGroup());
}
Also used : SiteMemberInfo(org.alfresco.service.cmr.site.SiteMemberInfo) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test)

Aggregations

SiteMemberInfo (org.alfresco.service.cmr.site.SiteMemberInfo)8 FilterPropString (org.alfresco.repo.node.getchildren.FilterPropString)4 HashMap (java.util.HashMap)3 FilterTypeString (org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString)2 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)2 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)2 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)2 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Set (java.util.Set)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 ResultSet (org.alfresco.service.cmr.search.ResultSet)1 QName (org.alfresco.service.namespace.QName)1