use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class CreateTemplateActionTest method fail_if_name_already_exists_in_database_case_insensitive.
@Test
public void fail_if_name_already_exists_in_database_case_insensitive() throws Exception {
loginAsAdmin(db.getDefaultOrganization());
PermissionTemplateDto template = db.permissionTemplates().insertTemplate(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("A template with the name '" + template.getName() + "' already exists (case insensitive).");
newRequest(template.getName(), null, null);
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class DeleteTemplateActionTest method insertTemplateAndAssociatedPermissions.
private PermissionTemplateDto insertTemplateAndAssociatedPermissions(OrganizationDto organization) {
PermissionTemplateDto dto = db.permissionTemplates().insertTemplate(organization);
UserDto user = db.getDbClient().userDao().insert(db.getSession(), UserTesting.newUserDto().setActive(true));
GroupDto group = db.getDbClient().groupDao().insert(db.getSession(), GroupTesting.newGroupDto());
db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), dto.getId(), user.getId(), UserRole.ADMIN);
db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), dto.getId(), group.getId(), UserRole.CODEVIEWER);
db.commit();
return dto;
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class PermissionTemplateServiceTest method apply_permission_template.
@Test
public void apply_permission_template() {
OrganizationDto organization = dbTester.organizations().insert();
ComponentDto project = dbTester.components().insertProject(organization);
GroupDto adminGroup = dbTester.users().insertGroup(organization);
GroupDto userGroup = dbTester.users().insertGroup(organization);
UserDto user = dbTester.users().insertUser();
dbTester.users().insertPermissionOnGroup(adminGroup, "admin");
dbTester.users().insertPermissionOnGroup(userGroup, "user");
dbTester.users().insertPermissionOnUser(organization, user, "admin");
PermissionTemplateDto permissionTemplate = dbTester.permissionTemplates().insertTemplate(organization);
dbTester.permissionTemplates().addGroupToTemplate(permissionTemplate, adminGroup, "admin");
dbTester.permissionTemplates().addGroupToTemplate(permissionTemplate, adminGroup, "issueadmin");
dbTester.permissionTemplates().addGroupToTemplate(permissionTemplate, userGroup, "user");
dbTester.permissionTemplates().addGroupToTemplate(permissionTemplate, userGroup, "codeviewer");
dbTester.permissionTemplates().addAnyoneToTemplate(permissionTemplate, "user");
dbTester.permissionTemplates().addAnyoneToTemplate(permissionTemplate, "codeviewer");
dbTester.permissionTemplates().addUserToTemplate(permissionTemplate, user, "admin");
assertThat(selectProjectPermissionsOfGroup(organization, adminGroup, project)).isEmpty();
assertThat(selectProjectPermissionsOfGroup(organization, userGroup, project)).isEmpty();
assertThat(selectProjectPermissionsOfGroup(organization, null, project)).isEmpty();
assertThat(selectProjectPermissionsOfUser(user, project)).isEmpty();
underTest.apply(session, permissionTemplate, singletonList(project));
assertThat(selectProjectPermissionsOfGroup(organization, adminGroup, project)).containsOnly("admin", "issueadmin");
assertThat(selectProjectPermissionsOfGroup(organization, userGroup, project)).containsOnly("user", "codeviewer");
assertThat(selectProjectPermissionsOfGroup(organization, null, project)).containsOnly("user", "codeviewer");
assertThat(selectProjectPermissionsOfUser(user, project)).containsOnly("admin");
checkAuthorizationUpdatedAtIsUpdated(project);
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class PermissionTemplateServiceTest method would_user_have_scann_permission_with_empty_template.
@Test
public void would_user_have_scann_permission_with_empty_template() {
PermissionTemplateDto template = templateDb.insertTemplate(dbTester.getDefaultOrganization());
dbTester.organizations().setDefaultTemplates(template, null);
checkWouldUserHaveScanPermission(dbTester.getDefaultOrganization(), null, false);
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class UpdateTemplateActionTest method update_all_permission_template_fields.
@Test
public void update_all_permission_template_fields() throws Exception {
loginAsAdmin(db.getDefaultOrganization());
String result = call(template.getUuid(), "Finance", "Permissions for financially related projects", ".*\\.finance\\..*");
assertJson(result).ignoreFields("id").isSimilarTo(getClass().getResource("update_template-example.json"));
PermissionTemplateDto finance = selectTemplateInDefaultOrganization("Finance");
assertThat(finance.getName()).isEqualTo("Finance");
assertThat(finance.getDescription()).isEqualTo("Permissions for financially related projects");
assertThat(finance.getKeyPattern()).isEqualTo(".*\\.finance\\..*");
assertThat(finance.getUuid()).isEqualTo(template.getUuid());
assertThat(finance.getCreatedAt()).isEqualTo(template.getCreatedAt());
assertThat(finance.getUpdatedAt().getTime()).isEqualTo(1440512328743L);
}
Aggregations