Search in sources :

Example 21 with Capability

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

the class ModelSecurityServiceImpl method canEdit.

/**
 * Indicates whether the current user can edit protected model artifact in the context
 * of a given node or not.
 *
 * @param nodeRef   node reference
 * @param artifact  protected model artifact
 * @return boolean  true if the current user can edit the protected model artifact, false otherwise
 */
private boolean canEdit(NodeRef nodeRef, ProtectedModelArtifact artifact) {
    boolean result = false;
    NodeRef filePlan = filePlanService.getFilePlan(nodeRef);
    if (filePlan != null) {
        for (Capability capability : artifact.getCapabilities()) {
            if (capability.hasPermission(nodeRef).equals(AccessStatus.ALLOWED)) {
                result = true;
                break;
            }
        }
    }
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Capability(org.alfresco.module.org_alfresco_module_rm.capability.Capability)

Example 22 with Capability

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

the class CreateRecordTest method testCreateRecordViaCoreServices.

/**
 * Given I have ViewRecord and CreateRecord capabilities
 * And I have filling on a record folder
 * When I create content via ScriptNode (simulated)
 * Then the record is successfully created
 *
 * @see https://issues.alfresco.com/jira/browse/RM-1956
 */
public void testCreateRecordViaCoreServices() throws Exception {
    doBehaviourDrivenTest(new BehaviourDrivenTest() {

        /**
         * test data
         */
        String roleName = GUID.generate();

        String user = GUID.generate();

        NodeRef recordFolder;

        NodeRef record;

        public void given() {
            // create a role with view and create capabilities
            Set<Capability> capabilities = new HashSet<Capability>(2);
            capabilities.add(capabilityService.getCapability("ViewRecords"));
            capabilities.add(capabilityService.getCapability("CreateRecords"));
            filePlanRoleService.createRole(filePlan, roleName, roleName, capabilities);
            // create user and assign to role
            createPerson(user, true);
            filePlanRoleService.assignRoleToAuthority(filePlan, roleName, user);
            // create file plan structure
            NodeRef rc = filePlanService.createRecordCategory(filePlan, GUID.generate());
            recordFolder = recordFolderService.createRecordFolder(rc, GUID.generate());
        }

        public void when() {
            // give read and file permissions to user
            filePlanPermissionService.setPermission(recordFolder, user, RMPermissionModel.FILING);
            record = AuthenticationUtil.runAs(new RunAsWork<NodeRef>() {

                public NodeRef doWork() throws Exception {
                    NodeRef record = fileFolderService.create(recordFolder, "testRecord.txt", ContentModel.TYPE_CONTENT).getNodeRef();
                    ContentData content = (ContentData) nodeService.getProperty(record, PROP_CONTENT);
                    nodeService.setProperty(record, PROP_CONTENT, ContentData.setMimetype(content, MimetypeMap.MIMETYPE_TEXT_PLAIN));
                    return record;
                }
            }, user);
        }

        public void then() {
            // check the details of the record
            assertTrue(recordService.isRecord(record));
            AuthenticationUtil.runAs(new RunAsWork<Void>() {

                public Void doWork() throws Exception {
                    // we are expecting an expception here
                    try {
                        ContentData content = (ContentData) nodeService.getProperty(record, PROP_CONTENT);
                        nodeService.setProperty(record, PROP_CONTENT, ContentData.setMimetype(content, MimetypeMap.MIMETYPE_TEXT_PLAIN));
                        fail("Expecting access denied exception");
                    } catch (AccessDeniedException exception) {
                    // expceted
                    }
                    return null;
                }
            }, user);
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) Set(java.util.Set) HashSet(java.util.HashSet) ContentData(org.alfresco.service.cmr.repository.ContentData) Capability(org.alfresco.module.org_alfresco_module_rm.capability.Capability) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException)

Example 23 with Capability

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

the class CreateRecordTest method testCreateRecordCapabilityOnlyFromFileFolderService.

/**
 */
public void testCreateRecordCapabilityOnlyFromFileFolderService() throws Exception {
    doBehaviourDrivenTest(new BehaviourDrivenTest() {

        /**
         * test data
         */
        String roleName = GUID.generate();

        String user = GUID.generate();

        NodeRef recordFolder;

        NodeRef record;

        public void given() {
            // create role
            Set<Capability> capabilities = new HashSet<Capability>(2);
            capabilities.add(capabilityService.getCapability("ViewRecords"));
            capabilities.add(capabilityService.getCapability("CreateRecords"));
            filePlanRoleService.createRole(filePlan, roleName, roleName, capabilities);
            // create user and assign to role
            createPerson(user, true);
            filePlanRoleService.assignRoleToAuthority(filePlan, roleName, user);
            // create file plan structure
            NodeRef rc = filePlanService.createRecordCategory(filePlan, GUID.generate());
            recordFolder = recordFolderService.createRecordFolder(rc, GUID.generate());
        }

        public void when() {
            // give read and file permissions to user
            filePlanPermissionService.setPermission(recordFolder, user, RMPermissionModel.FILING);
            AuthenticationUtil.runAs(new RunAsWork<Void>() {

                public Void doWork() throws Exception {
                    record = fileFolderService.create(recordFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
                    ContentWriter writer = contentService.getWriter(record, ContentModel.TYPE_CONTENT, true);
                    writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
                    writer.setEncoding("UTF-8");
                    writer.putContent("Lucy Wetherall");
                    return null;
                }
            }, user);
        }

        public void then() {
            // check the details of the record
            assertTrue(recordService.isRecord(record));
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) Set(java.util.Set) HashSet(java.util.HashSet) Capability(org.alfresco.module.org_alfresco_module_rm.capability.Capability) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)

Example 24 with Capability

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

the class MoveRecordFolderTest method testMoveDestroyedRecordFolder.

// try and move a destroyed folder
public void testMoveDestroyedRecordFolder() throws Exception {
    final NodeRef destination = doTestInTransaction(new Test<NodeRef>() {

        @Override
        public NodeRef run() {
            // create a record category (no disposition schedule)
            return filePlanService.createRecordCategory(filePlan, "Caitlin Reed");
        }
    });
    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 & destroy folder
            rmActionService.executeRecordsManagementAction(testFolder, CutOffAction.NAME);
            rmActionService.executeRecordsManagementAction(testFolder, DestroyAction.NAME);
            return testFolder;
        }
    });
    doTestInTransaction(new Test<NodeRef>() {

        @Override
        public NodeRef run() throws Exception {
            Capability moveCapability = capabilityService.getCapability("MoveRecordFolder");
            assertEquals(AccessDecisionVoter.ACCESS_GRANTED, moveCapability.evaluate(testFolder, destination));
            return fileFolderService.move(testFolder, destination, null).getNodeRef();
        }

        @Override
        public void test(NodeRef result) throws Exception {
            assertNotNull(result);
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) Capability(org.alfresco.module.org_alfresco_module_rm.capability.Capability) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with Capability

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

the class MoveRecordFolderTest method testMoveRecordFolderFromNoDisToDis.

/**
 * Try and move a folder from no disposition schedule to a disposition schedule
 *
 * @see https://issues.alfresco.com/jira/browse/RM-1039
 */
public void testMoveRecordFolderFromNoDisToDis() throws Exception {
    final NodeRef recordFolder = doTestInTransaction(new Test<NodeRef>() {

        @Override
        public NodeRef run() {
            // create a record category (no disposition schedule)
            NodeRef recordCategory = filePlanService.createRecordCategory(filePlan, "Caitlin Reed");
            // create a record folder
            return recordFolderService.createRecordFolder(recordCategory, "Grace Wetherall");
        }

        @Override
        public void test(NodeRef result) throws Exception {
            assertNotNull(result);
            assertNull(dispositionService.getDispositionSchedule(result));
            assertFalse(nodeService.hasAspect(result, ASPECT_DISPOSITION_LIFECYCLE));
            assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(result, FILING));
        }
    });
    final NodeRef record = doTestInTransaction(new Test<NodeRef>() {

        @Override
        public NodeRef run() {
            // create a record
            return fileFolderService.create(recordFolder, "mytest.txt", ContentModel.TYPE_CONTENT).getNodeRef();
        }

        @Override
        public void test(NodeRef result) throws Exception {
            assertNotNull(result);
            assertNull(dispositionService.getDispositionSchedule(result));
            assertFalse(nodeService.hasAspect(result, ASPECT_DISPOSITION_LIFECYCLE));
            assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(result, FILING));
        }
    });
    doTestInTransaction(new Test<NodeRef>() {

        @Override
        public NodeRef run() throws Exception {
            Capability capability = capabilityService.getCapability("CreateModifyDestroyFolders");
            assertEquals(AccessDecisionVoter.ACCESS_GRANTED, capability.evaluate(recordFolder));
            assertEquals(AccessDecisionVoter.ACCESS_GRANTED, capability.evaluate(recordFolder, rmContainer));
            // take a look at the move capability
            Capability moveCapability = capabilityService.getCapability("Move");
            assertEquals(AccessDecisionVoter.ACCESS_GRANTED, moveCapability.evaluate(recordFolder, rmContainer));
            // move the node
            return fileFolderService.move(recordFolder, rmContainer, null).getNodeRef();
        }

        @Override
        public void test(NodeRef result) throws Exception {
            assertNotNull(result);
            assertNotNull(dispositionService.getDispositionSchedule(result));
            assertTrue(nodeService.hasAspect(result, ASPECT_DISPOSITION_LIFECYCLE));
            DispositionAction dispositionAction = dispositionService.getNextDispositionAction(result);
            assertNotNull(dispositionAction);
            assertNull(dispositionAction.getAsOfDate());
            assertEquals("cutoff", dispositionAction.getName());
            assertEquals(1, dispositionAction.getEventCompletionDetails().size());
            // take a look at the record and check things are as we would expect
            assertFalse(nodeService.hasAspect(record, ASPECT_DISPOSITION_LIFECYCLE));
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Capability(org.alfresco.module.org_alfresco_module_rm.capability.Capability) DispositionAction(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction)

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