]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15142 add name to audit visibility update
authorPierre <pierre.guillot@sonarsource.com>
Wed, 11 Aug 2021 15:40:39 +0000 (17:40 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 19 Aug 2021 20:08:14 +0000 (20:08 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/ComponentNewValue.java
server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java
server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentNewValueTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java

index e40c970e3a78b0e66a6bcd3e48c7ac5d09a14fbc..c9fdc9c52df20f3172e1329d0e058fa9131f5ea0 100644 (file)
@@ -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;
index 02c397dc41d5f8f6e1d6756dfc9a062386848bca..b7fe807410c3a41be74b4e90bae7521a82f41ce8 100644 (file)
@@ -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());
   }
index 8e952796fa077decd70cecd863bd8cbd1b5139df..fd86977875a51787fcbea44b8410b9777ac761a5 100644 (file)
@@ -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");
index 9ebae98075c34d6114963048fe31eda7d417cc65..4d12e9846fe664a644f6e8b5718440111f496d50 100644 (file)
@@ -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
index 72634b9b37726093acf9ac54ea886bb54efb88d8..75dd564f4029210aa253a787cf4cc8d6cf4fbeab 100644 (file)
@@ -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);