use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class QgateProjectFinderTest method return_only_authorized_projects.
@Test
public void return_only_authorized_projects() throws Exception {
UserDto user = dbTester.users().insertUser("a_login");
OrganizationDto organizationDto = dbTester.organizations().insert();
ComponentDto project1 = componentDbTester.insertComponent(newProjectDto(organizationDto));
componentDbTester.insertComponent(newProjectDto(organizationDto));
// User can only see project 1
dbTester.users().insertProjectPermissionOnUser(user, UserRole.USER, project1);
userSession.logIn(user.getLogin()).setUserId(user.getId());
Association result = underTest.find(builder().gateId(Long.toString(qGate.getId())).build());
verifyProjects(result, project1.getId());
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class NotificationFactory method getAssignee.
@CheckForNull
public User getAssignee(@Nullable String assigneeUuid, Map<String, UserDto> assigneesByUuid) {
if (assigneeUuid == null) {
return null;
}
UserDto dto = assigneesByUuid.get(assigneeUuid);
checkState(dto != null, "Can not find DTO for assignee uuid %s", assigneeUuid);
return new User(dto.getUuid(), dto.getLogin(), dto.getName());
}
use of org.sonar.db.user.UserDto 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.user.UserDto in project sonarqube by SonarSource.
the class UserPermissionDaoTest method selectUserUuidsByQuery_is_ordering_by_users_having_permissions_first_then_by_name_lowercase.
@Test
public void selectUserUuidsByQuery_is_ordering_by_users_having_permissions_first_then_by_name_lowercase() {
UserDto user1 = insertUser(u -> u.setLogin("login1").setName("Z").setEmail("email1@email.com"));
UserDto user2 = insertUser(u -> u.setLogin("login2").setName("A").setEmail("email2@email.com"));
UserDto user3 = insertUser(u -> u.setLogin("login3").setName("Z").setEmail("zanother3@another.com"));
UserDto user4 = insertUser(u -> u.setLogin("login4").setName("A").setEmail("zanother3@another.com"));
addGlobalPermission(SYSTEM_ADMIN, user1);
addGlobalPermission(QUALITY_PROFILE_ADMIN, user2);
PermissionQuery query = PermissionQuery.builder().build();
assertThat(underTest.selectUserUuidsByQueryAndScope(dbSession, query)).containsExactly(user2.getUuid(), user1.getUuid(), user4.getUuid(), user3.getUuid());
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class UserPermissionDaoTest method selectUserUuidsByQuery_is_ordering_by_users_having_permissions_first_then_by_name_lowercase_when_high_number_of_users_for_global_permissions.
@Test
public void selectUserUuidsByQuery_is_ordering_by_users_having_permissions_first_then_by_name_lowercase_when_high_number_of_users_for_global_permissions() {
ComponentDto project = db.components().insertPrivateProject();
IntStream.rangeClosed(1, DEFAULT_PAGE_SIZE + 1).forEach(i -> {
UserDto user = insertUser(u -> u.setLogin("login" + i).setName("" + i));
// Add permission on project to be sure projects are excluded
db.users().insertProjectPermissionOnUser(user, SCAN.getKey(), project);
});
String lastLogin = "login" + (DEFAULT_PAGE_SIZE + 1);
UserDto lastUser = db.getDbClient().userDao().selectByLogin(dbSession, lastLogin);
addGlobalPermission(SYSTEM_ADMIN, lastUser);
PermissionQuery query = PermissionQuery.builder().build();
assertThat(underTest.selectUserUuidsByQueryAndScope(dbSession, query)).hasSize(DEFAULT_PAGE_SIZE).startsWith(lastUser.getUuid());
}
Aggregations