Search in sources :

Example 56 with PermissionTemplateDto

use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.

the class UpdateTemplateAction method validateTemplateNameForUpdate.

private void validateTemplateNameForUpdate(DbSession dbSession, String organizationUuid, String name, long id) {
    validateTemplateNameFormat(name);
    PermissionTemplateDto permissionTemplateWithSameName = dbClient.permissionTemplateDao().selectByName(dbSession, organizationUuid, name);
    checkRequest(permissionTemplateWithSameName == null || permissionTemplateWithSameName.getId() == id, format(MSG_TEMPLATE_WITH_SAME_NAME, name));
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto)

Example 57 with PermissionTemplateDto

use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.

the class RegisterPermissionTemplates method start.

public void start() {
    Profiler profiler = Profiler.create(Loggers.get(getClass())).startInfo("Register permission templates");
    try (DbSession dbSession = dbClient.openSession(false)) {
        String defaultOrganizationUuid = defaultOrganizationProvider.get().getUuid();
        Optional<DefaultTemplates> defaultTemplates = dbClient.organizationDao().getDefaultTemplates(dbSession, defaultOrganizationUuid);
        if (!defaultTemplates.isPresent()) {
            PermissionTemplateDto defaultTemplate = getOrInsertDefaultTemplate(dbSession, defaultOrganizationUuid);
            dbClient.organizationDao().setDefaultTemplates(dbSession, defaultOrganizationUuid, new DefaultTemplates().setProjectUuid(defaultTemplate.getUuid()));
            dbSession.commit();
        }
    }
    profiler.stopDebug();
}
Also used : DbSession(org.sonar.db.DbSession) PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) Profiler(org.sonar.api.utils.log.Profiler) DefaultTemplates(org.sonar.db.organization.DefaultTemplates)

Example 58 with PermissionTemplateDto

use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.

the class RegisterPermissionTemplates method getOrInsertDefaultTemplate.

private PermissionTemplateDto getOrInsertDefaultTemplate(DbSession dbSession, String defaultOrganizationUuid) {
    PermissionTemplateDto permissionTemplateDto = dbClient.permissionTemplateDao().selectByUuid(dbSession, DEFAULT_TEMPLATE_UUID);
    if (permissionTemplateDto != null) {
        return permissionTemplateDto;
    }
    PermissionTemplateDto template = new PermissionTemplateDto().setOrganizationUuid(defaultOrganizationUuid).setName("Default template").setUuid(DEFAULT_TEMPLATE_UUID).setDescription("This permission template will be used as default when no other permission configuration is available").setCreatedAt(new Date()).setUpdatedAt(new Date());
    dbClient.permissionTemplateDao().insert(dbSession, template);
    insertDefaultGroupPermissions(dbSession, template);
    dbSession.commit();
    return template;
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) Date(java.util.Date)

Example 59 with PermissionTemplateDto

use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.

the class DeleteActionTest method request_also_deletes_permissions_templates_and_permissions_and_groups_of_specified_organization.

