Search in sources :

Example 1 with SiteMemberInfo

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

the class SitesImpl method isMemberOfSite.

private SiteMemberInfo isMemberOfSite(String siteId, String id) {
    SiteInfo siteInfo = validateSite(siteId);
    if (siteInfo == null) {
        logger.debug("Site does not exist: " + siteId);
        throw new EntityNotFoundException(siteId);
    }
    validateGroup(id);
    SiteMemberInfo memberInfo = this.siteService.getMembersRoleInfo(siteId, id);
    if (memberInfo == null) {
        logger.debug("Given authority is not a member of the site");
        throw new InvalidArgumentException("Given authority is not a member of the site");
    }
    if (memberInfo.getMemberRole() == null) {
        logger.debug("Getting authority role but role is null");
        throw new RelationshipResourceNotFoundException(memberInfo.getMemberName(), siteId);
    }
    return memberInfo;
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) SiteMemberInfo(org.alfresco.service.cmr.site.SiteMemberInfo) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 2 with SiteMemberInfo

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

the class SitesImpl method addSiteGroupMembership.

@Override
public SiteGroup addSiteGroupMembership(String siteId, SiteGroup group) {
    SiteInfo siteInfo = validateSite(siteId);
    if (siteInfo == null) {
        logger.debug("Site does not exist: " + siteId);
        throw new EntityNotFoundException(siteId);
    }
    validateGroup(group.getId());
    SiteMemberInfo groupInfo = siteService.getMembersRoleInfo(siteId, group.getId());
    if (groupInfo != null) {
        logger.debug("addSiteGroupMembership:  " + group.getId() + " is already a member of site " + siteId);
        throw new ConstraintViolatedException(group.getId() + " is already a member of site " + siteId);
    }
    if (group.getRole() == null) {
        logger.debug("Getting member role but role is null");
        throw new RelationshipResourceNotFoundException(group.getId(), siteId);
    }
    siteService.setMembership(siteId, group.getId(), group.getRole());
    return group;
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) SiteMemberInfo(org.alfresco.service.cmr.site.SiteMemberInfo) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 3 with SiteMemberInfo

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

the class SiteServiceImpl method listMembersImpl.

protected Map<String, String> listMembersImpl(String shortName, String nameFilter, String roleFilter, int size, boolean expandGroups) {
    List<SiteMemberInfo> list = listMembersInfoImpl(shortName, nameFilter, roleFilter, size, expandGroups);
    Map<String, String> members = new HashMap<String, String>(list.size());
    for (SiteMemberInfo info : list) members.put(info.getMemberName(), info.getMemberRole());
    return members;
}
Also used : SiteMemberInfo(org.alfresco.service.cmr.site.SiteMemberInfo) HashMap(java.util.HashMap) FilterTypeString(org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString)

Example 4 with SiteMemberInfo

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

the class Site method isMemberOfGroup.

/**
 * Indicates whether a user belongs to a group with access rights to the site or not
 *
 * @param authorityName  user name
 * @return boolean  true if the user belongs to a group with access rights, false otherwise
 */
public boolean isMemberOfGroup(String authorityName) {
    boolean isMemberOfGroup = false;
    SiteMemberInfo membersRoleInfo = getMembersRoleInfo(authorityName);
    if (membersRoleInfo != null) {
        isMemberOfGroup = membersRoleInfo.isMemberOfGroup();
    }
    return isMemberOfGroup;
}
Also used : SiteMemberInfo(org.alfresco.service.cmr.site.SiteMemberInfo)

Example 5 with SiteMemberInfo

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

the class SiteMembershipsGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(SiteInfo site, WebScriptRequest req, Status status, Cache cache) {
    // Grab out filters
    String nameFilter = req.getParameter("nf");
    if (nameFilter != null) {
        nameFilter = nameFilter.endsWith("*") ? nameFilter : nameFilter + "*";
    }
    String roleFilter = req.getParameter("rf");
    String authorityType = req.getParameter("authorityType");
    String sizeS = req.getParameter("size");
    boolean collapseGroups = false;
    // Sanity check the types
    if (authorityType != null) {
        if ("USER".equals(authorityType)) {
            collapseGroups = true;
        } else if ("GROUP".equals(authorityType)) {
        // No extra settings needed
        } else {
            throw new WebScriptException(Status.STATUS_BAD_REQUEST, "The Authority must be one of USER or GROUP");
        }
    }
    // Figure out what to limit to, if anythign
    int limit = 0;
    if (sizeS != null) {
        try {
            limit = Integer.parseInt(sizeS);
        } catch (NumberFormatException e) {
            throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid size specified");
        }
    }
    // Fetch the membership details of the site
    List<SiteMemberInfo> members = this.siteService.listMembersInfo(site.getShortName(), nameFilter, roleFilter, limit, collapseGroups);
    // Process it ready for FreeMarker
    // Note that as usernames may be all numbers, we need to
    // prefix them with an underscore otherwise FTL can get confused!
    Map<String, Object> authorities = new HashMap<String, Object>(members.size());
    Map<String, Object> memberInfo = new LinkedHashMap<String, Object>(members.size());
    for (SiteMemberInfo authorityObj : members) {
        String ftlSafeName = "_" + authorityObj.getMemberName();
        if (authorityObj.getMemberName().startsWith("GROUP_")) {
            if (authorityType == null || authorityType.equals("GROUP")) {
                // Record the details
                authorities.put(ftlSafeName, scriptAuthorityService.getGroupForFullAuthorityName(authorityObj.getMemberName()));
                memberInfo.put(ftlSafeName, authorityObj);
            }
        } else {
            if (authorityType == null || authorityType.equals("USER")) {
                // Record the details
                authorities.put(ftlSafeName, personService.getPerson(authorityObj.getMemberName()));
                memberInfo.put(ftlSafeName, authorityObj);
            }
        }
    }
    // Pass the details to freemarker
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("site", site);
    model.put("authorities", authorities);
    model.put("memberInfo", memberInfo);
    return model;
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) SiteMemberInfo(org.alfresco.service.cmr.site.SiteMemberInfo) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

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