use of com.enonic.xp.security.User in project xp by enonic.
the class ModifyProfileHandler method execute.
public PropertyTreeMapper execute() {
final Optional<User> user = this.securityService.get().getUser(this.key);
if (user.isPresent()) {
final UpdateUserParams params = UpdateUserParams.create().userKey(this.key).editor(this::newProfileEditor).build();
final User updatedUser = this.securityService.get().updateUser(params);
final PropertyTree updatedProfile = updatedUser.getProfile();
return createPropertyTreeMapper(updatedProfile, false);
}
return null;
}
use of com.enonic.xp.security.User 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.User 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");
}
use of com.enonic.xp.security.User in project xp by enonic.
the class ModifyProfileHandlerTest method testExamples.
@Test
public void testExamples() {
final User user = TestDataFixtures.getTestUser();
Mockito.when(securityService.getUser(Mockito.any())).thenReturn(Optional.of(user));
Mockito.when(this.securityService.updateUser(Mockito.isA(UpdateUserParams.class))).thenAnswer(invocationOnMock -> invokeUpdate((UpdateUserParams) invocationOnMock.getArguments()[0], user));
runScript("/lib/xp/examples/auth/modifyProfile.js");
}
use of com.enonic.xp.security.User in project xp by enonic.
the class ModifyUserHandlerTest method invokeUpdate.
private User invokeUpdate(final UpdateUserParams params) {
final UserEditor editor = params.getEditor();
assertNotNull(editor);
final User user = TestDataFixtures.getTestUser();
final EditableUser editable = new EditableUser(user);
editor.edit(editable);
return editable.build();
}
Aggregations