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;
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);
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());
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;
}
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);
}
assertThat(organization.getUrl()).isNull();
assertThat(organization.getAvatarUrl()).isNull();
assertThat(organization.isGuarded()).isFalse();
+ assertThat(organization.getUserId()).isNull();
}
@Test
}
@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);
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);
}