aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server/src
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-02-10 16:33:52 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-02-10 18:29:38 +0100
commit5d28f7114fcab2087e3637b3055e497a4afd96cb (patch)
treee7ec1362c83afc3f1604bae9f25b82e99250e2e3 /server/sonar-server/src
parent04f7859ab0bcff24a9ab1d621c67d37ba44aa5bb (diff)
downloadsonarqube-5d28f7114fcab2087e3637b3055e497a4afd96cb.tar.gz
sonarqube-5d28f7114fcab2087e3637b3055e497a4afd96cb.zip
SONAR-8752 persist id of user for whom personal org was created
Diffstat (limited to 'server/sonar-server/src')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationCreationImpl.java13
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationCreationImplTest.java7
2 files changed, 13 insertions, 7 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationCreationImpl.java b/server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationCreationImpl.java
index fc842cf492b..e695811667f 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationCreationImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationCreationImpl.java
@@ -21,6 +21,7 @@ package org.sonar.server.organization;
import java.util.Date;
import java.util.Optional;
+import java.util.function.Consumer;
import javax.annotation.Nullable;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.System2;
@@ -67,7 +68,8 @@ public class OrganizationCreationImpl implements OrganizationCreation {
throw new KeyConflictException(format("Organization key '%s' is already used", key));
}
- OrganizationDto organization = insertOrganization(dbSession, newOrganization, false);
+ OrganizationDto organization = insertOrganization(dbSession, newOrganization, dto -> {
+ });
GroupDto group = insertOwnersGroup(dbSession, organization);
insertDefaultTemplate(dbSession, organization, group);
addCurrentUserToGroup(dbSession, group, creatorUserId);
@@ -92,7 +94,8 @@ public class OrganizationCreationImpl implements OrganizationCreation {
newOrganization.getKey(),
newUser.getLogin());
- OrganizationDto organization = insertOrganization(dbSession, newOrganization, true);
+ OrganizationDto organization = insertOrganization(dbSession, newOrganization,
+ dto -> dto.setGuarded(true).setUserId(newUser.getId()));
GroupDto group = insertOwnersGroup(dbSession, organization);
insertDefaultTemplate(dbSession, organization, group);
addCurrentUserToGroup(dbSession, group, newUser.getId());
@@ -122,15 +125,15 @@ public class OrganizationCreationImpl implements OrganizationCreation {
organizationValidation.checkAvatar(newOrganization.getAvatar());
}
- private OrganizationDto insertOrganization(DbSession dbSession, NewOrganization newOrganization, boolean guarded) {
+ private OrganizationDto insertOrganization(DbSession dbSession, NewOrganization newOrganization, Consumer<OrganizationDto> extendCreation) {
OrganizationDto res = new OrganizationDto()
.setUuid(uuidFactory.create())
.setName(newOrganization.getName())
.setKey(newOrganization.getKey())
.setDescription(newOrganization.getDescription())
.setUrl(newOrganization.getUrl())
- .setAvatarUrl(newOrganization.getAvatar())
- .setGuarded(guarded);
+ .setAvatarUrl(newOrganization.getAvatar());
+ extendCreation.accept(res);
dbClient.organizationDao().insert(dbSession, res);
return res;
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationCreationImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationCreationImplTest.java
index 0933ae201ec..be73210c965 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationCreationImplTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationCreationImplTest.java
@@ -151,7 +151,8 @@ public class OrganizationCreationImplTest {
assertThat(organization.getDescription()).isEqualTo(FULL_POPULATED_NEW_ORGANIZATION.getDescription());
assertThat(organization.getUrl()).isEqualTo(FULL_POPULATED_NEW_ORGANIZATION.getUrl());
assertThat(organization.getAvatarUrl()).isEqualTo(FULL_POPULATED_NEW_ORGANIZATION.getAvatar());
- assertThat(organization.isGuarded()).isFalse();
+ assertThat(organization.isGuarded()).isFalse();
+ assertThat(organization.getUserId()).isNull();
assertThat(organization.getCreatedAt()).isEqualTo(SOME_DATE);
assertThat(organization.getUpdatedAt()).isEqualTo(SOME_DATE);
}
@@ -183,6 +184,7 @@ public class OrganizationCreationImplTest {
assertThat(organization.getUrl()).isNull();
assertThat(organization.getAvatarUrl()).isNull();
assertThat(organization.isGuarded()).isFalse();
+ assertThat(organization.getUserId()).isNull();
}
@Test
@@ -224,7 +226,7 @@ public class OrganizationCreationImplTest {
}
@Test
- public void createForUser_creates_guarded_organization_with_name_and_key_generated_from_login() {
+ public void createForUser_creates_guarded_organization_with_name_and_key_generated_from_login_and_associated_to_user() {
UserDto user = dbTester.users().insertUser(A_LOGIN);
when(organizationValidation.generateKeyFrom(A_LOGIN)).thenReturn(SLUG_OF_A_LOGIN);
mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
@@ -240,6 +242,7 @@ public class OrganizationCreationImplTest {
assertThat(organization.getUrl()).isNull();
assertThat(organization.getAvatarUrl()).isNull();
assertThat(organization.isGuarded()).isTrue();
+ assertThat(organization.getUserId()).isEqualTo(user.getId());
assertThat(organization.getCreatedAt()).isEqualTo(SOME_DATE);
assertThat(organization.getUpdatedAt()).isEqualTo(SOME_DATE);
}