From ce94c8112cf4ae300ca17ca1efbc5b00202278fa Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Mon, 16 Aug 2021 15:44:41 -0500 Subject: [PATCH] SONAR-15142 Set a permission template default for Projects / Applications / Portfolios is not tracked --- .../audit/model/GroupPermissionNewValue.java | 2 +- .../sonar/db/audit/model/UserNewValue.java | 12 ++-- .../audit/model/UserPermissionNewValue.java | 2 +- .../GroupPermissionDaoWithPersisterTest.java | 4 +- .../UserPermissionDaoWithPersisterTest.java | 59 +++++++------------ .../db/user/UserDaoWithPersisterTest.java | 6 +- .../permission/UserPermissionChange.java | 8 +-- .../server/permission/ws/AddUserAction.java | 4 +- .../permission/ws/PermissionWsSupport.java | 5 +- .../permission/ws/RemoveUserAction.java | 4 +- .../ws/template/AddUserToTemplateAction.java | 4 +- .../RemoveUserFromTemplateAction.java | 4 +- .../ws/UpdateVisibilityActionTest.java | 32 ++-------- 13 files changed, 53 insertions(+), 93 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java index ca0fec0c2dd..bad70117882 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java @@ -61,7 +61,7 @@ public class GroupPermissionNewValue extends PermissionNewValue { 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); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserNewValue.java index ff8f4dd95eb..62bd6e87bb1 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserNewValue.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserNewValue.java @@ -26,7 +26,7 @@ import org.sonar.db.user.UserDto; public class UserNewValue extends NewValue { private String userUuid; - private String login; + private String userLogin; @Nullable private String name; @@ -63,12 +63,12 @@ public class UserNewValue extends NewValue { 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(); @@ -86,8 +86,8 @@ public class UserNewValue extends NewValue { return this.userUuid; } - public String getLogin() { - return this.login; + public String getUserLogin() { + return this.userLogin; } @CheckForNull @@ -149,7 +149,7 @@ public class UserNewValue extends NewValue { 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); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java index bcc93c41473..6a42acd4957 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java @@ -60,7 +60,7 @@ public class UserPermissionNewValue extends PermissionNewValue { 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); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterTest.java index a50e9b10b16..63d0a755617 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterTest.java @@ -51,7 +51,7 @@ public class GroupPermissionDaoWithPersisterTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE, auditPersister); - public final SequenceUuidFactory uuidFactory = new SequenceUuidFactory(); + private final SequenceUuidFactory uuidFactory = new SequenceUuidFactory(); private final ArgumentCaptor newValueCaptor = ArgumentCaptor.forClass(GroupPermissionNewValue.class); private final DbSession dbSession = db.getSession(); private final GroupPermissionDao underTest = db.getDbClient().groupPermissionDao(); @@ -172,7 +172,7 @@ public class GroupPermissionDaoWithPersisterTest { 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); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoWithPersisterTest.java index b423bf01e2b..7be718c1c12 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoWithPersisterTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoWithPersisterTest.java @@ -59,20 +59,14 @@ public class UserPermissionDaoWithPersisterTest { 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"); } @@ -95,22 +89,15 @@ public class UserPermissionDaoWithPersisterTest { 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 @@ -134,12 +121,8 @@ public class UserPermissionDaoWithPersisterTest { 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 @@ -151,12 +134,8 @@ public class UserPermissionDaoWithPersisterTest { 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 @@ -169,10 +148,7 @@ public class UserPermissionDaoWithPersisterTest { 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"); } @@ -196,10 +172,7 @@ public class UserPermissionDaoWithPersisterTest { 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"); } @@ -213,7 +186,15 @@ public class UserPermissionDaoWithPersisterTest { 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 populateUserDto) { - return db.users().insertUser(populateUserDto); + return db.users().insertUser(populateUserDto); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoWithPersisterTest.java index 695a3e49dad..c4db20ec07f 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoWithPersisterTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoWithPersisterTest.java @@ -69,7 +69,7 @@ public class UserDaoWithPersisterTest { 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"); } @@ -108,7 +108,7 @@ public class UserDaoWithPersisterTest { 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(), @@ -148,7 +148,7 @@ public class UserDaoWithPersisterTest { 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()); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChange.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChange.java index 2f23bd4a569..bdd710fbc04 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChange.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChange.java @@ -21,20 +21,20 @@ package org.sonar.server.permission; 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; } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddUserAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddUserAction.java index 3cd8361e068..3603ab09003 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddUserAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddUserAction.java @@ -27,10 +27,10 @@ import org.sonar.api.server.ws.WebService; 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; @@ -86,7 +86,7 @@ public class AddUserAction implements PermissionsWsAction { @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 project = wsSupport.findProject(dbSession, request); checkProjectAdmin(userSession, configuration, project.orElse(null)); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java index 27a1b09f9a4..f107f8275d8 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java @@ -28,10 +28,11 @@ import org.sonar.db.DbSession; 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; @@ -85,7 +86,7 @@ public class PermissionWsSupport { 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()); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java index c6938cea0e6..84b9e2a0cca 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java @@ -26,11 +26,11 @@ import org.sonar.api.server.ws.WebService; 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; @@ -84,7 +84,7 @@ public class RemoveUserAction implements PermissionsWsAction { @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"); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/AddUserToTemplateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/AddUserToTemplateAction.java index a508348156b..5ab0b023f33 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/AddUserToTemplateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/AddUserToTemplateAction.java @@ -29,7 +29,7 @@ import org.sonar.db.DbClient; 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; @@ -95,7 +95,7 @@ public class AddUserToTemplateAction implements PermissionsWsAction { 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, diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateAction.java index 4d014c2e726..f093ba44447 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateAction.java @@ -27,8 +27,8 @@ import org.sonar.api.server.ws.WebService; 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; @@ -96,7 +96,7 @@ public class RemoveUserFromTemplateAction implements PermissionsWsAction { 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(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java index c97a0c51780..ee0a2f20e2c 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java @@ -19,6 +19,11 @@ */ 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; @@ -68,11 +73,6 @@ import static org.mockito.Mockito.mock; 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"; @@ -489,28 +489,6 @@ public class UpdateVisibilityActionTest { .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(); -- 2.39.5