use of com.enonic.xp.security.PrincipalKeys in project xp by enonic.
the class IssueQueryNodeQueryTranslator method translate.
public static NodeQuery translate(final IssueQuery issueQuery) {
final NodeQuery.Builder builder = NodeQuery.create();
final ValueFilter issueCollectionFilter = ValueFilter.create().fieldName(NodeIndexPath.NODE_TYPE.getPath()).addValue(ValueFactory.newString(IssueConstants.ISSUE_NODE_COLLECTION.getName())).build();
if (issueQuery.isCount()) {
builder.searchMode(SearchMode.COUNT);
}
builder.from(issueQuery.getFrom()).size(issueQuery.getSize()).addQueryFilter(issueCollectionFilter);
final PrincipalKey creator = issueQuery.getCreator();
if (creator != null) {
builder.addQueryFilter(ValueFilter.create().fieldName(CREATOR).addValues(creator.toString()).build());
}
final PrincipalKeys approvers = issueQuery.getApprovers();
if (approvers != null && approvers.isNotEmpty()) {
builder.addQueryFilter(ValueFilter.create().fieldName(APPROVERS).addValues(approvers.stream().map(PrincipalKey::toString).collect(toList())).build());
}
final ContentIds items = issueQuery.getItems();
if (items != null && items.isNotEmpty()) {
builder.addQueryFilter(ValueFilter.create().fieldName(PUBLISH_REQUEST_ITEM_ID).addValues(items.stream().map(ContentId::toString).collect(toList())).build());
}
final IssueStatus status = issueQuery.getStatus();
if (status != null) {
builder.addQueryFilter(ValueFilter.create().fieldName(STATUS).addValues(status.toString()).build());
}
final IssueType type = issueQuery.getType();
if (type != null) {
final Filter isOfType = ValueFilter.create().fieldName(TYPE).addValues(type.toString()).build();
if (type == IssueType.STANDARD) {
final Filter notExists = BooleanFilter.create().mustNot(ExistsFilter.create().fieldName(TYPE).build()).build();
final Filter isStandard = BooleanFilter.create().should(isOfType).should(notExists).build();
builder.addQueryFilter(isStandard);
} else {
builder.addQueryFilter(isOfType);
}
}
builder.setOrderExpressions(IssueConstants.DEFAULT_CHILD_ORDER.getOrderExpressions());
return builder.build();
}
use of com.enonic.xp.security.PrincipalKeys in project xp by enonic.
the class GetMembershipsHandler method getMemberships.
public List<PrincipalMapper> getMemberships() {
final PrincipalKeys principalKeys;
if (transitive) {
principalKeys = this.securityService.get().getAllMemberships(this.principalKey);
} else {
principalKeys = this.securityService.get().getMemberships(this.principalKey);
}
final Principals principals = this.securityService.get().getPrincipals(principalKeys);
return principals.stream().map(PrincipalMapper::new).collect(Collectors.toList());
}
use of com.enonic.xp.security.PrincipalKeys in project xp by enonic.
the class GetMembersHandler method getMembers.
public List<PrincipalMapper> getMembers() {
final PrincipalRelationships relationships = this.securityService.get().getRelationships(this.principalKey);
final PrincipalKeys principalKeys = PrincipalKeys.from(relationships.stream().map(PrincipalRelationship::getTo).toArray(PrincipalKey[]::new));
final Principals principals = this.securityService.get().getPrincipals(principalKeys);
return principals.stream().map(PrincipalMapper::new).collect(Collectors.toList());
}
use of com.enonic.xp.security.PrincipalKeys in project xp by enonic.
the class GetMembersHandlerTest method testGetMembers.
@Test
public void testGetMembers() {
final Group group = TestDataFixtures.getTestGroup();
final User user1 = TestDataFixtures.getTestUser();
final User user2 = TestDataFixtures.getTestUser2();
final PrincipalKeys principalKeys = PrincipalKeys.from(user1.getKey(), user2.getKey());
final PrincipalRelationships relationships = PrincipalRelationships.from(PrincipalRelationship.from(group.getKey()).to(user1.getKey()), PrincipalRelationship.from(group.getKey()).to(user2.getKey()));
Mockito.when(securityService.getRelationships(group.getKey())).thenReturn(relationships);
Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(user1, user2));
runFunction("/test/getMembers-test.js", "getMembers");
}
use of com.enonic.xp.security.PrincipalKeys in project xp by enonic.
the class GetMembersHandlerTest method testExamples.
@Test
public void testExamples() {
final Group group = TestDataFixtures.getTestGroup();
final User user1 = TestDataFixtures.getTestUser();
final User user2 = TestDataFixtures.getTestUser2();
final PrincipalKeys principalKeys = PrincipalKeys.from(user1.getKey(), user2.getKey());
final PrincipalRelationships relationships = PrincipalRelationships.from(PrincipalRelationship.from(group.getKey()).to(user1.getKey()), PrincipalRelationship.from(group.getKey()).to(user2.getKey()));
Mockito.when(securityService.getRelationships(group.getKey())).thenReturn(relationships);
Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(user1, user2));
runScript("/lib/xp/examples/auth/getMembers.js");
}
Aggregations