diff options
Diffstat (limited to 'server/sonar-webserver-core')
2 files changed, 15 insertions, 16 deletions
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java index dbaaff2b528..a32c28e89e1 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java @@ -58,7 +58,7 @@ public class RegisterPermissionTemplates implements Startable { String defaultOrganizationUuid = defaultOrganizationProvider.get().getUuid(); Optional<DefaultTemplates> defaultTemplates = dbClient.organizationDao().getDefaultTemplates(dbSession, defaultOrganizationUuid); if (!defaultTemplates.isPresent()) { - PermissionTemplateDto defaultTemplate = getOrInsertDefaultTemplate(dbSession, defaultOrganizationUuid); + PermissionTemplateDto defaultTemplate = getOrInsertDefaultTemplate(dbSession); dbClient.organizationDao().setDefaultTemplates(dbSession, defaultOrganizationUuid, new DefaultTemplates().setProjectUuid(defaultTemplate.getUuid())); dbSession.commit(); } @@ -72,14 +72,14 @@ public class RegisterPermissionTemplates implements Startable { // nothing to do } - private PermissionTemplateDto getOrInsertDefaultTemplate(DbSession dbSession, String defaultOrganizationUuid) { + private PermissionTemplateDto getOrInsertDefaultTemplate(DbSession dbSession) { PermissionTemplateDto permissionTemplateDto = dbClient.permissionTemplateDao().selectByUuid(dbSession, DEFAULT_TEMPLATE_UUID); if (permissionTemplateDto != null) { return permissionTemplateDto; } PermissionTemplateDto template = new PermissionTemplateDto() - .setOrganizationUuid(defaultOrganizationUuid) + .setOrganizationUuid(defaultOrganizationProvider.get().getUuid()) .setName("Default template") .setUuid(DEFAULT_TEMPLATE_UUID) .setDescription("This permission template will be used as default when no other permission configuration is available") @@ -98,7 +98,7 @@ public class RegisterPermissionTemplates implements Startable { } private void insertPermissionForAdministrators(DbSession dbSession, PermissionTemplateDto template) { - Optional<GroupDto> admins = dbClient.groupDao().selectByName(dbSession, template.getOrganizationUuid(), DefaultGroups.ADMINISTRATORS); + Optional<GroupDto> admins = dbClient.groupDao().selectByName(dbSession, DefaultGroups.ADMINISTRATORS); if (admins.isPresent()) { insertGroupPermission(dbSession, template, UserRole.ADMIN, admins.get()); insertGroupPermission(dbSession, template, OrganizationPermission.APPLICATION_CREATOR.getKey(), admins.get()); @@ -109,11 +109,10 @@ public class RegisterPermissionTemplates implements Startable { } private void insertPermissionsForDefaultGroup(DbSession dbSession, PermissionTemplateDto template) { - String organizationUuid = template.getOrganizationUuid(); - String defaultGroupUuid = dbClient.organizationDao().getDefaultGroupUuid(dbSession, organizationUuid) - .orElseThrow(() -> new IllegalStateException(format("Default group for organization %s is not defined", organizationUuid))); + String defaultGroupUuid = dbClient.organizationDao().getDefaultGroupUuid(dbSession, defaultOrganizationProvider.get().getUuid()) + .orElseThrow(() -> new IllegalStateException("Default group is not defined")); GroupDto defaultGroup = Optional.ofNullable(dbClient.groupDao().selectByUuid(dbSession, defaultGroupUuid)) - .orElseThrow(() -> new IllegalStateException(format("Default group with id %s for organization %s doesn't exist", defaultGroupUuid, organizationUuid))); + .orElseThrow(() -> new IllegalStateException(format("Default group with id %s doesn't exist", defaultGroupUuid))); insertGroupPermission(dbSession, template, UserRole.USER, defaultGroup); insertGroupPermission(dbSession, template, UserRole.CODEVIEWER, defaultGroup); insertGroupPermission(dbSession, template, UserRole.ISSUE_ADMIN, defaultGroup); diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterPermissionTemplatesTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterPermissionTemplatesTest.java index ef39fb391aa..232a907ac32 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterPermissionTemplatesTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterPermissionTemplatesTest.java @@ -64,7 +64,7 @@ public class RegisterPermissionTemplatesTest { @Test public void fail_with_ISE_if_default_template_must_be_created_and_no_default_group_is_defined() { expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Default group for organization " + db.getDefaultOrganization().getUuid() + " is not defined"); + expectedException.expectMessage("Default group is not defined"); underTest.start(); } @@ -74,7 +74,7 @@ public class RegisterPermissionTemplatesTest { setDefaultGroup(new GroupDto().setUuid("22")); expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Default group with id 22 for organization " + db.getDefaultOrganization().getUuid() + " doesn't exist"); + expectedException.expectMessage("Default group with id 22 doesn't exist"); underTest.start(); } @@ -82,7 +82,7 @@ public class RegisterPermissionTemplatesTest { @Test public void insert_default_permission_template_if_fresh_install_without_governance() { GroupDto defaultGroup = createAndSetDefaultGroup(); - db.users().insertGroup(db.getDefaultOrganization(), DefaultGroups.ADMINISTRATORS); + db.users().insertGroup(DefaultGroups.ADMINISTRATORS); when(resourceTypes.isQualifierPresent(eq(Qualifiers.APP))).thenReturn(false); when(resourceTypes.isQualifierPresent(eq(Qualifiers.VIEW))).thenReturn(false); @@ -109,7 +109,7 @@ public class RegisterPermissionTemplatesTest { @Test public void insert_default_permission_template_if_fresh_install_with_governance() { GroupDto defaultGroup = createAndSetDefaultGroup(); - db.users().insertGroup(db.getDefaultOrganization(), DefaultGroups.ADMINISTRATORS); + db.users().insertGroup(DefaultGroups.ADMINISTRATORS); when(resourceTypes.isQualifierPresent(eq(Qualifiers.APP))).thenReturn(true); when(resourceTypes.isQualifierPresent(eq(Qualifiers.VIEW))).thenReturn(true); @@ -168,8 +168,8 @@ public class RegisterPermissionTemplatesTest { @Test public void do_not_fail_if_default_template_exists_and_is_registered() { PermissionTemplateDto projectTemplate = db.permissionTemplates().insertTemplate(newPermissionTemplateDto() - .setOrganizationUuid(db.getDefaultOrganization().getUuid()) - .setUuid(DEFAULT_TEMPLATE_UUID)); + .setOrganizationUuid(db.getDefaultOrganization().getUuid()) + .setUuid(DEFAULT_TEMPLATE_UUID)); db.organizations().setDefaultTemplates(projectTemplate, null, null); underTest.start(); @@ -189,7 +189,7 @@ public class RegisterPermissionTemplatesTest { String expectedGroupName) { assertThat( groupPermissions.stream().anyMatch(gp -> gp.getPermission().equals(expectedPermission) && Objects.equals(gp.getGroupName(), expectedGroupName))) - .isTrue(); + .isTrue(); } private void verifyDefaultTemplates() { @@ -205,7 +205,7 @@ public class RegisterPermissionTemplatesTest { } private GroupDto createAndSetDefaultGroup() { - GroupDto res = db.users().insertGroup(db.getDefaultOrganization()); + GroupDto res = db.users().insertGroup(); setDefaultGroup(res); return res; } |