Search in sources :

Example 61 with UserDto

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());
}
Also used : ProjectQgateAssociation(org.sonar.db.qualitygate.ProjectQgateAssociation) Association(org.sonar.server.qualitygate.QgateProjectFinder.Association) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 62 with UserDto

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());
}
Also used : User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) UserDto(org.sonar.db.user.UserDto) CheckForNull(javax.annotation.CheckForNull)

Example 63 with UserDto

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()));
}
Also used : IntStream(java.util.stream.IntStream) ISSUE_ADMIN(org.sonar.api.web.UserRole.ISSUE_ADMIN) QUALITY_PROFILE_ADMIN(org.sonar.core.permission.GlobalPermissions.QUALITY_PROFILE_ADMIN) Arrays(java.util.Arrays) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PROVISION_PROJECTS(org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS) Random(java.util.Random) ADMINISTER(org.sonar.db.permission.GlobalPermission.ADMINISTER) DbSession(org.sonar.db.DbSession) DEFAULT_PAGE_SIZE(org.sonar.db.permission.PermissionQuery.DEFAULT_PAGE_SIZE) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) ADMIN(org.sonar.api.web.UserRole.ADMIN) Uuids(org.sonar.core.util.Uuids) SCAN(org.sonar.db.permission.GlobalPermission.SCAN) Arrays.asList(java.util.Arrays.asList) SYSTEM_ADMIN(org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN) PROVISIONING(org.sonar.core.permission.GlobalPermissions.PROVISIONING) ADMINISTER_QUALITY_GATES(org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES) DbTester(org.sonar.db.DbTester) Tuple(org.assertj.core.groups.Tuple) System2(org.sonar.api.utils.System2) Assertions.tuple(org.assertj.core.api.Assertions.tuple) USER(org.sonar.api.web.UserRole.USER) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Test(org.junit.Test) NoOpAuditPersister(org.sonar.db.audit.NoOpAuditPersister) Consumer(java.util.function.Consumer) ComponentTesting.newPrivateProjectDto(org.sonar.db.component.ComponentTesting.newPrivateProjectDto) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) UserRole(org.sonar.api.web.UserRole) Arrays.stream(java.util.Arrays.stream) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 64 with UserDto

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());
}
Also used : UserDto(org.sonar.db.user.UserDto) Test(org.junit.Test)

Example 65 with UserDto

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());
}
Also used : UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

UserDto (org.sonar.db.user.UserDto)1318 Test (org.junit.Test)1173 ComponentDto (org.sonar.db.component.ComponentDto)332 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)216 GroupDto (org.sonar.db.user.GroupDto)152 IssueDto (org.sonar.db.issue.IssueDto)131 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)108 TestRequest (org.sonar.server.ws.TestRequest)102 NotFoundException (org.sonar.server.exceptions.NotFoundException)84 DbSession (org.sonar.db.DbSession)82 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)80 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)64 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)57 Rule (org.junit.Rule)57 DbTester (org.sonar.db.DbTester)54 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)52 WebService (org.sonar.api.server.ws.WebService)44 BadRequestException (org.sonar.server.exceptions.BadRequestException)43 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)41 UserSessionRule (org.sonar.server.tester.UserSessionRule)41