private void insertAnAdministratorInDefaultOrganization() { db.users().insertAdminByUserPermission(db.getDefaultOrganization()); }
@Test public void remove_org_admin_is_allowed_when_another_org_admin_exists() { OrganizationDto anotherOrganization = db.organizations().insert(); UserDto admin1 = db.users().insertAdminByUserPermission(anotherOrganization); db.organizations().addMember(anotherOrganization, admin1); UserDto admin2 = db.users().insertAdminByUserPermission(anotherOrganization); db.organizations().addMember(anotherOrganization, admin2); userIndexer.commitAndIndex(db.getSession(), asList(admin1, admin2)); call(anotherOrganization.getKey(), admin1.getLogin()); assertNotAMember(anotherOrganization.getUuid(), admin1); assertMember(anotherOrganization.getUuid(), admin2); }
@Before public void setUp() { organization = db.organizations().insert(); project = db.components().insertPrivateProject(organization); user = db.users().insertUser(); db.organizations().addMember(organization, user); UserDto adminUser = db.users().insertAdminByUserPermission(organization); db.organizations().addMember(organization, adminUser); userIndexer.indexOnStartup(new HashSet<>()); }
@Test public void remove_user_by_group_name_in_specific_organization() { OrganizationDto org = db.organizations().insert(); db.users().insertDefaultGroup(org); GroupDto group = db.users().insertGroup(org, "a_group"); UserDto user = db.users().insertUser("a_user"); db.users().insertMember(group, user); // keep an administrator db.users().insertAdminByUserPermission(org); loginAsAdmin(org); newRequest() .setParam(PARAM_ORGANIZATION_KEY, org.getKey()) .setParam(PARAM_GROUP_NAME, group.getName()) .setParam(PARAM_LOGIN, user.getLogin()) .execute(); assertThat(db.users().selectGroupIdsOfUser(user)).isEmpty(); }
@Test public void fail_to_remove_last_organization_admin() { OrganizationDto anotherOrganization = db.organizations().insert(); UserDto admin = db.users().insertAdminByUserPermission(anotherOrganization); db.organizations().addMember(anotherOrganization, admin); UserDto user = db.users().insertUser(); db.organizations().addMember(anotherOrganization, user); expectedException.expect(BadRequestException.class); expectedException.expectMessage("The last administrator member cannot be removed"); call(anotherOrganization.getKey(), admin.getLogin()); }