use of org.alfresco.module.org_alfresco_module_rm.capability.Capability in project records-management by Alfresco.
the class CompositeCapabilityTest method testUpdateProperties.
public void testUpdateProperties() {
final Capability capability = capabilityService.getCapability("UpdateProperties");
assertNotNull(capability);
doTestInTransaction(new Test<Void>() {
@Override
public Void run() {
assertEquals(AccessStatus.ALLOWED, capability.hasPermission(rmContainer));
assertEquals(AccessStatus.ALLOWED, capability.hasPermission(rmFolder));
assertEquals(AccessStatus.ALLOWED, capability.hasPermission(record));
assertEquals(AccessStatus.ALLOWED, capability.hasPermission(declaredRecord));
return null;
}
}, recordsManagerName);
doTestInTransaction(new Test<Void>() {
@Override
public Void run() {
assertEquals(AccessStatus.DENIED, capability.hasPermission(rmContainer));
assertEquals(AccessStatus.DENIED, capability.hasPermission(rmFolder));
assertEquals(AccessStatus.DENIED, capability.hasPermission(record));
assertEquals(AccessStatus.DENIED, capability.hasPermission(declaredRecord));
return null;
}
}, userName);
}
use of org.alfresco.module.org_alfresco_module_rm.capability.Capability in project records-management by Alfresco.
the class DeleteRecordFolderTest method testDeleteDestroyedRecordFolder.
// delete a destroyed record folder
public void testDeleteDestroyedRecordFolder() throws Exception {
final NodeRef testFolder = doTestInTransaction(new Test<NodeRef>() {
@Override
public NodeRef run() {
// create folder
NodeRef testFolder = recordFolderService.createRecordFolder(rmContainer, "Peter Edward Francis");
// complete event
Map<String, Serializable> params = new HashMap<String, Serializable>(1);
params.put(CompleteEventAction.PARAM_EVENT_NAME, CommonRMTestUtils.DEFAULT_EVENT_NAME);
rmActionService.executeRecordsManagementAction(testFolder, CompleteEventAction.NAME, params);
// cutoff folder
rmActionService.executeRecordsManagementAction(testFolder, CutOffAction.NAME);
// destroy folder
rmActionService.executeRecordsManagementAction(testFolder, DestroyAction.NAME);
return testFolder;
}
@Override
public void test(NodeRef testFolder) throws Exception {
// take a look at delete capability
Capability deleteCapability = capabilityService.getCapability("DeleteRecordFolder");
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, deleteCapability.evaluate(testFolder));
}
});
doTestInTransaction(new Test<Void>() {
@Override
public Void run() throws Exception {
fileFolderService.delete(testFolder);
return null;
}
});
}
use of org.alfresco.module.org_alfresco_module_rm.capability.Capability in project records-management by Alfresco.
the class RM1008Test method testHold.
public void testHold() {
final NodeRef hold = doTestInTransaction(new Test<NodeRef>() {
@Override
public NodeRef run() {
// create hold object
NodeRef hold = holdService.createHold(filePlan, "my hold", "my reason", "my description");
holdService.addToHold(hold, rmFolder);
return hold;
}
}, ADMIN_USER);
doTestInTransaction(new Test<Void>() {
@Override
public Void run() {
Capability viewRecords = capabilityService.getCapability("ViewRecords");
assertNotNull(viewRecords);
assertEquals(AccessStatus.ALLOWED, viewRecords.hasPermission(hold));
assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(hold, RMPermissionModel.FILING));
return null;
}
}, ADMIN_USER);
doTestInTransaction(new Test<Void>() {
@Override
public Void run() {
Capability viewRecords = capabilityService.getCapability("ViewRecords");
assertNotNull(viewRecords);
assertEquals(AccessStatus.DENIED, viewRecords.hasPermission(hold));
assertEquals(AccessStatus.DENIED, permissionService.hasPermission(hold, RMPermissionModel.FILING));
return null;
}
}, myUser);
doTestInTransaction(new Test<Void>() {
@Override
public Void run() {
filePlanPermissionService.setPermission(filePlan, myUser, FILING);
return null;
}
}, ADMIN_USER);
doTestInTransaction(new Test<Void>() {
@Override
public Void run() {
Capability viewRecords = capabilityService.getCapability("ViewRecords");
assertNotNull(viewRecords);
assertEquals(AccessStatus.DENIED, viewRecords.hasPermission(hold));
assertEquals(AccessStatus.DENIED, permissionService.hasPermission(hold, RMPermissionModel.READ_RECORDS));
assertEquals(AccessStatus.DENIED, permissionService.hasPermission(hold, RMPermissionModel.FILING));
return null;
}
}, myUser);
doTestInTransaction(new Test<Void>() {
@Override
public Void run() {
filePlanPermissionService.deletePermission(filePlan, myUser, FILING);
return null;
}
}, ADMIN_USER);
doTestInTransaction(new Test<Void>() {
@Override
public Void run() {
Capability viewRecords = capabilityService.getCapability("ViewRecords");
assertNotNull(viewRecords);
assertEquals(AccessStatus.DENIED, viewRecords.hasPermission(hold));
assertEquals(AccessStatus.DENIED, permissionService.hasPermission(hold, RMPermissionModel.FILING));
return null;
}
}, myUser);
}
use of org.alfresco.module.org_alfresco_module_rm.capability.Capability in project records-management by Alfresco.
the class RmSubstitutionSuggestionsGet method isNodeRefAppropriateForPathSuggestion.
/**
* Identifies record category and record folder types of nodeRef
*
* @param nodeRef Instance of NodeRef to be tested
* @return True if the passed NodeRef instance is a record category or record folder
*/
private boolean isNodeRefAppropriateForPathSuggestion(NodeRef nodeRef, boolean unfiled) {
// check node type
QName type = nodeService.getType(nodeRef);
boolean isCorrectType = (!unfiled && (RecordsManagementModel.TYPE_RECORD_FOLDER.equals(type) || RecordsManagementModel.TYPE_RECORD_CATEGORY.equals(type)) || (unfiled && RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER.equals(type)));
// check permissions
boolean canView = false;
if (isCorrectType) {
Capability createCapability = capabilityService.getCapability(CREATE_CAPABILITY);
Capability viewCapability = capabilityService.getCapability(VIEW_CAPABILITY);
if ((createCapability != null) && (viewCapability != null)) {
List<String> requiredCapabilities = new ArrayList<String>();
requiredCapabilities.add(CREATE_CAPABILITY);
requiredCapabilities.add(VIEW_CAPABILITY);
Map<Capability, AccessStatus> map = capabilityService.getCapabilitiesAccessState(nodeRef, requiredCapabilities);
if (map.containsKey(createCapability) && map.containsKey(viewCapability)) {
AccessStatus createAccessStatus = map.get(createCapability);
AccessStatus viewAccessStatus = map.get(viewCapability);
if (createAccessStatus.equals(AccessStatus.ALLOWED) && viewAccessStatus.equals(AccessStatus.ALLOWED)) {
canView = true;
}
}
}
}
return isCorrectType && canView;
}
use of org.alfresco.module.org_alfresco_module_rm.capability.Capability in project records-management by Alfresco.
the class RecordServiceImpl method isPropertyEditable.
/**
* @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#isPropertyEditable(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
*/
@Override
public boolean isPropertyEditable(NodeRef record, QName property) {
ParameterCheck.mandatory("record", record);
ParameterCheck.mandatory("property", property);
if (!isRecord(record)) {
throw new AlfrescoRuntimeException("Cannot check if the property " + property.toString() + " is editable, because node reference is not a record.");
}
NodeRef filePlan = getFilePlan(record);
// DEBUG ...
boolean debugEnabled = LOGGER.isDebugEnabled();
if (debugEnabled) {
LOGGER.debug("Checking whether property " + property.toString() + " is editable for user " + AuthenticationUtil.getRunAsUser());
Set<Role> roles = filePlanRoleService.getRolesByUser(filePlan, AuthenticationUtil.getRunAsUser());
LOGGER.debug(" ... users roles");
for (Role role : roles) {
LOGGER.debug(" ... user has role " + role.getName() + " with capabilities ");
for (Capability cap : role.getCapabilities()) {
LOGGER.debug(" ... " + cap.getName());
}
}
LOGGER.debug(" ... user has the following set permissions on the file plan");
Set<AccessPermission> perms = permissionService.getAllSetPermissions(filePlan);
for (AccessPermission perm : perms) {
if ((perm.getPermission().contains(RMPermissionModel.EDIT_NON_RECORD_METADATA) || perm.getPermission().contains(RMPermissionModel.EDIT_RECORD_METADATA))) {
LOGGER.debug(" ... " + perm.getAuthority() + " - " + perm.getPermission() + " - " + perm.getAccessStatus().toString());
}
}
if (permissionService.hasPermission(filePlan, RMPermissionModel.EDIT_NON_RECORD_METADATA).equals(AccessStatus.ALLOWED)) {
LOGGER.debug(" ... user has the edit non record metadata permission on the file plan");
}
}
// END DEBUG ...
boolean result = alwaysEditProperty(property);
if (result) {
LOGGER.debug(" ... property marked as always editable.");
} else {
boolean allowRecordEdit = false;
boolean allowNonRecordEdit = false;
AccessStatus accessNonRecord = capabilityService.getCapabilityAccessState(record, RMPermissionModel.EDIT_NON_RECORD_METADATA);
AccessStatus accessDeclaredRecord = capabilityService.getCapabilityAccessState(record, RMPermissionModel.EDIT_DECLARED_RECORD_METADATA);
AccessStatus accessRecord = capabilityService.getCapabilityAccessState(record, RMPermissionModel.EDIT_RECORD_METADATA);
if (AccessStatus.ALLOWED.equals(accessNonRecord)) {
LOGGER.debug(" ... user has edit nonrecord metadata capability");
allowNonRecordEdit = true;
}
if (AccessStatus.ALLOWED.equals(accessRecord) || AccessStatus.ALLOWED.equals(accessDeclaredRecord)) {
LOGGER.debug(" ... user has edit record or declared metadata capability");
allowRecordEdit = true;
}
if (allowNonRecordEdit && allowRecordEdit) {
LOGGER.debug(" ... so all properties can be edited.");
result = true;
} else if (allowNonRecordEdit && !allowRecordEdit) {
// can only edit non record properties
if (!isRecordMetadata(filePlan, property)) {
LOGGER.debug(" ... property is not considered record metadata so editable.");
result = true;
} else {
LOGGER.debug(" ... property is considered record metadata so not editable.");
}
} else if (!allowNonRecordEdit && allowRecordEdit) {
// can only edit record properties
if (isRecordMetadata(filePlan, property)) {
LOGGER.debug(" ... property is considered record metadata so editable.");
result = true;
} else {
LOGGER.debug(" ... property is not considered record metadata so not editable.");
}
}
// otherwise we can't edit any properties so just return the empty set
}
return result;
}
Aggregations