mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-6881 Don't allow rejecting completed records through rule
This commit is contained in:
@@ -26,20 +26,27 @@
|
||||
*/
|
||||
package org.alfresco.rest.rm.community.records;
|
||||
|
||||
import static org.alfresco.rest.core.v0.BaseAPI.NODE_PREFIX;
|
||||
import static org.alfresco.rest.rm.community.requests.gscore.api.FilesAPI.PARENT_ID_PARAM;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomName;
|
||||
import static org.alfresco.utility.report.log.Step.STEP;
|
||||
import static org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.alfresco.dataprep.CMISUtil;
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.model.record.Record;
|
||||
import org.alfresco.rest.rm.community.model.record.RecordBodyFile;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
||||
import org.alfresco.rest.rm.community.model.rules.ActionsOnRule;
|
||||
import org.alfresco.rest.rm.community.model.rules.RuleDefinition;
|
||||
import org.alfresco.rest.v0.RecordsAPI;
|
||||
import org.alfresco.rest.v0.RulesAPI;
|
||||
import org.alfresco.test.AlfrescoTest;
|
||||
import org.alfresco.utility.model.FileModel;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
@@ -55,12 +62,15 @@ import org.testng.annotations.Test;
|
||||
*/
|
||||
public class RejectRecordTests extends BaseRMRestTest
|
||||
{
|
||||
private final static String REJECT_REASON = "Just because";
|
||||
private SiteModel publicSite;
|
||||
private RecordCategory recordCategory;
|
||||
private RecordCategoryChild recordFolder, linkRecordFolder;
|
||||
|
||||
@Autowired
|
||||
private RecordsAPI recordsAPI;
|
||||
@Autowired
|
||||
private RulesAPI rulesAPI;
|
||||
|
||||
@BeforeClass (alwaysRun = true)
|
||||
public void setUp() throws Exception
|
||||
@@ -76,7 +86,7 @@ public class RejectRecordTests extends BaseRMRestTest
|
||||
*/
|
||||
@Test
|
||||
@AlfrescoTest(jira = "RM-6869")
|
||||
public void rejectLinkedRecord() throws Exception
|
||||
public void rejectLinkedRecord()
|
||||
{
|
||||
STEP("Create a document in the collaboration site");
|
||||
FileModel testFile = dataContent.usingSite(publicSite)
|
||||
@@ -97,7 +107,7 @@ public class RejectRecordTests extends BaseRMRestTest
|
||||
assertTrue(isMatchingRecordInRecordFolder(testFile, linkRecordFolder), "Linked record not created");
|
||||
|
||||
STEP("Reject record");
|
||||
recordsAPI.rejectRecord(getAdminUser().getUsername(), getAdminUser().getPassword(), record.getName(), "Just because");
|
||||
recordsAPI.rejectRecord(getAdminUser().getUsername(), getAdminUser().getPassword(), record.getName(), REJECT_REASON);
|
||||
|
||||
STEP("Check record has been rejected");
|
||||
assertFalse(isMatchingRecordInRecordFolder(testFile, recordFolder), "Record rejection failure");
|
||||
@@ -106,6 +116,44 @@ public class RejectRecordTests extends BaseRMRestTest
|
||||
assertFalse(isMatchingRecordInRecordFolder(testFile, linkRecordFolder), "Record link not removed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that rejecting a completed record is not possible
|
||||
*/
|
||||
@Test
|
||||
@AlfrescoTest(jira = "RM-6881")
|
||||
public void rejectCompletedRecord() throws Exception
|
||||
{
|
||||
STEP("Create a document in the collaboration site");
|
||||
FileModel testFile = dataContent.usingSite(publicSite)
|
||||
.usingAdmin()
|
||||
.createContent(CMISUtil.DocumentType.TEXT_PLAIN);
|
||||
|
||||
STEP("Create a record folder with a reject rule");
|
||||
RecordCategoryChild folderWithRule = createFolder(recordCategory.getId(), getRandomName("recordFolder"));
|
||||
RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description")
|
||||
.applyToChildren(true).rejectReason(REJECT_REASON)
|
||||
.actions(Collections.singletonList(ActionsOnRule.REJECT.getActionValue()));
|
||||
rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition);
|
||||
|
||||
|
||||
STEP("Declare document as record to Unfiled Records folder");
|
||||
Record record = getRestAPIFactory().getFilesAPI().declareAsRecord(testFile.getNodeRefWithoutVersion());
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
STEP("Complete, then file the record to the folder with rule");
|
||||
completeRecord(record.getId());
|
||||
RecordBodyFile recordBodyFile = RecordBodyFile.builder().targetParentId(folderWithRule.getId()).build();
|
||||
getRestAPIFactory().getRecordsAPI().fileRecord(recordBodyFile, record.getId());
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
STEP("Check record hasn't been rejected through rule");
|
||||
assertTrue(isMatchingRecordInRecordFolder(testFile, folderWithRule), "Record rejection succeeded!");
|
||||
|
||||
STEP("Reject record directly through api");
|
||||
recordsAPI.rejectRecord(getAdminUser().getUsername(), getAdminUser().getPassword(), SC_INTERNAL_SERVER_ERROR,
|
||||
record.getName(), REJECT_REASON);
|
||||
}
|
||||
|
||||
@AfterClass (alwaysRun = true)
|
||||
public void cleanUp()
|
||||
{
|
||||
|
@@ -57,6 +57,7 @@ public class RejectAction extends RMActionExecuterAbstractBase
|
||||
protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
|
||||
{
|
||||
if (getNodeService().exists(actionedUponNodeRef) &&
|
||||
!getNodeService().hasAspect(actionedUponNodeRef, ASPECT_DECLARED_RECORD) &&
|
||||
!getFreezeService().isFrozen(actionedUponNodeRef) &&
|
||||
getNodeService().getProperty(actionedUponNodeRef, PROP_RECORD_ORIGINATING_LOCATION) != null)
|
||||
{
|
||||
|
Reference in New Issue
Block a user