Search in sources :

Example 11 with Capability

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

the class RM1008Test method testTransfer.

public void testTransfer() {
    final NodeRef transferFolder = doTestInTransaction(new Test<NodeRef>() {

        @Override
        public NodeRef run() {
            NodeRef transferCat = filePlanService.createRecordCategory(filePlan, "transferCat");
            Map<QName, Serializable> dsProps = new HashMap<QName, Serializable>(3);
            dsProps.put(PROP_DISPOSITION_AUTHORITY, "test");
            dsProps.put(PROP_DISPOSITION_INSTRUCTIONS, "test");
            dsProps.put(PROP_RECORD_LEVEL_DISPOSITION, false);
            DispositionSchedule dispositionSchedule = dispositionService.createDispositionSchedule(transferCat, dsProps);
            Map<QName, Serializable> adParams = new HashMap<QName, Serializable>(3);
            adParams.put(PROP_DISPOSITION_ACTION_NAME, "cutoff");
            adParams.put(PROP_DISPOSITION_DESCRIPTION, "test");
            adParams.put(PROP_DISPOSITION_PERIOD, "immediately|0");
            dispositionService.addDispositionActionDefinition(dispositionSchedule, adParams);
            adParams = new HashMap<QName, Serializable>(3);
            adParams.put(PROP_DISPOSITION_ACTION_NAME, "transfer");
            adParams.put(PROP_DISPOSITION_DESCRIPTION, "test");
            adParams.put(PROP_DISPOSITION_PERIOD, "immediately|0");
            dispositionService.addDispositionActionDefinition(dispositionSchedule, adParams);
            return recordFolderService.createRecordFolder(transferCat, "transferFolder");
        }
    });
    final NodeRef transfer = doTestInTransaction(new Test<NodeRef>() {

        @Override
        public NodeRef run() {
            rmActionService.executeRecordsManagementAction(transferFolder, "cutoff");
            rmActionService.executeRecordsManagementAction(transferFolder, "transfer");
            NodeRef transferContainer = filePlanService.getTransferContainer(filePlan);
            List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(transferContainer, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
            return childAssocs.get(0).getChildRef();
        }

        @Override
        public void test(NodeRef result) throws Exception {
            assertNotNull(result);
            assertEquals(TYPE_TRANSFER, nodeService.getType(result));
        }
    });
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() {
            Capability viewRecords = capabilityService.getCapability("ViewRecords");
            assertNotNull(viewRecords);
            assertEquals(AccessStatus.ALLOWED, viewRecords.hasPermission(transfer));
            assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(transfer, 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(transfer));
            assertEquals(AccessStatus.DENIED, permissionService.hasPermission(transfer, 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(transfer));
            assertEquals(AccessStatus.DENIED, permissionService.hasPermission(transfer, RMPermissionModel.READ_RECORDS));
            assertEquals(AccessStatus.DENIED, permissionService.hasPermission(transfer, 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(transfer));
            assertEquals(AccessStatus.DENIED, permissionService.hasPermission(transfer, RMPermissionModel.FILING));
            return null;
        }
    }, myUser);
}
Also used : Serializable(java.io.Serializable) Capability(org.alfresco.module.org_alfresco_module_rm.capability.Capability) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) DispositionSchedule(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule) NodeRef(org.alfresco.service.cmr.repository.NodeRef) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with Capability

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

the class DeclarativeCapabilityTest method testMoveRecordFolderCapability.

public void testMoveRecordFolderCapability() {
    // grab the move record capability
    final Capability capability = capabilityService.getCapability("MoveRecordFolder");
    assertNotNull(capability);
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() {
            // first take a look at just the record
            assertEquals(AccessStatus.DENIED, capability.hasPermission(rmContainer));
            assertEquals(AccessStatus.UNDETERMINED, capability.hasPermission(rmFolder));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(record));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(declaredRecord));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(frozenRecordFolder));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(recordFolderContainsFrozen));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(frozenRecord));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(closedFolder));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(undeclaredRecord));
            assertEquals(AccessDecisionVoter.ACCESS_DENIED, capability.evaluate(rmFolder, moveToCategory));
            return null;
        }
    }, recordsManagerName);
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() {
            for (String user : testUsers) {
                filePlanPermissionService.setPermission(moveToCategory, user, RMPermissionModel.FILING);
            }
            return null;
        }
    }, ADMIN_USER);
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() {
            assertEquals(AccessStatus.DENIED, capability.hasPermission(rmContainer));
            assertEquals(AccessStatus.UNDETERMINED, capability.hasPermission(rmFolder));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(record));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(declaredRecord));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(frozenRecordFolder));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(recordFolderContainsFrozen));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(frozenRecord));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(closedFolder));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(undeclaredRecord));
            assertEquals(AccessDecisionVoter.ACCESS_GRANTED, capability.evaluate(rmFolder, moveToCategory));
            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));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(frozenRecordFolder));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(recordFolderContainsFrozen));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(frozenRecord));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(closedFolder));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(undeclaredRecord));
            assertEquals(AccessDecisionVoter.ACCESS_DENIED, capability.evaluate(rmFolder, moveToCategory));
            return null;
        }
    }, rmUserName);
}
Also used : DeclarativeCompositeCapability(org.alfresco.module.org_alfresco_module_rm.capability.declarative.DeclarativeCompositeCapability) DeclarativeCapability(org.alfresco.module.org_alfresco_module_rm.capability.declarative.DeclarativeCapability) Capability(org.alfresco.module.org_alfresco_module_rm.capability.Capability)

Example 13 with Capability

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

the class DeclarativeCapabilityTest method testCreateRecordCapability.

/**
 * Specific declarative capability tests
 */
