Search in sources :

Example 1 with Capability

use of org.alfresco.module.org_alfresco_module_rm.capability.Capability in project records-management by Alfresco.

the class FilePlanRoleServiceImpl method getCapabilitiesImpl.

/**
 * @param rmRootNode
 * @param roleAuthority
 * @return
 */
private Set<Capability> getCapabilitiesImpl(NodeRef rmRootNode, String roleAuthority) {
    Set<AccessPermission> permissions = permissionService.getAllSetPermissions(rmRootNode);
    Set<Capability> capabilities = new HashSet<Capability>(52);
    for (AccessPermission permission : permissions) {
        if (permission.getAuthority().equals(roleAuthority)) {
            String capabilityName = permission.getPermission();
            Capability capability = capabilityService.getCapability(capabilityName);
            if (capability != null && !capability.isPrivate()) {
                capabilities.add(capability);
            }
        }
    }
    return capabilities;
}
Also used : Capability(org.alfresco.module.org_alfresco_module_rm.capability.Capability) AccessPermission(org.alfresco.service.cmr.security.AccessPermission) HashSet(java.util.HashSet)

Example 2 with Capability

use of org.alfresco.module.org_alfresco_module_rm.capability.Capability in project records-management by Alfresco.

the class CustomRefsGet method hasView.

/**
 * Determines whether the current user has view capabilities on the given node.
 *
 * @param  nodeRef Node reference
 * @return boolean <code>true</code> if current user has view capability, <code>false</code> otherwise
 */
private boolean hasView(NodeRef nodeRef) {
    boolean result = false;
    Capability viewRecordCapability = getCapabilityService().getCapability(ViewRecordsCapability.NAME);
    if (AccessStatus.ALLOWED.equals(viewRecordCapability.hasPermission(nodeRef))) {
        result = true;
    }
    return result;
}
Also used : ViewRecordsCapability(org.alfresco.module.org_alfresco_module_rm.capability.impl.ViewRecordsCapability) Capability(org.alfresco.module.org_alfresco_module_rm.capability.Capability)

Example 3 with Capability

use of org.alfresco.module.org_alfresco_module_rm.capability.Capability in project records-management by Alfresco.

the class RmRolePut method executeImpl.

@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    JSONObject json = null;
    try {
        // Role name
        Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
        String roleParam = templateVars.get("rolename");
        if (roleParam == null) {
            throw new WebScriptException(Status.STATUS_NOT_FOUND, "No role name was provided on the URL.");
        }
        json = new JSONObject(new JSONTokener(req.getContent().getContent()));
        String name = json.getString("name");
        // TODO check
        String displayLabel = json.getString("displayLabel");
        // TODO check
        JSONArray capabilitiesArray = json.getJSONArray("capabilities");
        Set<Capability> capabilites = new HashSet<Capability>(capabilitiesArray.length());
        for (int i = 0; i < capabilitiesArray.length(); i++) {
            Capability capability = capabilityService.getCapability(capabilitiesArray.getString(i));
            capabilites.add(capability);
        }
        // get the file plan
        NodeRef filePlan = getFilePlan(req);
        if (filePlan == null) {
            throw new WebScriptException(Status.STATUS_NOT_FOUND, "File plan does not exist.");
        }
        // Check that the role exists
        if (!filePlanRoleService.existsRole(filePlan, roleParam)) {
            throw new WebScriptException(Status.STATUS_NOT_FOUND, "The role " + roleParam + " does not exist on the records managment root " + filePlan);
        }
        Role role = filePlanRoleService.updateRole(filePlan, name, displayLabel, capabilites);
        model.put("role", new RoleItem(role));
    } catch (IOException iox) {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", iox);
    } catch (JSONException je) {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je);
    }
    return model;
}
Also used : Capability(org.alfresco.module.org_alfresco_module_rm.capability.Capability) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IOException(java.io.IOException) JSONTokener(org.json.JSONTokener) Role(org.alfresco.module.org_alfresco_module_rm.role.Role) NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JSONObject(org.json.JSONObject) HashSet(java.util.HashSet)

Example 4 with Capability

use of org.alfresco.module.org_alfresco_module_rm.capability.Capability in project records-management by Alfresco.

the class RmRolesPost method executeImpl.

@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    JSONObject json = null;
    try {
        json = new JSONObject(new JSONTokener(req.getContent().getContent()));
        String name = json.getString("name");
        // TODO check
        String displayString = json.getString("displayLabel");
        // TODO check
        JSONArray capabilitiesArray = json.getJSONArray("capabilities");
        Set<Capability> capabilites = new HashSet<Capability>(capabilitiesArray.length());
        for (int i = 0; i < capabilitiesArray.length(); i++) {
            Capability capability = capabilityService.getCapability(capabilitiesArray.getString(i));
            capabilites.add(capability);
        }
        // get the file plan
        NodeRef filePlan = getFilePlan(req);
        if (filePlan == null) {
            throw new WebScriptException(Status.STATUS_NOT_FOUND, "File plan does not exist.");
        }
        Role role = filePlanRoleService.createRole(filePlan, name, displayString, capabilites);
        model.put("role", new RoleItem(role));
    } catch (IOException iox) {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", iox);
    } catch (JSONException je) {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je);
    }
    return model;
}
Also used : Capability(org.alfresco.module.org_alfresco_module_rm.capability.Capability) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IOException(java.io.IOException) JSONTokener(org.json.JSONTokener) Role(org.alfresco.module.org_alfresco_module_rm.role.Role) NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JSONObject(org.json.JSONObject) HashSet(java.util.HashSet)

