mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-3365 Add support for GET rule sets isInherited. (#1415)
This commit is contained in:
@@ -208,7 +208,13 @@ public class GetRuleSetsTests extends RestTest
|
||||
.getRuleSet(ruleSetId);
|
||||
|
||||
restClient.assertStatusCodeIs(OK);
|
||||
ruleSet.assertThat().field("id").is(ruleSetId);
|
||||
ruleSet.assertThat().field("id").is(ruleSetId)
|
||||
// Also check that the optional fields are not included by default.
|
||||
.assertThat().field("owningFolder").isNull()
|
||||
.assertThat().field("inheritedBy").isNull()
|
||||
.assertThat().field("linkedToBy").isNull()
|
||||
.assertThat().field("isInherited").isNull()
|
||||
.assertThat().field("isLinkedTo").isNull();
|
||||
}
|
||||
|
||||
/** Check we can get a rule set using the "-default-" synonym. */
|
||||
@@ -360,6 +366,87 @@ public class GetRuleSetsTests extends RestTest
|
||||
.assertThat().field("id").is(ruleSetId);
|
||||
}
|
||||
|
||||
/** Check that a user can see that a rule set is inherited even if they don't have permission to view the inheriting folder. */
|
||||
@Test
|
||||
public void getRuleSetAndIsInheritedWithoutPermission()
|
||||
{
|
||||
STEP("Create a site owned by admin and add user as a contributor");
|
||||
SiteModel siteModel = dataSite.usingAdmin().createPrivateRandomSite();
|
||||
dataUser.addUserToSite(user, siteModel, UserRole.SiteContributor);
|
||||
|
||||
STEP("Create a folder with a rule set and a private child folder to inherit it");
|
||||
FolderModel ruleFolder = dataContent.usingUser(user).usingSite(siteModel).createFolder();
|
||||
dataContent.usingAdmin().usingResource(ruleFolder).createFolder();
|
||||
RestRuleModel ruleModel = createRuleModelWithDefaultValues();
|
||||
coreAPIForUser().usingNode(ruleFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||
|
||||
STEP("Remove the user from the site");
|
||||
dataUser.removeUserFromSite(user, siteModel);
|
||||
|
||||
STEP("Get the rule set and isInherited field");
|
||||
RestRuleSetModel ruleSet = coreAPIForUser().usingNode(ruleFolder)
|
||||
.include("isInherited", "inheritedBy")
|
||||
.getDefaultRuleSet();
|
||||
|
||||
restClient.assertStatusCodeIs(OK);
|
||||
ruleSet.assertThat().field("isInherited").is(true)
|
||||
.assertThat().field("inheritedBy").isEmpty();
|
||||
|
||||
}
|
||||
|
||||
/** Check that the isInherited field includes rule sets which are only inherited via links. */
|
||||
@Test
|
||||
public void getRuleSetAndIsInheritedViaLink()
|
||||
{
|
||||
STEP("Create a site and a folder with a rule");
|
||||
SiteModel siteModel = dataSite.usingUser(user).createPublicRandomSite();
|
||||
FolderModel ruleFolder = dataContent.usingUser(user).usingSite(siteModel).createFolder();
|
||||
RestRuleModel ruleModel = createRuleModelWithDefaultValues();
|
||||
coreAPIForUser().usingNode(ruleFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||
|
||||
STEP("Create a second folder in the site that links to the rule set");
|
||||
FolderModel secondFolder = dataContent.usingUser(user).usingSite(siteModel).createFolder();
|
||||
dataContent.usingUser(user).usingResource(secondFolder).createFolder();
|
||||
RestRuleSetLinkModel ruleSetLink = new RestRuleSetLinkModel();
|
||||
ruleSetLink.setId(ruleFolder.getNodeRef());
|
||||
coreAPIForUser().usingNode(secondFolder).createRuleLink(ruleSetLink);
|
||||
|
||||
STEP("Get the rule set and isInherited field");
|
||||
RestRuleSetModel ruleSet = coreAPIForUser().usingNode(ruleFolder)
|
||||
.include("isInherited")
|
||||
.getDefaultRuleSet();
|
||||
|
||||
restClient.assertStatusCodeIs(OK);
|
||||
ruleSet.assertThat().field("isInherited").is(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that if a rule set is owned and linked to but not inherited then isInherited returns false.
|
||||
*/
|
||||
@Test
|
||||
public void getRuleSetAndIsInheritedCanBeFalse()
|
||||
{
|
||||
STEP("Create a site and a folder with a rule");
|
||||
SiteModel siteModel = dataSite.usingUser(user).createPublicRandomSite();
|
||||
FolderModel ruleFolder = dataContent.usingUser(user).usingSite(siteModel).createFolder();
|
||||
RestRuleModel ruleModel = createRuleModelWithDefaultValues();
|
||||
coreAPIForUser().usingNode(ruleFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||
|
||||
STEP("Create a second folder in the site that links to the rule set");
|
||||
FolderModel secondFolder = dataContent.usingUser(user).usingSite(siteModel).createFolder();
|
||||
RestRuleSetLinkModel ruleSetLink = new RestRuleSetLinkModel();
|
||||
ruleSetLink.setId(ruleFolder.getNodeRef());
|
||||
coreAPIForUser().usingNode(secondFolder).createRuleLink(ruleSetLink);
|
||||
|
||||
STEP("Get the rule set and isInherited field");
|
||||
RestRuleSetModel ruleSet = coreAPIForUser().usingNode(ruleFolder)
|
||||
.include("isInherited")
|
||||
.getDefaultRuleSet();
|
||||
|
||||
restClient.assertStatusCodeIs(OK);
|
||||
ruleSet.assertThat().field("isInherited").is(false);
|
||||
}
|
||||
|
||||
private RestCoreAPI coreAPIForUser()
|
||||
{
|
||||
return restClient.authenticateUser(user).withCoreAPI();
|
||||
|
@@ -32,6 +32,7 @@ import static org.alfresco.rest.api.model.rules.InclusionType.OWNED;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.rest.api.model.rules.RuleSet;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
@@ -47,6 +48,7 @@ public class RuleSetLoader
|
||||
protected static final String INCLUSION_TYPE = "inclusionType";
|
||||
protected static final String INHERITED_BY = "inheritedBy";
|
||||
protected static final String LINKED_TO_BY = "linkedToBy";
|
||||
protected static final String IS_INHERITED = "isInherited";
|
||||
private static final int MAX_INHERITED_BY_SIZE = 100;
|
||||
private NodeService nodeService;
|
||||
private RuleService ruleService;
|
||||
@@ -98,6 +100,10 @@ public class RuleSetLoader
|
||||
.collect(Collectors.toList());
|
||||
ruleSet.setLinkedToBy(linkedToBy);
|
||||
}
|
||||
if (includes.contains(IS_INHERITED))
|
||||
{
|
||||
ruleSet.setIsInherited(loadIsInherited(ruleSetNodeRef));
|
||||
}
|
||||
}
|
||||
return ruleSet;
|
||||
}
|
||||
@@ -107,6 +113,11 @@ public class RuleSetLoader
|
||||
return ruleService.getFoldersInheritingRuleSet(ruleSetNodeRef, MAX_INHERITED_BY_SIZE);
|
||||
}
|
||||
|
||||
private boolean loadIsInherited(NodeRef ruleSetNodeRef)
|
||||
{
|
||||
return AuthenticationUtil.runAsSystem(() -> !ruleService.getFoldersInheritingRuleSet(ruleSetNodeRef, 1).isEmpty());
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
|
@@ -43,6 +43,7 @@ public class RuleSet
|
||||
private InclusionType inclusionType;
|
||||
private List<NodeRef> inheritedBy;
|
||||
private List<NodeRef> linkedToBy;
|
||||
private Boolean isInherited;
|
||||
|
||||
public static RuleSet of(String id)
|
||||
{
|
||||
@@ -109,6 +110,26 @@ public class RuleSet
|
||||
this.linkedToBy = linkedToBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a flag indicating that the rule set is inherited by a folder.
|
||||
*
|
||||
* @param inherited The flag.
|
||||
*/
|
||||
public void setIsInherited(Boolean inherited)
|
||||
{
|
||||
isInherited = inherited;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find if the rule set is inherited by a folder.
|
||||
*
|
||||
* @return The value of the flag.
|
||||
*/
|
||||
public Boolean getIsInherited()
|
||||
{
|
||||
return isInherited;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
@@ -119,6 +140,7 @@ public class RuleSet
|
||||
.add("inclusionType='" + inclusionType + "'")
|
||||
.add("inheritedBy='" + inheritedBy + "'")
|
||||
.add("linkedToBy='" + linkedToBy + "'")
|
||||
.add("isInherited='" + isInherited + "'")
|
||||
.toString()
|
||||
+ '}';
|
||||
}
|
||||
@@ -135,13 +157,14 @@ public class RuleSet
|
||||
&& Objects.equals(owningFolder, ruleSet.owningFolder)
|
||||
&& inclusionType == ruleSet.inclusionType
|
||||
&& Objects.equals(inheritedBy, ruleSet.inheritedBy)
|
||||
&& Objects.equals(linkedToBy, ruleSet.linkedToBy);
|
||||
&& Objects.equals(linkedToBy, ruleSet.linkedToBy)
|
||||
&& Objects.equals(isInherited, ruleSet.isInherited);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(id, owningFolder, inclusionType, inheritedBy, linkedToBy);
|
||||
return Objects.hash(id, owningFolder, inclusionType, inheritedBy, linkedToBy, isInherited);
|
||||
}
|
||||
|
||||
public static Builder builder()
|
||||
@@ -156,6 +179,7 @@ public class RuleSet
|
||||
private InclusionType inclusionType;
|
||||
private List<NodeRef> inheritedBy;
|
||||
private List<NodeRef> linkedToBy;
|
||||
private Boolean isInherited;
|
||||
|
||||
public Builder id(String id)
|
||||
{
|
||||
@@ -187,6 +211,12 @@ public class RuleSet
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isInherited(Boolean isInherited)
|
||||
{
|
||||
this.isInherited = isInherited;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RuleSet create()
|
||||
{
|
||||
final RuleSet ruleSet = new RuleSet();
|
||||
@@ -195,6 +225,7 @@ public class RuleSet
|
||||
ruleSet.setInclusionType(inclusionType);
|
||||
ruleSet.setInheritedBy(inheritedBy);
|
||||
ruleSet.setLinkedToBy(linkedToBy);
|
||||
ruleSet.setIsInherited(isInherited);
|
||||
return ruleSet;
|
||||
}
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@ package org.alfresco.rest.api.impl.rules;
|
||||
|
||||
import static org.alfresco.rest.api.impl.rules.RuleSetLoader.INCLUSION_TYPE;
|
||||
import static org.alfresco.rest.api.impl.rules.RuleSetLoader.INHERITED_BY;
|
||||
import static org.alfresco.rest.api.impl.rules.RuleSetLoader.IS_INHERITED;
|
||||
import static org.alfresco.rest.api.impl.rules.RuleSetLoader.LINKED_TO_BY;
|
||||
import static org.alfresco.rest.api.impl.rules.RuleSetLoader.OWNING_FOLDER;
|
||||
import static org.alfresco.rest.api.model.rules.InclusionType.INHERITED;
|
||||
@@ -159,4 +160,14 @@ public class RuleSetLoaderTest extends TestCase
|
||||
RuleSet expected = RuleSet.builder().id(RULE_SET_ID).linkedToBy(List.of(LINKING_FOLDER)).create();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadRuleSet_isInherited()
|
||||
{
|
||||
// Call the method under test.
|
||||
RuleSet actual = ruleSetLoader.loadRuleSet(RULE_SET_NODE, FOLDER_NODE, List.of(IS_INHERITED));
|
||||
|
||||
RuleSet expected = RuleSet.builder().id(RULE_SET_ID).isInherited(true).create();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user