public String toString() {
StringBuilder sb = new StringBuilder("{");
addField(sb, "\"permissionUuid\": ", this.permissionUuid, true);
- addField(sb, "\"role\": ", this.role, true);
+ addField(sb, "\"permission\": ", this.permission, true);
addField(sb, "\"groupUuid\": ", this.groupUuid, true);
addField(sb, "\"groupName\": ", this.groupName, true);
addField(sb, "\"componentUuid\": ", this.componentUuid, true);
public class UserNewValue extends NewValue {
private String userUuid;
- private String login;
+ private String userLogin;
@Nullable
private String name;
public UserNewValue(String userUuid, String userLogin) {
this.userUuid = userUuid;
- this.login = userLogin;
+ this.userLogin = userLogin;
}
public UserNewValue(UserDto userDto) {
this.userUuid = userDto.getUuid();
- this.login = userDto.getLogin();
+ this.userLogin = userDto.getLogin();
this.name = userDto.getName();
this.email = userDto.getEmail();
this.isActive = userDto.isActive();
return this.userUuid;
}
- public String getLogin() {
- return this.login;
+ public String getUserLogin() {
+ return this.userLogin;
}
@CheckForNull
public String toString() {
StringBuilder sb = new StringBuilder("{");
addField(sb, "\"userUuid\": ", this.userUuid, true);
- addField(sb, "\"userLogin\": ", this.login, true);
+ addField(sb, "\"userLogin\": ", this.userLogin, true);
addField(sb, "\"name\": ", this.name, true);
addField(sb, "\"email\": ", this.email, true);
addField(sb, "\"isActive\": ", ObjectUtils.toString(this.isActive), false);
public String toString() {
StringBuilder sb = new StringBuilder("{");
addField(sb, "\"permissionUuid\": ", this.permissionUuid, true);
- addField(sb, "\"role\": ", this.role, true);
+ addField(sb, "\"permission\": ", this.permission, true);
addField(sb, "\"componentUuid\": ", this.componentUuid, true);
addField(sb, "\"componentName\": ", this.componentName, true);
addField(sb, "\"userUuid\": ", this.userUuid, true);
@Rule
public DbTester db = DbTester.create(System2.INSTANCE, auditPersister);
- public final SequenceUuidFactory uuidFactory = new SequenceUuidFactory();
+ private final SequenceUuidFactory uuidFactory = new SequenceUuidFactory();
private final ArgumentCaptor<GroupPermissionNewValue> newValueCaptor = ArgumentCaptor.forClass(GroupPermissionNewValue.class);
private final DbSession dbSession = db.getSession();
private final GroupPermissionDao underTest = db.getDbClient().groupPermissionDao();
private void assertNewValue(GroupPermissionNewValue newValue, String uuid, String groupUuid, String groupName, String cUuid, String permission, String cName, String qualifier) {
assertThat(newValue)
- .extracting("permissionUuid", "groupUuid", "groupName", "componentUuid", "role", "componentName", "qualifier")
+ .extracting("permissionUuid", "groupUuid", "groupName", "componentUuid", "permission", "componentName", "qualifier")
.containsExactly(uuid, groupUuid, groupName, cUuid, permission, cName, qualifier);
}
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)
- .containsExactly(dto.getUuid(), user.getUuid(), user.getLogin(), null, dto.getPermission(), null, null);
+ assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), null, dto.getPermission(), null, null);
assertThat(newValue.toString()).doesNotContain("projectUuid");
underTest.deleteGlobalPermission(dbSession, user, SYSTEM_ADMIN);
verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture());
newValue = newValueCaptor.getValue();
- assertThat(newValue)
- .extracting(UserPermissionNewValue::getPermissionUuid, UserPermissionNewValue::getUserUuid, UserPermissionNewValue::getUserLogin, UserPermissionNewValue::getComponentUuid,
- UserPermissionNewValue::getPermission, UserPermissionNewValue::getComponentName)
- .containsExactly(null, user.getUuid(), user.getLogin(), null, dto.getPermission(), null);
+ assertNewValue(newValue, null, user.getUuid(), user.getLogin(), null, dto.getPermission(), null, null);
assertThat(newValue.toString()).doesNotContain("permissionUuid");
}
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)
- .containsExactly(dto.getUuid(), user.getUuid(), user.getLogin(), project.uuid(), dto.getPermission(), project.name(), "project");
+ assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), project.uuid(), dto.getPermission(), project.name(), "project");
assertThat(newValue.toString()).contains("componentUuid");
underTest.deleteProjectPermission(dbSession, user, SYSTEM_ADMIN, project);
verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture());
newValue = newValueCaptor.getValue();
- assertThat(newValue)
- .extracting(UserPermissionNewValue::getPermissionUuid, UserPermissionNewValue::getUserUuid, UserPermissionNewValue::getUserLogin,
- UserPermissionNewValue::getComponentUuid, UserPermissionNewValue::getPermission, UserPermissionNewValue::getComponentName)
- .containsExactly(null, user.getUuid(), user.getLogin(), project.uuid(), dto.getPermission(), project.name());
- assertThat(newValue.toString())
- .doesNotContain("permissionUuid");
+ assertNewValue(newValue, null, user.getUuid(), user.getLogin(), project.uuid(), dto.getPermission(), project.name(), "project");
+ assertThat(newValue.toString()).doesNotContain("permissionUuid");
}
@Test
verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture());
UserPermissionNewValue newValue = newValueCaptor.getValue();
- assertThat(newValue)
- .extracting(UserPermissionNewValue::getPermissionUuid, UserPermissionNewValue::getUserUuid, UserPermissionNewValue::getComponentUuid,
- UserPermissionNewValue::getPermission, UserPermissionNewValue::getComponentName, UserPermissionNewValue::getQualifier)
- .containsExactly(dto.getUuid(), user.getUuid(), portfolio.uuid(), dto.getPermission(), portfolio.name(), "portfolio");
- assertThat(newValue.toString())
- .contains("componentUuid");
+ assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), portfolio.uuid(), dto.getPermission(), portfolio.name(), "portfolio");
+ assertThat(newValue.toString()).contains("componentUuid");
}
@Test
verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture());
UserPermissionNewValue newValue = newValueCaptor.getValue();
- assertThat(newValue)
- .extracting(UserPermissionNewValue::getPermissionUuid, UserPermissionNewValue::getUserUuid, UserPermissionNewValue::getComponentUuid,
- UserPermissionNewValue::getPermission, UserPermissionNewValue::getComponentName, UserPermissionNewValue::getQualifier)
- .containsExactly(dto.getUuid(), user.getUuid(), application.uuid(), dto.getPermission(), application.name(), "application");
- assertThat(newValue.toString())
- .contains("componentUuid");
+ assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), application.uuid(), dto.getPermission(), application.name(), "application");
+ assertThat(newValue.toString()).contains("componentUuid");
}
@Test
verify(auditPersister).deleteUserPermission(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)
- .containsExactly(null, null, null, project.uuid(), SCAN_EXECUTION, project.name(), "project");
+ assertNewValue(newValue, null, null, null, project.uuid(), dto.getPermission(), project.name(), "project");
assertThat(newValue.toString()).doesNotContain("userUuid");
}
verify(auditPersister).deleteUserPermission(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)
- .containsExactly(null, user.getUuid(), user.getLogin(), null, null, null, null);
+ assertNewValue(newValue, null, user.getUuid(), user.getLogin(), null, null, null, null);
assertThat(newValue.toString()).contains("userUuid");
}
verifyNoMoreInteractions(auditPersister);
}
+ private void assertNewValue(UserPermissionNewValue newValue, String permissionUuid, String userUuid, String userLogin, String componentUuid, String permission,
+ String componentName, String qualifier) {
+ assertThat(newValue)
+ .extracting(UserPermissionNewValue::getPermissionUuid, UserPermissionNewValue::getUserUuid, UserPermissionNewValue::getUserLogin,
+ UserPermissionNewValue::getComponentUuid, UserPermissionNewValue::getPermission, UserPermissionNewValue::getComponentName, UserPermissionNewValue::getQualifier)
+ .containsExactly(permissionUuid, userUuid, userLogin, componentUuid, permission, componentName, qualifier);
+ }
+
private UserDto insertUser(Consumer<UserDto> populateUserDto) {
- return db.users().insertUser(populateUserDto);
+ return db.users().insertUser(populateUserDto);
}
}
verify(auditPersister).addUser(eq(db.getSession()), newValueCaptor.capture());
UserNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
- .extracting(UserNewValue::getUserUuid, UserNewValue::getLogin)
+ .extracting(UserNewValue::getUserUuid, UserNewValue::getUserLogin)
.containsExactly(user.getUuid(), user.getLogin());
assertThat(newValue.toString()).doesNotContain("name");
}
verify(auditPersister).updateUser(eq(db.getSession()), newValueCaptor.capture());
UserNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
- .extracting(UserNewValue::getUserUuid, UserNewValue::getLogin, UserNewValue::getName, UserNewValue::getEmail, UserNewValue::isActive,
+ .extracting(UserNewValue::getUserUuid, UserNewValue::getUserLogin, UserNewValue::getName, UserNewValue::getEmail, UserNewValue::isActive,
UserNewValue::getScmAccounts, UserNewValue::getExternalId, UserNewValue::getExternalLogin, UserNewValue::getExternalIdentityProvider,
UserNewValue::isLocal, UserNewValue::isOnboarded, UserNewValue::isRoot, UserNewValue::getLastConnectionDate)
.containsExactly(updatedUser.getUuid(), updatedUser.getLogin(), updatedUser.getName(), updatedUser.getEmail(), updatedUser.isActive(),
verify(auditPersister).deactivateUser(eq(db.getSession()), newValueCaptor.capture());
assertThat(newValueCaptor.getValue())
- .extracting(UserNewValue::getUserUuid, UserNewValue::getLogin)
+ .extracting(UserNewValue::getUserUuid, UserNewValue::getUserLogin)
.containsExactly(user.getUuid(), user.getLogin());
}
import javax.annotation.Nullable;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.user.UserIdDto;
+import org.sonar.db.user.UserId;
import static java.util.Objects.requireNonNull;
public class UserPermissionChange extends PermissionChange {
- private final UserIdDto userId;
+ private final UserId userId;
- public UserPermissionChange(Operation operation, String permission, @Nullable ComponentDto project, UserIdDto userId, PermissionService permissionService) {
+ public UserPermissionChange(Operation operation, String permission, @Nullable ComponentDto project, UserId userId, PermissionService permissionService) {
super(operation, permission, project, permissionService);
this.userId = requireNonNull(userId);
}
- public UserIdDto getUserId() {
+ public UserId getUserId() {
return userId;
}
}
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.user.UserId;
import org.sonar.server.permission.PermissionChange;
import org.sonar.server.permission.PermissionService;
import org.sonar.server.permission.PermissionUpdater;
-import org.sonar.db.user.UserIdDto;
import org.sonar.server.permission.UserPermissionChange;
import org.sonar.server.user.UserSession;
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
- UserIdDto user = wsSupport.findUser(dbSession, request.mandatoryParam(PARAM_USER_LOGIN));
+ UserId user = wsSupport.findUser(dbSession, request.mandatoryParam(PARAM_USER_LOGIN));
Optional<ComponentDto> project = wsSupport.findProject(dbSession, request);
checkProjectAdmin(userSession, configuration, project.orElse(null));
import org.sonar.db.component.ComponentDto;
import org.sonar.db.permission.template.PermissionTemplateDto;
import org.sonar.db.user.UserDto;
+import org.sonar.db.user.UserId;
+import org.sonar.db.user.UserIdDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.permission.GroupUuidOrAnyone;
-import org.sonar.db.user.UserIdDto;
import org.sonar.server.permission.ws.template.WsTemplateRef;
import org.sonar.server.user.UserSession;
import org.sonar.server.usergroups.ws.GroupWsRef;
return groupWsSupport.findGroupOrAnyone(dbSession, groupRef);
}
- public UserIdDto findUser(DbSession dbSession, String login) {
+ public UserId findUser(DbSession dbSession, String login) {
UserDto dto = ofNullable(dbClient.userDao().selectActiveUserByLogin(dbSession, login))
.orElseThrow(() -> new NotFoundException(format("User with login '%s' is not found'", login)));
return new UserIdDto(dto.getUuid(), dto.getLogin());
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.user.UserId;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.permission.PermissionChange;
import org.sonar.server.permission.PermissionService;
import org.sonar.server.permission.PermissionUpdater;
-import org.sonar.db.user.UserIdDto;
import org.sonar.server.permission.UserPermissionChange;
import org.sonar.server.user.UserSession;
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
- UserIdDto user = wsSupport.findUser(dbSession, request.mandatoryParam(PARAM_USER_LOGIN));
+ UserId user = wsSupport.findUser(dbSession, request.mandatoryParam(PARAM_USER_LOGIN));
String permission = request.mandatoryParam(PARAM_PERMISSION);
if (ADMINISTER.getKey().equals(permission) && user.getLogin().equals(userSession.getLogin())) {
throw BadRequestException.create("As an admin, you can't remove your own admin right");
import org.sonar.db.DbSession;
import org.sonar.db.permission.PermissionQuery;
import org.sonar.db.permission.template.PermissionTemplateDto;
-import org.sonar.db.user.UserIdDto;
+import org.sonar.db.user.UserId;
import org.sonar.server.permission.ws.PermissionWsSupport;
import org.sonar.server.permission.ws.PermissionsWsAction;
import org.sonar.server.permission.ws.WsParameters;
PermissionTemplateDto template = wsSupport.findTemplate(dbSession, newTemplateRef(
request.getTemplateId(), request.getTemplateName()));
checkGlobalAdmin(userSession);
- UserIdDto user = wsSupport.findUser(dbSession, userLogin);
+ UserId user = wsSupport.findUser(dbSession, userLogin);
if (!isUserAlreadyAdded(dbSession, template.getUuid(), userLogin, permission)) {
dbClient.permissionTemplateDao().insertUserPermission(dbSession, template.getUuid(), user.getUuid(), permission,
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.permission.template.PermissionTemplateDto;
+import org.sonar.db.user.UserId;
import org.sonar.server.permission.RequestValidator;
-import org.sonar.db.user.UserIdDto;
import org.sonar.server.permission.ws.PermissionWsSupport;
import org.sonar.server.permission.ws.PermissionsWsAction;
import org.sonar.server.permission.ws.WsParameters;
PermissionTemplateDto template = wsSupport.findTemplate(dbSession, WsTemplateRef.newTemplateRef(request.getTemplateId(), request.getTemplateName()));
checkGlobalAdmin(userSession);
- UserIdDto user = wsSupport.findUser(dbSession, userLogin);
+ UserId user = wsSupport.findUser(dbSession, userLogin);
dbClient.permissionTemplateDao().deleteUserPermission(dbSession, template.getUuid(), user.getUuid(), permission, template.getName(), user.getLogin());
dbSession.commit();
*/
package org.sonar.server.project.ws;
+import java.util.Arrays;
+import java.util.Random;
+import java.util.Set;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Configuration;
import static org.mockito.Mockito.when;
import static org.sonar.api.CoreProperties.CORE_ALLOW_PERMISSION_MANAGEMENT_FOR_PROJECT_ADMINS_PROPERTY;
import static org.sonar.db.component.ComponentTesting.newProjectCopy;
-import java.util.Arrays;
-import java.util.Random;
-import java.util.Set;
-import java.util.stream.IntStream;
-import java.util.stream.Stream;
public class UpdateVisibilityActionTest {
private static final String PARAM_VISIBILITY = "visibility";
.isEmpty();
}
- @Test
- public void update_a_portfolio_to_private_givenWeCanFindUserByUUID_stillUpdatePermissions() {
- ComponentDto portfolio = dbTester.components().insertPublicPortfolio();
- GroupDto group = dbTester.users().insertGroup();
- dbTester.users().insertProjectPermissionOnGroup(group, UserRole.ISSUE_ADMIN, portfolio);
- UserDto userDto = mock(UserDto.class);
- when(userDto.getUuid()).thenReturn("uuid");
- when(userDto.getLogin()).thenReturn("login");
- dbTester.users().insertProjectPermissionOnUser(userDto, UserRole.ADMIN, portfolio);
- userSessionRule.addProjectPermission(UserRole.ADMIN, portfolio);
-
- request.setParam(PARAM_PROJECT, portfolio.getDbKey())
- .setParam(PARAM_VISIBILITY, PRIVATE)
- .execute();
-
- assertThat(dbClient.componentDao().selectByUuid(dbSession, portfolio.uuid()).get().isPrivate()).isTrue();
- assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, group.getUuid(), portfolio.uuid()))
- .containsOnly(UserRole.USER, UserRole.CODEVIEWER, UserRole.ISSUE_ADMIN);
- assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, "uuid", portfolio.uuid()))
- .containsOnly(UserRole.USER, UserRole.CODEVIEWER, UserRole.ADMIN);
- }
-
@Test
public void update_a_portfolio_to_private() {
ComponentDto portfolio = dbTester.components().insertPublicPortfolio();