use of org.sonar.db.organization.DefaultTemplates in project sonarqube by SonarSource.
the class OrganizationCreationImpl method insertPersonalOrgDefaultTemplate.
private void insertPersonalOrgDefaultTemplate(DbSession dbSession, OrganizationDto organizationDto) {
long now = system2.now();
Date dateNow = new Date(now);
PermissionTemplateDto permissionTemplateDto = dbClient.permissionTemplateDao().insert(dbSession, new PermissionTemplateDto().setOrganizationUuid(organizationDto.getUuid()).setUuid(uuidFactory.create()).setName("Default template").setDescription(format(PERM_TEMPLATE_DESCRIPTION_PATTERN, organizationDto.getName())).setCreatedAt(dateNow).setUpdatedAt(dateNow));
insertProjectCreatorPermission(dbSession, permissionTemplateDto, UserRole.ADMIN, now);
insertProjectCreatorPermission(dbSession, permissionTemplateDto, UserRole.ISSUE_ADMIN, now);
insertProjectCreatorPermission(dbSession, permissionTemplateDto, OrganizationPermission.SCAN.getKey(), now);
insertGroupPermission(dbSession, permissionTemplateDto, UserRole.USER, null);
insertGroupPermission(dbSession, permissionTemplateDto, UserRole.CODEVIEWER, null);
dbClient.organizationDao().setDefaultTemplates(dbSession, organizationDto.getUuid(), new DefaultTemplates().setProjectUuid(permissionTemplateDto.getUuid()));
}
use of org.sonar.db.organization.DefaultTemplates in project sonarqube by SonarSource.
the class SearchTemplatesDataLoader method load.
public SearchTemplatesData load(DbSession dbSession, SearchTemplatesWsRequest request) {
SearchTemplatesData.Builder data = builder();
List<PermissionTemplateDto> templates = searchTemplates(dbSession, request);
List<Long> templateIds = Lists.transform(templates, PermissionTemplateDto::getId);
DefaultTemplates defaultTemplates = checkFoundWithOptional(dbClient.organizationDao().getDefaultTemplates(dbSession, request.getOrganizationUuid()), "No Default templates for organization with uuid '%s'", request.getOrganizationUuid());
ResolvedDefaultTemplates resolvedDefaultTemplates = defaultTemplatesResolver.resolve(defaultTemplates);
data.templates(templates).defaultTemplates(resolvedDefaultTemplates).userCountByTemplateIdAndPermission(userCountByTemplateIdAndPermission(dbSession, templateIds)).groupCountByTemplateIdAndPermission(groupCountByTemplateIdAndPermission(dbSession, templateIds)).withProjectCreatorByTemplateIdAndPermission(withProjectCreatorsByTemplateIdAndPermission(dbSession, templateIds));
return data.build();
}
use of org.sonar.db.organization.DefaultTemplates in project sonarqube by SonarSource.
the class DeleteTemplateAction method doHandle.
private void doHandle(DeleteTemplateWsRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
PermissionTemplateDto template = finder.findTemplate(dbSession, newTemplateRef(request.getTemplateId(), request.getOrganization(), request.getTemplateName()));
checkGlobalAdmin(userSession, template.getOrganizationUuid());
DefaultTemplates defaultTemplates = retrieveDefaultTemplates(dbSession, template);
checkTemplateUuidIsNotDefault(template, defaultTemplates);
dbClient.permissionTemplateDao().deleteById(dbSession, template.getId());
updateViewDefaultTemplateWhenGovernanceIsNotInstalled(dbSession, template, defaultTemplates);
dbSession.commit();
}
}
use of org.sonar.db.organization.DefaultTemplates in project sonarqube by SonarSource.
the class OrganizationCreationImplTest method create_creates_default_template_for_new_organization.
@Test
public void create_creates_default_template_for_new_organization() throws OrganizationCreation.KeyConflictException {
mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
underTest.create(dbSession, SOME_USER_ID, FULL_POPULATED_NEW_ORGANIZATION);
OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, FULL_POPULATED_NEW_ORGANIZATION.getKey()).get();
GroupDto ownersGroup = dbClient.groupDao().selectByName(dbSession, organization.getUuid(), "Owners").get();
PermissionTemplateDto defaultTemplate = dbClient.permissionTemplateDao().selectByName(dbSession, organization.getUuid(), "default template");
assertThat(defaultTemplate.getName()).isEqualTo("Default template");
assertThat(defaultTemplate.getDescription()).isEqualTo("Default permission template of organization " + FULL_POPULATED_NEW_ORGANIZATION.getName());
DefaultTemplates defaultTemplates = dbClient.organizationDao().getDefaultTemplates(dbSession, organization.getUuid()).get();
assertThat(defaultTemplates.getProjectUuid()).isEqualTo(defaultTemplate.getUuid());
assertThat(defaultTemplates.getViewUuid()).isNull();
assertThat(dbClient.permissionTemplateDao().selectGroupPermissionsByTemplateId(dbSession, defaultTemplate.getId())).extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getPermission).containsOnly(tuple(ownersGroup.getId(), UserRole.ADMIN), tuple(ownersGroup.getId(), UserRole.ISSUE_ADMIN), tuple(ownersGroup.getId(), GlobalPermissions.SCAN_EXECUTION), tuple(ANYONE_GROUP_ID, UserRole.USER), tuple(ANYONE_GROUP_ID, UserRole.CODEVIEWER));
}
use of org.sonar.db.organization.DefaultTemplates in project sonarqube by SonarSource.
the class CreateActionTest method request_creates_default_template_for_owner_group_and_anyone.
@Test
public void request_creates_default_template_for_owner_group_and_anyone() {
mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
UserDto user = dbTester.users().insertUser();
userSession.logIn(user).setSystemAdministrator();
executeRequest("orgFoo");
OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, "orgfoo").get();
GroupDto ownersGroup = dbClient.groupDao().selectByName(dbSession, organization.getUuid(), "Owners").get();
PermissionTemplateDto defaultTemplate = dbClient.permissionTemplateDao().selectByName(dbSession, organization.getUuid(), "default template");
assertThat(defaultTemplate.getName()).isEqualTo("Default template");
assertThat(defaultTemplate.getDescription()).isEqualTo("Default permission template of organization orgFoo");
DefaultTemplates defaultTemplates = dbClient.organizationDao().getDefaultTemplates(dbSession, organization.getUuid()).get();
assertThat(defaultTemplates.getProjectUuid()).isEqualTo(defaultTemplate.getUuid());
assertThat(defaultTemplates.getViewUuid()).isNull();
assertThat(dbClient.permissionTemplateDao().selectGroupPermissionsByTemplateId(dbSession, defaultTemplate.getId())).extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getPermission).containsOnly(tuple(ownersGroup.getId(), UserRole.ADMIN), tuple(ownersGroup.getId(), UserRole.ISSUE_ADMIN), tuple(ownersGroup.getId(), GlobalPermissions.SCAN_EXECUTION), tuple(0, UserRole.USER), tuple(0, UserRole.CODEVIEWER));
}
Aggregations