Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ private boolean validate(UserActionEntityRestrictions restrictions, Restrictions
return restrictions.getGroups() != null
&& params.getUserGroups() != null
&& restrictions.getGroups().getPrefix() != null
&& restrictions.getGroups().getSuffix() != null;
&& restrictions.getGroups().getSuffix() != null
&& params.getProjectKey() != null;
}

private boolean evaluateConditions(UserActionEntityRestrictions restrictions, RestrictionsParams params) {
return params.getUserGroups().stream().anyMatch(group ->
restrictions.getGroups().getPrefix().stream().anyMatch(group::startsWith) &&
restrictions.getGroups().getSuffix().stream().anyMatch(group::endsWith));
restrictions.getGroups().getSuffix().stream().anyMatch(group::endsWith) &&
group.contains(params.getProjectKey())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ void givenValidRestrictions_AndValidParams_whenEvaluate_ThenEvaluationPass_AndRe

CatalogItemUserActionGroupsRestriction groupsRestriction = CatalogItemUserActionGroupsRestrictionMother.of();
UserActionEntityRestrictions restrictions = UserActionEntityRestrictionsMother.of(groupsRestriction);
RestrictionsParams params = RestrictionsParamsMother.of(List.of("prefix-1-group-1-suffix-2"));
RestrictionsParams params = RestrictionsParamsMother.of(List.of("prefix-1-projectKey-suffix-2"));
params.setProjectKey(projectKey);
var evaluationRestrictions = new EvaluationRestrictions(projectKey, restrictions);

// When
Expand All @@ -32,6 +33,23 @@ void givenValidRestrictions_AndValidParams_whenEvaluate_ThenEvaluationPass_AndRe
assertThat(evaluateResult.getLeft()).isTrue();
}

@Test
void givenValidRestrictions_AndInValidParams_whenEvaluate_ThenEvaluationNotPass_AndReturnFalse() {
// Given
var projectKey = "projectKey";

CatalogItemUserActionGroupsRestriction groupsRestriction = CatalogItemUserActionGroupsRestrictionMother.of();
UserActionEntityRestrictions restrictions = UserActionEntityRestrictionsMother.of(groupsRestriction);
RestrictionsParams params = RestrictionsParamsMother.of(List.of("prefix-1-group-1-suffix-2"));
var evaluationRestrictions = new EvaluationRestrictions(projectKey, restrictions);

// When
Pair<Boolean, String> evaluateResult = groupsRestrictionsEvaluator.evaluate(evaluationRestrictions, params);

// Then
assertThat(evaluateResult.getLeft()).isFalse();
}

@Test
void givenValidRestrictions_AndValidParams_whenEvaluate_ThenEvaluationNotPass_AndReturnFalse() {
// Given
Expand Down