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));
}
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();
}
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;
}
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");
}
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));
}
Aggregations