Search in sources :

Example 1 with DefaultTemplates

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()));
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) Date(java.util.Date) DefaultTemplates(org.sonar.db.organization.DefaultTemplates)

Example 2 with DefaultTemplates

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();
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) ResolvedDefaultTemplates(org.sonar.server.permission.ws.template.DefaultTemplatesResolver.ResolvedDefaultTemplates) DefaultTemplates(org.sonar.db.organization.DefaultTemplates) ResolvedDefaultTemplates(org.sonar.server.permission.ws.template.DefaultTemplatesResolver.ResolvedDefaultTemplates)

Example 3 with DefaultTemplates

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();
    }
}
Also used : DbSession(org.sonar.db.DbSession) PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) DefaultTemplates(org.sonar.db.organization.DefaultTemplates)

Example 4 with DefaultTemplates

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));
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) PermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateGroupDto) GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) DefaultTemplates(org.sonar.db.organization.DefaultTemplates) Test(org.junit.Test)

Example 5 with DefaultTemplates

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));
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) UserDto(org.sonar.db.user.UserDto) PermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateGroupDto) GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) DefaultTemplates(org.sonar.db.organization.DefaultTemplates) Test(org.junit.Test)

Aggregations

DefaultTemplates (org.sonar.db.organization.DefaultTemplates)13 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)8 Test (org.junit.Test)6 OrganizationDto (org.sonar.db.organization.OrganizationDto)3 Date (java.util.Date)2 DbSession (org.sonar.db.DbSession)2 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)2 GroupDto (org.sonar.db.user.GroupDto)2 UserDto (org.sonar.db.user.UserDto)2 ArrayList (java.util.ArrayList)1 CheckForNull (javax.annotation.CheckForNull)1 OrganizationDao (org.sonar.db.organization.OrganizationDao)1 ResolvedDefaultTemplates (org.sonar.server.permission.ws.template.DefaultTemplatesResolver.ResolvedDefaultTemplates)1 DefaultTemplatesResolverImpl (org.sonar.server.permission.ws.template.DefaultTemplatesResolverImpl)1