From: Pierre Date: Wed, 11 Aug 2021 15:40:39 +0000 (+0200) Subject: SONAR-15142 add name to audit visibility update X-Git-Tag: 9.1.0.47736~140 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5aa5e0d62d01397b6af395afe87d61e52348b0b2;p=sonarqube.git SONAR-15142 add name to audit visibility update --- diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/ComponentNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/ComponentNewValue.java index e40c970e3a7..c9fdc9c52df 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/ComponentNewValue.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/ComponentNewValue.java @@ -58,6 +58,14 @@ public class ComponentNewValue implements NewValue { this.generateComponentPrefix(qualifier); } + + public ComponentNewValue(String componentUuid, String name, boolean isPrivate, String qualifier) { + this.componentUuid = componentUuid; + this.componentName = name; + this.isPrivate = isPrivate; + this.generateComponentPrefix(qualifier); + } + public ComponentNewValue(String uuid, String name, String key, boolean enabled, String path, String qualifier) { this.componentUuid = uuid; this.componentName = name; diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java index 02c397dc41d..b7fe807410c 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java @@ -103,9 +103,9 @@ public class ProjectDao implements Dao { return mapper(session).selectByUuids(uuids); } - public void updateVisibility(DbSession session, String uuid, boolean isPrivate, String qualifier) { + public void updateVisibility(DbSession session, String uuid, boolean isPrivate, String qualifier, String name) { if (auditPersister != null) { - auditPersister.updateComponentVisibility(session, new ComponentNewValue(uuid, isPrivate, qualifier), qualifier); + auditPersister.updateComponentVisibility(session, new ComponentNewValue(uuid, name, isPrivate, qualifier), qualifier); } mapper(session).updateVisibility(uuid, isPrivate, system2.now()); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentNewValueTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentNewValueTest.java index 8e952796fa0..fd86977875a 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentNewValueTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentNewValueTest.java @@ -44,6 +44,15 @@ public class ComponentNewValueTest { assertThat(newValue.toString()).contains("portfolioUuid"); } + @Test + public void toString_project_uuid_and_name_and_isPrivate() { + ComponentNewValue newValue = new ComponentNewValue("uuid", "name", true,"TRK"); + + assertThat(newValue.toString()).contains("\"projectUuid\": \"uuid\""); + assertThat(newValue.toString()).contains("\"projectName\": \"name\""); + assertThat(newValue.toString()).contains("\"isPrivate\": true"); + } + @Test public void toString_addsProjectPrefix() { ComponentNewValue newValue = new ComponentNewValue("uuid", "name", "key", true, "path", "TRK"); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java index 9ebae98075c..4d12e9846fe 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java @@ -37,6 +37,7 @@ import org.sonar.db.audit.AuditPersister; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -148,8 +149,8 @@ public class ProjectDaoTest { assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", true); assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", false); - projectDao.updateVisibility(db.getSession(), dto1.getUuid(), false, Qualifiers.PROJECT); - projectDao.updateVisibility(db.getSession(), dto2.getUuid(), true, Qualifiers.PROJECT); + projectDao.updateVisibility(db.getSession(), dto1.getUuid(), false, Qualifiers.PROJECT, dto1.getName()); + projectDao.updateVisibility(db.getSession(), dto2.getUuid(), true, Qualifiers.PROJECT, dto2.getName()); projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); assertThat(projectsByUuids).hasSize(2); @@ -209,9 +210,9 @@ public class ProjectDaoTest { public void updateVisibility_shouldCallAuditPersister() { ProjectDto dto1 = createProject("o1", "p1"); - projectDaoWithAuditPersister.updateVisibility(db.getSession(), dto1.getUuid(), false, Qualifiers.PROJECT); + projectDaoWithAuditPersister.updateVisibility(db.getSession(), dto1.getUuid(), false, Qualifiers.PROJECT, dto1.getName()); - verify(auditPersister, times(1)).updateComponentVisibility(any(), any(), any()); + verify(auditPersister, times(1)).updateComponentVisibility(any(), any(), eq(Qualifiers.PROJECT)); } @Test diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java index 72634b9b377..75dd564f402 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java @@ -133,7 +133,7 @@ public class UpdateVisibilityAction implements ProjectsWsAction { dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, uuid, isPrivate, component.qualifier()); if (component.qualifier().equals(Qualifiers.PROJECT) || component.qualifier().equals(Qualifiers.APP)) { - dbClient.projectDao().updateVisibility(dbSession, uuid, isPrivate, component.qualifier()); + dbClient.projectDao().updateVisibility(dbSession, uuid, isPrivate, component.qualifier(), component.name()); } ComponentMapper mapper = dbSession.getMapper(ComponentMapper.class);