aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorAurelien Poscia <aurelien.poscia@sonarsource.com>2024-08-08 11:22:35 +0200
committersonartech <sonartech@sonarsource.com>2024-08-19 20:02:44 +0000
commitb3cb7680a75b804c1e88a74bb516488fc814f6f8 (patch)
treef463319759e1f539c41e655c9ef8ba48666d7941 /server
parent240d05623b7251933d9e0f86e665f16c1d5fb8f6 (diff)
downloadsonarqube-b3cb7680a75b804c1e88a74bb516488fc814f6f8.tar.gz
sonarqube-b3cb7680a75b804c1e88a74bb516488fc814f6f8.zip
SONAR-22559 Display project name instead of ID in logs
Diffstat (limited to 'server')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/user/UserIdDto.java5
-rw-r--r--server/sonar-webserver-common/src/main/java/org/sonar/server/common/permission/UserPermissionChange.java12
-rw-r--r--server/sonar-webserver-common/src/test/java/org/sonar/server/common/permission/UserPermissionChangeTest.java46
3 files changed, 63 insertions, 0 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserIdDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserIdDto.java
index 278da5e76ec..180b3038de9 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserIdDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserIdDto.java
@@ -51,4 +51,9 @@ public class UserIdDto implements UserId {
public static UserIdDto from(UserDto dto) {
return new UserIdDto(dto.getUuid(), dto.getLogin());
}
+
+ @Override
+ public String toString() {
+ return "login='" + login + "'";
+ }
}
diff --git a/server/sonar-webserver-common/src/main/java/org/sonar/server/common/permission/UserPermissionChange.java b/server/sonar-webserver-common/src/main/java/org/sonar/server/common/permission/UserPermissionChange.java
index d532f71126e..815b0bdd851 100644
--- a/server/sonar-webserver-common/src/main/java/org/sonar/server/common/permission/UserPermissionChange.java
+++ b/server/sonar-webserver-common/src/main/java/org/sonar/server/common/permission/UserPermissionChange.java
@@ -19,6 +19,8 @@
*/
package org.sonar.server.common.permission;
+import java.util.Optional;
+import java.util.StringJoiner;
import javax.annotation.Nullable;
import org.sonar.db.entity.EntityDto;
import org.sonar.db.user.UserId;
@@ -44,4 +46,14 @@ public class UserPermissionChange extends PermissionChange {
public String getUuidOfGrantee() {
return userId.getUuid();
}
+
+ @Override
+ public String toString() {
+ return new StringJoiner(", ", UserPermissionChange.class.getSimpleName() + "[", "]")
+ .add("userId=" + userId)
+ .add("operation=" + getOperation())
+ .add("permission='" + getPermission() + "'")
+ .add("entity=" + Optional.ofNullable(getEntity()).map(EntityDto::getName).orElse("null"))
+ .toString();
+ }
}
diff --git a/server/sonar-webserver-common/src/test/java/org/sonar/server/common/permission/UserPermissionChangeTest.java b/server/sonar-webserver-common/src/test/java/org/sonar/server/common/permission/UserPermissionChangeTest.java
new file mode 100644
index 00000000000..c3981edeb58
--- /dev/null
+++ b/server/sonar-webserver-common/src/test/java/org/sonar/server/common/permission/UserPermissionChangeTest.java
@@ -0,0 +1,46 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.common.permission;
+
+import java.util.List;
+import org.junit.jupiter.api.Test;
+import org.sonar.db.entity.EntityDto;
+import org.sonar.db.user.UserIdDto;
+import org.sonar.server.permission.PermissionService;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class UserPermissionChangeTest {
+
+ @Test
+ void toString_shouldReturnStringRepresentation() {
+ PermissionService permissionService = mock();
+ when(permissionService.getAllProjectPermissions()).thenReturn(List.of("permission1", "permission2"));
+
+ EntityDto entityDto = mock();
+ when(entityDto.getName()).thenReturn("entityName");
+ UserPermissionChange userPermissionChange = new UserPermissionChange(Operation.ADD, "permission2", entityDto, new UserIdDto("uuid1", "login1"), permissionService);
+
+ assertThat(userPermissionChange).hasToString("UserPermissionChange[userId=login='login1', operation=ADD, permission='permission2', entity=entityName]");
+ }
+
+}