use of org.sonar.db.permission.GlobalPermission.SCAN in project sonarqube by SonarSource.
the class UserPermissionDaoTest method deleteByUserId.
@Test
public void deleteByUserId() {
UserDto user1 = insertUser();
UserDto user2 = insertUser();
ComponentDto project = db.components().insertPrivateProject();
db.users().insertPermissionOnUser(user1, SCAN);
db.users().insertPermissionOnUser(user1, ADMINISTER);
db.users().insertProjectPermissionOnUser(user1, ADMINISTER_QUALITY_GATES.getKey(), project);
db.users().insertPermissionOnUser(user2, SCAN);
db.users().insertProjectPermissionOnUser(user2, ADMINISTER_QUALITY_GATES.getKey(), project);
underTest.deleteByUserUuid(dbSession, user1);
dbSession.commit();
assertThat(db.select("select user_uuid as \"userUuid\", component_uuid as \"projectUuid\", role as \"permission\" from user_roles")).extracting((row) -> row.get("userUuid"), (row) -> row.get("projectUuid"), (row) -> row.get("permission")).containsOnly(tuple(user2.getUuid(), null, SCAN.getKey()), tuple(user2.getUuid(), project.uuid(), ADMINISTER_QUALITY_GATES.getKey()));
}
use of org.sonar.db.permission.GlobalPermission.SCAN in project sonarqube by SonarSource.
the class BranchReportSubmitterTest method submit_report_on_missing_branch_of_missing_project_provisions_project_when_PROVISION_PROJECT_perm.
@Test
public void submit_report_on_missing_branch_of_missing_project_provisions_project_when_PROVISION_PROJECT_perm() {
ComponentDto nonExistingProject = newPrivateProjectDto();
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS).addPermission(SCAN);
Map<String, String> randomCharacteristics = randomNonEmptyMap();
ComponentDto createdBranch = createButDoNotInsertBranch(nonExistingProject);
BranchSupport.ComponentKey componentKey = createComponentKeyOfBranch(createdBranch);
when(branchSupportDelegate.createComponentKey(nonExistingProject.getDbKey(), randomCharacteristics)).thenReturn(componentKey);
when(componentUpdater.createWithoutCommit(any(), any(), eq(user.getUuid()), eq(user.getLogin()), any())).thenAnswer((Answer<ComponentDto>) invocation -> db.components().insertPrivateProject(nonExistingProject));
when(branchSupportDelegate.createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingProject), any())).thenReturn(createdBranch);
when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(DbSession.class), any(), eq(nonExistingProject.getKey()))).thenReturn(true);
String taskUuid = mockSuccessfulPrepareSubmitCall();
InputStream reportInput = IOUtils.toInputStream("{binary}", StandardCharsets.UTF_8);
underTest.submit(nonExistingProject.getDbKey(), nonExistingProject.name(), randomCharacteristics, reportInput);
BranchDto exitingProjectMainBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), nonExistingProject.uuid()).get();
verify(branchSupport).createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingProject), eq(exitingProjectMainBranch));
verify(branchSupportDelegate).createComponentKey(nonExistingProject.getDbKey(), randomCharacteristics);
verify(branchSupportDelegate).createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingProject), eq(exitingProjectMainBranch));
verifyNoMoreInteractions(branchSupportDelegate);
verifyQueueSubmit(nonExistingProject, createdBranch, user, randomCharacteristics, taskUuid);
verify(componentUpdater).commitAndIndex(any(DbSession.class), eq(nonExistingProject));
}
Aggregations