Search in sources :

Example 86 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class UserPermissionDaoWithPersisterTest method userProjectPermissionDeleteWithoutAffectedRowsIsNotPersisted.

@Test
public void userProjectPermissionDeleteWithoutAffectedRowsIsNotPersisted() {
    UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
    ComponentDto project = db.components().insertPrivateProject();
    underTest.deleteProjectPermission(dbSession, user, SYSTEM_ADMIN, project);
    verify(auditPersister).addUser(any(), any());
    verify(auditPersister).addComponent(any(), any());
    verifyNoMoreInteractions(auditPersister);
}
Also used : UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 87 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class UserPermissionDaoWithPersisterTest method userGlobalPermissionInsertWithTemplateIsPersisted.

@Test
public void userGlobalPermissionInsertWithTemplateIsPersisted() {
    PermissionTemplateDto templateDto = newPermissionTemplateDto();
    db.getDbClient().permissionTemplateDao().insert(db.getSession(), templateDto);
    UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
    UserPermissionDto dto = new UserPermissionDto(Uuids.create(), SYSTEM_ADMIN, user.getUuid(), null);
    underTest.insert(dbSession, dto, null, user, templateDto);
    verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture());
    UserPermissionNewValue newValue = newValueCaptor.getValue();
    assertThat(newValue).extracting(UserPermissionNewValue::getPermissionUuid, UserPermissionNewValue::getUserUuid, UserPermissionNewValue::getUserLogin, UserPermissionNewValue::getComponentUuid, UserPermissionNewValue::getPermission, UserPermissionNewValue::getComponentName, UserPermissionNewValue::getQualifier, UserPermissionNewValue::getPermissionTemplateId, UserPermissionNewValue::getPermissionTemplateName).containsExactly(dto.getUuid(), user.getUuid(), user.getLogin(), null, dto.getPermission(), null, null, templateDto.getUuid(), templateDto.getName());
    assertThat(newValue.toString()).doesNotContain("projectUuid");
}
Also used : UserPermissionNewValue(org.sonar.db.audit.model.UserPermissionNewValue) PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) PermissionTemplateTesting.newPermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto) UserDto(org.sonar.db.user.UserDto) Test(org.junit.Test)

Example 88 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class UserPermissionDaoWithPersisterTest method deleteUserPermissionByUserUuidIsPersisted.

@Test
public void deleteUserPermissionByUserUuidIsPersisted() {
    UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
    ComponentDto project = db.components().insertPrivateProject();
    UserPermissionDto dto = new UserPermissionDto(Uuids.create(), SYSTEM_ADMIN, user.getUuid(), project.uuid());
    underTest.insert(dbSession, dto, project, user, null);
    underTest.deleteByUserUuid(dbSession, user);
    verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture());
    UserPermissionNewValue newValue = newValueCaptor.getValue();
    assertNewValue(newValue, null, user.getUuid(), user.getLogin(), null, null, null, null, null);
    assertThat(newValue.toString()).contains("userUuid");
}
Also used : UserPermissionNewValue(org.sonar.db.audit.model.UserPermissionNewValue) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 89 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class UserPermissionDaoWithPersisterTest method deleteUserPermissionOfAnyUserIsPersisted.

@Test
public void deleteUserPermissionOfAnyUserIsPersisted() {
    UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
    ComponentDto project = db.components().insertPrivateProject();
    UserPermissionDto dto = new UserPermissionDto(Uuids.create(), SCAN_EXECUTION, user.getUuid(), project.uuid());
    underTest.insert(dbSession, dto, project, user, null);
    underTest.deleteProjectPermissionOfAnyUser(dbSession, SCAN_EXECUTION, project);
    verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture());
    UserPermissionNewValue newValue = newValueCaptor.getValue();
    assertNewValue(newValue, null, null, null, project.uuid(), dto.getPermission(), project.getKey(), project.name(), "TRK");
    assertThat(newValue.toString()).doesNotContain("userUuid");
}
Also used : UserPermissionNewValue(org.sonar.db.audit.model.UserPermissionNewValue) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 90 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class UserPermissionDaoWithPersisterTest method deleteUserPermissionByUserUuidWithoutAffectedRowsIsNotPersisted.

@Test
public void deleteUserPermissionByUserUuidWithoutAffectedRowsIsNotPersisted() {
    UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
    underTest.deleteByUserUuid(dbSession, user);
    verify(auditPersister).addUser(any(), any());
    verifyNoMoreInteractions(auditPersister);
}
Also used : UserDto(org.sonar.db.user.UserDto) 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