"Organization with key '%s' not found",
key);
- userSession.checkOrganizationPermission(organizationDto.getUuid(), SYSTEM_ADMIN);
+ if (organizationDto.isGuarded()) {
+ userSession.checkIsRoot();
+ } else {
+ userSession.checkOrganizationPermission(organizationDto.getUuid(), SYSTEM_ADMIN);
+ }
deleteProjects(dbSession, organizationDto.getUuid());
deletePermissions(dbSession, organizationDto.getUuid());
}
@Test
- public void request_fails_with_ForbiddenException_when_user_has_no_System_Administer_permission() {
+ public void request_fails_with_ForbiddenException_when_user_has_no_System_Administer_permission_for_non_guarded_organization() {
OrganizationDto organization = dbTester.organizations().insert();
userSession.logIn();
}
@Test
- public void request_fails_with_ForbiddenException_when_user_does_not_have_System_Administer_permission_on_specified_organization() {
+ public void request_fails_with_ForbiddenException_when_user_does_not_have_System_Administer_permission_on_specified_non_guarded_organization() {
OrganizationDto organization = dbTester.organizations().insert();
userSession.logIn().addOrganizationPermission(dbTester.getDefaultOrganization().getUuid(), SYSTEM_ADMIN);
}
@Test
- public void request_deletes_specified_organization_if_exists_and_user_has_Admin_permission_on_it() {
+ public void request_deletes_specified_non_guarded_organization_if_exists_and_user_has_Admin_permission_on_it() {
OrganizationDto organization = dbTester.organizations().insert();
userSession.logIn().addOrganizationPermission(organization.getUuid(), SYSTEM_ADMIN);
}
@Test
- public void request_deletes_specified_organization_if_exists_and_user_is_root() {
+ public void request_fails_with_ForbiddenException_when_user_has_System_Administer_permission_on_specified_guarded_organization() {
+ OrganizationDto organization = dbTester.organizations().insert(dto -> dto.setGuarded(true));
+ userSession.logIn().addOrganizationPermission(organization.getUuid(), SYSTEM_ADMIN);
+
+ expectedException.expect(ForbiddenException.class);
+ expectedException.expectMessage("Insufficient privileges");
+
+ sendRequest(organization);
+ }
+
+ @Test
+ public void request_deletes_specified_non_guarded_organization_if_exists_and_user_is_root() {
OrganizationDto organization = dbTester.organizations().insert();
userSession.logIn().setRoot();
verifyOrganizationDoesNotExist(organization);
}
+ @Test
+ public void request_deletes_specified_guarded_organization_if_exists_and_user_is_root() {
+ OrganizationDto organization = dbTester.organizations().insert(dto -> dto.setGuarded(true));
+ userSession.logIn().setRoot();
+
+ sendRequest(organization);
+
+ verifyOrganizationDoesNotExist(organization);
+ }
+
@Test
public void request_also_deletes_components_of_specified_organization() {
userSession.logIn().setRoot();
*/
package org.sonar.db.organization;
+import java.util.function.Consumer;
import javax.annotation.Nullable;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
return insert(OrganizationTesting.newOrganizationDto());
}
+ public OrganizationDto insert(Consumer<OrganizationDto> populator) {
+ OrganizationDto dto = OrganizationTesting.newOrganizationDto();
+ populator.accept(dto);
+ return insert(dto);
+ }
+
public OrganizationDto insertForKey(String key) {
- return insert(OrganizationTesting.newOrganizationDto().setKey(key));
+ return insert(dto -> dto.setKey(key));
}
public OrganizationDto insertForUuid(String organizationUuid) {
- return insert(OrganizationTesting.newOrganizationDto().setUuid(organizationUuid));
+ return insert(dto -> dto.setUuid(organizationUuid));
}
/**