@Test
public void request_also_deletes_permissions_templates_and_permissions_and_groups_of_specified_organization() {
    OrganizationDto org = dbTester.organizations().insert();
    OrganizationDto otherOrg = dbTester.organizations().insert();
    UserDto user1 = dbTester.users().insertUser();
    UserDto user2 = dbTester.users().insertUser();
    GroupDto group1 = dbTester.users().insertGroup(org);
    GroupDto group2 = dbTester.users().insertGroup(org);
    GroupDto otherGroup1 = dbTester.users().insertGroup(otherOrg);
    GroupDto otherGroup2 = dbTester.users().insertGroup(otherOrg);
    ComponentDto projectDto = dbTester.components().insertProject(org);
    ComponentDto otherProjectDto = dbTester.components().insertProject(otherOrg);
    dbTester.users().insertPermissionOnAnyone(org, "u1");
    dbTester.users().insertPermissionOnAnyone(otherOrg, "not deleted u1");
    dbTester.users().insertPermissionOnUser(org, user1, "u2");
    dbTester.users().insertPermissionOnUser(otherOrg, user1, "not deleted u2");
    dbTester.users().insertPermissionOnGroup(group1, "u3");
    dbTester.users().insertPermissionOnGroup(otherGroup1, "not deleted u3");
    dbTester.users().insertProjectPermissionOnAnyone("u4", projectDto);
    dbTester.users().insertProjectPermissionOnAnyone("not deleted u4", otherProjectDto);
    dbTester.users().insertProjectPermissionOnGroup(group1, "u5", projectDto);
    dbTester.users().insertProjectPermissionOnGroup(otherGroup1, "not deleted u5", otherProjectDto);
    dbTester.users().insertProjectPermissionOnUser(user1, "u6", projectDto);
    dbTester.users().insertProjectPermissionOnUser(user1, "not deleted u6", otherProjectDto);
    PermissionTemplateDto templateDto = dbTester.permissionTemplates().insertTemplate(org);
    PermissionTemplateDto otherTemplateDto = dbTester.permissionTemplates().insertTemplate(otherOrg);
    logInAsAdministrator(org);
    sendRequest(org);
    verifyOrganizationDoesNotExist(org);
    assertThat(dbClient.groupDao().selectByIds(session, of(group1.getId(), otherGroup1.getId(), group2.getId(), otherGroup2.getId()))).extracting(GroupDto::getId).containsOnly(otherGroup1.getId(), otherGroup2.getId());
    assertThat(dbClient.permissionTemplateDao().selectByUuid(session, templateDto.getUuid())).isNull();
    assertThat(dbClient.permissionTemplateDao().selectByUuid(session, otherTemplateDto.getUuid())).isNotNull();
    assertThat(dbTester.select("select role as \"role\" from USER_ROLES")).extracting(row -> (String) row.get("role")).doesNotContain("u2", "u6").contains("not deleted u2", "not deleted u6");
    assertThat(dbTester.select("select role as \"role\" from GROUP_ROLES")).extracting(row -> (String) row.get("role")).doesNotContain("u1", "u3", "u4", "u5").contains("not deleted u1", "not deleted u3", "not deleted u4", "not deleted u5");
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 60 with PermissionTemplateDto

use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.

the class OrganizationCreationImplTest method createForUser_creates_default_template_for_new_organization.

@Test
public void createForUser_creates_default_template_for_new_organization() throws OrganizationCreation.KeyConflictException {
    UserDto user = dbTester.users().insertUser(dto -> dto.setLogin(A_LOGIN).setName(A_NAME));
    when(organizationValidation.generateKeyFrom(A_LOGIN)).thenReturn(SLUG_OF_A_LOGIN);
    mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
    enableCreatePersonalOrg(true);
    underTest.createForUser(dbSession, user);
    OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, SLUG_OF_A_LOGIN).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 " + A_NAME);
    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(ANYONE_GROUP_ID, UserRole.USER), tuple(ANYONE_GROUP_ID, UserRole.CODEVIEWER));
    assertThat(dbClient.permissionTemplateCharacteristicDao().selectByTemplateIds(dbSession, Collections.singletonList(defaultTemplate.getId()))).extracting(PermissionTemplateCharacteristicDto::getWithProjectCreator, PermissionTemplateCharacteristicDto::getPermission).containsOnly(tuple(true, UserRole.ADMIN), tuple(true, UserRole.ISSUE_ADMIN), tuple(true, GlobalPermissions.SCAN_EXECUTION));
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) UserDto(org.sonar.db.user.UserDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) DefaultTemplates(org.sonar.db.organization.DefaultTemplates) Test(org.junit.Test)

Aggregations

PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)97 Test (org.junit.Test)63 BasePermissionWsTest (org.sonar.server.permission.ws.BasePermissionWsTest)42 OrganizationDto (org.sonar.db.organization.OrganizationDto)33 GroupDto (org.sonar.db.user.GroupDto)17 DbSession (org.sonar.db.DbSession)16 UserDto (org.sonar.db.user.UserDto)15 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)14 InputStream (java.io.InputStream)13 PermissionTemplateTesting.newPermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto)12 DefaultTemplates (org.sonar.db.organization.DefaultTemplates)10 PermissionTemplateUserDto (org.sonar.db.permission.template.PermissionTemplateUserDto)9 WsPermissions (org.sonarqube.ws.WsPermissions)9 PermissionTemplateTesting.newPermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateGroupDto)8 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)8 PermissionTemplateTesting.newPermissionTemplateUserDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateUserDto)7 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)7 WsGroupsResponse (org.sonarqube.ws.WsPermissions.WsGroupsResponse)7 ComponentDto (org.sonar.db.component.ComponentDto)6 Date (java.util.Date)5