use of io.gravitee.rest.api.model.UpdateGroupEntity in project gravitee-management-rest-api by gravitee-io.
the class GroupResource method updateGroup.
@PUT
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Update an existing group")
@ApiResponses({ @ApiResponse(code = 200, message = "Group successfully updated", response = GroupEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.ENVIRONMENT_GROUP, acls = RolePermissionAction.UPDATE), @Permission(value = RolePermission.GROUP_MEMBER, acls = RolePermissionAction.UPDATE) })
public GroupEntity updateGroup(@ApiParam(name = "group", required = true) @Valid @NotNull final UpdateGroupEntity updateGroupEntity) {
final GroupEntity groupEntity = checkRights();
// check if user is a 'simple group admin' or a platform admin
if (!permissionService.hasPermission(RolePermission.ENVIRONMENT_GROUP, GraviteeContext.getCurrentEnvironment(), CREATE, UPDATE, DELETE)) {
updateGroupEntity.setMaxInvitation(groupEntity.getMaxInvitation());
updateGroupEntity.setLockApiRole(groupEntity.isLockApiRole());
updateGroupEntity.setLockApplicationRole(groupEntity.isLockApplicationRole());
updateGroupEntity.setSystemInvitation(groupEntity.isSystemInvitation());
updateGroupEntity.setEmailInvitation(groupEntity.isEmailInvitation());
if (groupEntity.isLockApiRole()) {
updateGroupEntity.getRoles().put(RoleScope.API, groupEntity.getRoles().get(RoleScope.API));
}
if (groupEntity.isLockApplicationRole()) {
updateGroupEntity.getRoles().put(RoleScope.APPLICATION, groupEntity.getRoles().get(RoleScope.APPLICATION));
}
}
return groupService.update(group, updateGroupEntity);
}
use of io.gravitee.rest.api.model.UpdateGroupEntity in project gravitee-management-rest-api by gravitee-io.
the class GroupService_UpdateTest method shouldUpdateGroup.
@Test
public void shouldUpdateGroup() throws Exception {
UpdateGroupEntity updatedGroupEntity = new UpdateGroupEntity();
updatedGroupEntity.setDisableMembershipNotifications(true);
updatedGroupEntity.setEmailInvitation(true);
updatedGroupEntity.setEventRules(null);
updatedGroupEntity.setLockApiRole(true);
updatedGroupEntity.setLockApplicationRole(true);
updatedGroupEntity.setMaxInvitation(100);
updatedGroupEntity.setName("my-group-name");
updatedGroupEntity.setRoles(Maps.<RoleScope, String>builder().put(RoleScope.API, "OWNER").build());
updatedGroupEntity.setSystemInvitation(false);
when(groupRepository.findById(GROUP_ID)).thenReturn(Optional.of(Mockito.mock(Group.class)));
when(permissionService.hasPermission(RolePermission.ENVIRONMENT_GROUP, "DEFAULT", CREATE, UPDATE, DELETE)).thenReturn(true);
when(membershipService.getRoles(any(), any(), any(), any())).thenReturn(Collections.emptySet());
groupService.update(GROUP_ID, updatedGroupEntity);
verify(groupRepository).update(argThat(group -> group.isDisableMembershipNotifications() && group.isEmailInvitation() && group.getEventRules() == null && group.isLockApiRole() && group.isLockApplicationRole() && group.getMaxInvitation() == 100 && group.getName().equals("my-group-name") && !group.isSystemInvitation()));
verify(membershipService).addRoleToMemberOnReference(argThat(membershipReference -> membershipReference.getType() == MembershipReferenceType.API && membershipReference.getId() == null), argThat(membershipMember -> membershipMember.getMemberId().equals(GROUP_ID) && membershipMember.getReference() == null && membershipMember.getMemberType() == MembershipMemberType.GROUP), argThat(membershipRole -> membershipRole.getScope() == RoleScope.API && membershipRole.getName().equals("OWNER")));
}
use of io.gravitee.rest.api.model.UpdateGroupEntity in project gravitee-management-rest-api by gravitee-io.
the class GroupService_UpdateTest method shouldNotUpdateDefaultRoleBecausePrimaryOwner.
@Test
public void shouldNotUpdateDefaultRoleBecausePrimaryOwner() throws Exception {
UpdateGroupEntity updatedGroupEntity = new UpdateGroupEntity();
updatedGroupEntity.setRoles(Maps.<RoleScope, String>builder().put(RoleScope.API, "PRIMARY_OWNER").put(RoleScope.APPLICATION, "PRIMARY_OWNER").build());
when(groupRepository.findById(GROUP_ID)).thenReturn(Optional.of(Mockito.mock(Group.class)));
when(permissionService.hasPermission(RolePermission.ENVIRONMENT_GROUP, "DEFAULT", CREATE, UPDATE, DELETE)).thenReturn(true);
when(membershipService.getRoles(any(), any(), any(), any())).thenReturn(Collections.emptySet());
groupService.update(GROUP_ID, updatedGroupEntity);
verify(membershipService, never()).deleteReferenceMember(any(), any(), any(), any());
verify(membershipService, never()).addRoleToMemberOnReference(any(), any(), any());
}
Aggregations