Example 5 with Capability

use of org.alfresco.module.org_alfresco_module_rm.capability.Capability in project records-management by Alfresco.

the class CapabilitiesGet method executeImpl.

/**
 * @see org.alfresco.repo.web.scripts.content.StreamContent#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
 */
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String storeType = templateVars.get("store_type");
    String storeId = templateVars.get("store_id");
    String nodeId = templateVars.get("id");
    NodeRef nodeRef = null;
    if (StringUtils.isNotBlank(storeType) && StringUtils.isNotBlank(storeId) && StringUtils.isNotBlank(nodeId)) {
        nodeRef = new NodeRef(new StoreRef(storeType, storeId), nodeId);
    } else {
        // we are talking about the file plan node
        // TODO we are making the assumption there is only one file plan here!
        nodeRef = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
        if (nodeRef == null) {
            throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "The default file plan node could not be found.");
        }
    }
    boolean grouped = false;
    String groupedString = req.getParameter("grouped");
    if (StringUtils.isNotBlank(groupedString)) {
        grouped = Boolean.parseBoolean(groupedString);
    }
    Map<String, Object> model = new TreeMap<String, Object>();
    if (grouped) {
        // Construct the map which is needed to build the model
        Map<String, GroupedCapabilities> groupedCapabilitiesMap = new TreeMap<String, GroupedCapabilities>();
        List<Group> groups = capabilityService.getGroups();
        for (Group group : groups) {
            String capabilityGroupTitle = group.getTitle();
            if (StringUtils.isNotBlank(capabilityGroupTitle)) {
                String capabilityGroupId = group.getId();
                List<Capability> capabilities = capabilityService.getCapabilitiesByGroupId(capabilityGroupId);
                for (Capability capability : capabilities) {
                    String capabilityName = capability.getName();
                    String capabilityTitle = capability.getTitle();
                    if (groupedCapabilitiesMap.containsKey(capabilityGroupId)) {
                        groupedCapabilitiesMap.get(capabilityGroupId).addCapability(capabilityName, capabilityTitle);
                    } else {
                        GroupedCapabilities groupedCapabilities = new GroupedCapabilities(capabilityGroupId, capabilityGroupTitle, capabilityName, capabilityTitle);
                        groupedCapabilities.addCapability(capabilityName, capabilityTitle);
                        groupedCapabilitiesMap.put(capabilityGroupId, groupedCapabilities);
                    }
                }
            }
        }
        model.put("groupedCapabilities", groupedCapabilitiesMap);
    } else {
        boolean includePrivate = false;
        String includePrivateString = req.getParameter("includeAll");
        if (StringUtils.isNotBlank(includePrivateString)) {
            includePrivate = Boolean.parseBoolean(includePrivateString);
        }
        Map<Capability, AccessStatus> map = capabilityService.getCapabilitiesAccessState(nodeRef, includePrivate);
        List<String> list = new ArrayList<String>(map.size());
        for (Map.Entry<Capability, AccessStatus> entry : map.entrySet()) {
            AccessStatus accessStatus = entry.getValue();
            if (!AccessStatus.DENIED.equals(accessStatus)) {
                Capability capability = entry.getKey();
                list.add(capability.getName());
            }
        }
        model.put("capabilities", list);
    }
    return model;
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) Group(org.alfresco.module.org_alfresco_module_rm.capability.Group) Capability(org.alfresco.module.org_alfresco_module_rm.capability.Capability) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) AccessStatus(org.alfresco.service.cmr.security.AccessStatus) NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

Capability (org.alfresco.module.org_alfresco_module_rm.capability.Capability)29 NodeRef (org.alfresco.service.cmr.repository.NodeRef)15 HashSet (java.util.HashSet)8 HashMap (java.util.HashMap)6 Map (java.util.Map)5 Serializable (java.io.Serializable)4 Role (org.alfresco.module.org_alfresco_module_rm.role.Role)4 AccessStatus (org.alfresco.service.cmr.security.AccessStatus)4 JSONArray (org.json.JSONArray)4 JSONObject (org.json.JSONObject)4 DeclarativeCapability (org.alfresco.module.org_alfresco_module_rm.capability.declarative.DeclarativeCapability)3 DeclarativeCompositeCapability (org.alfresco.module.org_alfresco_module_rm.capability.declarative.DeclarativeCompositeCapability)3 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)2 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)2 AccessPermission (org.alfresco.service.cmr.security.AccessPermission)2