use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class UserPermissionDaoTest method selectProjectPermissionsOfUser.
@Test
public void selectProjectPermissionsOfUser() {
UserDto user1 = insertUser();
UserDto user2 = insertUser();
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto project2 = db.components().insertPrivateProject();
ComponentDto project3 = db.components().insertPrivateProject();
addGlobalPermission("perm1", user1);
addProjectPermission("perm2", user1, project1);
addProjectPermission("perm3", user1, project1);
addProjectPermission("perm4", user1, project2);
addProjectPermission("perm5", user2, project1);
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getUuid(), project1.uuid())).containsOnly("perm2", "perm3");
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getUuid(), project2.uuid())).containsOnly("perm4");
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getUuid(), project3.uuid())).isEmpty();
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class UserPermissionDaoTest method selectGroupUuidsWithPermissionOnProjectBut_returns_empty_if_project_does_not_exist.
@Test
public void selectGroupUuidsWithPermissionOnProjectBut_returns_empty_if_project_does_not_exist() {
ComponentDto project = randomPublicOrPrivateProject();
UserDto user = insertUser();
db.users().insertProjectPermissionOnUser(user, "foo", project);
assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, "1234", UserRole.USER)).isEmpty();
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class UserPermissionDaoTest method selectGroupUuidsWithPermissionOnProjectBut_does_not_return_groups_which_have_no_permission_at_all_on_specified_project.
@Test
public void selectGroupUuidsWithPermissionOnProjectBut_does_not_return_groups_which_have_no_permission_at_all_on_specified_project() {
ComponentDto project = randomPublicOrPrivateProject();
UserDto user1 = insertUser();
UserDto user2 = insertUser();
db.users().insertProjectPermissionOnUser(user1, "p1", project);
db.users().insertProjectPermissionOnUser(user2, "p2", project);
assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p2")).extracting("uuid", "login").containsOnly(tuple(user1.getUuid(), user1.getLogin()));
assertThat(underTest.selectUserIdsWithPermissionOnProjectBut(dbSession, project.uuid(), "p1")).extracting("uuid", "login").containsOnly(tuple(user2.getUuid(), user2.getLogin()));
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class UserPermissionDaoTest method selectUserUuidsByQueryAndScope_with_global_scope.
@Test
public void selectUserUuidsByQueryAndScope_with_global_scope() {
UserDto user1 = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
UserDto user2 = insertUser(u -> u.setLogin("login2").setName("Marie").setEmail("email2@email.com"));
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto project2 = db.components().insertPrivateProject();
addProjectPermission(USER, user1, project1);
addGlobalPermission(PROVISIONING, user1);
addProjectPermission(ISSUE_ADMIN, user2, project2);
PermissionQuery query = PermissionQuery.builder().build();
List<String> result = underTest.selectUserUuidsByQueryAndScope(dbSession, query);
// users with any kind of global permissions are first on the list and then sorted by name
assertThat(result).containsExactly(user1.getUuid(), user2.getUuid());
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class UserPermissionDaoTest method deleteProjectPermissionOfAnyUser_has_no_effect_if_specified_component_does_not_have_specified_permission.
@Test
public void deleteProjectPermissionOfAnyUser_has_no_effect_if_specified_component_does_not_have_specified_permission() {
UserDto user = insertUser();
db.users().insertPermissionOnUser(user, SCAN);
ComponentDto project = randomPublicOrPrivateProject();
db.users().insertProjectPermissionOnUser(user, SCAN.getKey(), project);
int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, "p1", project);
assertThat(deletedCount).isZero();
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getUuid())).containsOnly(SCAN.getKey());
assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user.getUuid(), project.uuid())).containsOnly(SCAN.getKey());
}
Aggregations