checkNotTryingToDeleteDefaultGroup(dbSession, groupId);
checkNotTryingToDeleteLastAdminGroup(dbSession, groupId);
- removeGroupMembers(dbSession, groupId);
removeGroupPermissions(dbSession, groupId);
removeFromPermissionTemplates(dbSession, groupId);
+ updateRootFlagOfMembers(dbSession, groupId);
+ removeGroupMembers(dbSession, groupId);
dbClient.groupDao().deleteById(dbSession, groupId.getId());
dbSession.commit();
checkArgument(remaining > 0, "The last system admin group cannot be deleted");
}
- private void removeGroupMembers(DbSession dbSession, GroupId groupId) {
- dbClient.userGroupDao().deleteByGroupId(dbSession, groupId.getId());
- }
-
private void removeGroupPermissions(DbSession dbSession, GroupId groupId) {
dbClient.roleDao().deleteGroupRolesByGroupId(dbSession, groupId.getId());
}
private void removeFromPermissionTemplates(DbSession dbSession, GroupId groupId) {
dbClient.permissionTemplateDao().deleteByGroup(dbSession, groupId.getId());
}
+
+ private void updateRootFlagOfMembers(DbSession dbSession, GroupId groupId) {
+ dbClient.groupDao().updateRootFlagOfUsersInGroupFromPermissions(dbSession, groupId.getId(), defaultOrganizationProvider.get().getUuid());
+ }
+
+ private void removeGroupMembers(DbSession dbSession, GroupId groupId) {
+ dbClient.userGroupDao().deleteByGroupId(dbSession, groupId.getId());
+ }
}
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("The last system admin group cannot be deleted");
- newRequest().setParam(PARAM_GROUP_ID, adminGroup.getId().toString()).execute();
+ executeDeleteGroupRequest(adminGroup);
}
@Test
db.users().insertMember(adminGroup2, bigBoss);
loginAsAdmin(org);
- newRequest().setParam(PARAM_GROUP_ID, adminGroup1.getId().toString()).execute();
+ executeDeleteGroupRequest(adminGroup1);
assertThat(db.users().selectGroupPermissions(adminGroup2, null)).hasSize(1);
}
+ @Test
+ public void deleting_a_group_of_default_organization_with_admin_permissions_updates_root_flag_of_its_members() throws Exception {
+ UserDto rootByUserPermission1 = db.users().insertRootByUserPermission("root1");
+ UserDto rootByUserPermission2 = db.users().insertRootByUserPermission("root2");
+ UserDto rootByUserPermission3 = db.users().insertRootByUserPermission("root3");
+ GroupDto adminGroup1 = db.users().insertAdminGroup(db.getDefaultOrganization());
+ GroupDto adminGroup2 = db.users().insertAdminGroup(db.getDefaultOrganization());
+ // member of admin group 1
+ UserDto rootByGroupPermission1 = db.users().insertRootByGroupPermission(adminGroup1);
+ UserDto rootByGroupPermission2 = db.users().insertRootByGroupPermission(adminGroup1);
+ db.users().insertMembers(adminGroup1, rootByUserPermission1);
+ db.users().insertMembers(adminGroup1, rootByUserPermission3);
+ // members of admin group 2
+ UserDto rootByGroupPermission3 = db.users().insertRootByGroupPermission(adminGroup2);
+ db.users().insertMembers(adminGroup2, rootByUserPermission2);
+ db.users().insertMembers(adminGroup2, rootByUserPermission3);
+ db.users().insertMembers(adminGroup2, rootByGroupPermission2);
+ loginAsAdmin(db.getDefaultOrganization());
+
+ executeDeleteGroupRequest(adminGroup1);
+ db.rootFlag().verify(rootByUserPermission1, true);
+ db.rootFlag().verifyUnchanged(rootByUserPermission2);
+ db.rootFlag().verify(rootByUserPermission3, true);
+ db.rootFlag().verify(rootByGroupPermission1, false);
+ db.rootFlag().verify(rootByGroupPermission2, true);
+ db.rootFlag().verifyUnchanged(rootByGroupPermission3);
+
+ executeDeleteGroupRequest(adminGroup2);
+ db.rootFlag().verify(rootByUserPermission1, true);
+ db.rootFlag().verify(rootByUserPermission2, true);
+ db.rootFlag().verify(rootByUserPermission3, true);
+ db.rootFlag().verify(rootByGroupPermission1, false);
+ db.rootFlag().verify(rootByGroupPermission2, false);
+ db.rootFlag().verify(rootByGroupPermission3, false);
+ }
+
+ @Test
+ public void deleting_a_group_of_other_organization_with_admin_permissions_does_not_update_root_flag_of_its_members() throws Exception {
+ OrganizationDto otherOrganization = db.organizations().insert();
+ UserDto rootByUserPermission1 = db.users().insertRootByUserPermission("root1");
+ UserDto rootByUserPermission2 = db.users().insertRootByUserPermission("root2");
+ UserDto rootByUserPermission3 = db.users().insertRootByUserPermission("root3");
+ db.users().insertPermissionOnUser(otherOrganization, rootByUserPermission1, SYSTEM_ADMIN);
+ db.users().insertPermissionOnUser(otherOrganization, rootByUserPermission2, SYSTEM_ADMIN);
+ db.users().insertPermissionOnUser(otherOrganization, rootByUserPermission3, SYSTEM_ADMIN);
+ GroupDto adminGroup1 = db.users().insertAdminGroup(otherOrganization);
+ GroupDto adminGroup2 = db.users().insertAdminGroup(otherOrganization);
+ // member of admin group 1
+ UserDto falselyRootByGroupPermission1 = db.users().makeRoot(db.users().insertUser());
+ UserDto falselyRootByGroupPermission2 = db.users().makeRoot(db.users().insertUser());
+ db.users().insertMembers(adminGroup1, falselyRootByGroupPermission1);
+ db.users().insertMembers(adminGroup1, falselyRootByGroupPermission2);
+ db.users().insertMembers(adminGroup1, rootByUserPermission1);
+ db.users().insertMembers(adminGroup1, rootByUserPermission3);
+ // members of admin group 2
+ UserDto falselyRootByGroupPermission3 = db.users().makeRoot(db.users().insertUser());
+ db.users().insertMembers(adminGroup2, falselyRootByGroupPermission3);
+ db.users().insertMembers(adminGroup2, rootByUserPermission2);
+ db.users().insertMembers(adminGroup2, rootByUserPermission3);
+ db.users().insertMembers(adminGroup2, falselyRootByGroupPermission2);
+ loginAsAdmin(otherOrganization);
+
+ executeDeleteGroupRequest(adminGroup1);
+ db.rootFlag().verify(rootByUserPermission1, true);
+ db.rootFlag().verifyUnchanged(rootByUserPermission2);
+ db.rootFlag().verify(rootByUserPermission3, true);
+ db.rootFlag().verify(falselyRootByGroupPermission1, false);
+ db.rootFlag().verify(falselyRootByGroupPermission2, false);
+ db.rootFlag().verifyUnchanged(falselyRootByGroupPermission3);
+
+ executeDeleteGroupRequest(adminGroup2);
+ db.rootFlag().verify(rootByUserPermission1, true);
+ db.rootFlag().verify(rootByUserPermission2, true);
+ db.rootFlag().verify(rootByUserPermission3, true);
+ db.rootFlag().verify(falselyRootByGroupPermission1, false);
+ db.rootFlag().verify(falselyRootByGroupPermission2, false);
+ db.rootFlag().verify(falselyRootByGroupPermission3, false);
+ }
+
+ private WsTester.Result executeDeleteGroupRequest(GroupDto adminGroup1) throws Exception {
+ return newRequest()
+ .setParam(PARAM_GROUP_ID, adminGroup1.getId().toString())
+ .execute();
+ }
+
private void addAdminToDefaultOrganization() {
addAdmin(db.getDefaultOrganization());
}