public void testCreateRecordCapability() {
    final Capability capability = capabilityService.getCapability("CreateRecords");
    assertNotNull(capability);
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() {
            assertEquals(AccessStatus.DENIED, capability.hasPermission(rmContainer));
            assertEquals(AccessStatus.ALLOWED, capability.hasPermission(rmFolder));
            assertEquals(AccessStatus.ALLOWED, capability.hasPermission(record));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(declaredRecord));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(frozenRecordFolder));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(recordFolderContainsFrozen));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(frozenRecord));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(closedFolder));
            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));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(frozenRecordFolder));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(recordFolderContainsFrozen));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(frozenRecord));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(closedFolder));
            return null;
        }
    }, rmUserName);
}
Also used : DeclarativeCompositeCapability(org.alfresco.module.org_alfresco_module_rm.capability.declarative.DeclarativeCompositeCapability) DeclarativeCapability(org.alfresco.module.org_alfresco_module_rm.capability.declarative.DeclarativeCapability) Capability(org.alfresco.module.org_alfresco_module_rm.capability.Capability)

Example 14 with Capability

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

the class DeclarativeCapabilityTest method testMoveRecordCapability.

public void testMoveRecordCapability() {
    // grab the move record capability
    final Capability capability = capabilityService.getCapability("MoveRecords");
    assertNotNull(capability);
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() {
            // first take a look at just the record
            assertEquals(AccessStatus.DENIED, capability.hasPermission(rmContainer));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(rmFolder));
            assertEquals(AccessStatus.UNDETERMINED, capability.hasPermission(record));
            assertEquals(AccessStatus.UNDETERMINED, capability.hasPermission(declaredRecord));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(frozenRecordFolder));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(recordFolderContainsFrozen));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(frozenRecord));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(closedFolder));
            assertEquals(AccessStatus.UNDETERMINED, capability.hasPermission(undeclaredRecord));
            // now lets take a look when we know what the destination is
            // NOTE:  should be denied since we do not have file permission on the destination folder
            // despite having the capability!
            assertEquals(AccessDecisionVoter.ACCESS_DENIED, capability.evaluate(record, moveToFolder));
            assertEquals(AccessDecisionVoter.ACCESS_DENIED, capability.evaluate(declaredRecord, moveToFolder));
            assertEquals(AccessDecisionVoter.ACCESS_DENIED, capability.evaluate(undeclaredRecord, moveToFolder));
            assertEquals(AccessDecisionVoter.ACCESS_DENIED, capability.evaluate(frozenRecord, moveToFolder));
            return null;
        }
    }, recordsManagerName);
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() {
            for (String user : testUsers) {
                filePlanPermissionService.setPermission(moveToFolder, user, RMPermissionModel.FILING);
            }
            return null;
        }
    }, ADMIN_USER);
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() {
            // first take a look at just the record
            assertEquals(AccessStatus.DENIED, capability.hasPermission(rmContainer));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(rmFolder));
            assertEquals(AccessStatus.UNDETERMINED, capability.hasPermission(record));
            assertEquals(AccessStatus.UNDETERMINED, capability.hasPermission(declaredRecord));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(frozenRecordFolder));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(recordFolderContainsFrozen));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(frozenRecord));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(closedFolder));
            assertEquals(AccessStatus.UNDETERMINED, capability.hasPermission(undeclaredRecord));
            // now lets take a look when we know what the destination is
            // NOTE:  should be allowed now since we have filling permission on the destination folder
            assertEquals(AccessDecisionVoter.ACCESS_GRANTED, capability.evaluate(record, moveToFolder));
            assertEquals(AccessDecisionVoter.ACCESS_GRANTED, capability.evaluate(declaredRecord, moveToFolder));
            assertEquals(AccessDecisionVoter.ACCESS_GRANTED, capability.evaluate(undeclaredRecord, moveToFolder));
            assertEquals(AccessDecisionVoter.ACCESS_DENIED, capability.evaluate(frozenRecord, moveToFolder));
            return null;
        }
    }, recordsManagerName);
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() {
            // first take a look at just the record
            assertEquals(AccessStatus.DENIED, capability.hasPermission(rmContainer));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(rmFolder));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(record));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(declaredRecord));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(frozenRecordFolder));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(recordFolderContainsFrozen));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(frozenRecord));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(closedFolder));
            assertEquals(AccessStatus.DENIED, capability.hasPermission(undeclaredRecord));
            // now lets take a look when we know what the destination is
            // NOTE:  should be allowed now since we have filling permission on the destination folder
            assertEquals(AccessDecisionVoter.ACCESS_DENIED, capability.evaluate(record, moveToFolder));
            assertEquals(AccessDecisionVoter.ACCESS_DENIED, capability.evaluate(declaredRecord, moveToFolder));
            assertEquals(AccessDecisionVoter.ACCESS_DENIED, capability.evaluate(undeclaredRecord, moveToFolder));
            assertEquals(AccessDecisionVoter.ACCESS_DENIED, capability.evaluate(frozenRecord, moveToFolder));
            return null;
        }
    }, rmUserName);
}
Also used : DeclarativeCompositeCapability(org.alfresco.module.org_alfresco_module_rm.capability.declarative.DeclarativeCompositeCapability) DeclarativeCapability(org.alfresco.module.org_alfresco_module_rm.capability.declarative.DeclarativeCapability) Capability(org.alfresco.module.org_alfresco_module_rm.capability.Capability)

Example 15 with Capability

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

the class CompositeCapabilityTest method testUpdate.

public void testUpdate() {
    final Capability capability = capabilityService.getCapability("Update");
    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);
}
Also used : Capability(org.alfresco.module.org_alfresco_module_rm.capability.Capability)

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