]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15142 - Log Permission, Plugin, Secret Key, License and Settings
authorBelen Pruvost <belen.pruvost@sonarsource.com>
Tue, 20 Jul 2021 11:56:34 +0000 (13:56 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 27 Jul 2021 20:03:02 +0000 (20:03 +0000)
157 files changed:
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactoryTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java
server/sonar-ce/src/main/java/org/sonar/ce/db/ReadOnlyPropertiesDao.java
server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
server/sonar-ce/src/test/java/org/sonar/ce/db/ReadOnlyPropertiesDaoTest.java
server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/AlmPatDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/audit/AuditPersister.java
server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/DevOpsPlatformSettingNewValue.java [new file with mode: 0644]
server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/LicenseNewValue.java [new file with mode: 0644]
server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/NewValue.java
server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PermissionNewValue.java [new file with mode: 0644]
server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PermissionTemplateNewValue.java [new file with mode: 0644]
server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PersonalAccessTokenNewValue.java [new file with mode: 0644]
server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PluginNewValue.java [new file with mode: 0644]
server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PropertyNewValue.java
server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserGroupNewValue.java
server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserNewValue.java
server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserTokenNewValue.java
server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/WebhookNewValue.java [new file with mode: 0644]
server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/plugin/PluginDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/user/UserPropertiesDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/webhook/WebhookDao.java
server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-dao/src/test/java/org/sonar/db/alm/pat/AlmPatDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/alm/pat/AlmPatDaoWithPersisterTest.java [new file with mode: 0644]
server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/AlmSettingDaoWithPersisterTest.java [new file with mode: 0644]
server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoWithPersisterTest.java [new file with mode: 0644]
server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/LicenseNewValueTest.java [new file with mode: 0644]
server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterTest.java [new file with mode: 0644]
server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoWithPersisterTest.java [new file with mode: 0644]
server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicDaoWithPersisterTest.java [new file with mode: 0644]
server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoWithPersisterTest.java [new file with mode: 0644]
server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/plugin/PluginDaoWithPersisterTest.java [new file with mode: 0644]
server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoWithPersisterTest.java [new file with mode: 0644]
server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupDaoWithPersisterTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoWithPersisterTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/user/UserGroupDaoWithPersisterTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/user/UserPropertiesDaoWithPersisterTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/user/UserTokenDaoWithPersisterTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoWithPersisterTest.java [new file with mode: 0644]
server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDeliveryDaoTest.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/alm/integration/pat/AlmPatsDbTester.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/almsettings/AlmSettingsDbTester.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyDbTester.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/webhook/WebhookDbTester.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/CreateAuditTable.java
server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java
server/sonar-server-common/src/test/java/org/sonar/server/favorite/FavoriteUpdaterTest.java
server/sonar-server-common/src/test/java/org/sonar/server/platform/StartupMetadataProviderTest.java
server/sonar-server-common/src/test/java/org/sonar/server/webhook/AsynchronousWebHooksImplTest.java
server/sonar-server-common/src/test/java/org/sonar/server/webhook/SynchronousWebHooksImplTest.java
server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginConsentVerifier.java
server/sonar-webserver-api/src/main/java/org/sonar/server/project/ProjectDefaultVisibility.java
server/sonar-webserver-auth/src/test/java/org/sonar/server/user/UserUpdaterUpdateTest.java
server/sonar-webserver-core/src/main/java/org/sonar/server/platform/PersistentSettings.java
server/sonar-webserver-core/src/main/java/org/sonar/server/platform/serverid/ServerIdManager.java
server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java
server/sonar-webserver-core/src/test/java/org/sonar/server/platform/serverid/ServerIdManagerTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/SetPatAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/github/ImportGithubProjectAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/github/ListGithubOrganizationsAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/gitlab/ImportGitLabProjectAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/AddAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/RemoveAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChanger.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/AddGroupToTemplateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/AddProjectCreatorToTemplateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/AddUserToTemplateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/DeleteTemplateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/RemoveProjectCreatorFromTemplateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/CreateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/GenerateSecretKeyAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingsUpdater.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/DeleteAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/CreateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/DeleteAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/UpdateAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/CheckPatActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/ListAzureProjectsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/SearchAzureReposActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/ListBitbucketServerProjectsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/SearchBitbucketServerReposActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/gitlab/SearchGitlabReposActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/ReportSubmitterTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/AppActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/RemoveActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/SearchActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/AddProjectCreatorToTemplateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/DeleteTemplateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/RemoveProjectCreatorFromTemplateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/TemplateGroupsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/TemplateUsersActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/CreateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/GenerateSecretKeyActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/GenerateSecretKeyActionWithPersisterTest.java [new file with mode: 0644]
server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/ListActionTest.java

index 48b20950211c3808aa164551ed5d96950c474bf8..91821b0ac8e898d2c419c8fc97c756746b9c39a9 100644 (file)
@@ -52,7 +52,7 @@ public class ProjectConfigurationFactoryTest {
   @Test
   public void return_project_settings() {
     ComponentDto project = db.components().insertPrivateProject();
-    db.properties().insertProperties(
+    db.properties().insertProperties(null, project.name(),
       newComponentPropertyDto(project).setKey("1").setValue("val1"),
       newComponentPropertyDto(project).setKey("2").setValue("val2"),
       newComponentPropertyDto(project).setKey("3").setValue("val3"));
@@ -68,7 +68,7 @@ public class ProjectConfigurationFactoryTest {
   public void project_settings_override_global_settings() {
     settings.setProperty("key", "value");
     ComponentDto project = db.components().insertPrivateProject();
-    db.properties().insertProperties(newComponentPropertyDto(project).setKey("key").setValue("value2"));
+    db.properties().insertProperties(null, project.name(), newComponentPropertyDto(project).setKey("key").setValue("value2"));
 
     Configuration projectConfig = underTest.newProjectConfiguration(project.getDbKey(), new DefaultBranchImpl());
 
index 3e5ea15043b507b4c335e06b9235658c1aafeccd..e22196d73bce6c2db62cd3c16188758412aa4c12 100644 (file)
@@ -139,6 +139,7 @@ public class ConfigurationRepositoryTest {
   }
 
   private void insertProjectProperty(ComponentDto project, String propertyKey, String propertyValue) {
-    db.properties().insertProperties(new PropertyDto().setKey(propertyKey).setValue(propertyValue).setComponentUuid(project.uuid()));
+    db.properties().insertProperties(null, project.name(),
+      new PropertyDto().setKey(propertyKey).setValue(propertyValue).setComponentUuid(project.uuid()));
   }
 }
index a5e900a17b7b27cb1d946f079b4fdfcfe59928bf..af6175bd1bf5f08c2a95236f222d69d0d07639d0 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.ce.db;
 
 import java.util.Map;
+import javax.annotation.Nullable;
 import org.sonar.api.utils.System2;
 import org.sonar.core.util.UuidFactory;
 import org.sonar.db.DbSession;
@@ -42,7 +43,8 @@ public class ReadOnlyPropertiesDao extends PropertiesDao {
   }
 
   @Override
-  public void saveProperty(DbSession session, PropertyDto property) {
+  public void saveProperty(DbSession session, PropertyDto property, @Nullable String userLogin,
+    @Nullable String projectName) {
     // do nothing
   }
 
@@ -52,12 +54,12 @@ public class ReadOnlyPropertiesDao extends PropertiesDao {
   }
 
   @Override
-  public void deleteProjectProperty(String key, String projectUuid) {
+  public void deleteProjectProperty(String key, String projectUuid, String projectName) {
     // do nothing
   }
 
   @Override
-  public void deleteProjectProperty(String key, String projectUuid, DbSession session) {
+  public void deleteProjectProperty(String key, String projectUuid, DbSession session, String projectName) {
     // do nothing
   }
 
index 872b23dc2b4f73d8a11eabd6482ad7a4cc4c0f74..5d4170ff6d4b8a44bc9cc40711b644165d1156e9 100644 (file)
@@ -144,7 +144,7 @@ public class ComputeEngineContainerImplTest {
 
   private void insertProperty(String key, String value) {
     PropertyDto dto = new PropertyDto().setKey(key).setValue(value);
-    db.getDbClient().propertiesDao().saveProperty(db.getSession(), dto);
+    db.getDbClient().propertiesDao().saveProperty(db.getSession(), dto, null, null);
     db.commit();
   }
 
index 1c683b6791b2923aebe44cd6878ff08ba3cc1f92..ae6cea38f6c47603620d484d1401d66c02555098 100644 (file)
@@ -40,7 +40,7 @@ public class ReadOnlyPropertiesDaoTest {
 
   @Test
   public void insertProperty() {
-    underTest.saveProperty(dbSession, propertyDto);
+    underTest.saveProperty(dbSession, propertyDto, null, null);
 
     assertNoInteraction();
   }
@@ -54,7 +54,7 @@ public class ReadOnlyPropertiesDaoTest {
 
   @Test
   public void deleteProjectProperty() {
-    underTest.deleteProjectProperty(null, null);
+    underTest.deleteProjectProperty(null, null, null);
 
     assertNoInteraction();
 
@@ -62,7 +62,7 @@ public class ReadOnlyPropertiesDaoTest {
 
   @Test
   public void deleteProjectProperty1() {
-    underTest.deleteProjectProperty(null, null, dbSession);
+    underTest.deleteProjectProperty(null, null, dbSession, null);
 
     assertNoInteraction();
 
index aa90bf9f74b7deed7efdd6b397f4979e458d423d..f2d29cf5313c63ca9289ce9c6019c9a04d792b94 100644 (file)
 package org.sonar.db.alm.pat;
 
 import java.util.Optional;
+import javax.annotation.Nullable;
 import org.sonar.api.utils.System2;
 import org.sonar.core.util.UuidFactory;
 import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
 import org.sonar.db.alm.setting.AlmSettingDto;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PersonalAccessTokenNewValue;
 import org.sonar.db.user.UserDto;
 
 public class AlmPatDao implements Dao {
 
   private final System2 system2;
   private final UuidFactory uuidFactory;
+  private AuditPersister auditPersister;
 
   public AlmPatDao(System2 system2, UuidFactory uuidFactory) {
     this.system2 = system2;
     this.uuidFactory = uuidFactory;
   }
 
+  public AlmPatDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
+    this.system2 = system2;
+    this.uuidFactory = uuidFactory;
+    this.auditPersister = auditPersister;
+  }
+
   private static AlmPatMapper getMapper(DbSession dbSession) {
     return dbSession.getMapper(AlmPatMapper.class);
   }
@@ -49,31 +59,46 @@ public class AlmPatDao implements Dao {
     return Optional.ofNullable(getMapper(dbSession).selectByUserAndAlmSetting(userUuid, almSettingDto.getUuid()));
   }
 
-  public void insert(DbSession dbSession, AlmPatDto almPatDto) {
+  public void insert(DbSession dbSession, AlmPatDto almPatDto, @Nullable String userLogin, @Nullable String almSettingKey) {
     String uuid = uuidFactory.create();
     long now = system2.now();
     almPatDto.setUuid(uuid);
     almPatDto.setCreatedAt(now);
     almPatDto.setUpdatedAt(now);
     getMapper(dbSession).insert(almPatDto);
+
+    if (auditPersister != null) {
+      auditPersister.addPersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almPatDto, userLogin, almSettingKey));
+    }
   }
 
-  public void update(DbSession dbSession, AlmPatDto almPatDto) {
+  public void update(DbSession dbSession, AlmPatDto almPatDto, @Nullable String userLogin, @Nullable String almSettingKey) {
     long now = system2.now();
     almPatDto.setUpdatedAt(now);
     getMapper(dbSession).update(almPatDto);
+    if (auditPersister != null) {
+      auditPersister.updatePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almPatDto, userLogin, almSettingKey));
+    }
   }
 
-  public void delete(DbSession dbSession, AlmPatDto almPatDto) {
+  public void delete(DbSession dbSession, AlmPatDto almPatDto, @Nullable String userLogin, @Nullable String almSettingKey) {
     getMapper(dbSession).deleteByUuid(almPatDto.getUuid());
+    if (auditPersister != null) {
+      auditPersister.deletePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almPatDto, userLogin, almSettingKey));
+    }
   }
 
   public void deleteByUser(DbSession dbSession, UserDto user) {
     getMapper(dbSession).deleteByUser(user.getUuid());
+    if (auditPersister != null) {
+      auditPersister.deletePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(user));
+    }
   }
 
   public void deleteByAlmSetting(DbSession dbSession, AlmSettingDto almSetting) {
     getMapper(dbSession).deleteByAlmSetting(almSetting.getUuid());
+    if (auditPersister != null) {
+      auditPersister.deletePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almSetting));
+    }
   }
-
 }
index f8c80ca0ee184ffd248292a90eed0a752b0c32ef..b946a7c87972351e2acd48ce7b4b133e1c11d05b 100644 (file)
@@ -25,17 +25,26 @@ import org.sonar.api.utils.System2;
 import org.sonar.core.util.UuidFactory;
 import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.DevOpsPlatformSettingNewValue;
 
 public class AlmSettingDao implements Dao {
 
   private final System2 system2;
   private final UuidFactory uuidFactory;
 
+  private AuditPersister auditPersister;
+
   public AlmSettingDao(System2 system2, UuidFactory uuidFactory) {
     this.system2 = system2;
     this.uuidFactory = uuidFactory;
   }
 
+  public AlmSettingDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
+    this(system2, uuidFactory);
+    this.auditPersister = auditPersister;
+  }
+
   private static AlmSettingMapper getMapper(DbSession dbSession) {
     return dbSession.getMapper(AlmSettingMapper.class);
   }
@@ -47,6 +56,11 @@ public class AlmSettingDao implements Dao {
     almSettingDto.setCreatedAt(now);
     almSettingDto.setUpdatedAt(now);
     getMapper(dbSession).insert(almSettingDto);
+
+    if (auditPersister != null) {
+      auditPersister.addDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto.getUuid(),
+        almSettingDto.getKey()));
+    }
   }
 
   public Optional<AlmSettingDto> selectByUuid(DbSession dbSession, String uuid) {
@@ -67,11 +81,20 @@ public class AlmSettingDao implements Dao {
 
   public void delete(DbSession dbSession, AlmSettingDto almSettingDto) {
     getMapper(dbSession).deleteByKey(almSettingDto.getKey());
+
+    if (auditPersister != null) {
+      auditPersister.deleteDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto.getUuid(),
+        almSettingDto.getKey()));
+    }
   }
 
   public void update(DbSession dbSession, AlmSettingDto almSettingDto) {
     long now = system2.now();
     almSettingDto.setUpdatedAt(now);
     getMapper(dbSession).update(almSettingDto);
+
+    if (auditPersister != null) {
+      auditPersister.updateDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto));
+    }
   }
 }
index 5db19b90d766695f7a1bd261a704cf6a8c3f5552..caa11bea5b550f3b00f43766eeece2f7303f89c0 100644 (file)
@@ -26,6 +26,8 @@ import org.sonar.api.utils.System2;
 import org.sonar.core.util.UuidFactory;
 import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.DevOpsPlatformSettingNewValue;
 import org.sonar.db.project.ProjectDto;
 
 import static org.sonar.db.DatabaseUtils.executeLargeInputs;
@@ -34,31 +36,62 @@ public class ProjectAlmSettingDao implements Dao {
 
   private final System2 system2;
   private final UuidFactory uuidFactory;
+  private AuditPersister auditPersister;
 
   public ProjectAlmSettingDao(System2 system2, UuidFactory uuidFactory) {
     this.system2 = system2;
     this.uuidFactory = uuidFactory;
   }
 
-  public void insertOrUpdate(DbSession dbSession, ProjectAlmSettingDto projectAlmSettingDto) {
+  public ProjectAlmSettingDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
+    this(system2, uuidFactory);
+    this.auditPersister = auditPersister;
+  }
+
+  public void insertOrUpdate(DbSession dbSession, ProjectAlmSettingDto projectAlmSettingDto,
+    String key, String projectName) {
     String uuid = uuidFactory.create();
     long now = system2.now();
     ProjectAlmSettingMapper mapper = getMapper(dbSession);
+    boolean isUpdate = true;
 
     if (mapper.update(projectAlmSettingDto, now) == 0) {
       mapper.insert(projectAlmSettingDto, uuid, now);
       projectAlmSettingDto.setUuid(uuid);
       projectAlmSettingDto.setCreatedAt(now);
+      isUpdate = false;
     }
     projectAlmSettingDto.setUpdatedAt(now);
+
+    if (auditPersister != null) {
+      if (isUpdate) {
+        auditPersister.updateDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(projectAlmSettingDto, key, projectName));
+      } else {
+        auditPersister.addDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(projectAlmSettingDto.getAlmSettingUuid(),
+          projectAlmSettingDto.getProjectUuid(), key, projectName));
+      }
+    }
   }
 
   public void deleteByProject(DbSession dbSession, ProjectDto project) {
     getMapper(dbSession).deleteByProjectUuid(project.getUuid());
+
+    if (auditPersister != null) {
+      auditPersister.deleteDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(project));
+    }
   }
 
   public void deleteByAlmSetting(DbSession dbSession, AlmSettingDto almSetting) {
+    deleteByAlmSetting(dbSession, almSetting, false);
+  }
+
+  public void deleteByAlmSetting(DbSession dbSession, AlmSettingDto almSetting, boolean track) {
     getMapper(dbSession).deleteByAlmSettingUuid(almSetting.getUuid());
+
+    if (track && auditPersister != null) {
+      auditPersister.deleteDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSetting.getUuid(),
+        almSetting.getKey()));
+    }
   }
 
   public int countByAlmSetting(DbSession dbSession, AlmSettingDto almSetting) {
index 535f286014c5907782656e7ba04d38d363572ada..abeb69ff0e10eb55b7c2071e275e9cc39dce8149 100644 (file)
@@ -42,11 +42,11 @@ public interface AuditPersister {
 
   void deleteUserFromGroup(DbSession dbSession, NewValue newValue);
 
-  void addUserProperty(DbSession dbSession, NewValue newValue);
+  void addProperty(DbSession dbSession, NewValue newValue, boolean isUserProperty);
 
-  void updateUserProperty(DbSession dbSession, NewValue newValue);
+  void updateProperty(DbSession dbSession, NewValue newValue, boolean isUserProperty);
 
-  void deleteUserProperty(DbSession dbSession, NewValue newValue);
+  void deleteProperty(DbSession dbSession, NewValue newValue, boolean isUserProperty);
 
   void addUserToken(DbSession dbSession, NewValue newValue);
 
@@ -54,5 +54,57 @@ public interface AuditPersister {
 
   void deleteUserToken(DbSession dbSession, NewValue newValue);
 
+  void addGroupPermission(DbSession dbSession, NewValue newValue);
+
+  void deleteGroupPermission(DbSession dbSession, NewValue newValue);
+
+  void addUserPermission(DbSession dbSession, NewValue newValue);
+
+  void deleteUserPermission(DbSession dbSession, NewValue newValue);
+
+  void addPermissionTemplate(DbSession dbSession, NewValue newValue);
+
+  void updatePermissionTemplate(DbSession dbSession, NewValue newValue);
+
+  void deletePermissionTemplate(DbSession dbSession, NewValue newValue);
+
+  void addUserToPermissionTemplate(DbSession dbSession, NewValue newValue);
+
+  void deleteUserFromPermissionTemplate(DbSession dbSession, NewValue newValue);
+
+  void addGroupToPermissionTemplate(DbSession dbSession, NewValue newValue);
+
+  void deleteGroupFromPermissionTemplate(DbSession dbSession, NewValue newValue);
+
+  void addCharacteristicToPermissionTemplate(DbSession dbSession, NewValue newValue);
+
+  void updateCharacteristicInPermissionTemplate(DbSession dbSession, NewValue newValue);
+
+  void addPlugin(DbSession dbSession, NewValue newValue);
+
+  void updatePlugin(DbSession dbSession, NewValue newValue);
+
+  void generateSecretKey(DbSession dbSession);
+
+  void setLicense(DbSession dbSession, boolean isSet, NewValue newValue);
+
+  void addWebhook(DbSession dbSession, NewValue newValue);
+
+  void updateWebhook(DbSession dbSession, NewValue newValue);
+
+  void deleteWebhook(DbSession dbSession, NewValue newValue);
+
+  void addDevOpsPlatformSetting(DbSession dbSession, NewValue newValue);
+
+  void updateDevOpsPlatformSetting(DbSession dbSession, NewValue newValue);
+
+  void deleteDevOpsPlatformSetting(DbSession dbSession, NewValue newValue);
+
+  void addPersonalAccessToken(DbSession dbSession, NewValue newValue);
+
+  void updatePersonalAccessToken(DbSession dbSession, NewValue newValue);
+
+  void deletePersonalAccessToken(DbSession dbSession, NewValue newValue);
+
   boolean isTrackedProperty(String propertyKey);
 }
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/DevOpsPlatformSettingNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/DevOpsPlatformSettingNewValue.java
new file mode 100644 (file)
index 0000000..bfef1ea
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.audit.model;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.apache.commons.lang.ObjectUtils;
+import org.sonar.db.alm.setting.AlmSettingDto;
+import org.sonar.db.alm.setting.ProjectAlmSettingDto;
+import org.sonar.db.project.ProjectDto;
+
+public class DevOpsPlatformSettingNewValue implements NewValue {
+  @Nullable
+  private String devOpsPlatformSettingUuid;
+
+  @Nullable
+  private String key;
+
+  @Nullable
+  private String devOpsPlatformName;
+
+  @Nullable
+  private String url;
+
+  @Nullable
+  private String appId;
+
+  @Nullable
+  private String clientId;
+
+  @Nullable
+  private String projectUuid;
+
+  @Nullable
+  private String projectName;
+
+  @Nullable
+  private String almRepo;
+
+  @Nullable
+  private String almSlug;
+
+  @Nullable
+  private Boolean isSummaryCommentEnabled;
+
+  @Nullable
+  private Boolean isMonorepo;
+
+  public DevOpsPlatformSettingNewValue(String devOpsPlatformSettingUuid, String key) {
+    this.devOpsPlatformSettingUuid = devOpsPlatformSettingUuid;
+    this.key = key;
+  }
+
+  public DevOpsPlatformSettingNewValue(AlmSettingDto dto) {
+    this.devOpsPlatformSettingUuid = dto.getUuid();
+    this.key = dto.getKey();
+    this.devOpsPlatformName = dto.getAppId();
+    this.url = dto.getUrl();
+    this.appId = dto.getAppId();
+    this.clientId = dto.getClientId();
+  }
+
+  public DevOpsPlatformSettingNewValue(ProjectAlmSettingDto dto, String key, String projectName) {
+    this.devOpsPlatformSettingUuid = dto.getAlmSettingUuid();
+    this.key = key;
+    this.projectUuid = dto.getProjectUuid();
+    this.projectName = projectName;
+    this.almRepo = dto.getAlmRepo();
+    this.almSlug = dto.getAlmSlug();
+    this.isSummaryCommentEnabled = dto.getSummaryCommentEnabled();
+    this.isMonorepo = dto.getMonorepo();
+  }
+
+  public DevOpsPlatformSettingNewValue(String devOpsPlatformSettingUuid, String projectUuid, String key, String projectName) {
+    this.devOpsPlatformSettingUuid = devOpsPlatformSettingUuid;
+    this.key = key;
+    this.projectUuid = projectUuid;
+    this.projectName = projectName;
+  }
+
+  public DevOpsPlatformSettingNewValue(ProjectDto projectDto) {
+    this.projectUuid = projectDto.getUuid();
+    this.projectName = projectDto.getName();
+  }
+
+  @CheckForNull
+  public String getDevOpsPlatformSettingUuid() {
+    return this.devOpsPlatformSettingUuid;
+  }
+
+  @CheckForNull
+  public String getKey() {
+    return this.key;
+  }
+
+  @CheckForNull
+  public String getDevOpsPlatformName() {
+    return this.devOpsPlatformName;
+  }
+
+  @CheckForNull
+  public String getUrl() {
+    return this.url;
+  }
+
+  @CheckForNull
+  public String getAppId() {
+    return this.appId;
+  }
+
+  @CheckForNull
+  public String getClientId() {
+    return this.clientId;
+  }
+
+  @CheckForNull
+  public String getProjectUuid() {
+    return this.projectUuid;
+  }
+
+  @CheckForNull
+  public String getProjectName() {
+    return this.projectName;
+  }
+
+  @CheckForNull
+  public String getAlmRepo() {
+    return this.almRepo;
+  }
+
+  @CheckForNull
+  public String getAlmSlug() {
+    return this.almSlug;
+  }
+
+  @CheckForNull
+  public Boolean isSummaryCommentEnabled() {
+    return this.isSummaryCommentEnabled;
+  }
+
+  @CheckForNull
+  public Boolean isMonorepo() {
+    return this.isMonorepo;
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder("{");
+    addField(sb, "\"devOpsPlatformSettingUuid\": ", this.devOpsPlatformSettingUuid, true);
+    addField(sb, "\"key\": ", this.key, true);
+    addField(sb, "\"devOpsPlatformName\": ", this.devOpsPlatformName, true);
+    addField(sb, "\"url\": ", this.url, true);
+    addField(sb, "\"appId\": ", this.appId, true);
+    addField(sb, "\"clientId\": ", this.clientId, true);
+    addField(sb, "\"projectUuid\": ", this.projectUuid, true);
+    addField(sb, "\"projectName\": ", this.projectName, true);
+    addField(sb, "\"almRepo\": ", this.almRepo, true);
+    addField(sb, "\"almSlug\": ", this.almSlug, true);
+    addField(sb, "\"isSummaryCommentEnabled\": ", ObjectUtils.toString(this.isSummaryCommentEnabled), false);
+    addField(sb, "\"isMonorepo\": ", ObjectUtils.toString(this.isMonorepo), false);
+    endString(sb);
+    return sb.toString();
+  }
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/LicenseNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/LicenseNewValue.java
new file mode 100644 (file)
index 0000000..9445c53
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.audit.model;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+public class LicenseNewValue implements NewValue {
+  @Nullable
+  private String edition;
+
+  public LicenseNewValue(@Nullable String edition) {
+    this.edition = edition;
+  }
+
+  @CheckForNull
+  public String getEdition() {
+    return this.edition;
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder("{");
+    addField(sb, "\"edition\": ", this.edition, true);
+    endString(sb);
+    return sb.toString();
+  }
+}
index b46946cfc479e02dce2c17f9186f67fee98d4899..547acb31f7d9803a390730cf34a95524080545f8 100644 (file)
@@ -29,13 +29,21 @@ public interface NewValue {
       addQuote(sb, isString);
       sb.append(value);
       addQuote(sb, isString);
-      sb.append(",");
+      sb.append(", ");
     }
   }
 
+  default void endString(StringBuilder sb) {
+    int length = sb.length();
+    if(sb.length() > 1) {
+      sb.delete(length - 2, length - 1);
+    }
+    sb.append("}");
+  }
+
   private static void addQuote(StringBuilder sb, boolean isString) {
     if(isString) {
-      sb.append("'");
+      sb.append("\"");
     }
   }
 }
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PermissionNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PermissionNewValue.java
new file mode 100644 (file)
index 0000000..61e071e
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.audit.model;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.sonar.db.permission.GroupPermissionDto;
+import org.sonar.db.permission.UserPermissionDto;
+
+public class PermissionNewValue implements NewValue {
+  @Nullable
+  private String permissionUuid;
+
+  @Nullable
+  private String groupUuid;
+
+  @Nullable
+  private String userUuid;
+
+  @Nullable
+  private String projectUuid;
+
+  @Nullable
+  private String projectName;
+
+  @Nullable
+  private String role;
+
+  public PermissionNewValue(GroupPermissionDto groupPermissionDto, String projectName) {
+    this.permissionUuid = groupPermissionDto.getUuid();
+    this.groupUuid = groupPermissionDto.getGroupUuid();
+    this.projectUuid = groupPermissionDto.getComponentUuid();
+    this.role = groupPermissionDto.getRole();
+    this.projectName = projectName;
+  }
+
+  public PermissionNewValue(UserPermissionDto permissionDto, @Nullable String projectName) {
+    this.permissionUuid = permissionDto.getUuid();
+    this.userUuid = permissionDto.getUserUuid();
+    this.projectUuid = permissionDto.getComponentUuid();
+    this.role = permissionDto.getPermission();
+    this.projectName = projectName;
+  }
+
+  public  PermissionNewValue(@Nullable String role, @Nullable String groupUuid, @Nullable String rootComponentUuid,
+    @Nullable String projectName, @Nullable String userUuid) {
+    this.role = role;
+    this.groupUuid = groupUuid;
+    this.projectUuid = rootComponentUuid;
+    this.projectName = projectName;
+    this.userUuid = userUuid;
+  }
+
+  @CheckForNull
+  public String getPermissionUuid() {
+    return this.permissionUuid;
+  }
+
+  @CheckForNull
+  public String getGroupUuid() {
+    return this.groupUuid;
+  }
+
+  @CheckForNull
+  public String getProjectUuid() {
+    return this.projectUuid;
+  }
+
+  @CheckForNull
+  public String getRole() {
+    return this.role;
+  }
+
+  @CheckForNull
+  public String getProjectName() {
+    return this.projectName;
+  }
+
+  @CheckForNull
+  public String getUserUuid() {
+    return this.userUuid;
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder("{");
+    addField(sb, "\"permissionUuid\": ", this.permissionUuid, true);
+    addField(sb, "\"groupUuid\": ", this.groupUuid, true);
+    addField(sb, "\"projectUuid\": ", this.projectUuid, true);
+    addField(sb, "\"role\": ", this.role, true);
+    addField(sb, "\"projectName\": ", this.projectName, true);
+    addField(sb, "\"userUuid\": ", this.userUuid, true);
+    endString(sb);
+    return sb.toString();
+  }
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PermissionTemplateNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PermissionTemplateNewValue.java
new file mode 100644 (file)
index 0000000..1ca5679
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.audit.model;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.apache.commons.lang.ObjectUtils;
+import org.sonar.db.permission.template.PermissionTemplateDto;
+
+public class PermissionTemplateNewValue implements NewValue {
+  private String templateUuid;
+  private String name;
+
+  @Nullable
+  private String keyPattern;
+
+  @Nullable
+  private String description;
+
+  @Nullable
+  private String role;
+
+  @Nullable
+  private String userUuid;
+
+  @Nullable
+  private String userLogin;
+
+  @Nullable
+  private String groupUuid;
+
+  @Nullable
+  private String groupName;
+
+  @Nullable
+  private Boolean withProjectCreator;
+
+  public PermissionTemplateNewValue(String templateUuid, String name) {
+    this.templateUuid = templateUuid;
+    this.name = name;
+  }
+
+  public PermissionTemplateNewValue(PermissionTemplateDto permissionTemplateDto) {
+    this.templateUuid = permissionTemplateDto.getUuid();
+    this.name = permissionTemplateDto.getName();
+    this.keyPattern = permissionTemplateDto.getKeyPattern();
+    this.description = permissionTemplateDto.getDescription();
+  }
+
+  public PermissionTemplateNewValue(@Nullable String templateUuid, @Nullable String name, @Nullable String role,
+    @Nullable String userUuid, @Nullable String userLogin, @Nullable String groupUuid, @Nullable String groupName) {
+    this.templateUuid = templateUuid;
+    this.name = name;
+    this.role = role;
+    this.userUuid = userUuid;
+    this.userLogin = userLogin;
+    this.groupUuid = groupUuid;
+    this.groupName = groupName;
+  }
+
+  public PermissionTemplateNewValue(String templateUuid, String role, String name, boolean withProjectCreator) {
+    this.templateUuid = templateUuid;
+    this.name = name;
+    this.role = role;
+    this.withProjectCreator = withProjectCreator;
+  }
+
+  public String getTemplateUuid() {
+    return this.templateUuid;
+  }
+
+  public String getName() {
+    return this.name;
+  }
+
+  @CheckForNull
+  public String getKeyPattern() {
+    return this.keyPattern;
+  }
+
+  @CheckForNull
+  public String getDescription() {
+    return this.description;
+  }
+
+  @CheckForNull
+  public String getRole() {
+    return this.role;
+  }
+
+  @CheckForNull
+  public String getUserUuid() {
+    return this.userUuid;
+  }
+
+  @CheckForNull
+  public String getUserLogin() {
+    return this.userLogin;
+  }
+
+  @CheckForNull
+  public String getGroupUuid() {
+    return this.groupUuid;
+  }
+
+  @CheckForNull
+  public String getGroupName() {
+    return this.groupName;
+  }
+
+  @CheckForNull
+  public Boolean isWithProjectCreator() {
+    return this.withProjectCreator;
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder("{");
+    addField(sb, "\"templateUuid\": ", this.templateUuid, true);
+    addField(sb, "\"name\": ", this.name, true);
+    addField(sb, "\"keyPattern\": ", this.keyPattern, true);
+    addField(sb, "\"description\": ", this.description, true);
+    addField(sb, "\"role\": ", this.role, true);
+    addField(sb, "\"userUuid\": ", this.userUuid, true);
+    addField(sb, "\"userLogin\": ", this.userLogin, true);
+    addField(sb, "\"groupUuid\": ", this.groupUuid, true);
+    addField(sb, "\"groupName\": ", this.groupName, true);
+    addField(sb, "\"withProjectCreator\": ", ObjectUtils.toString(this.withProjectCreator), false);
+    endString(sb);
+    return sb.toString();
+  }
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PersonalAccessTokenNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PersonalAccessTokenNewValue.java
new file mode 100644 (file)
index 0000000..3f46932
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.audit.model;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.sonar.db.alm.pat.AlmPatDto;
+import org.sonar.db.alm.setting.AlmSettingDto;
+import org.sonar.db.user.UserDto;
+
+public class PersonalAccessTokenNewValue implements NewValue {
+  @Nullable
+  private String patUuid;
+
+  @Nullable
+  private String userUuid;
+
+  @Nullable
+  private String userLogin;
+
+  @Nullable
+  private String almSettingUuid;
+
+  @Nullable
+  private String almSettingKey;
+
+  public PersonalAccessTokenNewValue(AlmPatDto almPatDto, @Nullable String userLogin, @Nullable String almSettingKey) {
+    this.patUuid = almPatDto.getUuid();
+    this.userUuid = almPatDto.getUserUuid();
+    this.almSettingUuid = almPatDto.getAlmSettingUuid();
+    this.userLogin = userLogin;
+    this.almSettingKey = almSettingKey;
+  }
+
+  public PersonalAccessTokenNewValue(UserDto userDto) {
+    this.userUuid = userDto.getUuid();
+    this.userLogin = userDto.getLogin();
+  }
+
+  public PersonalAccessTokenNewValue(AlmSettingDto almSettingDto) {
+    this.almSettingUuid = almSettingDto.getUuid();
+    this.almSettingKey = almSettingDto.getKey();
+  }
+
+  @CheckForNull
+  public String getPatUuid() {
+    return this.patUuid;
+  }
+
+  @CheckForNull
+  public String getUserUuid() {
+    return this.userUuid;
+  }
+
+  @CheckForNull
+  public String getUserLogin() {
+    return this.userLogin;
+  }
+
+  @CheckForNull
+  public String getAlmSettingUuid() {
+    return this.almSettingUuid;
+  }
+
+  @CheckForNull
+  public String getAlmSettingKey() {
+    return this.almSettingKey;
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder("{");
+    addField(sb, "\"patUuid\": ", this.patUuid, true);
+    addField(sb, "\"userUuid\": ", this.userUuid, true);
+    addField(sb, "\"userLogin\": ", this.userLogin, true);
+    addField(sb, "\"almSettingUuid\": ", this.almSettingUuid, true);
+    addField(sb, "\"almSettingKey\": ", this.almSettingKey, true);
+    endString(sb);
+    return sb.toString();
+  }
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PluginNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PluginNewValue.java
new file mode 100644 (file)
index 0000000..3dfd947
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.audit.model;
+
+import org.sonar.db.plugin.PluginDto;
+
+public class PluginNewValue implements NewValue {
+  private String pluginUuid;
+  private String kee;
+  private String basePluginKey;
+  private String type;
+
+  public PluginNewValue(PluginDto pluginDto) {
+    this.pluginUuid = pluginDto.getUuid();
+    this.kee = pluginDto.getKee();
+    this.basePluginKey = pluginDto.getBasePluginKey();
+    this.type = pluginDto.getType().name();
+  }
+
+  public String getPluginUuid() {
+    return this.pluginUuid;
+  }
+
+  public String getKee() {
+    return this.kee;
+  }
+
+  public String getBasePluginKey() {
+    return this.basePluginKey;
+  }
+
+  public String getType() {
+    return this.type;
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder("{");
+    addField(sb, "\"pluginUuid\": ", this.pluginUuid, true);
+    addField(sb, "\"kee\": ", this.kee, true);
+    addField(sb, "\"basePluginKey\": ", this.basePluginKey, true);
+    addField(sb, "\"type\": ", this.type, true);
+    endString(sb);
+    return sb.toString();
+  }
+}
index 31d19b37e54ab3a89d38f7452d2812c3e9b5c69d..e3f371b7f5e93648a2588de5e47b5d228d3f7607 100644 (file)
  */
 package org.sonar.db.audit.model;
 
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.sonar.db.property.PropertyDto;
 import org.sonar.db.user.UserPropertyDto;
 
 public class PropertyNewValue implements NewValue {
+  @Nullable
   private String propertyKey;
+
+  @Nullable
   private String propertyValue;
+
+  @Nullable
   private String userUuid;
+
+  @Nullable
   private String userLogin;
 
+  @Nullable
+  private String projectUuid;
+
+  @Nullable
+  private String projectName;
+
   public PropertyNewValue(UserPropertyDto userPropertyDto, String login) {
     this.propertyKey = userPropertyDto.getKey();
     this.userUuid = userPropertyDto.getUserUuid();
     this.userLogin = login;
 
-    if(!propertyKey.contains(".secured")) {
-      this.propertyValue = userPropertyDto.getValue();
-    }
+    setValue(propertyKey, userPropertyDto.getValue());
+  }
+
+  public PropertyNewValue(PropertyDto propertyDto, @Nullable String userLogin, @Nullable String projectName) {
+    this.propertyKey = propertyDto.getKey();
+    this.userUuid = propertyDto.getUserUuid();
+    this.userLogin = userLogin;
+    this.projectUuid = propertyDto.getComponentUuid();
+    this.projectName = projectName;
+
+    setValue(propertyKey, propertyDto.getValue());
+  }
+
+  public PropertyNewValue(String propertyKey) {
+    this.propertyKey = propertyKey;
+  }
+
+  public PropertyNewValue(String propertyKey, @Nullable String userUuid, String userLogin) {
+    this.propertyKey = propertyKey;
+    this.userUuid = userUuid;
+    this.userLogin = userLogin;
+  }
+
+  public PropertyNewValue(String propertyKey, String propertyValue) {
+    this.propertyKey = propertyKey;
+
+    setValue(propertyKey, propertyValue);
+  }
+
+  public PropertyNewValue(@Nullable String propertyKey, @Nullable String projectUuid,
+    @Nullable String projectName, @Nullable String userUuid) {
+    this.propertyKey = propertyKey;
+    this.projectUuid = projectUuid;
+    this.projectName = projectName;
+    this.userUuid = userUuid;
   }
 
+  @CheckForNull
   public String getPropertyKey() {
     return this.propertyKey;
   }
 
+  @CheckForNull
   public String getPropertyValue() {
     return this.propertyValue;
   }
 
+  @CheckForNull
   public String getUserUuid() {
     return this.userUuid;
   }
 
+  @CheckForNull
   public String getUserLogin() {
     return this.userLogin;
   }
 
+  @CheckForNull
+  public String getProjectUuid() {
+    return this.projectUuid;
+  }
+
+  @CheckForNull
+  public String getProjectName() {
+    return this.projectName;
+  }
+
   @Override
   public String toString() {
     StringBuilder sb = new StringBuilder("{");
-    addField(sb, "'propertyKey':", this.propertyKey, true);
-    addField(sb, "'propertyValue':", this.propertyValue, true);
-    addField(sb, "'userUuid':", this.userUuid, true);
-    addField(sb, "'userLogin':", this.userLogin, true);
-    sb.append("}");
+    addField(sb, "\"propertyKey\": ", this.propertyKey, true);
+    addField(sb, "\"propertyValue\": ", this.propertyValue, true);
+    addField(sb, "\"userUuid\": ", this.userUuid, true);
+    addField(sb, "\"userLogin\": ", this.userLogin, true);
+    addField(sb, "\"projectUuid\": ", this.projectUuid, true);
+    addField(sb, "\"projectName\": ", this.projectName, true);
+    endString(sb);
     return sb.toString();
   }
 
+  private void setValue(String propertyKey, String value) {
+    if (!propertyKey.contains(".secured")) {
+      this.propertyValue = value;
+    }
+  }
 }
index f22892acbdfd6e3c36b50d1645ec14ea0cc68ca6..3e2bc548aa6d27823a2edeed1b4782781f7bd1f8 100644 (file)
  */
 package org.sonar.db.audit.model;
 
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.db.user.UserGroupDto;
 
 public class UserGroupNewValue implements NewValue {
+
+  @Nullable
   private String groupUuid;
+
+  @Nullable
   private String name;
+
+  @Nullable
   private String description;
+
+  @Nullable
   private String userUuid;
+
+  @Nullable
   private String userLogin;
 
   public UserGroupNewValue(String groupUuid, String name) {
@@ -60,22 +72,27 @@ public class UserGroupNewValue implements NewValue {
     this.userLogin = userLogin;
   }
 
+  @CheckForNull
   public String getGroupUuid() {
     return this.groupUuid;
   }
 
+  @CheckForNull
   public String getName() {
     return this.name;
   }
 
+  @CheckForNull
   public String getDescription() {
     return this.description;
   }
 
+  @CheckForNull
   public String getUserUuid() {
     return this.userUuid;
   }
 
+  @CheckForNull
   public String getUserLogin() {
     return this.userLogin;
   }
@@ -83,13 +100,12 @@ public class UserGroupNewValue implements NewValue {
   @Override
   public String toString() {
     StringBuilder sb = new StringBuilder("{");
-    addField(sb, "'groupUuid':", this.groupUuid, true);
-    addField(sb, "'name':", this.name, true);
-    addField(sb, "'description':", this.description, true);
-    addField(sb, "'userUuid':", this.userUuid, true);
-    addField(sb, "'userLogin':", this.userLogin, true);
-    sb.append("}");
+    addField(sb, "\"groupUuid\": ", this.groupUuid, true);
+    addField(sb, "\"name\": ", this.name, true);
+    addField(sb, "\"description\": ", this.description, true);
+    addField(sb, "\"userUuid\": ", this.userUuid, true);
+    addField(sb, "\"userLogin\": ", this.userLogin, true);
+    endString(sb);
     return sb.toString();
   }
-
 }
index 5d072fd8bb1da18acb0367b6b0f20373c6d75a0a..c14fad1e4bb2b9a3142fc4804c6e95d73ef4474e 100644 (file)
  */
 package org.sonar.db.audit.model;
 
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
 import org.apache.commons.lang.ObjectUtils;
 import org.sonar.db.user.UserDto;
 
 public class UserNewValue implements NewValue {
   private String userUuid;
   private String login;
+
+  @Nullable
   private String name;
+
+  @Nullable
   private String email;
+
+  @Nullable
   private Boolean isActive;
+
+  @Nullable
   private String scmAccounts;
+
+  @Nullable
   private String externalId;
+
+  @Nullable
   private String externalLogin;
+
+  @Nullable
   private String externalIdentityProvider;
+
+  @Nullable
   private Boolean local;
+
+  @Nullable
   private Boolean onboarded;
+
+  @Nullable
   private Boolean root;
+
+  @Nullable
   private Long lastConnectionDate;
 
   public UserNewValue(String userUuid, String userLogin) {
@@ -66,46 +90,57 @@ public class UserNewValue implements NewValue {
     return this.login;
   }
 
+  @CheckForNull
   public String getName() {
     return this.name;
   }
 
+  @CheckForNull
   public String getEmail() {
     return this.email;
   }
 
+  @CheckForNull
   public boolean isActive() {
     return this.isActive;
   }
 
+  @CheckForNull
   public String getScmAccounts() {
     return this.scmAccounts;
   }
 
+  @CheckForNull
   public String getExternalId() {
     return this.externalId;
   }
 
+  @CheckForNull
   public String getExternalLogin() {
     return this.externalLogin;
   }
 
+  @CheckForNull
   public String getExternalIdentityProvider() {
     return this.externalIdentityProvider;
   }
 
+  @CheckForNull
   public boolean isLocal() {
     return this.local;
   }
 
+  @CheckForNull
   public boolean isOnboarded() {
     return this.onboarded;
   }
 
+  @CheckForNull
   public boolean isRoot() {
     return this.root;
   }
 
+  @CheckForNull
   public Long getLastConnectionDate() {
     return this.lastConnectionDate;
   }
@@ -113,21 +148,20 @@ public class UserNewValue implements NewValue {
   @Override
   public String toString() {
     StringBuilder sb = new StringBuilder("{");
-    addField(sb, "'userUuid':", this.userUuid, true);
-    addField(sb, "'login':", this.login, true);
-    addField(sb, "'name':", this.name, true);
-    addField(sb, "'email':", this.email, true);
-    addField(sb, "'isActive':", ObjectUtils.toString(this.isActive), false);
-    addField(sb, "'scmAccounts':", this.scmAccounts, true);
-    addField(sb, "'externalId':", this.externalId, true);
-    addField(sb, "'externalLogin':", this.externalLogin, true);
-    addField(sb, "'externalIdentityProvider':", this.externalIdentityProvider, true);
-    addField(sb, "'local':", ObjectUtils.toString(this.local), false);
-    addField(sb, "'onboarded':", ObjectUtils.toString(this.onboarded), false);
-    addField(sb, "'root':", ObjectUtils.toString(this.root), false);
-    addField(sb, "'lastConnectionDate':", ObjectUtils.toString(this.lastConnectionDate), false);
-    sb.append("}");
+    addField(sb, "\"userUuid\": ", this.userUuid, true);
+    addField(sb, "\"login\": ", this.login, true);
+    addField(sb, "\"name\": ", this.name, true);
+    addField(sb, "\"email\": ", this.email, true);
+    addField(sb, "\"isActive\": ", ObjectUtils.toString(this.isActive), false);
+    addField(sb, "\"scmAccounts\": ", this.scmAccounts, true);
+    addField(sb, "\"externalId\": ", this.externalId, true);
+    addField(sb, "\"externalLogin\": ", this.externalLogin, true);
+    addField(sb, "\"externalIdentityProvider\": ", this.externalIdentityProvider, true);
+    addField(sb, "\"local\": ", ObjectUtils.toString(this.local), false);
+    addField(sb, "\"onboarded\": ", ObjectUtils.toString(this.onboarded), false);
+    addField(sb, "\"root\": ", ObjectUtils.toString(this.root), false);
+    addField(sb, "\"lastConnectionDate\": ", ObjectUtils.toString(this.lastConnectionDate), false);
+    endString(sb);
     return sb.toString();
   }
-
 }
index fd12379bdf348db7c88e4d0c3f89d5afac90d2ca..cb5c69ea438c47b0d80b52754e1721eefabc0a90 100644 (file)
  */
 package org.sonar.db.audit.model;
 
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
 import org.apache.commons.lang.ObjectUtils;
 import org.sonar.db.user.UserDto;
 import org.sonar.db.user.UserTokenDto;
 
 public class UserTokenNewValue implements NewValue {
+  @Nullable
   private String tokenUuid;
+
   private String userUuid;
+
+  @Nullable
   private String userLogin;
+
+  @Nullable
   private String tokenName;
+
+  @Nullable
   private Long lastConnectionDate;
 
   public UserTokenNewValue(UserTokenDto userTokenDto, @Nullable String userLogin) {
@@ -48,6 +58,7 @@ public class UserTokenNewValue implements NewValue {
     this.tokenName = tokenName;
   }
 
+  @CheckForNull
   public String getTokenUuid() {
     return this.tokenUuid;
   }
@@ -56,14 +67,17 @@ public class UserTokenNewValue implements NewValue {
     return this.userUuid;
   }
 
+  @CheckForNull
   public String getUserLogin() {
     return this.userLogin;
   }
 
+  @CheckForNull
   public String getTokenName() {
     return this.tokenName;
   }
 
+  @CheckForNull
   public Long getLastConnectionDate() {
     return this.lastConnectionDate;
   }
@@ -71,13 +85,12 @@ public class UserTokenNewValue implements NewValue {
   @Override
   public String toString() {
     StringBuilder sb = new StringBuilder("{");
-    addField(sb, "'tokenUuid':", this.tokenUuid, true);
-    addField(sb, "'userUuid':", this.userUuid, true);
-    addField(sb, "'userLogin':", this.userLogin, true);
-    addField(sb, "'tokenName':", this.tokenName, true);
-    addField(sb, "'lastConnectionDate':", ObjectUtils.toString(this.lastConnectionDate), false);
-    sb.append("}");
+    addField(sb, "\"tokenUuid\": ", this.tokenUuid, true);
+    addField(sb, "\"userUuid\": ", this.userUuid, true);
+    addField(sb, "\"userLogin\": ", this.userLogin, true);
+    addField(sb, "\"tokenName\": ", this.tokenName, true);
+    addField(sb, "\"lastConnectionDate\": ", ObjectUtils.toString(this.lastConnectionDate), false);
+    endString(sb);
     return sb.toString();
   }
-
 }
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/WebhookNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/WebhookNewValue.java
new file mode 100644 (file)
index 0000000..cdf2be4
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.audit.model;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.sonar.db.project.ProjectDto;
+import org.sonar.db.webhook.WebhookDto;
+
+public class WebhookNewValue implements NewValue {
+  @Nullable
+  private String webhookUuid;
+
+  @Nullable
+  private String name;
+
+  @Nullable
+  private String url;
+
+  @Nullable
+  private String projectUuid;
+
+  @Nullable
+  private String projectName;
+
+  public WebhookNewValue(WebhookDto dto, @Nullable String projectName) {
+    this.webhookUuid = dto.getUuid();
+    this.name = dto.getName();
+    this.url = dto.getUrl();
+    this.projectUuid = dto.getProjectUuid();
+    this.projectName = projectName;
+  }
+
+  public WebhookNewValue(String webhookUuid, String webhookName) {
+    this.webhookUuid = webhookUuid;
+    this.name = webhookName;
+  }
+
+  public WebhookNewValue(String webhookUuid, String webhookName, @Nullable String projectUuid, @Nullable String projectName) {
+    this(webhookUuid, webhookName);
+    this.projectUuid = projectUuid;
+    this.projectName = projectName;
+  }
+
+  public WebhookNewValue(ProjectDto projectDto) {
+    this.projectUuid = projectDto.getUuid();
+    this.projectName = projectDto.getName();
+  }
+
+  @CheckForNull
+  public String getWebhookUuid() {
+    return this.webhookUuid;
+  }
+
+  @CheckForNull
+  public String getName() {
+    return this.name;
+  }
+
+  @CheckForNull
+  public String getUrl() {
+    return this.url;
+  }
+
+  @CheckForNull
+  public String getProjectUuid() {
+    return this.projectUuid;
+  }
+
+  @CheckForNull
+  public String getProjectName() {
+    return this.projectName;
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder("{");
+    addField(sb, "\"webhookUuid\": ", this.webhookUuid, true);
+    addField(sb, "\"name\": ", this.name, true);
+    addField(sb, "\"url\": ", this.url, true);
+    addField(sb, "\"projectUuid\": ", this.projectUuid, true);
+    addField(sb, "\"projectName\": ", this.projectName, true);
+    endString(sb);
+    return sb.toString();
+  }
+}
index 17287fc4bdae793c306e7b3482081e3d7bcc12d0..3e1da592e150f735c24aee8a67afc008fb99f994 100644 (file)
@@ -29,6 +29,9 @@ import org.apache.ibatis.session.RowBounds;
 import org.sonar.api.security.DefaultGroups;
 import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PermissionNewValue;
+import org.sonar.db.component.ComponentDto;
 
 import static org.sonar.db.DatabaseUtils.executeLargeInputs;
 import static org.sonar.db.DatabaseUtils.executeLargeInputsWithoutOutput;
@@ -37,6 +40,15 @@ public class GroupPermissionDao implements Dao {
 
   private static final String ANYONE_GROUP_PARAMETER = "anyoneGroup";
 
+  private AuditPersister auditPersister;
+
+  public GroupPermissionDao() {
+  }
+
+  public GroupPermissionDao(AuditPersister auditPersister) {
+    this.auditPersister = auditPersister;
+  }
+
   /**
    * Returns the names of the groups that match the given query.
    * The virtual group "Anyone" may be returned as the value {@link DefaultGroups#ANYONE}.
@@ -110,30 +122,51 @@ public class GroupPermissionDao implements Dao {
     return mapper(session).selectGroupUuidsWithPermissionOnProjectBut(projectUuid, permission);
   }
 
-  public void insert(DbSession dbSession, GroupPermissionDto dto) {
+  public void insert(DbSession dbSession, GroupPermissionDto dto, @Nullable ComponentDto componentDto) {
     mapper(dbSession).insert(dto);
+
+    if (auditPersister != null) {
+      String projectName = (componentDto != null) ? componentDto.name() : null;
+      auditPersister.addGroupPermission(dbSession, new PermissionNewValue(dto, projectName));
+    }
   }
 
   /**
    * Delete all the permissions associated to a root component (project)
    */
-  public void deleteByRootComponentUuid(DbSession dbSession, String rootComponentUuid) {
+  public void deleteByRootComponentUuid(DbSession dbSession, String rootComponentUuid, String projectName) {
     mapper(dbSession).deleteByRootComponentUuid(rootComponentUuid);
+
+    if (auditPersister != null) {
+      auditPersister.deleteGroupPermission(dbSession, new PermissionNewValue(null, null, rootComponentUuid, projectName, null));
+    }
   }
 
   /**
    * Delete all permissions of the specified group (group "AnyOne" if {@code groupUuid} is {@code null}) for the specified
    * component.
    */
-  public int deleteByRootComponentUuidAndGroupUuid(DbSession dbSession, String rootComponentUuid, @Nullable String groupUuid) {
-    return mapper(dbSession).deleteByRootComponentUuidAndGroupUuid(rootComponentUuid, groupUuid);
+  public int deleteByRootComponentUuidAndGroupUuid(DbSession dbSession, String rootComponentUuid, @Nullable String groupUuid, String projectName) {
+    int deletedRecords =  mapper(dbSession).deleteByRootComponentUuidAndGroupUuid(rootComponentUuid, groupUuid);
+
+    if (auditPersister != null) {
+      auditPersister.deleteGroupPermission(dbSession, new PermissionNewValue(null, groupUuid, rootComponentUuid, projectName, null));
+    }
+
+    return deletedRecords;
   }
 
   /**
    * Delete the specified permission for the specified component for any group (including group AnyOne).
    */
-  public int deleteByRootComponentUuidAndPermission(DbSession dbSession, String rootComponentUuid, String permission) {
-    return mapper(dbSession).deleteByRootComponentUuidAndPermission(rootComponentUuid, permission);
+  public int deleteByRootComponentUuidAndPermission(DbSession dbSession, String rootComponentUuid, String permission, String projectName) {
+    int deletedRecords = mapper(dbSession).deleteByRootComponentUuidAndPermission(rootComponentUuid, permission);
+
+    if (auditPersister != null) {
+      auditPersister.deleteGroupPermission(dbSession, new PermissionNewValue(permission, null, rootComponentUuid, projectName, null));
+    }
+
+    return deletedRecords;
   }
 
   /**
@@ -149,8 +182,13 @@ public class GroupPermissionDao implements Dao {
    * @param groupUuid if null, then anyone, else uuid of group
    * @param rootComponentUuid if null, then global permission, otherwise the uuid of root component (project)
    */
-  public void delete(DbSession dbSession, String permission, @Nullable String groupUuid, @Nullable String rootComponentUuid) {
+  public void delete(DbSession dbSession, String permission, @Nullable String groupUuid, @Nullable String rootComponentUuid, @Nullable ComponentDto componentDto) {
     mapper(dbSession).delete(permission, groupUuid, rootComponentUuid);
+
+    if (auditPersister != null) {
+      String projectName = (componentDto != null) ? componentDto.name() : null;
+      auditPersister.deleteGroupPermission(dbSession, new PermissionNewValue(permission, groupUuid, rootComponentUuid, projectName, null));
+    }
   }
 
   private static GroupPermissionMapper mapper(DbSession session) {
index 77f42593ab95c9e4e10641a65813b5c5f0d8b94e..2c66213ac87e15337a5b0a90d1b644012fe776a2 100644 (file)
@@ -22,16 +22,28 @@ package org.sonar.db.permission;
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
+import javax.annotation.Nullable;
 import org.sonar.core.util.stream.MoreCollectors;
 import org.sonar.db.Dao;
 import org.sonar.db.DatabaseUtils;
 import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PermissionNewValue;
+import org.sonar.db.component.ComponentDto;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Collections.emptyList;
 import static org.sonar.db.DatabaseUtils.executeLargeInputs;
 
 public class UserPermissionDao implements Dao {
+  private AuditPersister auditPersister;
+
+  public UserPermissionDao() {
+  }
+
+  public UserPermissionDao(AuditPersister auditPersister) {
+    this.auditPersister = auditPersister;
+  }
 
   /**
    * List of user permissions ordered by alphabetical order of user names.
@@ -101,8 +113,13 @@ public class UserPermissionDao implements Dao {
     return mapper(session).selectUserUuidsWithPermissionOnProjectBut(projectUuid, permission);
   }
 
-  public void insert(DbSession dbSession, UserPermissionDto dto) {
+  public void insert(DbSession dbSession, UserPermissionDto dto, @Nullable ComponentDto componentDto) {
     mapper(dbSession).insert(dto);
+
+    if (auditPersister != null) {
+      String projectName = (componentDto != null) ? componentDto.name() : null;
+      auditPersister.addUserPermission(dbSession, new PermissionNewValue(dto, projectName));
+    }
   }
 
   /**
@@ -110,31 +127,54 @@ public class UserPermissionDao implements Dao {
    */
   public void deleteGlobalPermission(DbSession dbSession, String userUuid, String permission) {
     mapper(dbSession).deleteGlobalPermission(userUuid, permission);
+
+    if (auditPersister != null) {
+      auditPersister.deleteUserPermission(dbSession, new PermissionNewValue(permission, null, null,
+        null, userUuid));
+    }
   }
 
   /**
    * Removes a single project permission from user
    */
-  public void deleteProjectPermission(DbSession dbSession, String userUuid, String permission, String projectUuid) {
+  public void deleteProjectPermission(DbSession dbSession, String userUuid, String permission, String projectUuid, @Nullable String projectName) {
     mapper(dbSession).deleteProjectPermission(userUuid, permission, projectUuid);
+
+    if (auditPersister != null) {
+      auditPersister.deleteUserPermission(dbSession, new PermissionNewValue(permission, null, projectUuid, projectName, userUuid));
+    }
   }
 
   /**
    * Deletes all the permissions defined on a project
    */
-  public void deleteProjectPermissions(DbSession dbSession, String projectUuid) {
+  public void deleteProjectPermissions(DbSession dbSession, String projectUuid, String projectName) {
     mapper(dbSession).deleteProjectPermissions(projectUuid);
+
+    if (auditPersister != null) {
+      auditPersister.deleteUserPermission(dbSession, new PermissionNewValue(null, null, projectUuid, projectName, null));
+    }
   }
 
   /**
    * Deletes the specified permission on the specified project for any user.
    */
-  public int deleteProjectPermissionOfAnyUser(DbSession dbSession, String projectUuid, String permission) {
-    return mapper(dbSession).deleteProjectPermissionOfAnyUser(projectUuid, permission);
+  public int deleteProjectPermissionOfAnyUser(DbSession dbSession, String projectUuid, String permission, String projectName) {
+    int deletedRows = mapper(dbSession).deleteProjectPermissionOfAnyUser(projectUuid, permission);
+
+    if (auditPersister != null) {
+      auditPersister.deleteUserPermission(dbSession, new PermissionNewValue(permission, null, projectUuid, projectName, null));
+    }
+
+    return deletedRows;
   }
 
   public void deleteByUserUuid(DbSession dbSession, String userUuid) {
     mapper(dbSession).deleteByUserUuid(userUuid);
+
+    if (auditPersister != null) {
+      auditPersister.deleteUserPermission(dbSession, new PermissionNewValue(null, null, null, null, userUuid));
+    }
   }
 
   private static UserPermissionMapper mapper(DbSession dbSession) {
index be8b4f6636eaf1aae8d0bbcd6293b69d9351e449..ab4cede2f87622c0f9ce592c1cbe61b76294f6f0 100644 (file)
@@ -23,12 +23,22 @@ import java.util.List;
 import java.util.Optional;
 import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PermissionTemplateNewValue;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 import static org.sonar.db.DatabaseUtils.executeLargeInputs;
 
 public class PermissionTemplateCharacteristicDao implements Dao {
+  private AuditPersister auditPersister;
+
+  public PermissionTemplateCharacteristicDao() {
+  }
+
+  public PermissionTemplateCharacteristicDao(AuditPersister auditPersister) {
+    this.auditPersister = auditPersister;
+  }
 
   public List<PermissionTemplateCharacteristicDto> selectByTemplateUuids(DbSession dbSession, List<String> templateUuids) {
     return executeLargeInputs(templateUuids, partitionOfTemplateUuids -> mapper(dbSession).selectByTemplateUuids(partitionOfTemplateUuids));
@@ -39,15 +49,28 @@ public class PermissionTemplateCharacteristicDao implements Dao {
     return Optional.ofNullable(dto);
   }
 
-  public PermissionTemplateCharacteristicDto insert(DbSession dbSession, PermissionTemplateCharacteristicDto dto) {
+  public PermissionTemplateCharacteristicDto insert(DbSession dbSession, PermissionTemplateCharacteristicDto dto, String templateName) {
     checkArgument(dto.getCreatedAt() != 0L && dto.getUpdatedAt() != 0L);
     mapper(dbSession).insert(dto);
+
+    if (auditPersister != null) {
+      auditPersister.addCharacteristicToPermissionTemplate(dbSession, new PermissionTemplateNewValue(dto.getTemplateUuid(),
+        dto.getPermission(), templateName, dto.getWithProjectCreator()));
+    }
+
     return dto;
   }
 
-  public PermissionTemplateCharacteristicDto update(DbSession dbSession, PermissionTemplateCharacteristicDto templatePermissionDto) {
+  public PermissionTemplateCharacteristicDto update(DbSession dbSession, PermissionTemplateCharacteristicDto templatePermissionDto,
+    String templateName) {
     requireNonNull(templatePermissionDto.getUuid());
     mapper(dbSession).update(templatePermissionDto);
+
+    if (auditPersister != null) {
+      auditPersister.updateCharacteristicInPermissionTemplate(dbSession, new PermissionTemplateNewValue(templatePermissionDto.getTemplateUuid(),
+        templatePermissionDto.getPermission(), templateName, templatePermissionDto.getWithProjectCreator()));
+    }
+
     return templatePermissionDto;
   }
 
index e3b7f8d2c1723f910f18a87cc62823d5ab99fd06..8bf9c63f846919a9ab703af6e68f3d13b8420d29 100644 (file)
@@ -33,6 +33,8 @@ import org.sonar.api.utils.System2;
 import org.sonar.core.util.UuidFactory;
 import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PermissionTemplateNewValue;
 import org.sonar.db.permission.CountPerProjectPermission;
 import org.sonar.db.permission.PermissionQuery;
 
@@ -48,11 +50,18 @@ public class PermissionTemplateDao implements Dao {
   private final System2 system;
   private final UuidFactory uuidFactory;
 
+  private AuditPersister auditPersister;
+
   public PermissionTemplateDao(UuidFactory uuidFactory, System2 system) {
     this.uuidFactory = uuidFactory;
     this.system = system;
   }
 
+  public PermissionTemplateDao(UuidFactory uuidFactory, System2 system, AuditPersister auditPersister) {
+    this(uuidFactory, system);
+    this.auditPersister = auditPersister;
+  }
+
   /**
    * @return a paginated list of user logins.
    */
@@ -115,6 +124,11 @@ public class PermissionTemplateDao implements Dao {
       dto.setUuid(uuidFactory.create());
     }
     mapper(session).insert(dto);
+
+    if (auditPersister != null) {
+      auditPersister.addPermissionTemplate(session, new PermissionTemplateNewValue(dto.getUuid(), dto.getName()));
+    }
+
     return dto;
   }
 
@@ -151,20 +165,28 @@ public class PermissionTemplateDao implements Dao {
     return mapper(dbSession).selectAllGroupPermissionTemplatesByGroupUuid(groupUuid);
   }
 
-  public void deleteByUuid(DbSession session, String templateUuid) {
+  public void deleteByUuid(DbSession session, String templateUuid, String templateName) {
     PermissionTemplateMapper mapper = mapper(session);
     mapper.deleteUserPermissionsByTemplateUuid(templateUuid);
     mapper.deleteGroupPermissionsByTemplateUuid(templateUuid);
     session.getMapper(PermissionTemplateCharacteristicMapper.class).deleteByTemplateUuid(templateUuid);
     mapper.deleteByUuid(templateUuid);
+
+    if (auditPersister != null) {
+      auditPersister.deletePermissionTemplate(session, new PermissionTemplateNewValue(templateUuid, templateName));
+    }
   }
 
   public PermissionTemplateDto update(DbSession session, PermissionTemplateDto permissionTemplate) {
     mapper(session).update(permissionTemplate);
+    if (auditPersister != null) {
+      auditPersister.updatePermissionTemplate(session, new PermissionTemplateNewValue(permissionTemplate));
+    }
     return permissionTemplate;
   }
 
-  public void insertUserPermission(DbSession session, String templateUuid, String userUuid, String permission) {
+  public void insertUserPermission(DbSession session, String templateUuid, String userUuid, String permission,
+    String templateName, String userLogin) {
     PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto()
       .setUuid(uuidFactory.create())
       .setTemplateUuid(templateUuid)
@@ -174,23 +196,42 @@ public class PermissionTemplateDao implements Dao {
       .setUpdatedAt(now());
 
     mapper(session).insertUserPermission(permissionTemplateUser);
+
+    if (auditPersister != null) {
+      auditPersister.addUserToPermissionTemplate(session, new PermissionTemplateNewValue(templateUuid, templateName,
+        permission, userUuid, userLogin, null, null));
+    }
+
     session.commit();
   }
 
-  public void deleteUserPermission(DbSession session, String templateUuid, String userUuid, String permission) {
+  public void deleteUserPermission(DbSession session, String templateUuid, String userUuid, String permission,
+    String templateName, String userLogin) {
     PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto()
       .setTemplateUuid(templateUuid)
       .setPermission(permission)
       .setUserUuid(userUuid);
     mapper(session).deleteUserPermission(permissionTemplateUser);
+
+    if (auditPersister != null) {
+      auditPersister.deleteUserFromPermissionTemplate(session, new PermissionTemplateNewValue(templateUuid, templateName,
+        permission, userUuid, userLogin, null, null));
+    }
+
     session.commit();
   }
 
-  public void deleteUserPermissionsByUserUuid(DbSession dbSession, String userUuid) {
+  public void deleteUserPermissionsByUserUuid(DbSession dbSession, String userUuid, String userLogin) {
     mapper(dbSession).deleteUserPermissionsByUserUuid(userUuid);
+
+    if (auditPersister != null) {
+      auditPersister.deleteUserFromPermissionTemplate(dbSession, new PermissionTemplateNewValue(null, null,
+        null, userUuid, userLogin, null, null));
+    }
   }
 
-  public void insertGroupPermission(DbSession session, String templateUuid, @Nullable String groupUuid, String permission) {
+  public void insertGroupPermission(DbSession session, String templateUuid, @Nullable String groupUuid, String permission,
+    String templateName, @Nullable String groupName) {
     PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto()
       .setUuid(uuidFactory.create())
       .setTemplateUuid(templateUuid)
@@ -199,18 +240,35 @@ public class PermissionTemplateDao implements Dao {
       .setCreatedAt(now())
       .setUpdatedAt(now());
     mapper(session).insertGroupPermission(permissionTemplateGroup);
+
+    if (auditPersister != null) {
+      auditPersister.addGroupToPermissionTemplate(session, new PermissionTemplateNewValue(templateUuid, templateName,
+        permission, null, null, groupUuid, groupName));
+    }
   }
 
-  public void insertGroupPermission(DbSession session, PermissionTemplateGroupDto permissionTemplateGroup) {
+  public void insertGroupPermission(DbSession session, PermissionTemplateGroupDto permissionTemplateGroup, String templateName) {
     mapper(session).insertGroupPermission(permissionTemplateGroup);
+
+    if (auditPersister != null) {
+      auditPersister.addGroupToPermissionTemplate(session, new PermissionTemplateNewValue(permissionTemplateGroup.getTemplateUuid(), templateName,
+        permissionTemplateGroup.getPermission(), null, null, permissionTemplateGroup.getGroupUuid(), permissionTemplateGroup.getGroupName()));
+    }
   }
 
-  public void deleteGroupPermission(DbSession session, String templateUuid, @Nullable String groupUuid, String permission) {
+  public void deleteGroupPermission(DbSession session, String templateUuid, @Nullable String groupUuid, String permission, String templateName,
+    @Nullable String groupName) {
     PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto()
       .setTemplateUuid(templateUuid)
       .setPermission(permission)
       .setGroupUuid(groupUuid);
     mapper(session).deleteGroupPermission(permissionTemplateGroup);
+
+    if (auditPersister != null) {
+      auditPersister.deleteGroupFromPermissionTemplate(session, new PermissionTemplateNewValue(permissionTemplateGroup.getTemplateUuid(), templateName,
+        permissionTemplateGroup.getPermission(), null, null, permissionTemplateGroup.getGroupUuid(), groupName));
+    }
+
     session.commit();
   }
 
@@ -225,8 +283,13 @@ public class PermissionTemplateDao implements Dao {
   /**
    * Remove a group from all templates (used when removing a group)
    */
-  public void deleteByGroup(DbSession session, String groupUuid) {
+  public void deleteByGroup(DbSession session, String groupUuid, String groupName) {
     session.getMapper(PermissionTemplateMapper.class).deleteByGroupUuid(groupUuid);
+
+    if (auditPersister != null) {
+      auditPersister.deleteGroupFromPermissionTemplate(session, new PermissionTemplateNewValue(null, null,
+        null, null, null, groupUuid, groupName));
+    }
   }
 
   private Date now() {
index 5c684156f3da0fb5ee4db5cdb96a2f60f4a18984..821ef7c855d6cbe9b5ea2e900817686167960f70 100644 (file)
@@ -23,9 +23,21 @@ import java.util.List;
 import java.util.Optional;
 import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PluginNewValue;
 
 public class PluginDao implements Dao {
 
+  private AuditPersister auditPersister;
+
+  public PluginDao() {
+  }
+
+  public PluginDao(AuditPersister auditPersister) {
+    this.auditPersister = auditPersister;
+  }
+
+
   public List<PluginDto> selectAll(DbSession dbSession) {
     return mapper(dbSession).selectAll();
   }
@@ -36,10 +48,18 @@ public class PluginDao implements Dao {
 
   public void insert(DbSession dbSession, PluginDto dto) {
     mapper(dbSession).insert(dto);
+
+    if (auditPersister != null) {
+      auditPersister.addPlugin(dbSession, new PluginNewValue(dto));
+    }
   }
 
   public void update(DbSession dbSession, PluginDto dto) {
     mapper(dbSession).update(dto);
+
+    if (auditPersister != null) {
+      auditPersister.updatePlugin(dbSession, new PluginNewValue(dto));
+    }
   }
 
   private static PluginMapper mapper(DbSession dbSession) {
index ed59a6de59fe3aa0d83811f57c27eb93cddc5f32..f45ad0a9ad5f0182ae62d363b664805c7c2ae50c 100644 (file)
@@ -38,6 +38,8 @@ import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
 import org.sonar.db.EmailSubscriberDto;
 import org.sonar.db.MyBatis;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PropertyNewValue;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static org.apache.commons.lang.StringUtils.repeat;
@@ -52,7 +54,8 @@ public class PropertiesDao implements Dao {
 
   private final MyBatis mybatis;
   private final System2 system2;
-  private UuidFactory uuidFactory;
+  private final UuidFactory uuidFactory;
+  private AuditPersister auditPersister;
 
   public PropertiesDao(MyBatis mybatis, System2 system2, UuidFactory uuidFactory) {
     this.mybatis = mybatis;
@@ -60,6 +63,11 @@ public class PropertiesDao implements Dao {
     this.uuidFactory = uuidFactory;
   }
 
+  public PropertiesDao(MyBatis mybatis, System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
+    this(mybatis, system2, uuidFactory);
+    this.auditPersister = auditPersister;
+  }
+
   /**
    * Returns the logins of users who have subscribed to the given notification dispatcher with the given notification channel.
    * If a resource ID is passed, the search is made on users who have specifically subscribed for the given resource.
@@ -101,9 +109,9 @@ public class PropertiesDao implements Dao {
     }
 
     try (DbSession session = mybatis.openSession(false);
-      Connection connection = session.getConnection();
-      PreparedStatement pstmt = createStatement(projectUuid, dispatcherKeys, connection);
-      ResultSet rs = pstmt.executeQuery()) {
+         Connection connection = session.getConnection();
+         PreparedStatement pstmt = createStatement(projectUuid, dispatcherKeys, connection);
+         ResultSet rs = pstmt.executeQuery()) {
       return rs.next() && rs.getInt(1) > 0;
     } catch (SQLException e) {
       throw new IllegalStateException("Fail to execute SQL for hasProjectNotificationSubscribersForDispatchers", e);
@@ -202,8 +210,12 @@ public class PropertiesDao implements Dao {
    *
    * @throws IllegalArgumentException if {@link PropertyDto#getKey()} is {@code null} or empty
    */
-  public void saveProperty(DbSession session, PropertyDto property) {
+  public void saveProperty(DbSession session, PropertyDto property, @Nullable String userLogin, @Nullable String projectName) {
     save(getMapper(session), property.getKey(), property.getUserUuid(), property.getComponentUuid(), property.getValue());
+
+    if (auditPersister != null && auditPersister.isTrackedProperty(property.getKey())) {
+      auditPersister.addProperty(session, new PropertyNewValue(property, userLogin, projectName), false);
+    }
   }
 
   private void save(PropertiesMapper mapper, String key, @Nullable String userUuid, @Nullable String componentUuid, @Nullable String value) {
@@ -235,7 +247,7 @@ public class PropertiesDao implements Dao {
 
   public void saveProperty(PropertyDto property) {
     try (DbSession session = mybatis.openSession(false)) {
-      saveProperty(session, property);
+      saveProperty(session, property, null, null);
       session.commit();
     }
   }
@@ -248,26 +260,46 @@ public class PropertiesDao implements Dao {
    * Used by Governance.
    */
   public int deleteByQuery(DbSession dbSession, PropertyQuery query) {
-    return getMapper(dbSession).deleteByQuery(query);
+    int deletedRows = getMapper(dbSession).deleteByQuery(query);
+
+    if (auditPersister != null && query.key() != null && auditPersister.isTrackedProperty(query.key())) {
+      auditPersister.deleteProperty(dbSession, new PropertyNewValue(query.key(), query.componentUuid(),
+        null, query.userUuid()), false);
+    }
+
+    return deletedRows;
   }
 
-  public int delete(DbSession dbSession, PropertyDto dto) {
-    return getMapper(dbSession).delete(dto.getKey(), dto.getUserUuid(), dto.getComponentUuid());
+  public int delete(DbSession dbSession, PropertyDto dto, @Nullable String userLogin, @Nullable String projectName) {
+    int deletedRows = getMapper(dbSession).delete(dto.getKey(), dto.getUserUuid(), dto.getComponentUuid());
+
+    if (auditPersister != null && auditPersister.isTrackedProperty(dto.getKey())) {
+      auditPersister.deleteProperty(dbSession, new PropertyNewValue(dto, userLogin, projectName), false);
+    }
+    return deletedRows;
   }
 
-  public void deleteProjectProperty(String key, String projectUuid) {
+  public void deleteProjectProperty(String key, String projectUuid, String projectName) {
     try (DbSession session = mybatis.openSession(false)) {
-      deleteProjectProperty(key, projectUuid, session);
+      deleteProjectProperty(key, projectUuid, session, projectName);
       session.commit();
     }
   }
 
-  public void deleteProjectProperty(String key, String projectUuid, DbSession session) {
+  public void deleteProjectProperty(String key, String projectUuid, DbSession session, String projectName) {
     getMapper(session).deleteProjectProperty(key, projectUuid);
+
+    if (auditPersister != null && auditPersister.isTrackedProperty(key)) {
+      auditPersister.deleteProperty(session, new PropertyNewValue(key, projectUuid, projectName, null), false);
+    }
   }
 
   public void deleteProjectProperties(String key, String value, DbSession session) {
     getMapper(session).deleteProjectProperties(key, value);
+
+    if (auditPersister != null && auditPersister.isTrackedProperty(key)) {
+      auditPersister.deleteProperty(session, new PropertyNewValue(key, value), false);
+    }
   }
 
   public void deleteProjectProperties(String key, String value) {
@@ -279,6 +311,10 @@ public class PropertiesDao implements Dao {
 
   public void deleteGlobalProperty(String key, DbSession session) {
     getMapper(session).deleteGlobalProperty(key);
+
+    if (auditPersister != null && auditPersister.isTrackedProperty(key)) {
+      auditPersister.deleteProperty(session, new PropertyNewValue(key), false);
+    }
   }
 
   public void deleteGlobalProperty(String key) {
@@ -288,18 +324,28 @@ public class PropertiesDao implements Dao {
     }
   }
 
-  public void deleteByUser(DbSession dbSession, String userUuid) {
+  public void deleteByUser(DbSession dbSession, String userUuid, String userLogin) {
     List<String> uuids = getMapper(dbSession).selectUuidsByUser(userUuid);
+
+    persistDeletedProperties(dbSession, userUuid, userLogin, uuids);
+
     executeLargeInputsWithoutOutput(uuids, subList -> getMapper(dbSession).deleteByUuids(subList));
   }
 
   public void deleteByMatchingLogin(DbSession dbSession, String login, List<String> propertyKeys) {
     List<String> uuids = getMapper(dbSession).selectIdsByMatchingLogin(login, propertyKeys);
+
+    persistDeletedProperties(dbSession, null, login, uuids);
+
     executeLargeInputsWithoutOutput(uuids, list -> getMapper(dbSession).deleteByUuids(list));
   }
 
   public void deleteByKeyAndValue(DbSession dbSession, String key, String value) {
     getMapper(dbSession).deleteByKeyAndValue(key, value);
+
+    if (auditPersister != null && auditPersister.isTrackedProperty(key)) {
+      auditPersister.deleteProperty(dbSession, new PropertyNewValue(key, value), false);
+    }
   }
 
   public void saveGlobalProperties(Map<String, String> properties) {
@@ -308,6 +354,10 @@ public class PropertiesDao implements Dao {
       properties.forEach((key, value) -> {
         mapper.deleteGlobalProperty(key);
         save(mapper, key, null, null, value);
+
+        if (auditPersister != null && auditPersister.isTrackedProperty(key)) {
+          auditPersister.addProperty(session, new PropertyNewValue(key, value), false);
+        }
       });
       session.commit();
     }
@@ -329,4 +379,15 @@ public class PropertiesDao implements Dao {
     return session.getMapper(PropertiesMapper.class);
   }
 
+  private void persistDeletedProperties(DbSession dbSession, @Nullable String userUuid, String userLogin, List<String> uuids) {
+    if (auditPersister != null) {
+      List<PropertyDto> properties = executeLargeInputs(uuids, subList -> getMapper(dbSession).selectByUuids(subList));
+
+      properties
+        .stream()
+        .filter(p -> auditPersister.isTrackedProperty(p.getKey()))
+        .forEach(p -> auditPersister.deleteProperty(dbSession,
+          new PropertyNewValue(p.getKey(), userUuid, userLogin), false));
+    }
+  }
 }
index ba6e28ad7d1d5bec4782a1152f89c82eaaf9e569..b3ea7429be50fce1fbd8d99aa32023842563c41a 100644 (file)
@@ -77,6 +77,8 @@ public interface PropertiesMapper {
 
   void deleteByKeyAndValue(@Param("key") String key, @Param("value") String value);
 
+  List<PropertyDto> selectByUuids(@Param("uuids") List<String> uuids);
+
   int renamePropertyKey(@Param("oldKey") String oldKey, @Param("newKey") String newKey);
 
 }
index 5f1bc0a022d6e2a3d0a43313aaf3824c0dcd45f4..e42c92540d91936f2b588fdcbe53030371bbe287 100644 (file)
@@ -59,9 +59,9 @@ public class UserPropertiesDao implements Dao {
 
     if (auditPersister != null && auditPersister.isTrackedProperty(dto.getKey())) {
       if (isUpdate) {
-        auditPersister.updateUserProperty(session, new PropertyNewValue(dto, login));
+        auditPersister.updateProperty(session, new PropertyNewValue(dto, login), true);
       } else {
-        auditPersister.addUserProperty(session, new PropertyNewValue(dto, login));
+        auditPersister.addProperty(session, new PropertyNewValue(dto, login), true);
       }
     }
 
@@ -75,7 +75,7 @@ public class UserPropertiesDao implements Dao {
     if (auditPersister != null) {
       userProperties.stream()
         .filter(p -> auditPersister.isTrackedProperty(p.getKey()))
-        .forEach(p -> auditPersister.deleteUserProperty(session, new PropertyNewValue(p, user.getLogin())));
+        .forEach(p -> auditPersister.deleteProperty(session, new PropertyNewValue(p, user.getLogin()), true));
     }
   }
 
index 4baa61f2ce998e1312027d3b1f91b6f42b4f8856..246c3e89f9162f7a517a39a5dba05ab5c964a589 100644 (file)
@@ -21,19 +21,29 @@ package org.sonar.db.webhook;
 
 import java.util.List;
 import java.util.Optional;
+import javax.annotation.Nullable;
 import org.sonar.api.utils.System2;
 import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.WebhookNewValue;
 import org.sonar.db.project.ProjectDto;
 
 public class WebhookDao implements Dao {
 
   private final System2 system2;
+  private AuditPersister auditPersister;
+
 
   public WebhookDao(System2 system2) {
     this.system2 = system2;
   }
 
+  public WebhookDao(System2 system2, AuditPersister auditPersister) {
+    this.system2 = system2;
+    this.auditPersister = auditPersister;
+  }
+
   public List<WebhookDto> selectGlobalWebhooks(DbSession dbSession) {
     return mapper(dbSession).selectGlobalWebhooksOrderedByName();
   }
@@ -46,20 +56,37 @@ public class WebhookDao implements Dao {
     return mapper(dbSession).selectForProjectUuidOrderedByName(projectDto.getUuid());
   }
 
-  public void insert(DbSession dbSession, WebhookDto dto) {
+  public void insert(DbSession dbSession, WebhookDto dto, @Nullable String projectName) {
     mapper(dbSession).insert(dto.setCreatedAt(system2.now()).setUpdatedAt(system2.now()));
+
+    if (auditPersister != null) {
+      auditPersister.addWebhook(dbSession, new WebhookNewValue(dto.getUuid(), dto.getName(),
+        dto.getProjectUuid(), projectName));
+    }
   }
 
-  public void update(DbSession dbSession, WebhookDto dto) {
+  public void update(DbSession dbSession, WebhookDto dto, @Nullable String projectName) {
     mapper(dbSession).update(dto.setUpdatedAt(system2.now()));
+
+    if (auditPersister != null) {
+      auditPersister.updateWebhook(dbSession, new WebhookNewValue(dto, projectName));
+    }
   }
 
-  public void delete(DbSession dbSession, String uuid) {
+  public void delete(DbSession dbSession, String uuid, String webhookName) {
     mapper(dbSession).delete(uuid);
+
+    if (auditPersister != null) {
+      auditPersister.deleteWebhook(dbSession, new WebhookNewValue(uuid, webhookName));
+    }
   }
 
   public void deleteByProject(DbSession dbSession, ProjectDto projectDto) {
     mapper(dbSession).deleteForProjectUuid(projectDto.getUuid());
+
+    if (auditPersister != null) {
+      auditPersister.deleteWebhook(dbSession, new WebhookNewValue(projectDto));
+    }
   }
 
   private static WebhookMapper mapper(DbSession dbSession) {
index 7be56631a9fa1d46667e00057b4404aa590fde3c..40e2a56a55180e741e3d8a947e6b81185a7072a7 100644 (file)
     </foreach>
   </delete>
 
+  <select id="selectByUuids" parameterType="map" resultType="ScrapProperty">
+    select
+      <include refid="columnsToScrapPropertyDto"/>
+    from
+      properties p
+    where
+      uuid in
+    <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">
+      #{uuid}
+    </foreach>
+  </select>
+
   <update id="renamePropertyKey" parameterType="map">
     update properties set
       prop_key=#{newKey}
index a2f2267a9bd69cab989faedb049c1063c32c439a..f2d82930796dc5d88b86146fe07fcf70b5ce82cf 100644 (file)
@@ -104,7 +104,7 @@ CREATE TABLE "AUDITS"(
     "UUID" VARCHAR(40) NOT NULL,
     "USER_UUID" VARCHAR(40) NOT NULL,
     "USER_LOGIN" VARCHAR(255) NOT NULL,
-    "CATEGORY" VARCHAR(20) NOT NULL,
+    "CATEGORY" VARCHAR(25) NOT NULL,
     "OPERATION" VARCHAR(50) NOT NULL,
     "NEW_VALUE" VARCHAR(4000),
     "CREATED_AT" BIGINT NOT NULL
index 972f21623111d5c4a47e111812adc95bd025ca7f..5b4ac5b94e85764ea3e51562be347e67455ce7b7 100644 (file)
@@ -55,7 +55,7 @@ public class AlmPatDaoTest {
     when(uuidFactory.create()).thenReturn(A_UUID);
 
     AlmPatDto almPatDto = newAlmPatDto();
-    underTest.insert(dbSession, almPatDto);
+    underTest.insert(dbSession, almPatDto, null, null);
 
     assertThat(underTest.selectByUuid(dbSession, A_UUID).get())
       .extracting(AlmPatDto::getUuid, AlmPatDto::getPersonalAccessToken,
@@ -79,7 +79,7 @@ public class AlmPatDaoTest {
 
     String userUuid = randomAlphanumeric(40);
     almPatDto.setUserUuid(userUuid);
-    underTest.insert(dbSession, almPatDto);
+    underTest.insert(dbSession, almPatDto, null, null);
 
     assertThat(underTest.selectByUserAndAlmSetting(dbSession, userUuid, almSetting).get())
       .extracting(AlmPatDto::getUuid, AlmPatDto::getPersonalAccessToken,
@@ -95,13 +95,13 @@ public class AlmPatDaoTest {
   public void update() {
     when(uuidFactory.create()).thenReturn(A_UUID);
     AlmPatDto almPatDto = newAlmPatDto();
-    underTest.insert(dbSession, almPatDto);
+    underTest.insert(dbSession, almPatDto, null, null);
 
     String updated_pat = "updated pat";
     almPatDto.setPersonalAccessToken(updated_pat);
 
     system2.setNow(NOW + 1);
-    underTest.update(dbSession, almPatDto);
+    underTest.update(dbSession, almPatDto, null, null);
 
     AlmPatDto result = underTest.selectByUuid(dbSession, A_UUID).get();
     assertThat(result)
@@ -117,9 +117,9 @@ public class AlmPatDaoTest {
   public void delete() {
     when(uuidFactory.create()).thenReturn(A_UUID);
     AlmPatDto almPat = newAlmPatDto();
-    underTest.insert(dbSession, almPat);
+    underTest.insert(dbSession, almPat, null, null);
 
-    underTest.delete(dbSession, almPat);
+    underTest.delete(dbSession, almPat, null, null);
 
     assertThat(underTest.selectByUuid(dbSession, almPat.getUuid())).isNotPresent();
   }
@@ -130,7 +130,7 @@ public class AlmPatDaoTest {
     UserDto userDto = db.users().insertUser();
     AlmPatDto almPat = newAlmPatDto();
     almPat.setUserUuid(userDto.getUuid());
-    underTest.insert(dbSession, almPat);
+    underTest.insert(dbSession, almPat, userDto.getLogin(), null);
 
     underTest.deleteByUser(dbSession, userDto);
 
@@ -143,7 +143,7 @@ public class AlmPatDaoTest {
     AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
     AlmPatDto almPat = newAlmPatDto();
     almPat.setAlmSettingUuid(almSettingDto.getUuid());
-    underTest.insert(dbSession, almPat);
+    underTest.insert(dbSession, almPat, null, null);
 
     underTest.deleteByAlmSetting(dbSession, almSettingDto);
 
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/pat/AlmPatDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/pat/AlmPatDaoWithPersisterTest.java
new file mode 100644 (file)
index 0000000..db5c075
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.alm.pat;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.impl.utils.TestSystem2;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.alm.setting.AlmSettingDto;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PersonalAccessTokenNewValue;
+import org.sonar.db.user.UserDto;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto;
+
+public class AlmPatDaoWithPersisterTest {
+
+  private static final long NOW = 1000000L;
+  private static final String A_UUID = "SOME_UUID";
+  private final AuditPersister auditPersister = mock(AuditPersister.class);
+  private final ArgumentCaptor<PersonalAccessTokenNewValue> newValueCaptor = ArgumentCaptor.forClass(PersonalAccessTokenNewValue.class);
+  private TestSystem2 system2 = new TestSystem2().setNow(NOW);
+  @Rule
+  public DbTester db = DbTester.create(system2, auditPersister);
+
+  private DbSession dbSession = db.getSession();
+  private UuidFactory uuidFactory = mock(UuidFactory.class);
+
+  private AlmPatDao underTest = db.getDbClient().almPatDao();
+
+  @Test
+  public void insertAndUpdateArePersisted() {
+    when(uuidFactory.create()).thenReturn(A_UUID);
+
+    AlmPatDto almPatDto = newAlmPatDto();
+    underTest.insert(dbSession, almPatDto, "user-login", "alm-key");
+
+    verify(auditPersister).addPersonalAccessToken(eq(dbSession), newValueCaptor.capture());
+    PersonalAccessTokenNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PersonalAccessTokenNewValue::getPatUuid, PersonalAccessTokenNewValue::getUserUuid,
+        PersonalAccessTokenNewValue::getAlmSettingUuid, PersonalAccessTokenNewValue::getUserLogin,
+        PersonalAccessTokenNewValue::getAlmSettingKey)
+      .containsExactly(almPatDto.getUuid(), almPatDto.getUserUuid(), almPatDto.getAlmSettingUuid(),
+        "user-login", "alm-key");
+    assertThat(newValue.toString()).contains("userLogin");
+
+    String updated_pat = "updated pat";
+    almPatDto.setPersonalAccessToken(updated_pat);
+    system2.setNow(NOW + 1);
+    underTest.update(dbSession, almPatDto, null, null);
+
+    verify(auditPersister).updatePersonalAccessToken(eq(dbSession), newValueCaptor.capture());
+  }
+
+  @Test
+  public void deleteIsPersisted() {
+    when(uuidFactory.create()).thenReturn(A_UUID);
+
+    AlmPatDto almPat = newAlmPatDto();
+    underTest.insert(dbSession, almPat, null, null);
+    verify(auditPersister).addPersonalAccessToken(eq(dbSession), newValueCaptor.capture());
+
+    underTest.delete(dbSession, almPat, null, null);
+
+    verify(auditPersister).deletePersonalAccessToken(eq(dbSession), newValueCaptor.capture());
+    PersonalAccessTokenNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PersonalAccessTokenNewValue::getPatUuid, PersonalAccessTokenNewValue::getUserUuid,
+        PersonalAccessTokenNewValue::getAlmSettingUuid, PersonalAccessTokenNewValue::getUserLogin,
+        PersonalAccessTokenNewValue::getAlmSettingKey)
+      .containsExactly(almPat.getUuid(), almPat.getUserUuid(), almPat.getAlmSettingUuid(),
+        null, null);
+    assertThat(newValue.toString()).doesNotContain("userLogin");
+  }
+
+  @Test
+  public void deleteByUserIsPersisted() {
+    when(uuidFactory.create()).thenReturn(A_UUID);
+    UserDto userDto = db.users().insertUser();
+    AlmPatDto almPat = newAlmPatDto();
+    almPat.setUserUuid(userDto.getUuid());
+    underTest.insert(dbSession, almPat, userDto.getLogin(), null);
+    verify(auditPersister).addPersonalAccessToken(eq(dbSession), newValueCaptor.capture());
+
+    underTest.deleteByUser(dbSession, userDto);
+
+    verify(auditPersister).deletePersonalAccessToken(eq(dbSession), newValueCaptor.capture());
+    PersonalAccessTokenNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PersonalAccessTokenNewValue::getPatUuid, PersonalAccessTokenNewValue::getUserUuid,
+        PersonalAccessTokenNewValue::getUserLogin, PersonalAccessTokenNewValue::getAlmSettingKey)
+      .containsExactly(null, userDto.getUuid(), userDto.getLogin(), null);
+    assertThat(newValue.toString()).doesNotContain("patUuid");
+  }
+
+  @Test
+  public void deleteByAlmSettingIsPersisted() {
+    when(uuidFactory.create()).thenReturn(A_UUID);
+    AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
+    AlmPatDto almPat = newAlmPatDto();
+    almPat.setAlmSettingUuid(almSettingDto.getUuid());
+    underTest.insert(dbSession, almPat, null, almSettingDto.getKey());
+    verify(auditPersister).addPersonalAccessToken(eq(dbSession), newValueCaptor.capture());
+
+    underTest.deleteByAlmSetting(dbSession, almSettingDto);
+
+    verify(auditPersister).deletePersonalAccessToken(eq(dbSession), newValueCaptor.capture());
+    PersonalAccessTokenNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PersonalAccessTokenNewValue::getPatUuid, PersonalAccessTokenNewValue::getAlmSettingUuid,
+        PersonalAccessTokenNewValue::getAlmSettingKey)
+      .containsExactly(null, almPat.getAlmSettingUuid(), almSettingDto.getKey());
+    assertThat(newValue.toString()).doesNotContain("userUuid");
+  }
+
+}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/AlmSettingDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/AlmSettingDaoWithPersisterTest.java
new file mode 100644 (file)
index 0000000..fbde7b4
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.alm.setting;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.impl.utils.TestSystem2;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.DevOpsPlatformSettingNewValue;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.sonar.db.almsettings.AlmSettingsTesting.newGithubAlmSettingDto;
+
+public class AlmSettingDaoWithPersisterTest {
+
+  private static final long NOW = 1000000L;
+  private static final String A_UUID = "SOME_UUID";
+
+  private final ArgumentCaptor<DevOpsPlatformSettingNewValue> newValueCaptor = ArgumentCaptor.forClass(DevOpsPlatformSettingNewValue.class);
+  private final AuditPersister auditPersister = mock(AuditPersister.class);
+  private final TestSystem2 system2 = new TestSystem2().setNow(NOW);
+  @Rule
+  public final DbTester db = DbTester.create(system2, auditPersister);
+
+  private final DbSession dbSession = db.getSession();
+  private final UuidFactory uuidFactory = mock(UuidFactory.class);
+
+  private final AlmSettingDao underTest = db.getDbClient().almSettingDao();
+
+  @Test
+  public void insertAndUpdateArePersisted() {
+    when(uuidFactory.create()).thenReturn(A_UUID);
+    AlmSettingDto almSettingDto = newGithubAlmSettingDto();
+
+    underTest.insert(dbSession, almSettingDto);
+
+    verify(auditPersister).addDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture());
+    DevOpsPlatformSettingNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(DevOpsPlatformSettingNewValue::getDevOpsPlatformSettingUuid, DevOpsPlatformSettingNewValue::getKey)
+      .containsExactly(almSettingDto.getUuid(), almSettingDto.getKey());
+    assertThat(newValue.toString()).doesNotContain("url");
+
+    almSettingDto.setPrivateKey("updated private key");
+    almSettingDto.setAppId("updated app id");
+    almSettingDto.setUrl("updated url");
+    almSettingDto.setPersonalAccessToken("updated pat");
+    almSettingDto.setKey("updated key");
+    system2.setNow(NOW + 1);
+
+    underTest.update(dbSession, almSettingDto);
+
+    verify(auditPersister).updateDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture());
+    newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(DevOpsPlatformSettingNewValue::getDevOpsPlatformSettingUuid, DevOpsPlatformSettingNewValue::getKey,
+        DevOpsPlatformSettingNewValue::getAppId, DevOpsPlatformSettingNewValue::getDevOpsPlatformName,
+        DevOpsPlatformSettingNewValue::getUrl, DevOpsPlatformSettingNewValue::getClientId)
+      .containsExactly(almSettingDto.getUuid(), almSettingDto.getKey(), almSettingDto.getAppId(), almSettingDto.getAppId(),
+        almSettingDto.getUrl(), almSettingDto.getClientId());
+  }
+
+  @Test
+  public void deleteIsPersisted() {
+    when(uuidFactory.create()).thenReturn(A_UUID);
+    AlmSettingDto almSettingDto = newGithubAlmSettingDto();
+    underTest.insert(dbSession, almSettingDto);
+
+    underTest.delete(dbSession, almSettingDto);
+
+    verify(auditPersister).deleteDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture());
+    DevOpsPlatformSettingNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(DevOpsPlatformSettingNewValue::getDevOpsPlatformSettingUuid, DevOpsPlatformSettingNewValue::getKey)
+      .containsExactly(almSettingDto.getUuid(), almSettingDto.getKey());
+    assertThat(newValue.toString()).doesNotContain("url");
+  }
+}
index c62745d63dcde1a5669c71d19162213e47c0d114..1cab7cbd08cdf4f73cb07225fdd5ae414892c50c 100644 (file)
@@ -57,7 +57,7 @@ public class ProjectAlmSettingDaoTest {
     ProjectDto project = db.components().insertPrivateProjectDto();
     ProjectDto anotherProject = db.components().insertPrivateProjectDto();
     ProjectAlmSettingDto githubProjectAlmSettingDto = newGithubProjectAlmSettingDto(githubAlmSettingDto, project);
-    underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto);
+    underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto, githubAlmSettingDto.getKey(), anotherProject.getName());
 
     assertThat(underTest.selectByProject(dbSession, project).get())
       .extracting(ProjectAlmSettingDto::getUuid, ProjectAlmSettingDto::getAlmSettingUuid, ProjectAlmSettingDto::getProjectUuid,
@@ -78,11 +78,11 @@ public class ProjectAlmSettingDaoTest {
     ProjectDto project = db.components().insertPrivateProjectDto();
     ProjectAlmSettingDto bitbucketProjectAlmSettingDto = newBitbucketProjectAlmSettingDto(almSettingsDto, project);
     bitbucketProjectAlmSettingDto.setAlmSlug("slug1");
-    underTest.insertOrUpdate(dbSession, bitbucketProjectAlmSettingDto);
+    underTest.insertOrUpdate(dbSession, bitbucketProjectAlmSettingDto, almSettingsDto.getKey(), project.getName());
     ProjectAlmSettingDto bitbucketProjectAlmSettingDto2 = newBitbucketProjectAlmSettingDto(almSettingsDto, db.components().insertPrivateProjectDto());
     bitbucketProjectAlmSettingDto2.setAlmSlug("slug2");
     when(uuidFactory.create()).thenReturn(A_UUID + 1);
-    underTest.insertOrUpdate(dbSession, bitbucketProjectAlmSettingDto2);
+    underTest.insertOrUpdate(dbSession, bitbucketProjectAlmSettingDto2, almSettingsDto.getKey(), project.getName());
 
     Set<String> slugs = new HashSet<>();
     slugs.add("slug1");
@@ -106,11 +106,11 @@ public class ProjectAlmSettingDaoTest {
     ProjectDto project = db.components().insertPrivateProjectDto();
     ProjectAlmSettingDto githubProjectAlmSettingDto = newGithubProjectAlmSettingDto(almSettingsDto, project);
     githubProjectAlmSettingDto.setAlmRepo("repo1");
-    underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto);
+    underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto, almSettingsDto.getKey(), project.getName());
     ProjectAlmSettingDto githubProjectAlmSettingDto2 = newGithubProjectAlmSettingDto(almSettingsDto, db.components().insertPrivateProjectDto());
     githubProjectAlmSettingDto2.setAlmRepo("repo2");
     when(uuidFactory.create()).thenReturn(A_UUID + 1);
-    underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto2);
+    underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto2, almSettingsDto.getKey(), project.getName());
 
     Set<String> repos = new HashSet<>();
     repos.add("repo1");
@@ -138,7 +138,7 @@ public class ProjectAlmSettingDaoTest {
     system2.setNow(A_DATE_LATER);
     ProjectAlmSettingDto newProjectAlmSettingDto = newGithubProjectAlmSettingDto(anotherGithubAlmSetting, project)
       .setSummaryCommentEnabled(false);
-    underTest.insertOrUpdate(dbSession, newProjectAlmSettingDto);
+    underTest.insertOrUpdate(dbSession, newProjectAlmSettingDto, githubAlmSetting.getKey(), project.getName());
 
     assertThat(underTest.selectByProject(dbSession, project).get())
       .extracting(ProjectAlmSettingDto::getUuid, ProjectAlmSettingDto::getAlmSettingUuid, ProjectAlmSettingDto::getProjectUuid,
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoWithPersisterTest.java
new file mode 100644 (file)
index 0000000..5aa1978
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.alm.setting;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.impl.utils.TestSystem2;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.DevOpsPlatformSettingNewValue;
+import org.sonar.db.project.ProjectDto;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
+import static org.sonar.db.almsettings.AlmSettingsTesting.newGithubProjectAlmSettingDto;
+
+public class ProjectAlmSettingDaoWithPersisterTest {
+  private static final long A_DATE = 1_000_000_000_000L;
+  private static final long A_DATE_LATER = 1_700_000_000_000L;
+  private static final String A_UUID = "SOME_UUID";
+
+  private final ArgumentCaptor<DevOpsPlatformSettingNewValue> newValueCaptor = ArgumentCaptor.forClass(DevOpsPlatformSettingNewValue.class);
+  private final AuditPersister auditPersister = mock(AuditPersister.class);
+
+  private final TestSystem2 system2 = new TestSystem2().setNow(A_DATE);
+  @Rule
+  public final DbTester db = DbTester.create(system2, auditPersister);
+
+  private final DbSession dbSession = db.getSession();
+  private final UuidFactory uuidFactory = mock(UuidFactory.class);
+  private final ProjectAlmSettingDao underTest = db.getDbClient().projectAlmSettingDao();
+
+  @Test
+  public void insertAndUpdateExistingBindingArePersisted() {
+    when(uuidFactory.create()).thenReturn(A_UUID);
+    AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
+    ProjectDto project = db.components().insertPrivateProjectDto();
+    ProjectAlmSettingDto projectAlmSettingDto = newGithubProjectAlmSettingDto(githubAlmSetting, project)
+      .setSummaryCommentEnabled(false);
+    underTest.insertOrUpdate(dbSession, projectAlmSettingDto, githubAlmSetting.getKey(), project.getName());
+
+    verify(auditPersister).addDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture());
+    DevOpsPlatformSettingNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(DevOpsPlatformSettingNewValue::getDevOpsPlatformSettingUuid, DevOpsPlatformSettingNewValue::getKey,
+        DevOpsPlatformSettingNewValue::getProjectUuid, DevOpsPlatformSettingNewValue::getProjectName)
+      .containsExactly(githubAlmSetting.getUuid(), githubAlmSetting.getKey(), project.getUuid(), project.getName());
+    assertThat(newValue.toString()).doesNotContain("url");
+
+    AlmSettingDto anotherGithubAlmSetting = db.almSettings().insertGitHubAlmSetting();
+    system2.setNow(A_DATE_LATER);
+    ProjectAlmSettingDto newProjectAlmSettingDto = newGithubProjectAlmSettingDto(anotherGithubAlmSetting, project)
+      .setSummaryCommentEnabled(false);
+    underTest.insertOrUpdate(dbSession, newProjectAlmSettingDto, anotherGithubAlmSetting.getKey(), project.getName());
+
+    verify(auditPersister).updateDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture());
+    newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(DevOpsPlatformSettingNewValue::getDevOpsPlatformSettingUuid, DevOpsPlatformSettingNewValue::getKey,
+        DevOpsPlatformSettingNewValue::getProjectUuid, DevOpsPlatformSettingNewValue::getProjectName,
+        DevOpsPlatformSettingNewValue::getAlmRepo, DevOpsPlatformSettingNewValue::getAlmSlug,
+        DevOpsPlatformSettingNewValue::isSummaryCommentEnabled, DevOpsPlatformSettingNewValue::isMonorepo)
+      .containsExactly(anotherGithubAlmSetting.getUuid(), anotherGithubAlmSetting.getKey(), project.getUuid(), project.getName(),
+        newProjectAlmSettingDto.getAlmRepo(), newProjectAlmSettingDto.getAlmSlug(),
+        newProjectAlmSettingDto.getSummaryCommentEnabled(), newProjectAlmSettingDto.getMonorepo());
+    assertThat(newValue.toString()).doesNotContain("url");
+  }
+
+  @Test
+  public void deleteByProject() {
+    when(uuidFactory.create()).thenReturn(A_UUID);
+    AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
+    ProjectDto project = db.components().insertPrivateProjectDto();
+    ProjectAlmSettingDto projectAlmSettingDto = newGithubProjectAlmSettingDto(githubAlmSetting, project)
+      .setSummaryCommentEnabled(false);
+    underTest.insertOrUpdate(dbSession, projectAlmSettingDto, githubAlmSetting.getKey(), project.getName());
+    underTest.deleteByProject(dbSession, project);
+
+    verify(auditPersister).deleteDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture());
+    DevOpsPlatformSettingNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(DevOpsPlatformSettingNewValue::getProjectUuid, DevOpsPlatformSettingNewValue::getProjectName)
+      .containsExactly(project.getUuid(), project.getName());
+    assertThat(newValue.toString()).doesNotContain("devOpsPlatformSettingUuid");
+  }
+
+  @Test
+  public void deleteByAlmSettingWhenNotTracked() {
+    AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
+    underTest.deleteByAlmSetting(dbSession, githubAlmSetting);
+
+    verifyNoInteractions(auditPersister);
+  }
+
+  @Test
+  public void deleteByAlmSettingWhenTracked() {
+    AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
+    underTest.deleteByAlmSetting(dbSession, githubAlmSetting, true);
+
+    verify(auditPersister).deleteDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture());
+    DevOpsPlatformSettingNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(DevOpsPlatformSettingNewValue::getDevOpsPlatformSettingUuid, DevOpsPlatformSettingNewValue::getKey)
+      .containsExactly(githubAlmSetting.getUuid(), githubAlmSetting.getKey());
+    assertThat(newValue.toString()).doesNotContain("url");
+  }
+
+}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/LicenseNewValueTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/LicenseNewValueTest.java
new file mode 100644 (file)
index 0000000..eba4596
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.audit.model;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class LicenseNewValueTest {
+
+  @Test
+  public void toStringIsEmptyForNullEdition(){
+    LicenseNewValue newValue = new LicenseNewValue(null);
+    assertThat(newValue.toString()).isEqualTo("{}");
+  }
+
+  @Test
+  public void toStringHasEdition(){
+    LicenseNewValue newValue = new LicenseNewValue("Developer");
+    assertThat(newValue.toString()).contains("edition");
+  }
+}
index 83f288cb5ece3f3aef3aca1727247d73ae3baee5..9a4c0ef632e74c74c1fb7c262e4655037bd26cc8 100644 (file)
@@ -34,7 +34,6 @@ import org.sonar.core.util.stream.MoreCollectors;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.user.GroupDto;
 
 import static java.util.Arrays.asList;
@@ -562,7 +561,7 @@ public class GroupPermissionDaoTest {
     db.users().insertProjectPermissionOnGroup(group1, "perm2", project1);
     db.users().insertProjectPermissionOnGroup(group2, "perm3", project2);
 
-    underTest.deleteByRootComponentUuid(dbSession, project1.uuid());
+    underTest.deleteByRootComponentUuid(dbSession, project1.uuid(), project1.name());
     dbSession.commit();
 
     assertThat(db.countSql("select count(uuid) from group_roles where component_uuid='" + project1.uuid() + "'")).isZero();
@@ -581,7 +580,7 @@ public class GroupPermissionDaoTest {
     db.users().insertProjectPermissionOnAnyone("perm4", project1);
     db.users().insertProjectPermissionOnAnyone("perm5", project2);
 
-    underTest.deleteByRootComponentUuid(dbSession, project1.uuid());
+    underTest.deleteByRootComponentUuid(dbSession, project1.uuid(), project1.name());
     dbSession.commit();
 
     assertThat(db.countSql("select count(uuid) from group_roles where component_uuid='" + project1.uuid() + "'")).isZero();
@@ -597,7 +596,7 @@ public class GroupPermissionDaoTest {
     db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
     db.users().insertProjectPermissionOnAnyone("perm4", project1);
 
-    underTest.delete(dbSession, "perm2", group1.getUuid(), null);
+    underTest.delete(dbSession, "perm2", group1.getUuid(), null, project1);
     dbSession.commit();
 
     assertThatNoPermission("perm2");
@@ -612,7 +611,7 @@ public class GroupPermissionDaoTest {
     db.users().insertPermissionOnGroup(group1, "perm2");
     db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
 
-    underTest.delete(dbSession, "perm2", group1.getUuid(), null);
+    underTest.delete(dbSession, "perm2", group1.getUuid(), null, project1);
     dbSession.commit();
 
     assertThatNoPermission("perm2");
@@ -628,7 +627,7 @@ public class GroupPermissionDaoTest {
     db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
     db.users().insertProjectPermissionOnAnyone("perm4", project1);
 
-    underTest.delete(dbSession, "perm1", null, null);
+    underTest.delete(dbSession, "perm1", null, null, project1);
     dbSession.commit();
 
     assertThatNoPermission("perm1");
@@ -643,7 +642,7 @@ public class GroupPermissionDaoTest {
     db.users().insertPermissionOnGroup(group1, "perm2");
     db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
 
-    underTest.delete(dbSession, "perm3", group1.getUuid(), project1.uuid());
+    underTest.delete(dbSession, "perm3", group1.getUuid(), project1.uuid(), project1);
     dbSession.commit();
 
     assertThatNoPermission("perm3");
@@ -659,7 +658,7 @@ public class GroupPermissionDaoTest {
     db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
     db.users().insertProjectPermissionOnAnyone("perm4", project1);
 
-    underTest.delete(dbSession, "perm3", group1.getUuid(), project1.uuid());
+    underTest.delete(dbSession, "perm3", group1.getUuid(), project1.uuid(), project1);
     dbSession.commit();
 
     assertThatNoPermission("perm3");
@@ -675,7 +674,7 @@ public class GroupPermissionDaoTest {
     db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
     db.users().insertProjectPermissionOnAnyone("perm4", project1);
 
-    underTest.delete(dbSession, "perm4", null, project1.uuid());
+    underTest.delete(dbSession, "perm4", null, project1.uuid(), project1);
     dbSession.commit();
 
     assertThatNoPermission("perm4");
@@ -699,7 +698,7 @@ public class GroupPermissionDaoTest {
     assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, group.getUuid()))
       .containsOnly("p4");
 
-    int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), null);
+    int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), null, project.name());
 
     assertThat(deletedCount).isEqualTo(1);
     assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, null, project.uuid()))
@@ -737,7 +736,7 @@ public class GroupPermissionDaoTest {
     assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, group2.getUuid()))
       .containsOnly("p7");
 
-    int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group1.getUuid());
+    int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group1.getUuid(), project.name());
 
     assertThat(deletedCount).isEqualTo(1);
     assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, null, project.uuid()))
@@ -751,7 +750,7 @@ public class GroupPermissionDaoTest {
     assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, group2.getUuid()))
       .containsOnly("p7");
 
-    deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group2.getUuid());
+    deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group2.getUuid(), project.name());
 
     assertThat(deletedCount).isEqualTo(2);
     assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, null, project.uuid()))
@@ -770,8 +769,8 @@ public class GroupPermissionDaoTest {
   public void deleteByRootComponentUuidAndGroupUuid_has_no_effect_if_component_does_not_exist() {
     GroupDto group = db.users().insertGroup();
 
-    assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, "1234", null)).isZero();
-    assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, "1234", group.getUuid())).isZero();
+    assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, "1234", null, "")).isZero();
+    assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, "1234", group.getUuid(), "")).isZero();
   }
 
   @Test
@@ -779,15 +778,15 @@ public class GroupPermissionDaoTest {
     ComponentDto project = randomPublicOrPrivateProject();
     GroupDto group = db.users().insertGroup();
 
-    assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), null)).isZero();
-    assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group.getUuid())).isZero();
+    assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), null, project.name())).isZero();
+    assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group.getUuid(), project.name())).isZero();
   }
 
   @Test
   public void deleteByRootComponentUuidAndGroupUuid_has_no_effect_if_group_does_not_exist() {
     ComponentDto project = randomPublicOrPrivateProject();
 
-    assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), "5678")).isZero();
+    assertThat(underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), "5678", project.name())).isZero();
   }
 
   @Test
@@ -802,7 +801,7 @@ public class GroupPermissionDaoTest {
     db.users().insertPermissionOnAnyone("p2");
     db.users().insertPermissionOnGroup(group1, "p3");
 
-    int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), null);
+    int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), null, project.name());
 
     assertThat(deletedCount).isZero();
     assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, null, project.uuid()))
@@ -824,7 +823,7 @@ public class GroupPermissionDaoTest {
     db.users().insertPermissionOnAnyone("p2");
     db.users().insertPermissionOnGroup(group1, "p3");
 
-    int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group2.getUuid());
+    int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group2.getUuid(), project.name());
 
     assertThat(deletedCount).isZero();
     assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, group1.getUuid(), project.uuid()))
@@ -852,7 +851,7 @@ public class GroupPermissionDaoTest {
     assertThat(getProjectPermissionsForAnyOne(project)).containsOnly("p1", "p2");
     assertThat(getProjectPermissionsForGroup(project, group)).containsOnly("p1", "p2");
 
-    int deletedRows = underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p1");
+    int deletedRows = underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p1", project.name());
 
     assertThat(deletedRows).isEqualTo(2);
     assertThat(getGlobalPermissionsForAnyone()).containsOnly("p1", "p2");
@@ -860,7 +859,7 @@ public class GroupPermissionDaoTest {
     assertThat(getProjectPermissionsForAnyOne(project)).containsOnly("p2");
     assertThat(getProjectPermissionsForGroup(project, group)).containsOnly("p2");
 
-    deletedRows = underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p2");
+    deletedRows = underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p2", project.name());
 
     assertThat(deletedRows).isEqualTo(2);
     assertThat(getGlobalPermissionsForAnyone()).containsOnly("p1", "p2");
@@ -876,7 +875,7 @@ public class GroupPermissionDaoTest {
     db.users().insertPermissionOnAnyone("p1");
     db.users().insertPermissionOnGroup(group, "p1");
 
-    assertThat(underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p1")).isZero();
+    assertThat(underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p1", project.name())).isZero();
 
     assertThat(getGlobalPermissionsForAnyone()).containsOnly("p1");
     assertThat(getGlobalPermissionsForGroup(group)).containsOnly("p1");
@@ -893,7 +892,7 @@ public class GroupPermissionDaoTest {
     db.users().insertProjectPermissionOnGroup(group, "p1", project);
     db.users().insertProjectPermissionOnAnyone("p1", project);
 
-    assertThat(underTest.deleteByRootComponentUuidAndPermission(dbSession, "1324", "p1")).isZero();
+    assertThat(underTest.deleteByRootComponentUuidAndPermission(dbSession, "1324", "p1", "")).isZero();
 
     assertThat(getGlobalPermissionsForAnyone()).containsOnly("p1");
     assertThat(getGlobalPermissionsForGroup(group)).containsOnly("p1");
@@ -908,7 +907,7 @@ public class GroupPermissionDaoTest {
     db.users().insertPermissionOnAnyone("p1");
     db.users().insertPermissionOnGroup(group, "p1");
 
-    assertThat(underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p1")).isZero();
+    assertThat(underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), "p1", project.name())).isZero();
   }
 
   private Collection<String> getGlobalPermissionsForAnyone() {
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
new file mode 100644 (file)
index 0000000..a46e9c9
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.permission;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.utils.System2;
+import org.sonar.core.util.Uuids;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PermissionNewValue;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.user.GroupDto;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.sonar.api.web.UserRole.ADMIN;
+
+public class GroupPermissionDaoWithPersisterTest {
+  private final AuditPersister auditPersister = mock(AuditPersister.class);
+
+  @Rule
+  public DbTester db = DbTester.create(System2.INSTANCE, auditPersister);
+
+  private final ArgumentCaptor<PermissionNewValue> newValueCaptor = ArgumentCaptor.forClass(PermissionNewValue.class);
+  private final DbSession dbSession = db.getSession();
+  private final GroupPermissionDao underTest = db.getDbClient().groupPermissionDao();
+
+  @Test
+  public void groupGlobalPermissionInsertAndDeleteArePersisted() {
+    GroupDto group = db.users().insertGroup();
+    GroupPermissionDto dto = new GroupPermissionDto()
+      .setUuid(Uuids.createFast())
+      .setGroupUuid(group.getUuid())
+      .setRole(ADMIN);
+    underTest.insert(dbSession, dto, null);
+
+    verify(auditPersister).addGroupPermission(eq(dbSession), newValueCaptor.capture());
+    PermissionNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getGroupUuid, PermissionNewValue::getProjectUuid,
+        PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+      .containsExactly(dto.getUuid(), group.getUuid(), null, dto.getRole(), null);
+    assertThat(newValue.toString()).doesNotContain("projectUuid");
+
+    underTest.delete(dbSession, ADMIN, group.getUuid(), null, null);
+
+    verify(auditPersister).deleteGroupPermission(eq(dbSession), newValueCaptor.capture());
+    newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getGroupUuid, PermissionNewValue::getProjectUuid,
+        PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+      .containsExactly(null, group.getUuid(), null, ADMIN, null);
+    assertThat(newValue.toString()).doesNotContain("permissionUuid");
+  }
+
+  @Test
+  public void groupProjectPermissionDeleteByComponentIsPersisted() {
+    GroupDto group = db.users().insertGroup();
+    ComponentDto project = db.components().insertPrivateProject();
+    GroupPermissionDto dto = getGroupPermission(group, project);
+    underTest.insert(dbSession, dto, project);
+
+    verify(auditPersister).addGroupPermission(eq(dbSession), newValueCaptor.capture());
+    PermissionNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getGroupUuid, PermissionNewValue::getProjectUuid,
+        PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+      .containsExactly(dto.getUuid(), group.getUuid(), project.uuid(), dto.getRole(), project.name());
+    assertThat(newValue.toString()).contains("projectUuid");
+
+    underTest.deleteByRootComponentUuid(dbSession, project.uuid(), project.name());
+
+    verify(auditPersister).deleteGroupPermission(eq(dbSession), newValueCaptor.capture());
+    newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getGroupUuid, PermissionNewValue::getProjectUuid,
+        PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+      .containsExactly(null, null, project.uuid(), null, project.name());
+    assertThat(newValue.toString()).doesNotContain("permissionUuid");
+  }
+
+  @Test
+  public void groupProjectPermissionDeleteByComponentAndGroupIsPersisted() {
+    GroupDto group = db.users().insertGroup();
+    ComponentDto project = db.components().insertPrivateProject();
+    GroupPermissionDto dto = getGroupPermission(group, project);
+    underTest.insert(dbSession, dto, project);
+
+    verify(auditPersister).addGroupPermission(eq(dbSession), newValueCaptor.capture());
+    PermissionNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getGroupUuid, PermissionNewValue::getProjectUuid,
+        PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+      .containsExactly(dto.getUuid(), group.getUuid(), project.uuid(), dto.getRole(), project.name());
+    assertThat(newValue.toString()).contains("projectUuid");
+
+    underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, project.uuid(), group.getUuid(), project.name());
+
+    verify(auditPersister).deleteGroupPermission(eq(dbSession), newValueCaptor.capture());
+    newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getGroupUuid, PermissionNewValue::getProjectUuid,
+        PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+      .containsExactly(null, group.getUuid(), project.uuid(), null, project.name());
+    assertThat(newValue.toString()).doesNotContain("permissionUuid");
+  }
+
+  @Test
+  public void groupProjectPermissionDeleteByComponentAndPermissionIsPersisted() {
+    GroupDto group = db.users().insertGroup();
+    ComponentDto project = db.components().insertPrivateProject();
+    GroupPermissionDto dto = getGroupPermission(group, project);
+    underTest.insert(dbSession, dto, project);
+
+    verify(auditPersister).addGroupPermission(eq(dbSession), newValueCaptor.capture());
+    PermissionNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getGroupUuid, PermissionNewValue::getProjectUuid,
+        PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+      .containsExactly(dto.getUuid(), group.getUuid(), project.uuid(), dto.getRole(), project.name());
+    assertThat(newValue.toString()).contains("projectUuid");
+
+    underTest.deleteByRootComponentUuidAndPermission(dbSession, project.uuid(), dto.getRole(), project.name());
+
+    verify(auditPersister).deleteGroupPermission(eq(dbSession), newValueCaptor.capture());
+    newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getGroupUuid, PermissionNewValue::getProjectUuid,
+        PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+      .containsExactly(null, null, project.uuid(), ADMIN, project.name());
+    assertThat(newValue.toString()).doesNotContain("permissionUuid");
+  }
+
+  private GroupPermissionDto getGroupPermission(GroupDto group, ComponentDto project) {
+    return new GroupPermissionDto()
+      .setUuid(Uuids.createFast())
+      .setGroupUuid(group.getUuid())
+      .setRole(ADMIN)
+      .setComponentUuid(project.uuid());
+  }
+}
index 236d26bb5f4e7df46e69264e874a2de5d4e76326..eec32dd69f6802cfdbb7dd9c0b53923ede60edf7 100644 (file)
@@ -397,10 +397,10 @@ public class UserPermissionDaoTest {
     addProjectPermission("perm", user2, project1);
 
     // no such provision -> ignore
-    underTest.deleteProjectPermission(dbSession, user1.getUuid(), "anotherPerm", project1.uuid());
+    underTest.deleteProjectPermission(dbSession, user1.getUuid(), "anotherPerm", project1.uuid(), project1.name());
     assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(4);
 
-    underTest.deleteProjectPermission(dbSession, user1.getUuid(), "perm", project1.uuid());
+    underTest.deleteProjectPermission(dbSession, user1.getUuid(), "perm", project1.uuid(), project1.name());
     assertThatProjectPermissionDoesNotExist(user1, "perm", project1);
     assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(3);
   }
@@ -416,7 +416,7 @@ public class UserPermissionDaoTest {
     addProjectPermission("perm", user2, project1);
     addProjectPermission("perm", user1, project2);
 
-    underTest.deleteProjectPermissions(dbSession, project1.uuid());
+    underTest.deleteProjectPermissions(dbSession, project1.uuid(), project1.name());
     assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(2);
     assertThatProjectHasNoPermissions(project1);
   }
@@ -521,7 +521,7 @@ public class UserPermissionDaoTest {
     UserDto user = insertUser();
     db.users().insertPermissionOnUser(user, SCAN);
 
-    int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, "124", SCAN.getKey());
+    int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, "124", SCAN.getKey(), "");
 
     assertThat(deletedCount).isZero();
     assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getUuid())).containsOnly(SCAN.getKey());
@@ -533,7 +533,7 @@ public class UserPermissionDaoTest {
     db.users().insertPermissionOnUser(user, SCAN);
     ComponentDto project = randomPublicOrPrivateProject();
 
-    int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project.uuid(), SCAN.getKey());
+    int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project.uuid(), SCAN.getKey(), "");
 
     assertThat(deletedCount).isZero();
     assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getUuid())).containsOnly(SCAN.getKey());
@@ -546,7 +546,7 @@ public class UserPermissionDaoTest {
     ComponentDto project = randomPublicOrPrivateProject();
     db.users().insertProjectPermissionOnUser(user, SCAN.getKey(), project);
 
-    int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project.uuid(), "p1");
+    int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project.uuid(), "p1", project.name());
 
     assertThat(deletedCount).isZero();
     assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getUuid())).containsOnly(SCAN.getKey());
@@ -567,7 +567,7 @@ public class UserPermissionDaoTest {
     db.users().insertProjectPermissionOnUser(user2, SCAN.getKey(), project2);
     db.users().insertProjectPermissionOnUser(user2, PROVISION_PROJECTS.getKey(), project2);
 
-    int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project1.uuid(), SCAN.getKey());
+    int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project1.uuid(), SCAN.getKey(), project1.name());
 
     assertThat(deletedCount).isEqualTo(2);
     assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user1.getUuid())).containsOnly(SCAN.getKey());
@@ -577,7 +577,7 @@ public class UserPermissionDaoTest {
     assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user1.getUuid(), project2.uuid())).containsOnly(SCAN.getKey());
     assertThat(underTest.selectProjectPermissionsOfUser(dbSession, user2.getUuid(), project2.uuid())).containsOnly(SCAN.getKey(), PROVISION_PROJECTS.getKey());
 
-    deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project2.uuid(), SCAN.getKey());
+    deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, project2.uuid(), SCAN.getKey(), project2.name());
 
     assertThat(deletedCount).isEqualTo(2);
     assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user1.getUuid())).containsOnly(SCAN.getKey());
@@ -632,14 +632,14 @@ public class UserPermissionDaoTest {
 
   private UserPermissionDto addGlobalPermission(String permission, UserDto user) {
     UserPermissionDto dto = new UserPermissionDto(Uuids.create(), permission, user.getUuid(), null);
-    underTest.insert(dbSession, dto);
+    underTest.insert(dbSession, dto, null);
     db.commit();
     return dto;
   }
 
   private UserPermissionDto addProjectPermission(String permission, UserDto user, ComponentDto project) {
     UserPermissionDto dto = new UserPermissionDto(Uuids.create(), permission, user.getUuid(), project.uuid());
-    underTest.insert(dbSession, dto);
+    underTest.insert(dbSession, dto, project);
     db.commit();
     return dto;
   }
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
new file mode 100644 (file)
index 0000000..b0c37ac
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.permission;
+
+import java.util.function.Consumer;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.utils.System2;
+import org.sonar.core.util.Uuids;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PermissionNewValue;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.user.UserDto;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
+import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
+
+public class UserPermissionDaoWithPersisterTest {
+  private final AuditPersister auditPersister = mock(AuditPersister.class);
+
+  @Rule
+  public final DbTester db = DbTester.create(System2.INSTANCE, auditPersister);
+
+  private final ArgumentCaptor<PermissionNewValue> newValueCaptor = ArgumentCaptor.forClass(PermissionNewValue.class);
+  private final DbSession dbSession = db.getSession();
+  private final UserPermissionDao underTest = db.getDbClient().userPermissionDao();
+
+  @Test
+  public void userGlobalPermissionInsertAndDeleteArePersisted() {
+    UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
+    UserPermissionDto dto = new UserPermissionDto(Uuids.create(), SYSTEM_ADMIN, user.getUuid(), null);
+    underTest.insert(dbSession, dto, null);
+
+    verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture());
+    PermissionNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getUserUuid, PermissionNewValue::getProjectUuid,
+        PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+      .containsExactly(dto.getUuid(), user.getUuid(), null, dto.getPermission(), null);
+    assertThat(newValue.toString()).doesNotContain("projectUuid");
+
+    underTest.deleteGlobalPermission(dbSession, user.getUuid(), SYSTEM_ADMIN);
+
+    verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture());
+    newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getUserUuid, PermissionNewValue::getProjectUuid,
+        PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+      .containsExactly(null, user.getUuid(), null, dto.getPermission(), null);
+    assertThat(newValue.toString()).doesNotContain("permissionUuid");
+  }
+
+  @Test
+  public void userProjectPermissionInsertAndDeleteArePersisted() {
+    UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
+    ComponentDto project = db.components().insertPrivateProject();
+    UserPermissionDto dto = new UserPermissionDto(Uuids.create(), SYSTEM_ADMIN, user.getUuid(), project.uuid());
+    underTest.insert(dbSession, dto, project);
+
+    verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture());
+    PermissionNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getUserUuid, PermissionNewValue::getProjectUuid,
+        PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+      .containsExactly(dto.getUuid(), user.getUuid(), project.uuid(), dto.getPermission(), project.name());
+    assertThat(newValue.toString()).contains("projectUuid");
+
+    underTest.deleteProjectPermission(dbSession, user.getUuid(), SYSTEM_ADMIN, project.projectUuid(), project.name());
+
+    verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture());
+    newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getUserUuid, PermissionNewValue::getProjectUuid,
+        PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+      .containsExactly(null, user.getUuid(), project.uuid(), dto.getPermission(), project.name());
+    assertThat(newValue.toString()).doesNotContain("permissionUuid");
+  }
+
+  @Test
+  public void deleteUserPermissionOfAnyUserIsPersisted() {
+    UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
+    ComponentDto project = db.components().insertPrivateProject();
+    UserPermissionDto dto = new UserPermissionDto(Uuids.create(), SCAN_EXECUTION, user.getUuid(), project.uuid());
+    underTest.insert(dbSession, dto, project);
+    underTest.deleteProjectPermissionOfAnyUser(dbSession, project.projectUuid(), SCAN_EXECUTION, project.name());
+
+    verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture());
+    PermissionNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getUserUuid, PermissionNewValue::getProjectUuid,
+        PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+      .containsExactly(null, null, project.uuid(), SCAN_EXECUTION, project.name());
+    assertThat(newValue.toString()).doesNotContain("userUuid");
+  }
+
+  @Test
+  public void deleteUserPermissionByUserUuidIsPersisted() {
+    UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
+    ComponentDto project = db.components().insertPrivateProject();
+    UserPermissionDto dto = new UserPermissionDto(Uuids.create(), SYSTEM_ADMIN, user.getUuid(), project.uuid());
+    underTest.insert(dbSession, dto, project);
+    underTest.deleteByUserUuid(dbSession, user.getUuid());
+
+    verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture());
+    PermissionNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getUserUuid, PermissionNewValue::getProjectUuid,
+        PermissionNewValue::getRole, PermissionNewValue::getProjectName)
+      .containsExactly(null, user.getUuid(), null, null, null);
+    assertThat(newValue.toString()).contains("userUuid");
+  }
+
+  private UserDto insertUser(Consumer<UserDto> populateUserDto) {
+    UserDto user = db.users().insertUser(populateUserDto);
+    return user;
+  }
+}
index 62460fb777c4ab696a82051ef81cf02764aa1e99..dcac233f42854683e5126fd4bd6f2ff46870f4f3 100644 (file)
@@ -57,13 +57,13 @@ public class GroupWithPermissionTemplateDaoTest {
     GroupDto group3 = db.users().insertGroup("Group-3");
 
     PermissionTemplateDto template = permissionTemplateDbTester.insertTemplate();
-    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER);
-    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN);
-    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING);
+    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER, template.getName(), group1.getName());
+    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN, template.getName(), group1.getName());
+    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING, template.getName(), group2.getName());
 
     PermissionTemplateDto anotherTemplate = permissionTemplateDbTester.insertTemplate();
-    permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER);
-    permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING);
+    permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER, anotherTemplate.getName(), null);
+    permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING, anotherTemplate.getName(), group1.getName());
 
     assertThat(selectGroupNamesByQueryAndTemplate(builder(), template))
       .containsOnly("Group-1", "Group-2", "Group-3", "Anyone");
@@ -152,7 +152,7 @@ public class GroupWithPermissionTemplateDaoTest {
 
     GroupDto group = db.users().insertGroup("Group");
     PermissionTemplateDto otherTemplate = permissionTemplateDbTester.insertTemplate();
-    permissionTemplateDbTester.addGroupToTemplate(otherTemplate.getUuid(), group.getUuid(), USER);
+    permissionTemplateDbTester.addGroupToTemplate(otherTemplate.getUuid(), group.getUuid(), USER, otherTemplate.getName(), group.getName());
 
     assertThat(selectGroupNamesByQueryAndTemplate(builder().setSearchQuery("nyo"), template))
       .containsExactly("Anyone");
@@ -165,13 +165,13 @@ public class GroupWithPermissionTemplateDaoTest {
     GroupDto group3 = db.users().insertGroup("Group-3");
 
     PermissionTemplateDto template = permissionTemplateDbTester.insertTemplate();
-    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER);
-    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN);
-    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING);
+    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER, template.getName(), group1.getName());
+    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN, template.getName(), group1.getName());
+    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING, template.getName(), group2.getName());
 
     PermissionTemplateDto anotherTemplate = permissionTemplateDbTester.insertTemplate();
-    permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER);
-    permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING);
+    permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER, anotherTemplate.getName(), null);
+    permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING, anotherTemplate.getName(), group1.getName());
 
     assertThat(countGroupNamesByQueryAndTemplate(builder(), template))
       .isEqualTo(4);
@@ -200,13 +200,13 @@ public class GroupWithPermissionTemplateDaoTest {
     GroupDto group3 = db.users().insertGroup(newGroupDto().setName("Group-3"));
 
     PermissionTemplateDto template = permissionTemplateDbTester.insertTemplate();
-    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER);
-    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN);
-    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING);
+    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER, template.getName(), group1.getName());
+    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN, template.getName(), group1.getName());
+    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING, template.getName(), group2.getName());
 
     PermissionTemplateDto anotherTemplate = permissionTemplateDbTester.insertTemplate();
-    permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER);
-    permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING);
+    permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER, anotherTemplate.getName(), null);
+    permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING, anotherTemplate.getName(), group1.getName());
 
     assertThat(underTest.selectGroupPermissionsByTemplateIdAndGroupNames(session, template.getUuid(), asList("Group-1")))
       .extracting(PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission)
@@ -236,13 +236,13 @@ public class GroupWithPermissionTemplateDaoTest {
     GroupDto group3 = db.users().insertGroup(newGroupDto().setName("Group-3"));
 
     PermissionTemplateDto template = permissionTemplateDbTester.insertTemplate();
-    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER);
-    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN);
-    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING);
+    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), USER, template.getName(), group1.getName());
+    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group1.getUuid(), ADMIN, template.getName(), group1.getName());
+    permissionTemplateDbTester.addGroupToTemplate(template.getUuid(), group2.getUuid(), PROVISIONING, template.getName(), group2.getName());
 
     PermissionTemplateDto anotherTemplate = permissionTemplateDbTester.insertTemplate();
-    permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER);
-    permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING);
+    permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), null, USER, anotherTemplate.getName(), null);
+    permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getUuid(), group1.getUuid(), PROVISIONING, anotherTemplate.getName(), group1.getName());
 
     assertThat(underTest.selectGroupPermissionsByTemplateUuid(session, template.getUuid()))
       .extracting(PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission)
index a9dc37d07ed2fc5baff21a43366f968c4df38c4a..8cdf7c6d6988d4902ba96cd634aebb6b5511d577 100644 (file)
@@ -44,33 +44,37 @@ public class PermissionTemplateCharacteristicDaoTest {
   @Test
   public void selectByTemplateId_filter_by_template_uuid() {
     PermissionTemplateCharacteristicDto templatePermission1 = underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
-      .setUuid("uuid1")
-      .setPermission(UserRole.ADMIN)
-      .setTemplateUuid("1")
-      .setWithProjectCreator(true)
-      .setCreatedAt(1_000_000_000L)
-      .setUpdatedAt(2_000_000_000L));
+        .setUuid("uuid1")
+        .setPermission(UserRole.ADMIN)
+        .setTemplateUuid("1")
+        .setWithProjectCreator(true)
+        .setCreatedAt(1_000_000_000L)
+        .setUpdatedAt(2_000_000_000L),
+      "template");
     PermissionTemplateCharacteristicDto templatePermission2 = underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
-      .setUuid("uuid2")
-      .setPermission(UserRole.USER)
-      .setTemplateUuid("2")
-      .setWithProjectCreator(false)
-      .setCreatedAt(1_000_000_000L)
-      .setUpdatedAt(2_000_000_000L));
+        .setUuid("uuid2")
+        .setPermission(UserRole.USER)
+        .setTemplateUuid("2")
+        .setWithProjectCreator(false)
+        .setCreatedAt(1_000_000_000L)
+        .setUpdatedAt(2_000_000_000L),
+      "template");
     PermissionTemplateCharacteristicDto templatePermission3 = underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
-      .setUuid("uuid3")
-      .setPermission(UserRole.USER)
-      .setTemplateUuid("3")
-      .setWithProjectCreator(false)
-      .setCreatedAt(1_000_000_001L)
-      .setUpdatedAt(2_000_000_000L));
+        .setUuid("uuid3")
+        .setPermission(UserRole.USER)
+        .setTemplateUuid("3")
+        .setWithProjectCreator(false)
+        .setCreatedAt(1_000_000_001L)
+        .setUpdatedAt(2_000_000_000L),
+      "template");
     PermissionTemplateCharacteristicDto templatePermissionForAnotherTemplate = underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
-      .setUuid("uuid4")
-      .setPermission(UserRole.ADMIN)
-      .setTemplateUuid("42")
-      .setWithProjectCreator(true)
-      .setCreatedAt(1_000_000_000L)
-      .setUpdatedAt(2_000_000_000L));
+        .setUuid("uuid4")
+        .setPermission(UserRole.ADMIN)
+        .setTemplateUuid("42")
+        .setWithProjectCreator(true)
+        .setCreatedAt(1_000_000_000L)
+        .setUpdatedAt(2_000_000_000L),
+      "template");
 
     List<PermissionTemplateCharacteristicDto> result = underTest.selectByTemplateUuids(dbSession, newArrayList("1", "2", "3"));
     assertThat(result)
@@ -92,26 +96,29 @@ public class PermissionTemplateCharacteristicDaoTest {
   @Test
   public void selectByPermissionAndTemplateId() {
     PermissionTemplateCharacteristicDto templatePermission1 = underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
-      .setUuid("uuid1")
-      .setPermission(UserRole.ADMIN)
-      .setTemplateUuid("1")
-      .setWithProjectCreator(true)
-      .setCreatedAt(1_000_000_000L)
-      .setUpdatedAt(2_000_000_000L));
+        .setUuid("uuid1")
+        .setPermission(UserRole.ADMIN)
+        .setTemplateUuid("1")
+        .setWithProjectCreator(true)
+        .setCreatedAt(1_000_000_000L)
+        .setUpdatedAt(2_000_000_000L),
+      "template");
     underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
-      .setUuid("uuid2")
-      .setPermission(UserRole.USER)
-      .setTemplateUuid("1")
-      .setWithProjectCreator(false)
-      .setCreatedAt(1_000_000_000L)
-      .setUpdatedAt(2_000_000_000L));
+        .setUuid("uuid2")
+        .setPermission(UserRole.USER)
+        .setTemplateUuid("1")
+        .setWithProjectCreator(false)
+        .setCreatedAt(1_000_000_000L)
+        .setUpdatedAt(2_000_000_000L),
+      "template");
     underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
-      .setUuid("uuid3")
-      .setPermission(UserRole.ADMIN)
-      .setTemplateUuid("42")
-      .setWithProjectCreator(true)
-      .setCreatedAt(1_000_000_000L)
-      .setUpdatedAt(2_000_000_000L));
+        .setUuid("uuid3")
+        .setPermission(UserRole.ADMIN)
+        .setTemplateUuid("42")
+        .setWithProjectCreator(true)
+        .setCreatedAt(1_000_000_000L)
+        .setUpdatedAt(2_000_000_000L),
+      "template");
 
     Optional<PermissionTemplateCharacteristicDto> result = underTest.selectByPermissionAndTemplateId(dbSession, UserRole.ADMIN, "1");
 
@@ -122,12 +129,13 @@ public class PermissionTemplateCharacteristicDaoTest {
   @Test
   public void insert() {
     PermissionTemplateCharacteristicDto expectedResult = underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
-      .setUuid("uuid")
-      .setPermission(UserRole.USER)
-      .setTemplateUuid("1")
-      .setWithProjectCreator(true)
-      .setCreatedAt(123_456_789L)
-      .setUpdatedAt(2_000_000_000L));
+        .setUuid("uuid")
+        .setPermission(UserRole.USER)
+        .setTemplateUuid("1")
+        .setWithProjectCreator(true)
+        .setCreatedAt(123_456_789L)
+        .setUpdatedAt(2_000_000_000L),
+      "template");
 
     PermissionTemplateCharacteristicDto result = dbSession.getMapper(PermissionTemplateCharacteristicMapper.class).selectByUuid(expectedResult.getUuid());
     assertThat(result.getUuid()).isEqualTo("uuid");
@@ -137,20 +145,22 @@ public class PermissionTemplateCharacteristicDaoTest {
   @Test
   public void update_only_change_with_project_creator_and_updated_at() {
     PermissionTemplateCharacteristicDto insertedDto = underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
-      .setUuid("uuid")
-      .setPermission(UserRole.USER)
-      .setTemplateUuid("1")
-      .setWithProjectCreator(true)
-      .setCreatedAt(123_456_789L)
-      .setUpdatedAt(2_000_000_000L));
+        .setUuid("uuid")
+        .setPermission(UserRole.USER)
+        .setTemplateUuid("1")
+        .setWithProjectCreator(true)
+        .setCreatedAt(123_456_789L)
+        .setUpdatedAt(2_000_000_000L),
+      "template");
 
     underTest.update(dbSession, new PermissionTemplateCharacteristicDto()
-      .setUuid("uuid")
-      .setPermission("PERMISSION_ARE_NOT_UPDATABLE")
-      .setTemplateUuid("42")
-      .setCreatedAt(42L)
-      .setWithProjectCreator(false)
-      .setUpdatedAt(3_000_000_000L));
+        .setUuid("uuid")
+        .setPermission("PERMISSION_ARE_NOT_UPDATABLE")
+        .setTemplateUuid("42")
+        .setCreatedAt(42L)
+        .setWithProjectCreator(false)
+        .setUpdatedAt(3_000_000_000L),
+      "template");
 
     PermissionTemplateCharacteristicDto result = underTest.selectByPermissionAndTemplateId(dbSession, insertedDto.getPermission(), insertedDto.getTemplateUuid()).get();
     assertThat(result).extracting("uuid", "permission", "templateUuid", "createdAt")
@@ -167,7 +177,7 @@ public class PermissionTemplateCharacteristicDaoTest {
       .setTemplateUuid("1")
       .setWithProjectCreator(true)
       .setUpdatedAt(2_000_000_000L);
-    assertThatThrownBy(() -> underTest.insert(dbSession, characteristicDto))
+    assertThatThrownBy(() -> underTest.insert(dbSession, characteristicDto, "template"))
       .isInstanceOf(IllegalArgumentException.class);
   }
 
@@ -179,7 +189,7 @@ public class PermissionTemplateCharacteristicDaoTest {
       .setTemplateUuid("1")
       .setWithProjectCreator(true)
       .setCreatedAt(2_000_000_000L);
-    assertThatThrownBy(() -> underTest.insert(dbSession, characteristicDto))
+    assertThatThrownBy(() -> underTest.insert(dbSession, characteristicDto, "template"))
       .isInstanceOf(IllegalArgumentException.class);
 
   }
@@ -192,26 +202,28 @@ public class PermissionTemplateCharacteristicDaoTest {
       .setWithProjectCreator(true)
       .setCreatedAt(123_456_789L)
       .setUpdatedAt(2_000_000_000L);
-    assertThatThrownBy(() -> underTest.update(dbSession, characteristicDto))
+    assertThatThrownBy(() -> underTest.update(dbSession, characteristicDto, "template"))
       .isInstanceOf(NullPointerException.class);
   }
 
   @Test
   public void delete_by_permission_template_uuid() {
     underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
-      .setUuid("uuid1")
-      .setPermission(UserRole.USER)
-      .setTemplateUuid("1")
-      .setWithProjectCreator(true)
-      .setCreatedAt(123_456_789L)
-      .setUpdatedAt(2_000_000_000L));
+        .setUuid("uuid1")
+        .setPermission(UserRole.USER)
+        .setTemplateUuid("1")
+        .setWithProjectCreator(true)
+        .setCreatedAt(123_456_789L)
+        .setUpdatedAt(2_000_000_000L),
+      "template");
     underTest.insert(dbSession, new PermissionTemplateCharacteristicDto()
-      .setUuid("uuid2")
-      .setPermission(UserRole.USER)
-      .setTemplateUuid("2")
-      .setWithProjectCreator(true)
-      .setCreatedAt(123_456_789L)
-      .setUpdatedAt(2_000_000_000L));
+        .setUuid("uuid2")
+        .setPermission(UserRole.USER)
+        .setTemplateUuid("2")
+        .setWithProjectCreator(true)
+        .setCreatedAt(123_456_789L)
+        .setUpdatedAt(2_000_000_000L),
+      "template");
 
     assertThat(underTest.selectByTemplateUuids(dbSession, singletonList("1"))).hasSize(1);
     assertThat(underTest.selectByTemplateUuids(dbSession, asList("1", "2"))).hasSize(2);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicDaoWithPersisterTest.java
new file mode 100644 (file)
index 0000000..d6c646a
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.permission.template;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.utils.System2;
+import org.sonar.api.web.UserRole;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PermissionTemplateNewValue;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class PermissionTemplateCharacteristicDaoWithPersisterTest {
+  private final AuditPersister auditPersister = mock(AuditPersister.class);
+
+  @Rule
+  public final DbTester db = DbTester.create(System2.INSTANCE, auditPersister);
+  private final DbSession session = db.getSession();
+  private final PermissionTemplateCharacteristicDao underTest = db.getDbClient().permissionTemplateCharacteristicDao();
+  private final ArgumentCaptor<PermissionTemplateNewValue> newValueCaptor = ArgumentCaptor.forClass(PermissionTemplateNewValue.class);
+
+  @Test
+  public void insertPermissionTemplateCharacteristicIsPersisted() {
+    PermissionTemplateCharacteristicDto dto = getPermissionTemplateCharacteristic(UserRole.USER);
+    underTest.insert(session, dto, "template");
+
+    verify(auditPersister).addCharacteristicToPermissionTemplate(eq(session), newValueCaptor.capture());
+    PermissionTemplateNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+        PermissionTemplateNewValue::getRole, PermissionTemplateNewValue::isWithProjectCreator)
+      .containsExactly(dto.getTemplateUuid(), "template", dto.getPermission(), dto.getWithProjectCreator());
+    assertThat(newValue.toString()).contains("withProjectCreator");
+  }
+
+  @Test
+  public void updatePermissionTemplateCharacteristicIsPersisted() {
+    underTest.insert(session, getPermissionTemplateCharacteristic(UserRole.USER),
+      "template");
+    PermissionTemplateCharacteristicDto updated = getPermissionTemplateCharacteristic(UserRole.ADMIN);
+    underTest.update(session, updated, "template");
+
+    verify(auditPersister).updateCharacteristicInPermissionTemplate(eq(session), newValueCaptor.capture());
+    PermissionTemplateNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+        PermissionTemplateNewValue::getRole, PermissionTemplateNewValue::isWithProjectCreator)
+      .containsExactly(updated.getTemplateUuid(), "template", updated.getPermission(), updated.getWithProjectCreator());
+    assertThat(newValue.toString()).contains("withProjectCreator");
+  }
+
+  private PermissionTemplateCharacteristicDto getPermissionTemplateCharacteristic(String role) {
+    return new PermissionTemplateCharacteristicDto()
+      .setUuid("uuid")
+      .setPermission(role)
+      .setTemplateUuid("1")
+      .setWithProjectCreator(true)
+      .setCreatedAt(123_456_789L)
+      .setUpdatedAt(2_000_000_000L);
+  }
+}
index 7e41b324a70ce5c0357f6a0172ea05a60f0f7b67..980a2f32087a0867587ceb02b37363e980fcc338 100644 (file)
@@ -175,10 +175,10 @@ public class PermissionTemplateDaoTest {
     templateDb.addGroupToTemplate(permissionTemplate1, group2, "user");
     templateDb.addAnyoneToTemplate(permissionTemplate1, "admin");
     templateDb.addAnyoneToTemplate(permissionTemplate2, "admin");
-    templateDb.addProjectCreatorToTemplate(permissionTemplate1.getUuid(), "user");
-    templateDb.addProjectCreatorToTemplate(permissionTemplate2.getUuid(), "user");
+    templateDb.addProjectCreatorToTemplate(permissionTemplate1.getUuid(), "user", permissionTemplate1.getName());
+    templateDb.addProjectCreatorToTemplate(permissionTemplate2.getUuid(), "user", permissionTemplate2.getName());
 
-    underTest.deleteByUuid(dbSession, permissionTemplate1.getUuid());
+    underTest.deleteByUuid(dbSession, permissionTemplate1.getUuid(), permissionTemplate1.getName());
     dbSession.commit();
 
     assertThat(underTest.selectAll(db.getSession(), null))
@@ -198,7 +198,7 @@ public class PermissionTemplateDaoTest {
     PermissionTemplateDto permissionTemplate = templateDb.insertTemplate();
     UserDto user = db.users().insertUser();
 
-    underTest.insertUserPermission(dbSession, permissionTemplate.getUuid(), user.getUuid(), "user");
+    underTest.insertUserPermission(dbSession, permissionTemplate.getUuid(), user.getUuid(), "user", permissionTemplate.getName(), user.getLogin());
 
     assertThat(db.getDbClient().permissionTemplateDao().selectUserPermissionsByTemplateId(db.getSession(), permissionTemplate.getUuid()))
       .extracting(PermissionTemplateUserDto::getTemplateUuid, PermissionTemplateUserDto::getUserUuid, PermissionTemplateUserDto::getPermission,
@@ -216,7 +216,7 @@ public class PermissionTemplateDaoTest {
     templateDb.addUserToTemplate(permissionTemplate, user1, "admin");
     templateDb.addUserToTemplate(permissionTemplate, user2, "user");
 
-    underTest.deleteUserPermission(dbSession, permissionTemplate.getUuid(), user1.getUuid(), "user");
+    underTest.deleteUserPermission(dbSession, permissionTemplate.getUuid(), user1.getUuid(), "user", permissionTemplate.getName(), user1.getLogin());
 
     assertThat(db.getDbClient().permissionTemplateDao().selectUserPermissionsByTemplateId(db.getSession(), permissionTemplate.getUuid()))
       .extracting(PermissionTemplateUserDto::getUserUuid, PermissionTemplateUserDto::getPermission)
@@ -228,7 +228,7 @@ public class PermissionTemplateDaoTest {
     PermissionTemplateDto permissionTemplate = templateDb.insertTemplate();
     GroupDto group = db.users().insertGroup();
 
-    underTest.insertGroupPermission(dbSession, permissionTemplate.getUuid(), group.getUuid(), "user");
+    underTest.insertGroupPermission(dbSession, permissionTemplate.getUuid(), group.getUuid(), "user", permissionTemplate.getName(), group.getName());
     dbSession.commit();
 
     assertThat(db.getDbClient().permissionTemplateDao().selectGroupPermissionsByTemplateUuid(db.getSession(), permissionTemplate.getUuid()))
@@ -247,7 +247,7 @@ public class PermissionTemplateDaoTest {
     templateDb.addGroupToTemplate(permissionTemplate, group1, "admin");
     templateDb.addGroupToTemplate(permissionTemplate, group2, "user");
 
-    underTest.deleteByGroup(db.getSession(), group1.getUuid());
+    underTest.deleteByGroup(db.getSession(), group1.getUuid(), group1.getName());
     db.getSession().commit();
 
     assertThat(db.getDbClient().permissionTemplateDao().selectGroupPermissionsByTemplateUuid(db.getSession(), permissionTemplate.getUuid()))
@@ -259,7 +259,7 @@ public class PermissionTemplateDaoTest {
   public void add_group_permission_to_anyone() {
     PermissionTemplateDto permissionTemplate = templateDb.insertTemplate();
 
-    underTest.insertGroupPermission(dbSession, permissionTemplate.getUuid(), null, "user");
+    underTest.insertGroupPermission(dbSession, permissionTemplate.getUuid(), null, "user", permissionTemplate.getName(), null);
     dbSession.commit();
 
     assertThat(db.getDbClient().permissionTemplateDao().selectGroupPermissionsByTemplateUuid(db.getSession(), permissionTemplate.getUuid()))
@@ -277,13 +277,13 @@ public class PermissionTemplateDaoTest {
     GroupDto group1 = db.users().insertGroup(newGroupDto());
     GroupDto group2 = db.users().insertGroup(newGroupDto());
     GroupDto group3 = db.users().insertGroup(newGroupDto());
-    templateDb.addGroupToTemplate(template1.getUuid(), group1.getUuid(), CODEVIEWER);
-    templateDb.addGroupToTemplate(template1.getUuid(), group2.getUuid(), CODEVIEWER);
-    templateDb.addGroupToTemplate(template1.getUuid(), group3.getUuid(), CODEVIEWER);
-    templateDb.addGroupToTemplate(template1.getUuid(), null, CODEVIEWER);
-    templateDb.addGroupToTemplate(template1.getUuid(), group1.getUuid(), ADMIN);
-    templateDb.addGroupToTemplate(template2.getUuid(), group1.getUuid(), ADMIN);
-    templateDb.addGroupToTemplate(template4.getUuid(), group1.getUuid(), ISSUE_ADMIN);
+    templateDb.addGroupToTemplate(template1.getUuid(), group1.getUuid(), CODEVIEWER, template1.getName(), group1.getName());
+    templateDb.addGroupToTemplate(template1.getUuid(), group2.getUuid(), CODEVIEWER, template1.getName(), group2.getName());
+    templateDb.addGroupToTemplate(template1.getUuid(), group3.getUuid(), CODEVIEWER, template1.getName(), group3.getName());
+    templateDb.addGroupToTemplate(template1.getUuid(), null, CODEVIEWER, template1.getName(), null);
+    templateDb.addGroupToTemplate(template1.getUuid(), group1.getUuid(), ADMIN, template1.getName(), group1.getName());
+    templateDb.addGroupToTemplate(template2.getUuid(), group1.getUuid(), ADMIN, template2.getName(), group1.getName());
+    templateDb.addGroupToTemplate(template4.getUuid(), group1.getUuid(), ISSUE_ADMIN, template4.getName(), group1.getName());
 
     final List<CountByTemplateAndPermissionDto> result = new ArrayList<>();
     underTest.groupsCountByTemplateUuidAndPermission(dbSession, asList(template1.getUuid(), template2.getUuid(), template3.getUuid()),
@@ -304,12 +304,12 @@ public class PermissionTemplateDaoTest {
     UserDto user2 = db.users().insertUser();
     UserDto user3 = db.users().insertUser();
 
-    templateDb.addUserToTemplate(template1.getUuid(), user1.getUuid(), ADMIN);
-    templateDb.addUserToTemplate(template1.getUuid(), user2.getUuid(), ADMIN);
-    templateDb.addUserToTemplate(template1.getUuid(), user3.getUuid(), ADMIN);
-    templateDb.addUserToTemplate(template1.getUuid(), user1.getUuid(), USER);
-    templateDb.addUserToTemplate(template2.getUuid(), user1.getUuid(), USER);
-    templateDb.addUserToTemplate(anotherTemplate.getUuid(), user1.getUuid(), ISSUE_ADMIN);
+    templateDb.addUserToTemplate(template1.getUuid(), user1.getUuid(), ADMIN, template1.getName(), user1.getLogin());
+    templateDb.addUserToTemplate(template1.getUuid(), user2.getUuid(), ADMIN, template1.getName(), user2.getLogin());
+    templateDb.addUserToTemplate(template1.getUuid(), user3.getUuid(), ADMIN, template1.getName(), user3.getLogin());
+    templateDb.addUserToTemplate(template1.getUuid(), user1.getUuid(), USER, template1.getName(), user1.getLogin());
+    templateDb.addUserToTemplate(template2.getUuid(), user1.getUuid(), USER, template2.getName(), user1.getLogin());
+    templateDb.addUserToTemplate(anotherTemplate.getUuid(), user1.getUuid(), ISSUE_ADMIN, anotherTemplate.getName(), user1.getLogin());
 
     final List<CountByTemplateAndPermissionDto> result = new ArrayList<>();
     underTest.usersCountByTemplateUuidAndPermission(dbSession, asList(template1.getUuid(), template2.getUuid(), template3.getUuid()),
@@ -345,13 +345,13 @@ public class PermissionTemplateDaoTest {
     GroupDto group = db.users().insertGroup(newGroupDto());
     db.users().insertMember(group, user);
     PermissionTemplateDto template = templateDb.insertTemplate();
-    templateDb.addProjectCreatorToTemplate(template.getUuid(), SCAN_EXECUTION);
-    templateDb.addProjectCreatorToTemplate(template.getUuid(), UserRole.ADMIN);
-    templateDb.addUserToTemplate(template.getUuid(), user.getUuid(), UserRole.USER);
-    templateDb.addUserToTemplate(template.getUuid(), user.getUuid(), UserRole.ADMIN);
-    templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.CODEVIEWER);
-    templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.ADMIN);
-    templateDb.addGroupToTemplate(template.getUuid(), null, UserRole.ISSUE_ADMIN);
+    templateDb.addProjectCreatorToTemplate(template.getUuid(), SCAN_EXECUTION, template.getName());
+    templateDb.addProjectCreatorToTemplate(template.getUuid(), UserRole.ADMIN, template.getName());
+    templateDb.addUserToTemplate(template.getUuid(), user.getUuid(), UserRole.USER, template.getName(), user.getLogin());
+    templateDb.addUserToTemplate(template.getUuid(), user.getUuid(), UserRole.ADMIN, template.getName(), user.getLogin());
+    templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.CODEVIEWER, template.getName(), group.getName());
+    templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.ADMIN, template.getName(), group.getName());
+    templateDb.addGroupToTemplate(template.getUuid(), null, UserRole.ISSUE_ADMIN, template.getName(), null);
 
     List<String> resultWithUser = underTest.selectPotentialPermissionsByUserUuidAndTemplateUuid(dbSession, user.getUuid(), template.getUuid());
     List<String> resultWithoutUser = underTest.selectPotentialPermissionsByUserUuidAndTemplateUuid(dbSession, null, template.getUuid());
@@ -381,10 +381,10 @@ public class PermissionTemplateDaoTest {
     UserDto anotherUser = db.users().insertUser();
     PermissionTemplateDto template = db.permissionTemplates().insertTemplate();
     String permission = "PERMISSION";
-    db.permissionTemplates().addUserToTemplate(template.getUuid(), user.getUuid(), permission);
-    db.permissionTemplates().addUserToTemplate(template.getUuid(), anotherUser.getUuid(), permission);
+    db.permissionTemplates().addUserToTemplate(template.getUuid(), user.getUuid(), permission, template.getName(), user.getLogin());
+    db.permissionTemplates().addUserToTemplate(template.getUuid(), anotherUser.getUuid(), permission, template.getName(), anotherUser.getLogin());
 
-    underTest.deleteUserPermissionsByUserUuid(dbSession, user.getUuid());
+    underTest.deleteUserPermissionsByUserUuid(dbSession, user.getUuid(), user.getLogin());
     db.commit();
 
     assertThat(db.select("select template_uuid as \"templateUuid\", user_uuid as \"userUuid\", permission_reference as \"permission\" from perm_templates_users"))
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoWithPersisterTest.java
new file mode 100644 (file)
index 0000000..fe5d845
--- /dev/null
@@ -0,0 +1,200 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.permission.template;
+
+import java.util.Date;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.sonar.core.util.Uuids;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PermissionTemplateNewValue;
+import org.sonar.db.user.GroupDto;
+import org.sonar.db.user.UserDto;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.sonar.api.web.UserRole.ADMIN;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.user.GroupTesting.newGroupDto;
+
+public class PermissionTemplateDaoWithPersisterTest {
+  private final AuditPersister auditPersister = mock(AuditPersister.class);
+
+  private static final Date PAST = new Date(100_000_000_000L);
+  private static final Date NOW = new Date(500_000_000_000L);
+
+  @Rule
+  public final DbTester db = DbTester.create(auditPersister);
+  private final DbSession session = db.getSession();
+
+  private final ArgumentCaptor<PermissionTemplateNewValue> newValueCaptor = ArgumentCaptor.forClass(PermissionTemplateNewValue.class);
+  private final PermissionTemplateDao underTest = db.getDbClient().permissionTemplateDao();
+
+  @Test
+  public void insertPermissionTemplateIsPersisted() {
+    PermissionTemplateDto dto = insertPermissionTemplate();
+
+    verify(auditPersister).addPermissionTemplate(eq(session), newValueCaptor.capture());
+    PermissionTemplateNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName)
+      .containsExactly(dto.getUuid(), dto.getName());
+    assertThat(newValue.toString()).doesNotContain("keyPattern");
+  }
+
+  @Test
+  public void updatePermissionTemplateIsPersisted() {
+    PermissionTemplateDto dto = insertPermissionTemplate();
+    underTest.update(session, dto);
+
+    verify(auditPersister).updatePermissionTemplate(eq(session), newValueCaptor.capture());
+    PermissionTemplateNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+        PermissionTemplateNewValue::getDescription, PermissionTemplateNewValue::getKeyPattern)
+      .containsExactly(dto.getUuid(), dto.getName(), dto.getDescription(), dto.getKeyPattern());
+    assertThat(newValue.toString()).contains("keyPattern");
+  }
+
+  @Test
+  public void deletePermissionTemplateIsPersisted() {
+    PermissionTemplateDto dto = insertPermissionTemplate();
+    underTest.deleteByUuid(session, dto.getUuid(), dto.getName());
+
+    verify(auditPersister).deletePermissionTemplate(eq(session), newValueCaptor.capture());
+    PermissionTemplateNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName)
+      .containsExactly(dto.getUuid(), dto.getName());
+    assertThat(newValue.toString()).doesNotContain("keyPattern");
+  }
+
+  @Test
+  public void insertAndDeleteUserPermissionToTemplateIsPersisted() {
+    PermissionTemplateDto dto = insertPermissionTemplate();
+    UserDto user = db.users().insertUser();
+    underTest.insertUserPermission(session, dto.getUuid(), user.getUuid(), ADMIN, dto.getName(), user.getLogin());
+
+    verify(auditPersister).addUserToPermissionTemplate(eq(session), newValueCaptor.capture());
+    PermissionTemplateNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+        PermissionTemplateNewValue::getRole, PermissionTemplateNewValue::getUserUuid, PermissionTemplateNewValue::getUserLogin)
+      .containsExactly(dto.getUuid(), dto.getName(), ADMIN, user.getUuid(), user.getLogin());
+    assertThat(newValue.toString()).doesNotContain("groupUuid");
+
+    underTest.deleteUserPermission(session, dto.getUuid(), user.getUuid(), ADMIN, dto.getName(), user.getLogin());
+
+    verify(auditPersister).deleteUserFromPermissionTemplate(eq(session), newValueCaptor.capture());
+    newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+        PermissionTemplateNewValue::getRole, PermissionTemplateNewValue::getUserUuid, PermissionTemplateNewValue::getUserLogin)
+      .containsExactly(dto.getUuid(), dto.getName(), ADMIN, user.getUuid(), user.getLogin());
+    assertThat(newValue.toString()).doesNotContain("groupUuid");
+  }
+
+  @Test
+  public void insertAndDeleteUserPermissionByUserUuidToTemplateIsPersisted() {
+    PermissionTemplateDto dto = insertPermissionTemplate();
+    UserDto user = db.users().insertUser();
+    underTest.insertUserPermission(session, dto.getUuid(), user.getUuid(), ADMIN, dto.getName(), user.getLogin());
+    underTest.deleteUserPermissionsByUserUuid(session, user.getUuid(), user.getLogin());
+
+    verify(auditPersister).deleteUserFromPermissionTemplate(eq(session), newValueCaptor.capture());
+    PermissionTemplateNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+        PermissionTemplateNewValue::getRole, PermissionTemplateNewValue::getUserUuid, PermissionTemplateNewValue::getUserLogin)
+      .containsExactly(null, null, null, user.getUuid(), user.getLogin());
+    assertThat(newValue.toString()).doesNotContain("groupUuid");
+  }
+
+  @Test
+  public void insertAndDeleteGroupPermissionToTemplateIsPersisted() {
+    PermissionTemplateDto dto = insertPermissionTemplate();
+    GroupDto group = db.users().insertGroup(newGroupDto());
+    underTest.insertGroupPermission(session, dto.getUuid(), group.getUuid(), ADMIN, dto.getName(), group.getName());
+
+    verify(auditPersister).addGroupToPermissionTemplate(eq(session), newValueCaptor.capture());
+    PermissionTemplateNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+        PermissionTemplateNewValue::getRole, PermissionTemplateNewValue::getGroupUuid, PermissionTemplateNewValue::getGroupName)
+      .containsExactly(dto.getUuid(), dto.getName(), ADMIN, group.getUuid(), group.getName());
+    assertThat(newValue.toString()).contains("groupUuid");
+
+    underTest.deleteGroupPermission(session, dto.getUuid(), group.getUuid(), ADMIN, dto.getName(), group.getName());
+
+    verify(auditPersister).deleteGroupFromPermissionTemplate(eq(session), newValueCaptor.capture());
+    newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+        PermissionTemplateNewValue::getRole, PermissionTemplateNewValue::getGroupUuid, PermissionTemplateNewValue::getGroupName)
+      .containsExactly(dto.getUuid(), dto.getName(), ADMIN, group.getUuid(), group.getName());
+    assertThat(newValue.toString()).contains("groupUuid");
+  }
+
+  @Test
+  public void insertAndDeleteGroupPermissionByGroupUuidToTemplateIsPersisted() {
+    PermissionTemplateDto templateDto = insertPermissionTemplate();
+    PermissionTemplateGroupDto templateGroupDto = new PermissionTemplateGroupDto()
+      .setUuid(Uuids.createFast())
+      .setGroupName("group")
+      .setPermission(ADMIN)
+      .setTemplateUuid(templateDto.getUuid())
+      .setCreatedAt(new Date())
+      .setUpdatedAt(new Date());
+    underTest.insertGroupPermission(session, templateGroupDto, templateDto.getName());
+
+    verify(auditPersister).addGroupToPermissionTemplate(eq(session), newValueCaptor.capture());
+    PermissionTemplateNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+        PermissionTemplateNewValue::getRole, PermissionTemplateNewValue::getGroupUuid, PermissionTemplateNewValue::getGroupName)
+      .containsExactly(templateDto.getUuid(), templateDto.getName(), ADMIN, templateGroupDto.getGroupUuid(), templateGroupDto.getGroupName());
+    assertThat(newValue.toString()).doesNotContain("userUuid");
+
+    underTest.deleteByGroup(session, templateGroupDto.getGroupUuid(), templateGroupDto.getGroupName());
+
+    verify(auditPersister).deleteGroupFromPermissionTemplate(eq(session), newValueCaptor.capture());
+    newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PermissionTemplateNewValue::getTemplateUuid, PermissionTemplateNewValue::getName,
+        PermissionTemplateNewValue::getRole, PermissionTemplateNewValue::getGroupUuid, PermissionTemplateNewValue::getGroupName)
+      .containsExactly(null, null, null, templateGroupDto.getGroupUuid(), templateGroupDto.getGroupName());
+    assertThat(newValue.toString()).doesNotContain("userUuid");
+  }
+
+  private PermissionTemplateDto insertPermissionTemplate() {
+    return underTest.insert(session, newPermissionTemplateDto()
+      .setUuid("ABCD")
+      .setName("my template")
+      .setDescription("my description")
+      .setKeyPattern("myregexp")
+      .setCreatedAt(PAST)
+      .setUpdatedAt(NOW));
+  }
+}
index 86285b7774f63bcf4140a512b71898102bd0f24d..9af972c2446215cc0861f1c731ee5c1983f430ad 100644 (file)
@@ -140,7 +140,7 @@ public class UserWithPermissionTemplateDaoTest {
     UserDto user1 = db.users().insertUser(u -> u.setName("A"));
     UserDto user2 = db.users().insertUser(u -> u.setName("B"));
     UserDto user3 = db.users().insertUser(u -> u.setName("C"));
-    db.permissionTemplates().addUserToTemplate(template.getUuid(), user3.getUuid(), UserRole.USER);
+    db.permissionTemplates().addUserToTemplate(template.getUuid(), user3.getUuid(), UserRole.USER, template.getName(), user3.getLogin());
 
     PermissionQuery query = PermissionQuery.builder().build();
     assertThat(underTest.selectUserLoginsByQueryAndTemplate(db.getSession(), query, template.getUuid()))
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/plugin/PluginDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/plugin/PluginDaoWithPersisterTest.java
new file mode 100644 (file)
index 0000000..0d8132a
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.plugin;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PluginNewValue;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.sonar.db.plugin.PluginDto.Type.EXTERNAL;
+
+public class PluginDaoWithPersisterTest {
+  private final AuditPersister auditPersister = mock(AuditPersister.class);
+
+  @Rule
+  public final ExpectedException thrown = ExpectedException.none();
+  @Rule
+  public final DbTester db = DbTester.create(System2.INSTANCE, auditPersister);
+
+  private final ArgumentCaptor<PluginNewValue> newValueCaptor = ArgumentCaptor.forClass(PluginNewValue.class);
+  private final DbSession session = db.getSession();
+
+  private PluginDao underTest = db.getDbClient().pluginDao();
+
+  @Test
+  public void insert() {
+    PluginDto dto = getPluginDto();
+    underTest.insert(session, dto);
+
+    verify(auditPersister).addPlugin(eq(session), newValueCaptor.capture());
+    PluginNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PluginNewValue::getPluginUuid, PluginNewValue::getKee,
+        PluginNewValue::getBasePluginKey, PluginNewValue::getType)
+      .containsExactly(dto.getUuid(), dto.getKee(), dto.getBasePluginKey(), dto.getType().name());
+    assertThat(newValue.toString()).contains("pluginUuid");
+  }
+
+  @Test
+  public void update() {
+    PluginDto dto = getPluginDto();
+    underTest.update(session, dto);
+
+    verify(auditPersister).updatePlugin(eq(session), newValueCaptor.capture());
+    PluginNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PluginNewValue::getPluginUuid, PluginNewValue::getKee,
+        PluginNewValue::getBasePluginKey, PluginNewValue::getType)
+      .containsExactly(dto.getUuid(), dto.getKee(), dto.getBasePluginKey(), dto.getType().name());
+    assertThat(newValue.toString()).contains("pluginUuid");
+  }
+
+  private PluginDto getPluginDto() {
+    return new PluginDto()
+      .setUuid("plugin_uuid")
+      .setKee("plugin_kee")
+      .setBasePluginKey("plugin_base_key")
+      .setFileHash("plugin_file_hash")
+      .setType(EXTERNAL)
+      .setCreatedAt(1L)
+      .setUpdatedAt(2L);
+  }
+}
index 29521b96f0d78ae32d6ca8096d221c9db8c33e45..e560a5cc4fcd275989540a27987303fbe751fba2 100644 (file)
@@ -81,11 +81,11 @@ public class PropertiesDaoTest {
     UserDto user1 = db.users().insertUser(u -> u.setLogin("user1"));
     UserDto user2 = db.users().insertUser(u -> u.setLogin("user2"));
     UserDto user3 = db.users().insertUser(u -> u.setLogin("user3"));
-    insertProperty("notification.NewViolations.Email", "true", project1.uuid(), user2.getUuid());
-    insertProperty("notification.NewViolations.Twitter", "true", null, user3.getUuid());
-    insertProperty("notification.NewViolations.Twitter", "true", project2.uuid(), user1.getUuid());
-    insertProperty("notification.NewViolations.Twitter", "true", project1.uuid(), user2.getUuid());
-    insertProperty("notification.NewViolations.Twitter", "true", project2.uuid(), user3.getUuid());
+    insertProperty("notification.NewViolations.Email", "true", project1.uuid(), user2.getUuid(), user2.getLogin(), project1.name());
+    insertProperty("notification.NewViolations.Twitter", "true", null, user3.getUuid(), user3.getLogin(), null);
+    insertProperty("notification.NewViolations.Twitter", "true", project2.uuid(), user1.getUuid(), user1.getLogin(), project2.name());
+    insertProperty("notification.NewViolations.Twitter", "true", project1.uuid(), user2.getUuid(), user2.getLogin(), project1.name());
+    insertProperty("notification.NewViolations.Twitter", "true", project2.uuid(), user3.getUuid(), user3.getLogin(), project2.name());
     db.users().insertProjectPermissionOnUser(user2, UserRole.USER, project1);
     db.users().insertProjectPermissionOnUser(user3, UserRole.USER, project2);
     db.users().insertProjectPermissionOnUser(user1, UserRole.USER, project2);
@@ -117,19 +117,25 @@ public class PropertiesDaoTest {
 
   @Test
   public void hasNotificationSubscribers() {
-    String userUuid1 = db.users().insertUser(u -> u.setLogin("user1")).getUuid();
-    String userUuid2 = db.users().insertUser(u -> u.setLogin("user2")).getUuid();
+    UserDto user1 = db.users().insertUser(u -> u.setLogin("user1"));
+    UserDto user2 = db.users().insertUser(u -> u.setLogin("user2"));
     String projectUuid = randomAlphabetic(8);
+    String projectName = randomAlphabetic(4);
     db.components().insertPrivateProject(projectUuid);
 
     // global subscription
-    insertProperty("notification.DispatcherWithGlobalSubscribers.Email", "true", null, userUuid2);
+    insertProperty("notification.DispatcherWithGlobalSubscribers.Email", "true", null,
+      user2.getUuid(), user2.getLogin(), null);
     // project subscription
-    insertProperty("notification.DispatcherWithProjectSubscribers.Email", "true", projectUuid, userUuid1);
-    insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", "uuid56", userUuid1);
-    insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", projectUuid, userUuid1);
+    insertProperty("notification.DispatcherWithProjectSubscribers.Email", "true", projectUuid, user1.getUuid(),
+      user1.getLogin(), projectName);
+    insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", "uuid56", user1.getUuid(),
+      user1.getLogin(), projectName);
+    insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", projectUuid, user1.getUuid(),
+      user1.getLogin(), projectName);
     // global subscription
-    insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", null, userUuid2);
+    insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", null, user2.getUuid(),
+      user2.getLogin(), null);
 
     // Nobody is subscribed
     assertThat(underTest.hasProjectNotificationSubscribersForDispatchers(projectUuid, singletonList("NotSexyDispatcher")))
@@ -179,24 +185,24 @@ public class PropertiesDaoTest {
 
   @Test
   public void findEmailRecipientsForNotification_finds_only_globally_subscribed_users_if_projectKey_is_null() {
-    String userUuid1 = db.users().insertUser(withEmail("user1")).getUuid();
-    String userUuid2 = db.users().insertUser(withEmail("user2")).getUuid();
-    String userUuid3 = db.users().insertUser(withEmail("user3")).getUuid();
-    String userUuid4 = db.users().insertUser(withEmail("user4")).getUuid();
-    String projectUuid = insertPrivateProject("PROJECT_A").uuid();
+    UserDto user1 = db.users().insertUser(withEmail("user1"));
+    UserDto user2 = db.users().insertUser(withEmail("user2"));
+    UserDto user3 = db.users().insertUser(withEmail("user3"));
+    UserDto user4 = db.users().insertUser(withEmail("user4"));
+    ComponentDto project = insertPrivateProject("PROJECT_A");
     String dispatcherKey = randomAlphabetic(5);
     String otherDispatcherKey = randomAlphabetic(6);
     String channelKey = randomAlphabetic(7);
     String otherChannelKey = randomAlphabetic(8);
     // user1 subscribed only globally
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid1);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), null);
     // user2 subscribed on project and globally
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid2);
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid2);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), null);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), project.name());
     // user3 subscribed on project only
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid3);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user3.getUuid(), user3.getLogin(), project.name());
     // user4 did not subscribe
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userUuid4);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", project.uuid(), user4.getUuid(), user4.getLogin(), project.name());
 
     assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, null))
       .containsOnly(EmailSubscriberDto.create("user1", true, emailOf("user1")), EmailSubscriberDto.create("user2", true, emailOf("user2")));
@@ -211,24 +217,24 @@ public class PropertiesDaoTest {
 
   @Test
   public void findEmailRecipientsForNotification_with_logins_finds_only_globally_subscribed_specified_users_if_projectKey_is_null() {
-    String userUuid1 = db.users().insertUser(withEmail("user1")).getUuid();
-    String userUuid2 = db.users().insertUser(withEmail("user2")).getUuid();
-    String userUuid3 = db.users().insertUser(withEmail("user3")).getUuid();
-    String userUuid4 = db.users().insertUser(withEmail("user4")).getUuid();
-    String projectUuid = insertPrivateProject("PROJECT_A").uuid();
+    UserDto user1 = db.users().insertUser(withEmail("user1"));
+    UserDto user2 = db.users().insertUser(withEmail("user2"));
+    UserDto user3 = db.users().insertUser(withEmail("user3"));
+    UserDto user4 = db.users().insertUser(withEmail("user4"));
+    ComponentDto project = insertPrivateProject("PROJECT_A");
     String dispatcherKey = randomAlphabetic(5);
     String otherDispatcherKey = randomAlphabetic(6);
     String channelKey = randomAlphabetic(7);
     String otherChannelKey = randomAlphabetic(8);
     // user1 subscribed only globally
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid1);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), null);
     // user2 subscribed on project and globally
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid2);
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid2);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), null);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), project.name());
     // user3 subscribed on project only
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid3);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user3.getUuid(), user3.getLogin(), project.name());
     // user4 did not subscribe
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userUuid4);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", project.uuid(), user4.getUuid(), user4.getLogin(), project.name());
     Set<String> allLogins = of("user1", "user2", "user3", "user4");
 
     assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, null, allLogins))
@@ -252,26 +258,26 @@ public class PropertiesDaoTest {
 
   @Test
   public void findEmailRecipientsForNotification_finds_global_and_project_subscribed_users_when_projectKey_is_non_null() {
-    String userUuid1 = db.users().insertUser(withEmail("user1")).getUuid();
-    String userUuid2 = db.users().insertUser(withEmail("user2")).getUuid();
-    String userUuid3 = db.users().insertUser(withEmail("user3")).getUuid();
-    String userUuid4 = db.users().insertUser(withEmail("user4")).getUuid();
+    UserDto user1 = db.users().insertUser(withEmail("user1"));
+    UserDto user2 = db.users().insertUser(withEmail("user2"));
+    UserDto user3 = db.users().insertUser(withEmail("user3"));
+    UserDto user4 = db.users().insertUser(withEmail("user4"));
     String projectKey = randomAlphabetic(3);
     String otherProjectKey = randomAlphabetic(4);
-    String projectUuid = insertPrivateProject(projectKey).uuid();
+    ComponentDto project = insertPrivateProject(projectKey);
     String dispatcherKey = randomAlphabetic(5);
     String otherDispatcherKey = randomAlphabetic(6);
     String channelKey = randomAlphabetic(7);
     String otherChannelKey = randomAlphabetic(8);
     // user1 subscribed only globally
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid1);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), null);
     // user2 subscribed on project and globally
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid2);
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid2);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), null);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), project.name());
     // user3 subscribed on project only
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid3);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user3.getUuid(), user3.getLogin(), project.name());
     // user4 did not subscribe
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userUuid4);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", project.uuid(), user4.getUuid(), user4.getLogin(), project.name());
 
     assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey))
       .containsOnly(
@@ -291,26 +297,26 @@ public class PropertiesDaoTest {
 
   @Test
   public void findEmailRecipientsForNotification_with_logins_finds_global_and_project_subscribed_specified_users_when_projectKey_is_non_null() {
-    String userUuid1 = db.users().insertUser(withEmail("user1")).getUuid();
-    String userUuid2 = db.users().insertUser(withEmail("user2")).getUuid();
-    String userUuid3 = db.users().insertUser(withEmail("user3")).getUuid();
-    String userUuid4 = db.users().insertUser(withEmail("user4")).getUuid();
+    UserDto user1 = db.users().insertUser(withEmail("user1"));
+    UserDto user2 = db.users().insertUser(withEmail("user2"));
+    UserDto user3 = db.users().insertUser(withEmail("user3"));
+    UserDto user4 = db.users().insertUser(withEmail("user4"));
     String projectKey = randomAlphabetic(3);
     String otherProjectKey = randomAlphabetic(4);
-    String projectUuid = insertPrivateProject(projectKey).uuid();
+    ComponentDto project = insertPrivateProject(projectKey);
     String dispatcherKey = randomAlphabetic(5);
     String otherDispatcherKey = randomAlphabetic(6);
     String channelKey = randomAlphabetic(7);
     String otherChannelKey = randomAlphabetic(8);
     // user1 subscribed only globally
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid1);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), null);
     // user2 subscribed on project and globally
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid2);
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid2);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), null);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), project.name());
     // user3 subscribed on project only
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid3);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user3.getUuid(), user3.getLogin(), project.name());
     // user4 did not subscribe
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectUuid, userUuid4);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", project.uuid(), user4.getUuid(), user4.getLogin(), project.name());
     Set<String> allLogins = of("user1", "user2", "user3", "user4");
 
     assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey, allLogins))
@@ -341,22 +347,22 @@ public class PropertiesDaoTest {
 
   @Test
   public void findEmailRecipientsForNotification_ignores_subscribed_users_without_email() {
-    String userUuid1 = db.users().insertUser(withEmail("user1")).getUuid();
-    String userUuid2 = db.users().insertUser(noEmail("user2")).getUuid();
-    String userUuid3 = db.users().insertUser(withEmail("user3")).getUuid();
-    String userUuid4 = db.users().insertUser(noEmail("user4")).getUuid();
+    UserDto user1 = db.users().insertUser(withEmail("user1"));
+    UserDto user2 = db.users().insertUser(noEmail("user2"));
+    UserDto user3 = db.users().insertUser(withEmail("user3"));
+    UserDto user4 = db.users().insertUser(noEmail("user4"));
     String projectKey = randomAlphabetic(3);
-    String projectUuid = insertPrivateProject(projectKey).uuid();
+    ComponentDto project = insertPrivateProject(projectKey);
     String dispatcherKey = randomAlphabetic(4);
     String channelKey = randomAlphabetic(5);
     // user1 and user2 subscribed on project and globally
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid1);
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid1);
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid2);
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid2);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), null);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user1.getUuid(), user1.getLogin(), project.name());
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), null);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), project.name());
     // user3 and user4 subscribed only globally
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid3);
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid4);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user3.getUuid(), user3.getLogin(), null);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user4.getUuid(), user4.getLogin(), null);
 
     assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey))
       .containsOnly(
@@ -370,23 +376,23 @@ public class PropertiesDaoTest {
 
   @Test
   public void findEmailRecipientsForNotification_with_logins_ignores_subscribed_users_without_email() {
-    String userUuid1 = db.users().insertUser(withEmail("user1")).getUuid();
-    String userUuid2 = db.users().insertUser(noEmail("user2")).getUuid();
-    String userUuid3 = db.users().insertUser(withEmail("user3")).getUuid();
-    String userUuid4 = db.users().insertUser(noEmail("user4")).getUuid();
+    UserDto user1 = db.users().insertUser(withEmail("user1"));
+    UserDto user2 = db.users().insertUser(noEmail("user2"));
+    UserDto user3 = db.users().insertUser(withEmail("user3"));
+    UserDto user4 = db.users().insertUser(noEmail("user4"));
     Set<String> allLogins = of("user1", "user2", "user3");
     String projectKey = randomAlphabetic(3);
-    String projectUuid = insertPrivateProject(projectKey).uuid();
+    ComponentDto project = insertPrivateProject(projectKey);
     String dispatcherKey = randomAlphabetic(4);
     String channelKey = randomAlphabetic(5);
     // user1 and user2 subscribed on project and globally
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid1);
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid1);
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid2);
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", projectUuid, userUuid2);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), null);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user1.getUuid(), user1.getLogin(), project.name());
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), null);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), project.name());
     // user3 and user4 subscribed only globally
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid3);
-    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, userUuid4);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user3.getUuid(), user3.getLogin(), null);
+    insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user4.getUuid(), user4.getLogin(), null);
 
     assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey, allLogins))
       .containsOnly(
@@ -401,8 +407,8 @@ public class PropertiesDaoTest {
   @Test
   public void selectGlobalProperties() {
     // global
-    insertProperty("global.one", "one", null, null);
-    insertProperty("global.two", "two", null, null);
+    insertProperty("global.one", "one", null, null, null, null);
+    insertProperty("global.two", "two", null, null, null, null);
 
     List<PropertyDto> properties = underTest.selectGlobalProperties();
     assertThat(properties.size())
@@ -420,7 +426,7 @@ public class PropertiesDaoTest {
   @Test
   @UseDataProvider("allValuesForSelect")
   public void selectGlobalProperties_supports_all_values(String dbValue, String expected) {
-    insertProperty("global.one", dbValue, null, null);
+    insertProperty("global.one", dbValue, null, null, null, null);
 
     List<PropertyDto> dtos = underTest.selectGlobalProperties();
     assertThat(dtos)
@@ -434,12 +440,12 @@ public class PropertiesDaoTest {
   @Test
   public void selectGlobalProperty() {
     // global
-    insertProperty("global.one", "one", null, null);
-    insertProperty("global.two", "two", null, null);
+    insertProperty("global.one", "one", null, null, null, null);
+    insertProperty("global.two", "two", null, null, null, null);
     // project
-    insertProperty("project.one", "one", "uuid10", null);
+    insertProperty("project.one", "one", "uuid10", null, null, "component");
     // user
-    insertProperty("user.one", "one", null, "100");
+    insertProperty("user.one", "one", null, "100", "login", null);
 
     assertThat(underTest.selectGlobalProperty("global.one"))
       .extracting(PropertyDto::getComponentUuid, PropertyDto::getUserUuid, PropertyDto::getValue)
@@ -453,7 +459,7 @@ public class PropertiesDaoTest {
   @Test
   @UseDataProvider("allValuesForSelect")
   public void selectGlobalProperty_supports_all_values(String dbValue, String expected) {
-    insertProperty("global.one", dbValue, null, null);
+    insertProperty("global.one", dbValue, null, null, null, null);
 
     assertThat(underTest.selectGlobalProperty("global.one"))
       .extracting(PropertyDto::getComponentUuid, PropertyDto::getUserUuid, PropertyDto::getValue)
@@ -465,11 +471,11 @@ public class PropertiesDaoTest {
     ComponentDto projectDto = insertPrivateProject("A");
     String projectUuid = projectDto.uuid();
     // global
-    insertProperty("global.one", "one", null, null);
-    insertProperty("global.two", "two", null, null);
+    insertProperty("global.one", "one", null, null, null, null);
+    insertProperty("global.two", "two", null, null, null, null);
     // project
-    insertProperty("project.one", "Pone", projectUuid, null);
-    insertProperty("project.two", "Ptwo", projectUuid, null);
+    insertProperty("project.one", "Pone", projectUuid, null, null, projectDto.name());
+    insertProperty("project.two", "Ptwo", projectUuid, null, null, projectDto.name());
 
     List<PropertyDto> dtos = underTest.selectProjectProperties(projectDto.getDbKey());
     assertThat(dtos)
@@ -487,7 +493,7 @@ public class PropertiesDaoTest {
   @UseDataProvider("allValuesForSelect")
   public void selectProjectProperties_supports_all_values(String dbValue, String expected) {
     ComponentDto projectDto = insertPrivateProject("A");
-    insertProperty("project.one", dbValue, projectDto.uuid(), null);
+    insertProperty("project.one", dbValue, projectDto.uuid(), null, null, projectDto.name());
 
     List<PropertyDto> dtos = underTest.selectProjectProperties(projectDto.getDbKey());
     assertThat(dtos).hasSize(1);
@@ -499,7 +505,7 @@ public class PropertiesDaoTest {
 
   @DataProvider
   public static Object[][] allValuesForSelect() {
-    return new Object[][] {
+    return new Object[][]{
       {null, ""},
       {"", ""},
       {"some value", "some value"},
@@ -510,7 +516,7 @@ public class PropertiesDaoTest {
 
   @Test
   public void selectProjectProperty() {
-    insertProperty("project.one", "one", "uuid10", null);
+    insertProperty("project.one", "one", "uuid10", null, null, "component");
 
     PropertyDto property = underTest.selectProjectProperty("uuid10", "project.one");
 
@@ -522,17 +528,17 @@ public class PropertiesDaoTest {
   @Test
   public void select_by_query() {
     // global
-    insertProperty("global.one", "one", null, null);
-    insertProperty("global.two", "two", null, null);
+    insertProperty("global.one", "one", null, null, null, null);
+    insertProperty("global.two", "two", null, null, null, null);
     // struts
-    insertProperty("struts.one", "one", "uuid10", null);
+    insertProperty("struts.one", "one", "uuid10", null, null, "component");
     // commons
-    insertProperty("commonslang.one", "one", "uuid11", null);
+    insertProperty("commonslang.one", "one", "uuid11", null, null, "component");
     // user
-    insertProperty("user.one", "one", null, "100");
-    insertProperty("user.two", "two", "uuid10", "100");
+    insertProperty("user.one", "one", null, "100", "login", null);
+    insertProperty("user.two", "two", "uuid10", "100", "login", "component");
     // other
-    insertProperty("other.one", "one", "uuid12", null);
+    insertProperty("other.one", "one", "uuid12", null, null, "component");
 
     List<PropertyDto> results = underTest.selectByQuery(PropertyQuery.builder().setKey("user.two").setComponentUuid("uuid10")
       .setUserUuid("100").build(), db.getSession());
@@ -547,18 +553,18 @@ public class PropertiesDaoTest {
   @Test
   public void select_global_properties_by_keys() {
     insertPrivateProject("A");
-    String userUuid = db.users().insertUser(u -> u.setLogin("B")).getUuid();
+    UserDto user = db.users().insertUser(u -> u.setLogin("B"));
 
     String key = "key";
     String anotherKey = "anotherKey";
-    insertProperty(key, "value", null, null);
-    insertProperty(key, "value", "uuid10", null);
-    insertProperty(key, "value", null, userUuid);
-    insertProperty(anotherKey, "value", null, null);
+    insertProperty(key, "value", null, null, null, null);
+    insertProperty(key, "value", "uuid10", null, null, "component");
+    insertProperty(key, "value", null, user.getUuid(), user.getLogin(), null);
+    insertProperty(anotherKey, "value", null, null, null, null);
 
-    insertProperty("key1", "value", null, null);
-    insertProperty("key2", "value", null, null);
-    insertProperty("key3", "value", null, null);
+    insertProperty("key1", "value", null, null, null, null);
+    insertProperty("key2", "value", null, null, null, null);
+    insertProperty("key3", "value", null, null, null, null);
 
     assertThat(underTest.selectGlobalPropertiesByKeys(session, newHashSet(key)))
       .extracting("key")
@@ -586,20 +592,21 @@ public class PropertiesDaoTest {
 
     String key = "key";
     String anotherKey = "anotherKey";
-    insertProperties(
-      newGlobalPropertyDto().setKey(key),
-      newComponentPropertyDto(project).setKey(key),
-      newComponentPropertyDto(project2).setKey(key),
-      newComponentPropertyDto(project2).setKey(anotherKey),
-      newUserPropertyDto(user).setKey(key));
+    insertProperties(null, null, newGlobalPropertyDto().setKey(key));
+    insertProperties(null, project.name(), newComponentPropertyDto(project).setKey(key));
+    insertProperties(null, project2.name(), newComponentPropertyDto(project2).setKey(key),
+      newComponentPropertyDto(project2).setKey(anotherKey));
+    insertProperties(user.getLogin(), null, newUserPropertyDto(user).setKey(key));
+
+    newUserPropertyDto(user).setKey(key);
 
     assertThat(underTest.selectPropertiesByComponentUuids(session, newHashSet(project.uuid())))
       .extracting("key", "componentUuid").containsOnly(tuple(key, project.uuid()));
     assertThat(underTest.selectPropertiesByComponentUuids(session, newHashSet(project.uuid(), project2.uuid())))
       .extracting("key", "componentUuid").containsOnly(
-        tuple(key, project.uuid()),
-        tuple(key, project2.uuid()),
-        tuple(anotherKey, project2.uuid()));
+      tuple(key, project.uuid()),
+      tuple(key, project2.uuid()),
+      tuple(anotherKey, project2.uuid()));
 
     assertThat(underTest.selectPropertiesByComponentUuids(session, newHashSet("uuid123456789"))).isEmpty();
   }
@@ -612,24 +619,23 @@ public class PropertiesDaoTest {
 
     String key = "key";
     String anotherKey = "anotherKey";
-    insertProperties(
-      newGlobalPropertyDto().setKey(key),
-      newComponentPropertyDto(project).setKey(key),
-      newComponentPropertyDto(project2).setKey(key),
-      newComponentPropertyDto(project2).setKey(anotherKey),
-      newUserPropertyDto(user).setKey(key));
-
+    insertProperties(null, null, newGlobalPropertyDto().setKey(key));
+    insertProperties(null, project.name(), newComponentPropertyDto(project).setKey(key));
+    insertProperties(null, project2.name(), newComponentPropertyDto(project2).setKey(key),
+      newComponentPropertyDto(project2).setKey(anotherKey));
+    insertProperties(user.getLogin(), null, newUserPropertyDto(user).setKey(key));
+    
     assertThat(underTest.selectPropertiesByKeysAndComponentUuids(session, newHashSet(key), newHashSet(project.uuid())))
       .extracting("key", "componentUuid").containsOnly(tuple(key, project.uuid()));
     assertThat(underTest.selectPropertiesByKeysAndComponentUuids(session, newHashSet(key), newHashSet(project.uuid(), project2.uuid())))
       .extracting("key", "componentUuid").containsOnly(
-        tuple(key, project.uuid()),
-        tuple(key, project2.uuid()));
+      tuple(key, project.uuid()),
+      tuple(key, project2.uuid()));
     assertThat(underTest.selectPropertiesByKeysAndComponentUuids(session, newHashSet(key, anotherKey), newHashSet(project.uuid(), project2.uuid())))
       .extracting("key", "componentUuid").containsOnly(
-        tuple(key, project.uuid()),
-        tuple(key, project2.uuid()),
-        tuple(anotherKey, project2.uuid()));
+      tuple(key, project.uuid()),
+      tuple(key, project2.uuid()),
+      tuple(anotherKey, project2.uuid()));
 
     assertThat(underTest.selectPropertiesByKeysAndComponentUuids(session, newHashSet("unknown"), newHashSet(project.uuid()))).isEmpty();
     assertThat(underTest.selectPropertiesByKeysAndComponentUuids(session, newHashSet("key"), newHashSet("uuid123456789"))).isEmpty();
@@ -640,11 +646,10 @@ public class PropertiesDaoTest {
   public void select_by_key_and_matching_value() {
     ComponentDto project1 = db.components().insertPrivateProject();
     ComponentDto project2 = db.components().insertPrivateProject();
-    db.properties().insertProperties(
-      newComponentPropertyDto("key", "value", project1),
-      newComponentPropertyDto("key", "value", project2),
-      newGlobalPropertyDto("key", "value"),
-      newComponentPropertyDto("another key", "value", project1));
+    db.properties().insertProperties(null, project1.name(), newComponentPropertyDto("key", "value", project1));
+    db.properties().insertProperties(null, project2.name(), newComponentPropertyDto("key", "value", project2));
+    db.properties().insertProperties(null, null, newGlobalPropertyDto("key", "value"));
+    db.properties().insertProperties(null, project1.name(), newComponentPropertyDto("another key", "value", project1));
 
     assertThat(underTest.selectByKeyAndMatchingValue(db.getSession(), "key", "value"))
       .extracting(PropertyDto::getValue, PropertyDto::getComponentUuid)
@@ -661,13 +666,12 @@ public class PropertiesDaoTest {
     ComponentDto project1 = db.components().insertPrivateProject();
     ComponentDto file1 = db.components().insertComponent(ComponentTesting.newFileDto(project1));
     ComponentDto project2 = db.components().insertPrivateProject();
-    db.properties().insertProperties(
-      newPropertyDto("key", "1", project1, user1),
-      newPropertyDto("key", "2", project2, user1),
-      newPropertyDto("key", "3", file1, user1),
-      newPropertyDto("another key", "4", project1, user1),
-      newPropertyDto("key", "5", project1, user2),
-      newGlobalPropertyDto("key", "global"));
+    db.properties().insertProperties(user1.getLogin(), project1.name(), newPropertyDto("key", "1", project1, user1));
+    db.properties().insertProperties(user1.getLogin(), project2.name(), newPropertyDto("key", "2", project2, user1));
+    db.properties().insertProperties(user1.getLogin(), file1.name(), newPropertyDto("key", "3", file1, user1));
+    db.properties().insertProperties(user1.getLogin(), project1.name(), newPropertyDto("another key", "4", project1, user1));
+    db.properties().insertProperties(user2.getLogin(), project1.name(), newPropertyDto("key", "5", project1, user2));
+    db.properties().insertProperties(null, null, newGlobalPropertyDto("key", "global"));
 
     assertThat(underTest.selectByKeyAndUserUuidAndComponentQualifier(db.getSession(), "key", user1.getUuid(), "TRK"))
       .extracting(PropertyDto::getValue).containsExactlyInAnyOrder("1", "2");
@@ -786,7 +790,7 @@ public class PropertiesDaoTest {
   @Test
   @UseDataProvider("valueUpdatesDataProvider")
   public void saveProperty_deletes_then_inserts_global_properties_when_they_exist_in_db(@Nullable String oldValue, @Nullable String newValue) {
-    String uuid = insertProperty("global", oldValue, null, null);
+    String uuid = insertProperty("global", oldValue, null, null, null, null);
 
     underTest.saveProperty(new PropertyDto().setKey("global").setValue(newValue));
 
@@ -810,7 +814,7 @@ public class PropertiesDaoTest {
   @UseDataProvider("valueUpdatesDataProvider")
   public void saveProperty_deletes_then_inserts_component_properties_when_they_exist_in_db(@Nullable String oldValue, @Nullable String newValue) {
     String componentUuid = "uuid999";
-    String uuid = insertProperty("global", oldValue, componentUuid, null);
+    String uuid = insertProperty("global", oldValue, componentUuid, null, null, "component");
 
     underTest.saveProperty(new PropertyDto().setKey("global").setComponentUuid(componentUuid).setValue(newValue));
 
@@ -833,7 +837,7 @@ public class PropertiesDaoTest {
   @UseDataProvider("valueUpdatesDataProvider")
   public void saveProperty_deletes_then_inserts_user_properties_when_they_exist_in_db(@Nullable String oldValue, @Nullable String newValue) {
     String userUuid = "uuid-90";
-    String uuid = insertProperty("global", oldValue, null, userUuid);
+    String uuid = insertProperty("global", oldValue, null, userUuid, "login", null);
 
     underTest.saveProperty(new PropertyDto().setKey("global").setUserUuid(userUuid).setValue(newValue));
 
@@ -855,7 +859,7 @@ public class PropertiesDaoTest {
 
   @DataProvider
   public static Object[][] valueUpdatesDataProvider() {
-    return new Object[][] {
+    return new Object[][]{
       {null, null},
       {null, ""},
       {null, "some value"},
@@ -892,15 +896,15 @@ public class PropertiesDaoTest {
     insertPrivateProject("A");
     insertPrivateProject("B");
     insertPrivateProject("C");
-    String uuid1 = insertProperty("global.one", "one", null, null);
-    String uuid2 = insertProperty("global.two", "two", null, null);
-    String uuid3 = insertProperty("struts.one", "one", "project1", null);
-    String uuid4 = insertProperty("commonslang.one", "one", "project2", null);
-    String uuid5 = insertProperty("user.one", "one", null, "100");
-    String uuid6 = insertProperty("user.two", "two", null, "100");
-    String uuid7 = insertProperty("other.one", "one", "project3", null);
+    String uuid1 = insertProperty("global.one", "one", null, null, null, null);
+    String uuid2 = insertProperty("global.two", "two", null, null, null, null);
+    String uuid3 = insertProperty("struts.one", "one", "project1", null, null, "project1");
+    String uuid4 = insertProperty("commonslang.one", "one", "project2", null, null, "project2");
+    String uuid5 = insertProperty("user.one", "one", null, "100", "login", null);
+    String uuid6 = insertProperty("user.two", "two", null, "100", "login", null);
+    String uuid7 = insertProperty("other.one", "one", "project3", null, null, "project3");
 
-    underTest.deleteProjectProperty("struts.one", "project1");
+    underTest.deleteProjectProperty("struts.one", "project1", "project1");
 
     assertThatPropertiesRowByUuid(uuid1)
       .hasKey("global.one")
@@ -938,14 +942,14 @@ public class PropertiesDaoTest {
 
   @Test
   public void delete_project_properties() {
-    String uuid1 = insertProperty("sonar.profile.java", "Sonar Way", "uuid1", null);
-    String uuid2 = insertProperty("sonar.profile.java", "Sonar Way", "uuid2", null);
+    String uuid1 = insertProperty("sonar.profile.java", "Sonar Way", "uuid1", null, null, "component");
+    String uuid2 = insertProperty("sonar.profile.java", "Sonar Way", "uuid2", null, null, "component");
 
-    String uuid3 = insertProperty("sonar.profile.java", "Sonar Way", null, null);
+    String uuid3 = insertProperty("sonar.profile.java", "Sonar Way", null, null, null, "component");
 
-    String uuid4 = insertProperty("sonar.profile.js", "Sonar Way", "uuid1", null);
-    String uuid5 = insertProperty("sonar.profile.js", "Sonar Way", "uuid2", null);
-    String uuid6 = insertProperty("sonar.profile.js", "Sonar Way", null, null);
+    String uuid4 = insertProperty("sonar.profile.js", "Sonar Way", "uuid1", null, null, "component");
+    String uuid5 = insertProperty("sonar.profile.js", "Sonar Way", "uuid2", null, null, "component");
+    String uuid6 = insertProperty("sonar.profile.js", "Sonar Way", null, null, null, "component");
 
     underTest.deleteProjectProperties("sonar.profile.java", "Sonar Way");
 
@@ -978,12 +982,12 @@ public class PropertiesDaoTest {
   @Test
   public void deleteGlobalProperty() {
     // global
-    String uuid1 = insertProperty("global.key", "new_global", null, null);
-    String uuid2 = insertProperty("to_be_deleted", "xxx", null, null);
+    String uuid1 = insertProperty("global.key", "new_global", null, null, null, null);
+    String uuid2 = insertProperty("to_be_deleted", "xxx", null, null, null, null);
     // project - do not delete this project property that has the same key
-    String uuid3 = insertProperty("to_be_deleted", "new_project", "to_be_deleted", null);
+    String uuid3 = insertProperty("to_be_deleted", "new_project", "to_be_deleted", null, null, "component");
     // user
-    String uuid4 = insertProperty("user.key", "new_user", null, "100");
+    String uuid4 = insertProperty("user.key", "new_user", null, "100", "login", null);
 
     underTest.deleteGlobalProperty("to_be_deleted");
 
@@ -1014,12 +1018,12 @@ public class PropertiesDaoTest {
     ComponentDto anotherProject = db.components().insertPrivateProject();
     UserDto user = db.users().insertUser();
     UserDto anotherUser = db.users().insertUser();
-    insertProperty("KEY_11", "VALUE", project.uuid(), user.getUuid());
-    insertProperty("KEY_12", "VALUE", project.uuid(), user.getUuid());
-    insertProperty("KEY_11", "VALUE", project.uuid(), anotherUser.getUuid());
-    insertProperty("KEY_11", "VALUE", anotherProject.uuid(), user.getUuid());
+    insertProperty("KEY_11", "VALUE", project.uuid(), user.getUuid(), user.getLogin(), project.name());
+    insertProperty("KEY_12", "VALUE", project.uuid(), user.getUuid(), user.getLogin(), project.name());
+    insertProperty("KEY_11", "VALUE", project.uuid(), anotherUser.getUuid(), anotherUser.getLogin(), project.name());
+    insertProperty("KEY_11", "VALUE", anotherProject.uuid(), user.getUuid(), user.getLogin(), anotherProject.name());
 
-    underTest.deleteByUser(session, user.getUuid());
+    underTest.deleteByUser(session, user.getUuid(), user.getLogin());
 
     assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(project.uuid()).build(), session))
       .hasSize(1)
@@ -1034,10 +1038,10 @@ public class PropertiesDaoTest {
     ComponentDto anotherProject = db.components().insertPrivateProject();
     UserDto user = db.users().insertUser();
     UserDto anotherUser = db.users().insertUser();
-    insertProperty("KEY_11", user.getLogin(), project.uuid(), null);
-    insertProperty("KEY_12", user.getLogin(), project.uuid(), null);
-    insertProperty("KEY_11", anotherUser.getLogin(), project.uuid(), null);
-    insertProperty("KEY_11", user.getLogin(), anotherProject.uuid(), null);
+    insertProperty("KEY_11", user.getLogin(), project.uuid(), null, null, project.name());
+    insertProperty("KEY_12", user.getLogin(), project.uuid(), null, null, project.name());
+    insertProperty("KEY_11", anotherUser.getLogin(), project.uuid(), null, null, project.name());
+    insertProperty("KEY_11", user.getLogin(), anotherProject.uuid(), null, null, anotherProject.name());
 
     underTest.deleteByMatchingLogin(session, user.getLogin(), newArrayList("KEY_11", "KEY_12"));
 
@@ -1052,14 +1056,14 @@ public class PropertiesDaoTest {
   public void delete_by_key_and_value() {
     ComponentDto project = db.components().insertPrivateProject();
     ComponentDto anotherProject = db.components().insertPrivateProject();
-    insertProperty("KEY", "VALUE", null, null);
-    insertProperty("KEY", "VALUE", project.uuid(), null);
-    insertProperty("KEY", "VALUE", null, "100");
-    insertProperty("KEY", "VALUE", project.uuid(), "100");
-    insertProperty("KEY", "VALUE", anotherProject.uuid(), null);
+    insertProperty("KEY", "VALUE", null, null, null, null);
+    insertProperty("KEY", "VALUE", project.uuid(), null, null, project.name());
+    insertProperty("KEY", "VALUE", null, "100", "login", null);
+    insertProperty("KEY", "VALUE", project.uuid(), "100", "login", project.name());
+    insertProperty("KEY", "VALUE", anotherProject.uuid(), null, null, anotherProject.name());
     // Should not be removed
-    insertProperty("KEY", "ANOTHER_VALUE", null, null);
-    insertProperty("ANOTHER_KEY", "VALUE", project.uuid(), "100");
+    insertProperty("KEY", "ANOTHER_VALUE", null, null, null, null);
+    insertProperty("ANOTHER_KEY", "VALUE", project.uuid(), "100", "login", project.name());
 
     underTest.deleteByKeyAndValue(session, "KEY", "VALUE");
     db.commit();
@@ -1107,7 +1111,7 @@ public class PropertiesDaoTest {
 
   @Test
   public void saveGlobalProperties_delete_and_insert_new_value_when_property_exists_in_db() {
-    String uuid = insertProperty("to_be_updated", "old_value", null, null);
+    String uuid = insertProperty("to_be_updated", "old_value", null, null, null, null);
 
     underTest.saveGlobalProperties(ImmutableMap.of("to_be_updated", "new value"));
 
@@ -1133,12 +1137,12 @@ public class PropertiesDaoTest {
 
   @Test
   public void renamePropertyKey_updates_global_component_and_user_properties() {
-    String uuid1 = insertProperty("foo", "bar", null, null);
-    String uuid2 = insertProperty("old_name", "doc1", null, null);
-    String uuid3 = insertProperty("old_name", "doc2", "15", null);
-    String uuid4 = insertProperty("old_name", "doc3", "16", null);
-    String uuid5 = insertProperty("old_name", "doc4", null, "100");
-    String uuid6 = insertProperty("old_name", "doc5", null, "101");
+    String uuid1 = insertProperty("foo", "bar", null, null, null, null);
+    String uuid2 = insertProperty("old_name", "doc1", null, null, null, null);
+    String uuid3 = insertProperty("old_name", "doc2", "15", null, null, "component");
+    String uuid4 = insertProperty("old_name", "doc3", "16", null, null, "component");
+    String uuid5 = insertProperty("old_name", "doc4", null, "100", "login", null);
+    String uuid6 = insertProperty("old_name", "doc5", null, "101", "login", null);
 
     underTest.renamePropertyKey("old_name", "new_name");
 
@@ -1182,7 +1186,7 @@ public class PropertiesDaoTest {
 
   @Test
   public void rename_to_same_key_has_no_effect() {
-    String uuid = insertProperty("foo", "bar", null, null);
+    String uuid = insertProperty("foo", "bar", null, null, null, null);
 
     assertThatPropertiesRowByUuid(uuid)
       .hasCreatedAt(INITIAL_DATE);
@@ -1218,19 +1222,20 @@ public class PropertiesDaoTest {
     return null;
   }
 
-  private void insertProperties(PropertyDto... properties) {
+  private void insertProperties(@Nullable String userLogin, @Nullable String projectName, PropertyDto... properties) {
     for (PropertyDto propertyDto : properties) {
-      underTest.saveProperty(session, propertyDto);
+      underTest.saveProperty(session, propertyDto, userLogin, projectName);
     }
     session.commit();
   }
 
-  private String insertProperty(String key, @Nullable String value, @Nullable String componentUuid, @Nullable String userUuid) {
+  private String insertProperty(String key, @Nullable String value, @Nullable String componentUuid, @Nullable String userUuid,
+    @Nullable String userLogin, @Nullable String projectName) {
     PropertyDto dto = new PropertyDto().setKey(key)
       .setComponentUuid(componentUuid)
       .setUserUuid(userUuid)
       .setValue(value);
-    db.properties().insertProperty(dto);
+    db.properties().insertProperty(dto, projectName, userLogin);
 
     return (String) db.selectFirst(session, "select uuid as \"uuid\" from properties" +
       " where prop_key='" + key + "'" +
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoWithPersisterTest.java
new file mode 100644 (file)
index 0000000..d0349a5
--- /dev/null
@@ -0,0 +1,429 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.property;
+
+import com.tngtech.java.junit.dataprovider.DataProviderRunner;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.PropertyNewValue;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.user.UserDto;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.assertj.core.api.Assertions.assertThat;
+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;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+@RunWith(DataProviderRunner.class)
+public class PropertiesDaoWithPersisterTest {
+  private static final String KEY = "key";
+  private static final String ANOTHER_KEY = "another_key";
+  private static final String PROJECT_NAME = "project_name";
+  private static final String PROJECT_UUID = "project_uuid";
+  private static final String SECURED_KEY = "key.secured";
+  private static final String USER_LOGIN = "user_login";
+  private static final String USER_UUID = "user_uuid";
+  private static final String VALUE = "value";
+
+  private static final long INITIAL_DATE = 1_444_000L;
+
+  private final AlwaysIncreasingSystem2 system2 = new AlwaysIncreasingSystem2(INITIAL_DATE, 1);
+
+  private final AuditPersister auditPersister = mock(AuditPersister.class);
+  private final ArgumentCaptor<PropertyNewValue> newValueCaptor = ArgumentCaptor.forClass(PropertyNewValue.class);
+
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+  @Rule
+  public DbTester db = DbTester.create(system2, auditPersister);
+
+  private final DbClient dbClient = db.getDbClient();
+  private final DbSession session = db.getSession();
+  private final PropertiesDao underTest = dbClient.propertiesDao();
+
+  @Test
+  public void saveGlobalTrackedPropertyIsPersisted() {
+    when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+    underTest.saveProperty(new PropertyDto().setKey(KEY).setValue(VALUE));
+
+    verify(auditPersister).isTrackedProperty(KEY);
+    verify(auditPersister).addProperty(any(), newValueCaptor.capture(), eq(false));
+
+    PropertyNewValue newValue = newValueCaptor.getValue();
+
+    assertThat(newValue)
+      .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+        PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin)
+      .containsExactly(KEY, VALUE, null, null);
+    assertThat(newValue.toString()).doesNotContain("projectUuid");
+  }
+
+  @Test
+  public void saveGlobalNotTrackedPropertyIsNotPersisted() {
+    when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+
+    underTest.saveProperty(new PropertyDto().setKey(KEY).setValue(VALUE));
+
+    verify(auditPersister).isTrackedProperty(KEY);
+    verifyNoMoreInteractions(auditPersister);
+  }
+
+  @Test
+  public void saveGlobalTrackedAndSecuredPropertyIsPersisted() {
+    when(auditPersister.isTrackedProperty(SECURED_KEY)).thenReturn(true);
+
+    underTest.saveProperty(new PropertyDto().setKey(SECURED_KEY).setValue(VALUE));
+
+    verify(auditPersister).isTrackedProperty(SECURED_KEY);
+    verify(auditPersister).addProperty(any(), newValueCaptor.capture(), eq(false));
+    PropertyNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+        PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin)
+      .containsExactly(SECURED_KEY, null, null, null);
+    assertThat(newValue.toString()).doesNotContain("projectUuid");
+  }
+
+  @Test
+  public void saveProjectTrackedPropertyIsPersisted() {
+    when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+
+    PropertyDto propertyDto = getPropertyDto(KEY);
+    underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_NAME);
+
+    verify(auditPersister).isTrackedProperty(KEY);
+    verify(auditPersister).addProperty(any(), newValueCaptor.capture(), eq(false));
+    PropertyNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+        PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+        PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+      .containsExactly(propertyDto.getKey(), propertyDto.getValue(), propertyDto.getUserUuid(),
+        USER_LOGIN, propertyDto.getComponentUuid(), PROJECT_NAME);
+    assertThat(newValue.toString()).contains("projectUuid");
+  }
+
+  @Test
+  public void saveProjectTrackedAndSecuredPropertyIsPersisted() {
+    when(auditPersister.isTrackedProperty(SECURED_KEY)).thenReturn(true);
+
+    PropertyDto propertyDto = getPropertyDto(SECURED_KEY);
+    underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_NAME);
+
+    verify(auditPersister).isTrackedProperty(SECURED_KEY);
+    verify(auditPersister).addProperty(any(), newValueCaptor.capture(), eq(false));
+    PropertyNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+        PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+        PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+      .containsExactly(propertyDto.getKey(), null, propertyDto.getUserUuid(),
+        USER_LOGIN, propertyDto.getComponentUuid(), PROJECT_NAME);
+    assertThat(newValue.toString()).contains("projectUuid");
+  }
+
+  @Test
+  public void deleteTrackedPropertyByQueryIsPersisted() {
+    when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+
+    PropertyQuery query = getPropertyQuery(KEY);
+    underTest.deleteByQuery(session, query);
+
+    verify(auditPersister).isTrackedProperty(KEY);
+    verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
+    PropertyNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+        PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+        PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+      .containsExactly(query.key(), null, query.userUuid(),
+        null, query.componentUuid(), null);
+    assertThat(newValue.toString()).doesNotContain("userLogin");
+  }
+
+  @Test
+  public void deleteNotTrackedPropertyByQueryIsNotPersisted() {
+    when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+
+    PropertyQuery query = getPropertyQuery(KEY);
+    underTest.deleteByQuery(session, query);
+
+    verify(auditPersister).isTrackedProperty(KEY);
+    verifyNoMoreInteractions(auditPersister);
+  }
+
+  @Test
+  public void deleteTrackedPropertyIsPersisted() {
+    when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+
+    PropertyDto propertyDto = getPropertyDto(KEY);
+    underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_NAME);
+
+    verify(auditPersister).isTrackedProperty(KEY);
+    verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
+    PropertyNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+        PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+        PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+      .containsExactly(propertyDto.getKey(), propertyDto.getValue(), propertyDto.getUserUuid(),
+        USER_LOGIN, propertyDto.getComponentUuid(), PROJECT_NAME);
+    assertThat(newValue.toString()).contains("userLogin");
+  }
+
+  @Test
+  public void deleteNotTrackedPropertyIsNotPersisted() {
+    when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+
+    PropertyDto propertyDto = getPropertyDto(KEY);
+    underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_NAME);
+
+    verify(auditPersister).isTrackedProperty(KEY);
+    verifyNoMoreInteractions(auditPersister);
+  }
+
+  @Test
+  public void deleteTrackedProjectPropertyIsPersisted() {
+    when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+    underTest.deleteProjectProperty(KEY, PROJECT_UUID, PROJECT_NAME);
+
+    verify(auditPersister).isTrackedProperty(KEY);
+    verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
+    PropertyNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+        PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+        PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+      .containsExactly(KEY, null, null,
+        null, PROJECT_UUID, PROJECT_NAME);
+    assertThat(newValue.toString()).doesNotContain("userLogin");
+  }
+
+  @Test
+  public void deleteNotTrackedProjectPropertyIsNotPersisted() {
+    when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+
+    PropertyDto propertyDto = getPropertyDto(KEY);
+    underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_NAME);
+
+    verify(auditPersister).isTrackedProperty(KEY);
+    verifyNoMoreInteractions(auditPersister);
+  }
+
+  @Test
+  public void deleteTrackedProjectPropertiesIsPersisted() {
+    when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+
+    underTest.deleteProjectProperties(KEY, VALUE);
+
+    verify(auditPersister).isTrackedProperty(KEY);
+    verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
+    PropertyNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+        PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+        PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+      .containsExactly(KEY, VALUE, null,
+        null, null, null);
+    assertThat(newValue.toString()).doesNotContain("projectUuid");
+  }
+
+  @Test
+  public void deleteNotTrackedProjectPropertiesIsNotPersisted() {
+    when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+
+    underTest.deleteProjectProperties(KEY, VALUE);
+
+    verify(auditPersister).isTrackedProperty(KEY);
+    verifyNoMoreInteractions(auditPersister);
+  }
+
+  @Test
+  public void deleteTrackedGlobalPropertyIsPersisted() {
+    when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+
+    underTest.deleteGlobalProperty(KEY, session);
+
+    verify(auditPersister).isTrackedProperty(KEY);
+    verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
+    PropertyNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+        PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+        PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+      .containsExactly(KEY, null, null,
+        null, null, null);
+    assertThat(newValue.toString()).doesNotContain("projectUuid");
+  }
+
+  @Test
+  public void deleteNotTrackedGlobalPropertyIsNotPersisted() {
+    when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+
+    underTest.deleteGlobalProperty(KEY, session);
+
+    verify(auditPersister).isTrackedProperty(KEY);
+    verifyNoMoreInteractions(auditPersister);
+  }
+
+  @Test
+  public void deletePropertyByUserIsPersisted() {
+    UserDto user = setUserProperties(VALUE);
+    underTest.deleteByUser(session, user.getUuid(), user.getLogin());
+
+    verify(auditPersister, times(2)).isTrackedProperty(KEY);
+    verify(auditPersister, times(2)).isTrackedProperty(ANOTHER_KEY);
+    verify(auditPersister, times(2)).isTrackedProperty(SECURED_KEY);
+    verify(auditPersister, times(2)).deleteProperty(any(), newValueCaptor.capture(), eq(false));
+    List<PropertyNewValue> newValues = newValueCaptor.getAllValues();
+    assertThat(newValues.get(0))
+      .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+        PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+        PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+      .containsExactly(KEY, null, user.getUuid(),
+        user.getLogin(), null, null);
+    assertThat(newValues.get(0).toString()).contains("userUuid");
+    assertThat(newValues.get(1))
+      .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+        PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+        PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+      .containsExactly(SECURED_KEY, null, user.getUuid(),
+        user.getLogin(), null, null);
+    assertThat(newValues.get(1).toString()).doesNotContain("value");
+  }
+
+  @Test
+  public void deletePropertyByUserLoginIsPersisted() {
+    UserDto user = setUserProperties(null);
+    underTest.deleteByMatchingLogin(session, user.getLogin(), newArrayList(KEY, ANOTHER_KEY, SECURED_KEY));
+
+    verify(auditPersister, times(2)).isTrackedProperty(KEY);
+    verify(auditPersister, times(2)).isTrackedProperty(ANOTHER_KEY);
+    verify(auditPersister, times(2)).isTrackedProperty(SECURED_KEY);
+    verify(auditPersister, times(2)).deleteProperty(any(), newValueCaptor.capture(), eq(false));
+    List<PropertyNewValue> newValues = newValueCaptor.getAllValues();
+    assertThat(newValues.get(0))
+      .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+        PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+        PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+      .containsExactly(KEY, null, null,
+        user.getLogin(), null, null);
+    assertThat(newValues.get(0).toString()).contains("userLogin");
+    assertThat(newValues.get(1))
+      .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+        PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+        PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+      .containsExactly(SECURED_KEY, null, null,
+        user.getLogin(), null, null);
+    assertThat(newValues.get(1).toString()).doesNotContain("value");
+  }
+
+  @Test
+  public void deleteTrackedPropertyByKeyAndValueIsPersisted() {
+    when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+
+    underTest.deleteByKeyAndValue(session, KEY, VALUE);
+
+    verify(auditPersister).isTrackedProperty(KEY);
+    verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
+    PropertyNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue,
+        PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin,
+        PropertyNewValue::getProjectUuid, PropertyNewValue::getProjectName)
+      .containsExactly(KEY, VALUE, null,
+        null, null, null);
+    assertThat(newValue.toString()).doesNotContain("projectUuid");
+  }
+
+  @Test
+  public void deleteNotTrackedPropertyByKeyAndValueIsNotPersisted() {
+    when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+
+    underTest.deleteByKeyAndValue(session, KEY, VALUE);
+
+    verify(auditPersister).isTrackedProperty(KEY);
+    verifyNoMoreInteractions(auditPersister);
+  }
+
+  private PropertyDto getPropertyDto(String key) {
+    return new PropertyDto()
+      .setKey(key)
+      .setValue(VALUE)
+      .setUserUuid(USER_UUID)
+      .setComponentUuid(PROJECT_UUID);
+  }
+
+  private PropertyQuery getPropertyQuery(String key) {
+    return PropertyQuery.builder()
+      .setKey(key)
+      .setComponentUuid(PROJECT_UUID)
+      .setUserUuid(USER_UUID)
+      .build();
+  }
+
+  private UserDto setUserProperties(@Nullable String value) {
+    when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+    when(auditPersister.isTrackedProperty(ANOTHER_KEY)).thenReturn(false);
+    when(auditPersister.isTrackedProperty(SECURED_KEY)).thenReturn(true);
+
+    ComponentDto project = db.components().insertPrivateProject();
+    UserDto user = db.users().insertUser();
+
+    if (value == null) {
+      value = user.getLogin();
+    }
+
+    PropertyDto dto1 = new PropertyDto().setKey(KEY)
+      .setComponentUuid(project.uuid())
+      .setUserUuid(user.getUuid())
+      .setValue(value);
+    PropertyDto dto2 = new PropertyDto().setKey(ANOTHER_KEY)
+      .setComponentUuid(project.uuid())
+      .setUserUuid(user.getUuid())
+      .setValue(value);
+    PropertyDto dto3 = new PropertyDto().setKey(SECURED_KEY)
+      .setComponentUuid(project.uuid())
+      .setUserUuid(user.getUuid())
+      .setValue(value);
+    db.properties().insertProperty(dto1, project.name(), user.getLogin());
+    db.properties().insertProperty(dto2, project.name(), user.getLogin());
+    db.properties().insertProperty(dto3, project.name(), user.getLogin());
+    List<PropertyDto> list = db.getDbClient().propertiesDao().selectByKeyAndMatchingValue(session, KEY, VALUE);
+    list = db.getDbClient().propertiesDao().selectByKeyAndMatchingValue(session, ANOTHER_KEY, VALUE);
+    list = db.getDbClient().propertiesDao().selectByKeyAndMatchingValue(session, SECURED_KEY, VALUE);
+    return user;
+  }
+}
index 6157294c7a965d3bc5e991b622a1634c75a90ce9..89ae1e1c96dc98ebb9d2854bd165225109d6a141 100644 (file)
@@ -391,7 +391,7 @@ public class PurgeDaoTest {
 
   @Test
   public void selectPurgeableAnalyses() {
-    SnapshotDto[] analyses = new SnapshotDto[] {
+    SnapshotDto[] analyses = new SnapshotDto[]{
       newSnapshot()
         .setUuid("u1")
         .setComponentUuid(PROJECT_UUID)
@@ -1618,9 +1618,10 @@ public class PurgeDaoTest {
 
   private void insertPropertyFor(ComponentDto... components) {
     Stream.of(components).forEach(componentDto -> db.properties().insertProperty(new PropertyDto()
-      .setKey(randomAlphabetic(3))
-      .setValue(randomAlphabetic(3))
-      .setComponentUuid(componentDto.uuid())));
+        .setKey(randomAlphabetic(3))
+        .setValue(randomAlphabetic(3))
+        .setComponentUuid(componentDto.uuid()),
+      componentDto.name(), null));
   }
 
   private Stream<String> getComponentUuidsOfMeasures() {
index 1cd59a54b45875b85707a28d366d43847d061de8..936a8993b753c170721b96a526ae30571db7caaa 100644 (file)
@@ -62,7 +62,7 @@ public class GroupDaoWithPersisterTest {
   }
 
   @Test
-  public void insert_and_update() {
+  public void insertAndUpdateGroupIsPersisted() {
     dbClient.groupDao().insert(db.getSession(), aGroup);
 
     verify(auditPersister).addUserGroup(eq(db.getSession()), newValueCaptor.capture());
@@ -72,7 +72,7 @@ public class GroupDaoWithPersisterTest {
     assertThat(newValue)
       .extracting(UserGroupNewValue::getGroupUuid, UserGroupNewValue::getName)
       .containsExactly(aGroup.getUuid(), aGroup.getName());
-    assertThat(newValue.toString()).doesNotContain("'description':");
+    assertThat(newValue.toString()).doesNotContain("description");
 
     GroupDto dto = new GroupDto()
       .setUuid(aGroup.getUuid())
@@ -87,11 +87,11 @@ public class GroupDaoWithPersisterTest {
     assertThat(newValue)
       .extracting(UserGroupNewValue::getGroupUuid, UserGroupNewValue::getName, UserGroupNewValue::getDescription)
       .containsExactly(dto.getUuid(), dto.getName(), dto.getDescription());
-    assertThat(newValue.toString()).contains("'description':");
+    assertThat(newValue.toString()).contains("description");
   }
 
   @Test
-  public void deleteByUuid() {
+  public void deleteGroupIsPersisted() {
     dbClient.groupDao().insert(db.getSession(), aGroup);
 
     verify(auditPersister).addUserGroup(eq(db.getSession()), any());
index 541b9b3c07ae3924ef167be184d5d90cfb09e842..695a3e49dad6569d44fd6ba2fa169be043b6b448 100644 (file)
@@ -54,7 +54,7 @@ public class UserDaoWithPersisterTest {
   private final UserDao underTest = db.getDbClient().userDao();
 
   @Test
-  public void insert_user_with_default_values() {
+  public void insertUserIsPersisted() {
     UserDto userDto = new UserDto()
       .setLogin("john")
       .setName("John")
@@ -71,11 +71,11 @@ public class UserDaoWithPersisterTest {
     assertThat(newValue)
       .extracting(UserNewValue::getUserUuid, UserNewValue::getLogin)
       .containsExactly(user.getUuid(), user.getLogin());
-    assertThat(newValue.toString()).doesNotContain("'name':");
+    assertThat(newValue.toString()).doesNotContain("name");
   }
 
   @Test
-  public void update_user() {
+  public void updateUserIsPersisted() {
     UserDto user = db.users().insertUser(u -> u
       .setLogin("john")
       .setName("John")
@@ -114,11 +114,11 @@ public class UserDaoWithPersisterTest {
       .containsExactly(updatedUser.getUuid(), updatedUser.getLogin(), updatedUser.getName(), updatedUser.getEmail(), updatedUser.isActive(),
         updatedUser.getScmAccounts(), updatedUser.getExternalId(), updatedUser.getExternalLogin(), updatedUser.getExternalIdentityProvider(),
         updatedUser.isLocal(), updatedUser.isOnboarded(), updatedUser.isRoot(), updatedUser.getLastConnectionDate());
-    assertThat(newValue.toString()).contains("'name':");
+    assertThat(newValue.toString()).contains("name");
   }
 
   @Test
-  public void update_user_without_track() {
+  public void updateUserWithoutTrackIsNotPersisted() {
     UserDto user = db.users().insertUser(u -> u
       .setLogin("john")
       .setName("John")
@@ -139,7 +139,7 @@ public class UserDaoWithPersisterTest {
   }
 
   @Test
-  public void deactivate_user() {
+  public void deactivateUserIsPersisted() {
     UserDto user = insertActiveUser();
     insertUserGroup(user);
     underTest.update(db.getSession(), user.setLastConnectionDate(10_000_000_000L));
index 942de92882da0b9aa1b1492eaaa45fd67e2e3d01..f46b107377e56e6e4adbcc257996344dca7c356e 100644 (file)
@@ -46,7 +46,7 @@ public class UserGroupDaoWithPersisterTest {
   private final UserGroupDao underTest = dbClient.userGroupDao();
 
   @Test
-  public void insert() {
+  public void insertUserGroupIsPersisted() {
     UserDto user = db.users().insertUser();
 
     verify(auditPersister).addUser(eq(db.getSession()), any());
@@ -64,7 +64,7 @@ public class UserGroupDaoWithPersisterTest {
   }
 
   @Test
-  public void delete_members_by_group_uuid() {
+  public void deleteUserGroupByGroupIsPersisted() {
     UserDto user1 = db.users().insertUser();
     UserDto user2 = db.users().insertUser();
     GroupDto group1 = db.users().insertGroup();
@@ -85,7 +85,7 @@ public class UserGroupDaoWithPersisterTest {
   }
 
   @Test
-  public void delete_by_user() {
+  public void deleteUserGroupByUserIsPersisted() {
     UserDto user1 = db.users().insertUser();
     UserDto user2 = db.users().insertUser();
     GroupDto group1 = db.users().insertGroup();
index fbf81f564a6a7e6cc9bc09ffb5cb8dfff6da2324..1d74a380629a37d71184ecf89d0a643190fe231b 100644 (file)
@@ -52,7 +52,7 @@ public class UserPropertiesDaoWithPersisterTest {
   private UserPropertiesDao underTest = db.getDbClient().userPropertiesDao();
 
   @Test
-  public void insert_tracked_property() {
+  public void insertTrackedUserPropertyIsPersisted() {
     when(auditPersister.isTrackedProperty(PROPERTY_KEY)).thenReturn(true);
 
     UserDto user = db.users().insertUser();
@@ -65,7 +65,7 @@ public class UserPropertiesDaoWithPersisterTest {
         .setValue("a_value"),
       user.getLogin());
 
-    verify(auditPersister).addUserProperty(eq(db.getSession()), newValueCaptor.capture());
+    verify(auditPersister).addProperty(eq(db.getSession()), newValueCaptor.capture(), eq(true));
     verify(auditPersister).isTrackedProperty(PROPERTY_KEY);
     assertThat(newValueCaptor.getValue())
       .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid,
@@ -75,7 +75,7 @@ public class UserPropertiesDaoWithPersisterTest {
   }
 
   @Test
-  public void insert_tracked_secured_property() {
+  public void insertTrackedAndSecuredUserPropertyIsPersisted() {
     when(auditPersister.isTrackedProperty(SECURED_PROPERTY_KEY)).thenReturn(true);
 
     UserDto user = db.users().insertUser();
@@ -89,17 +89,17 @@ public class UserPropertiesDaoWithPersisterTest {
       user.getLogin());
 
     verify(auditPersister).isTrackedProperty(SECURED_PROPERTY_KEY);
-    verify(auditPersister).addUserProperty(eq(db.getSession()), newValueCaptor.capture());
+    verify(auditPersister).addProperty(eq(db.getSession()), newValueCaptor.capture(), eq(true));
     PropertyNewValue newValue = newValueCaptor.getValue();
     assertThat(newValue)
       .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid,
         PropertyNewValue::getUserLogin)
       .containsExactly(userSetting.getKey(), null, user.getUuid(), user.getLogin());
-    assertThat(newValue.toString()).doesNotContain("'propertyValue':");
+    assertThat(newValue.toString()).doesNotContain("propertyValue");
   }
 
   @Test
-  public void insert_not_tracked_property() {
+  public void insertNotTrackedUserPropertyIsNotPersisted() {
     when(auditPersister.isTrackedProperty(PROPERTY_KEY)).thenReturn(false);
 
     UserDto user = db.users().insertUser();
@@ -115,7 +115,7 @@ public class UserPropertiesDaoWithPersisterTest {
   }
 
   @Test
-  public void update() {
+  public void updateTrackedUserPropertyIsPersisted() {
     when(auditPersister.isTrackedProperty(PROPERTY_KEY)).thenReturn(true);
 
     UserDto user = db.users().insertUser();
@@ -132,8 +132,8 @@ public class UserPropertiesDaoWithPersisterTest {
       user.getLogin());
 
     verify(auditPersister).addUser(eq(db.getSession()), any());
-    verify(auditPersister).addUserProperty(eq(db.getSession()), any());
-    verify(auditPersister).updateUserProperty(eq(db.getSession()), newValueCaptor.capture());
+    verify(auditPersister).addProperty(eq(db.getSession()), any(), eq(true));
+    verify(auditPersister).updateProperty(eq(db.getSession()), newValueCaptor.capture(), eq(true));
     assertThat(newValueCaptor.getValue())
       .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid,
         PropertyNewValue::getUserLogin)
@@ -141,7 +141,7 @@ public class UserPropertiesDaoWithPersisterTest {
   }
 
   @Test
-  public void delete_by_user() {
+  public void deleteTrackedUserPropertyIsPersisted() {
     when(auditPersister.isTrackedProperty(PROPERTY_KEY)).thenReturn(true);
     when(auditPersister.isTrackedProperty(SECURED_PROPERTY_KEY)).thenReturn(false);
 
@@ -159,11 +159,11 @@ public class UserPropertiesDaoWithPersisterTest {
     underTest.deleteByUser(db.getSession(), user);
 
     verify(auditPersister).addUser(eq(db.getSession()), any());
-    verify(auditPersister).addUserProperty(eq(db.getSession()), any());
-    verify(auditPersister).addUserProperty(eq(db.getSession()), any());
+    verify(auditPersister).addProperty(eq(db.getSession()), any(), eq(true));
+    verify(auditPersister).addProperty(eq(db.getSession()), any(), eq(true));
     verify(auditPersister, times(2)).isTrackedProperty(PROPERTY_KEY);
     verify(auditPersister, times(2)).isTrackedProperty(SECURED_PROPERTY_KEY);
-    verify(auditPersister).deleteUserProperty(eq(db.getSession()), newValueCaptor.capture());
+    verify(auditPersister).deleteProperty(eq(db.getSession()), newValueCaptor.capture(), eq(true));
     verifyNoMoreInteractions(auditPersister);
     assertThat(newValueCaptor.getValue())
       .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid,
index 6e8df27c40e4dac6ca1b4249e932456af92e3dc0..b2dd97a6243aee319a4f6f366dd944f3a47432dd 100644 (file)
@@ -66,7 +66,7 @@ public class UserTokenDaoWithPersisterTest {
     assertThat(newValue)
       .extracting(UserTokenNewValue::getTokenUuid, UserTokenNewValue::getTokenName, UserTokenNewValue::getUserUuid, UserTokenNewValue::getLastConnectionDate)
       .containsExactly(userToken.getUuid(), userToken.getName(), userToken.getUserUuid(), userToken.getLastConnectionDate());
-    assertThat(newValue.toString()).contains("'tokenUuid':");
+    assertThat(newValue.toString()).contains("tokenUuid");
   }
 
   @Test
index 54161f2a626971b56cef11dee201d4385662c8f4..aed697b2e193a2b3df99419d8dfcd6132186f0f2 100644 (file)
@@ -82,7 +82,7 @@ public class WebhookDaoTest {
       .setUrl("URL_1")
       .setSecret("a_secret");
 
-    underTest.insert(dbSession, dto);
+    underTest.insert(dbSession, dto, null);
 
     WebhookDto stored = selectByUuid(dto.getUuid());
 
@@ -104,7 +104,7 @@ public class WebhookDaoTest {
       .setProjectUuid("UUID_2")
       .setSecret("a_secret");
 
-    underTest.insert(dbSession, dto);
+    underTest.insert(dbSession, dto, "project_name");
 
     WebhookDto reloaded = selectByUuid(dto.getUuid());
 
@@ -122,9 +122,10 @@ public class WebhookDaoTest {
     WebhookDto dto = webhookDbTester.insertGlobalWebhook();
 
     underTest.update(dbSession, dto
-      .setName("a-fancy-webhook")
-      .setUrl("http://www.fancy-webhook.io")
-      .setSecret(null));
+        .setName("a-fancy-webhook")
+        .setUrl("http://www.fancy-webhook.io")
+        .setSecret(null),
+      null);
 
     Optional<WebhookDto> optionalResult = underTest.selectByUuid(dbSession, dto.getUuid());
     assertThat(optionalResult).isPresent();
@@ -143,9 +144,10 @@ public class WebhookDaoTest {
     WebhookDto dto = webhookDbTester.insertGlobalWebhook();
 
     underTest.update(dbSession, dto
-      .setName("a-fancy-webhook")
-      .setUrl("http://www.fancy-webhook.io")
-      .setSecret("a_new_secret"));
+        .setName("a-fancy-webhook")
+        .setUrl("http://www.fancy-webhook.io")
+        .setSecret("a_new_secret"),
+      null);
 
     Optional<WebhookDto> optionalResult = underTest.selectByUuid(dbSession, dto.getUuid());
     assertThat(optionalResult).isPresent();
@@ -177,7 +179,7 @@ public class WebhookDaoTest {
   public void delete() {
     WebhookDto dto = webhookDbTester.insertGlobalWebhook();
 
-    underTest.delete(dbSession, dto.getUuid());
+    underTest.delete(dbSession, dto.getUuid(), dto.getName());
 
     Optional<WebhookDto> reloaded = underTest.selectByUuid(dbSession, dto.getUuid());
     assertThat(reloaded).isEmpty();
@@ -190,7 +192,7 @@ public class WebhookDaoTest {
       .setName("NAME_1")
       .setUrl("URL_1");
 
-    underTest.insert(dbSession, dto);
+    underTest.insert(dbSession, dto, null);
 
     Optional<WebhookDto> reloaded = underTest.selectByUuid(dbSession, dto.getUuid());
     assertThat(reloaded).isPresent();
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoWithPersisterTest.java
new file mode 100644 (file)
index 0000000..edb6f40
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.db.webhook;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.WebhookNewValue;
+import org.sonar.db.component.ComponentDbTester;
+import org.sonar.db.project.ProjectDto;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class WebhookDaoWithPersisterTest {
+  private AuditPersister auditPersister = mock(AuditPersister.class);
+
+  @Rule
+  public final DbTester dbTester = DbTester.create(System2.INSTANCE, auditPersister);
+
+  private final DbClient dbClient = dbTester.getDbClient();
+  private final DbSession dbSession = dbTester.getSession();
+  private final WebhookDao underTest = dbClient.webhookDao();
+  private final WebhookDbTester webhookDbTester = dbTester.webhooks();
+  private final ComponentDbTester componentDbTester = dbTester.components();
+
+  private final ArgumentCaptor<WebhookNewValue> newValueCaptor = ArgumentCaptor.forClass(WebhookNewValue.class);
+
+  @Test
+  public void insertGlobalWebhookIsPersisted() {
+    WebhookDto dto = new WebhookDto()
+      .setUuid("UUID_1")
+      .setName("NAME_1")
+      .setUrl("URL_1")
+      .setSecret("a_secret");
+
+    underTest.insert(dbSession, dto, null);
+
+    verify(auditPersister).addWebhook(eq(dbSession), newValueCaptor.capture());
+    WebhookNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(WebhookNewValue::getWebhookUuid, WebhookNewValue::getName)
+      .containsExactly(dto.getUuid(), dto.getName());
+    assertThat(newValue.toString()).doesNotContain("url");
+  }
+
+  @Test
+  public void insertProjectWebhookIsPersisted() {
+    WebhookDto dto = new WebhookDto()
+      .setUuid("UUID_1")
+      .setName("NAME_1")
+      .setUrl("URL_1")
+      .setProjectUuid("UUID_2")
+      .setSecret("a_secret");
+
+    underTest.insert(dbSession, dto, "project_name");
+
+    verify(auditPersister).addWebhook(eq(dbSession), newValueCaptor.capture());
+    WebhookNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(WebhookNewValue::getWebhookUuid, WebhookNewValue::getName, WebhookNewValue::getProjectUuid,
+        WebhookNewValue::getProjectName)
+      .containsExactly(dto.getUuid(), dto.getName(), dto.getProjectUuid(), "project_name");
+    assertThat(newValue.toString()).doesNotContain("url");
+  }
+
+  @Test
+  public void updateWebhookIsPersisted() {
+    WebhookDto dto = webhookDbTester.insertGlobalWebhook();
+    dto = dto
+      .setName("a-fancy-webhook")
+      .setUrl("http://www.fancy-webhook.io")
+      .setSecret(null);
+
+    underTest.update(dbSession, dto, null);
+
+    verify(auditPersister).updateWebhook(eq(dbSession), newValueCaptor.capture());
+    WebhookNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(WebhookNewValue::getWebhookUuid, WebhookNewValue::getName, WebhookNewValue::getUrl)
+      .containsExactly(dto.getUuid(), dto.getName(), dto.getUrl());
+    assertThat(newValue.toString()).doesNotContain("projectUuid");
+  }
+
+  @Test
+  public void deleteProjectWebhooksIsPersisted() {
+    ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
+    webhookDbTester.insertWebhook(projectDto);
+
+    underTest.deleteByProject(dbSession, projectDto);
+
+    verify(auditPersister).deleteWebhook(eq(dbSession), newValueCaptor.capture());
+    WebhookNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(WebhookNewValue::getProjectUuid, WebhookNewValue::getProjectName)
+      .containsExactly(projectDto.getUuid(), projectDto.getName());
+    assertThat(newValue.toString()).doesNotContain("webhookUuid");
+  }
+
+  @Test
+  public void deleteWebhookIsPersisted() {
+    WebhookDto dto = webhookDbTester.insertGlobalWebhook();
+
+    underTest.delete(dbSession, dto.getUuid(), dto.getName());
+
+    verify(auditPersister).deleteWebhook(eq(dbSession), newValueCaptor.capture());
+    WebhookNewValue newValue = newValueCaptor.getValue();
+    assertThat(newValue)
+      .extracting(WebhookNewValue::getWebhookUuid, WebhookNewValue::getName)
+      .containsExactly(dto.getUuid(), dto.getName());
+    assertThat(newValue.toString()).doesNotContain("url");
+  }
+}
index 738fe67b75f17413f8f9bdf0404d71ed847524f2..e271b82a78c7f4a052c56aab8dc66b8b9d6b0d23 100644 (file)
@@ -114,7 +114,7 @@ public class WebhookDeliveryDaoTest {
 
   @Test
   public void selectByWebhookUuid_returns_records_ordered_by_date() {
-    WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"));
+    WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"), "COMPONENT_NAME");
     WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", webhookDto.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
     WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW);
     WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "fake-webhook-uuid", "COMPONENT_2", "TASK_1").setCreatedAt(NOW);
@@ -129,7 +129,7 @@ public class WebhookDeliveryDaoTest {
 
   @Test
   public void selectByWebhookUuid_returns_records_according_to_pagination() {
-    WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"));
+    WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"), "COMPONENT_NAME");
     underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 5_000L));
     underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 4_000L));
     underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D3", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 3_000L));
@@ -144,11 +144,11 @@ public class WebhookDeliveryDaoTest {
 
   @Test
   public void selectLatestDelivery_of_a_webhook() {
-    WebhookDto webhook1 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"));
+    WebhookDto webhook1 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"), "COMPONENT_NAME");
     underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
     underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
 
-    WebhookDto webhook2 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"));
+    WebhookDto webhook2 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"), "COMPONENT_NAME");
     underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH2-DELIVERY-1-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
     underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH2-DELIVERY-2-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
 
@@ -197,7 +197,7 @@ public class WebhookDeliveryDaoTest {
   @Test
   public void deleteByWebhook() {
 
-    WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"));
+    WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"), "COMPONENT_NAME");
 
     underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", webhookDto.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L));
     underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(2_000_000L));
index b4733ef57be6e5f1aa210a98076383cfc6790d23..5c2a73191e3d2051da924ae2742c11d49c760151 100644 (file)
@@ -125,6 +125,10 @@ public class DbTester extends AbstractDbTester<TestDbImpl> {
     return new DbTester(System2.INSTANCE, null, null);
   }
 
+  public static DbTester create(AuditPersister auditPersister) {
+    return new DbTester(System2.INSTANCE, null, auditPersister);
+  }
+
   public static DbTester create(System2 system2, AuditPersister auditPersister) {
     return new DbTester(system2, null, auditPersister);
   }
index 4fc3a145a19790c0fb925e93d26e622615a4e1f8..0e2fe5a88f00233b3a1cf361b1a2d0f23c0c5876 100644 (file)
@@ -41,7 +41,7 @@ public class AlmPatsDbTester {
 
   private AlmPatDto insert(AlmPatDto dto, Consumer<AlmPatDto>[] populators) {
     stream(populators).forEach(p -> p.accept(dto));
-    db.getDbClient().almPatDao().insert(db.getSession(), dto);
+    db.getDbClient().almPatDao().insert(db.getSession(), dto, null, null);
     db.commit();
     return dto;
   }
index 29d2bbc718b07aef34a59f8f3c2e6277f6bcf1bc..10e245aaa8adb745293983ff7c6d6f4e02f7c4d8 100644 (file)
@@ -71,46 +71,60 @@ public class AlmSettingsDbTester {
   }
 
   @SafeVarargs
-  public final ProjectAlmSettingDto insertGitHubProjectAlmSetting(AlmSettingDto githubAlmSetting, ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) {
-    return insertProjectAlmSetting(newGithubProjectAlmSettingDto(githubAlmSetting, project), populators);
+  public final ProjectAlmSettingDto insertGitHubProjectAlmSetting(AlmSettingDto githubAlmSetting, ProjectDto project,
+    Consumer<ProjectAlmSettingDto>... populators) {
+    return insertProjectAlmSetting(newGithubProjectAlmSettingDto(githubAlmSetting, project), githubAlmSetting.getKey(),
+      project.getName(), populators);
   }
 
   public ProjectAlmSettingDto insertAzureProjectAlmSetting(AlmSettingDto azureAlmSetting, ProjectDto project) {
-    return insertProjectAlmSetting(newAzureProjectAlmSettingDto(azureAlmSetting, project));
+    return insertProjectAlmSetting(newAzureProjectAlmSettingDto(azureAlmSetting, project), azureAlmSetting.getKey(),
+      project.getName());
   }
 
   public ProjectAlmSettingDto insertAzureMonoRepoProjectAlmSetting(AlmSettingDto azureAlmSetting, ProjectDto project) {
-    return insertProjectAlmSetting(newAzureProjectAlmSettingDto(azureAlmSetting, project), d -> d.setMonorepo(true));
+    return insertProjectAlmSetting(newAzureProjectAlmSettingDto(azureAlmSetting, project), azureAlmSetting.getKey(),
+      project.getName(), d -> d.setMonorepo(true));
   }
 
   public ProjectAlmSettingDto insertGitlabProjectAlmSetting(AlmSettingDto gitlabAlmSetting, ProjectDto project) {
-    return insertProjectAlmSetting(newGitlabProjectAlmSettingDto(gitlabAlmSetting, project));
+    return insertProjectAlmSetting(newGitlabProjectAlmSettingDto(gitlabAlmSetting, project), gitlabAlmSetting.getKey(),
+      project.getName());
   }
 
   @SafeVarargs
-  public final ProjectAlmSettingDto insertAzureProjectAlmSetting(AlmSettingDto azureAlmSetting, ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) {
-    return insertProjectAlmSetting(newAzureProjectAlmSettingDto(azureAlmSetting, project), populators);
+  public final ProjectAlmSettingDto insertAzureProjectAlmSetting(AlmSettingDto azureAlmSetting, ProjectDto project,
+    Consumer<ProjectAlmSettingDto>... populators) {
+    return insertProjectAlmSetting(newAzureProjectAlmSettingDto(azureAlmSetting, project), azureAlmSetting.getKey(),
+      project.getName(), populators);
   }
 
   @SafeVarargs
-  public final ProjectAlmSettingDto insertGitlabProjectAlmSetting(AlmSettingDto gitlabAlmSetting, ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) {
-    return insertProjectAlmSetting(newGitlabProjectAlmSettingDto(gitlabAlmSetting, project), populators);
+  public final ProjectAlmSettingDto insertGitlabProjectAlmSetting(AlmSettingDto gitlabAlmSetting, ProjectDto project,
+    Consumer<ProjectAlmSettingDto>... populators) {
+    return insertProjectAlmSetting(newGitlabProjectAlmSettingDto(gitlabAlmSetting, project), gitlabAlmSetting.getKey(),
+      project.getName(), populators);
   }
 
   @SafeVarargs
-  public final ProjectAlmSettingDto insertBitbucketCloudProjectAlmSetting(AlmSettingDto bbCloudAlmSetting, ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) {
-    return insertProjectAlmSetting(newBitbucketCloudProjectAlmSettingDto(bbCloudAlmSetting, project), populators);
+  public final ProjectAlmSettingDto insertBitbucketCloudProjectAlmSetting(AlmSettingDto bbCloudAlmSetting, ProjectDto project,
+    Consumer<ProjectAlmSettingDto>... populators) {
+    return insertProjectAlmSetting(newBitbucketCloudProjectAlmSettingDto(bbCloudAlmSetting, project), bbCloudAlmSetting.getKey(),
+      project.getName(), populators);
   }
 
   @SafeVarargs
-  public final ProjectAlmSettingDto insertBitbucketProjectAlmSetting(AlmSettingDto bitbucketAlmSetting, ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) {
-    return insertProjectAlmSetting(newBitbucketProjectAlmSettingDto(bitbucketAlmSetting, project), populators);
+  public final ProjectAlmSettingDto insertBitbucketProjectAlmSetting(AlmSettingDto bitbucketAlmSetting,
+    ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) {
+    return insertProjectAlmSetting(newBitbucketProjectAlmSettingDto(bitbucketAlmSetting, project),
+      bitbucketAlmSetting.getKey(), project.getName(), populators);
   }
 
   @SafeVarargs
-  private final ProjectAlmSettingDto insertProjectAlmSetting(ProjectAlmSettingDto dto, Consumer<ProjectAlmSettingDto>... populators) {
+  private final ProjectAlmSettingDto insertProjectAlmSetting(ProjectAlmSettingDto dto, String key, String projectName,
+    Consumer<ProjectAlmSettingDto>... populators) {
     stream(populators).forEach(p -> p.accept(dto));
-    db.getDbClient().projectAlmSettingDao().insertOrUpdate(db.getSession(), dto);
+    db.getDbClient().projectAlmSettingDao().insertOrUpdate(db.getSession(), dto, key, projectName);
     db.commit();
     return dto;
   }
index baa2cc6e4bce50fc80832a0f3a666af3a15f255b..b31b05d85bd371d83ea081509a85332f4a6d7cb9 100644 (file)
@@ -38,11 +38,12 @@ public class FavoriteDbTester {
     this.dbSession = db.getSession();
   }
 
-  public void add(ComponentDto componentDto, String userUuid) {
+  public void add(ComponentDto componentDto, String userUuid, String userLogin) {
     dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto()
-      .setKey(PROP_FAVORITE_KEY)
-      .setUserUuid(userUuid)
-      .setComponentUuid(componentDto.uuid()));
+        .setKey(PROP_FAVORITE_KEY)
+        .setUserUuid(userUuid)
+        .setComponentUuid(componentDto.uuid()),
+      userLogin, componentDto.name());
     dbSession.commit();
   }
 
index d0d3227fb89feabd4f13446d302c5abb191ec8e3..96500a78418c0b9f5fbe62c5c9dd18c0869b3d7f 100644 (file)
@@ -70,36 +70,37 @@ public class PermissionTemplateDbTester {
   }
 
   public void addGroupToTemplate(PermissionTemplateDto permissionTemplate, GroupDto group, String permission) {
-    addGroupToTemplate(permissionTemplate.getUuid(), group.getUuid(), permission);
+    addGroupToTemplate(permissionTemplate.getUuid(), group.getUuid(), permission, permissionTemplate.getName(), group.getName());
   }
 
-  public void addGroupToTemplate(String templateUuid, @Nullable String groupUuid, String permission) {
-    dbClient.permissionTemplateDao().insertGroupPermission(dbSession, templateUuid, groupUuid, permission);
+  public void addGroupToTemplate(String templateUuid, @Nullable String groupUuid, String permission, String templateName, @Nullable String groupName) {
+    dbClient.permissionTemplateDao().insertGroupPermission(dbSession, templateUuid, groupUuid, permission, templateName, groupName);
     db.commit();
   }
 
   public void addAnyoneToTemplate(PermissionTemplateDto permissionTemplate, String permission) {
-    addGroupToTemplate(permissionTemplate.getUuid(), null, permission);
+    addGroupToTemplate(permissionTemplate.getUuid(), null, permission, permissionTemplate.getName(), null);
   }
 
   public void addUserToTemplate(PermissionTemplateDto permissionTemplate, UserDto user, String permission) {
-    addUserToTemplate(permissionTemplate.getUuid(), user.getUuid(), permission);
+    addUserToTemplate(permissionTemplate.getUuid(), user.getUuid(), permission, permissionTemplate.getName(), user.getName());
   }
 
-  public void addUserToTemplate(String templateUuid, String userUuid, String permission) {
-    dbClient.permissionTemplateDao().insertUserPermission(dbSession, templateUuid, userUuid, permission);
+  public void addUserToTemplate(String templateUuid, String userUuid, String permission, String templateName, String userLogin) {
+    dbClient.permissionTemplateDao().insertUserPermission(dbSession, templateUuid, userUuid, permission, templateName, userLogin);
     db.commit();
   }
 
   public void addProjectCreatorToTemplate(PermissionTemplateDto permissionTemplate, String permission) {
-    addProjectCreatorToTemplate(permissionTemplate.getUuid(), permission);
+    addProjectCreatorToTemplate(permissionTemplate.getUuid(), permission, permissionTemplate.getName());
   }
 
-  public void addProjectCreatorToTemplate(String templateUuid, String permission) {
+  public void addProjectCreatorToTemplate(String templateUuid, String permission, String templateName) {
     dbClient.permissionTemplateCharacteristicDao().insert(dbSession, newPermissionTemplateCharacteristicDto()
-      .setWithProjectCreator(true)
-      .setTemplateUuid(templateUuid)
-      .setPermission(permission));
+        .setWithProjectCreator(true)
+        .setTemplateUuid(templateUuid)
+        .setPermission(permission),
+      templateName);
     db.commit();
   }
 }
index 107378d24b26fc3a644a09cbb1c5a274fcadea46..c53992da6e1e22a622bd8b89d1692571af73a5a7 100644 (file)
@@ -47,20 +47,20 @@ public class PropertyDbTester {
     this.dbSession = db.getSession();
   }
 
-  public PropertyDto insertProperty(PropertyDto property) {
-    dbClient.propertiesDao().saveProperty(dbSession, property);
+  public PropertyDto insertProperty(PropertyDto property, @Nullable String componentName, @Nullable String userLogin) {
+    dbClient.propertiesDao().saveProperty(dbSession, property, userLogin, componentName);
     db.commit();
 
     return property;
   }
 
-  public void insertProperties(PropertyDto... properties) {
-    insertProperties(asList(properties));
+  public void insertProperties(@Nullable String userLogin, @Nullable String projectName, PropertyDto... properties) {
+    insertProperties(asList(properties), userLogin, projectName);
   }
 
-  public void insertProperties(List<PropertyDto> properties) {
+  public void insertProperties(List<PropertyDto> properties, @Nullable String userLogin, @Nullable String projectName) {
     for (PropertyDto propertyDto : properties) {
-      dbClient.propertiesDao().saveProperty(dbSession, propertyDto);
+      dbClient.propertiesDao().saveProperty(dbSession, propertyDto, userLogin, projectName);
     }
     dbSession.commit();
   }
@@ -87,7 +87,8 @@ public class PropertyDbTester {
     } else {
       propertyDtos.add(newGlobalPropertyDto().setKey(settingBaseKey).setValue(idsValue));
     }
-    insertProperties(propertyDtos);
+    String componentName = componentDto == null ? null : componentDto.name();
+    insertProperties(propertyDtos, null, componentName);
   }
 
   public PropertyDbTester verifyInternal(String key, @Nullable String expectedValue) {
index ac863cf91c825045d23014e1d06439163788daf7..f32d86c518955b05a5edb88234374326864a8eb5 100644 (file)
@@ -200,7 +200,7 @@ public class UserDbTester {
       .setUuid(Uuids.createFast())
       .setGroupUuid(null)
       .setRole(permission);
-    db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
+    db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, null);
     db.commit();
     return dto;
   }
@@ -214,7 +214,7 @@ public class UserDbTester {
       .setUuid(Uuids.createFast())
       .setGroupUuid(group.getUuid())
       .setRole(permission);
-    db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
+    db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, null);
     db.commit();
     return dto;
   }
@@ -224,7 +224,7 @@ public class UserDbTester {
   }
 
   public void deletePermissionFromGroup(GroupDto group, String permission) {
-    db.getDbClient().groupPermissionDao().delete(db.getSession(), permission, group.getUuid(), null);
+    db.getDbClient().groupPermissionDao().delete(db.getSession(), permission, group.getUuid(), null, null);
     db.commit();
   }
 
@@ -238,13 +238,13 @@ public class UserDbTester {
       .setGroupUuid(null)
       .setRole(permission)
       .setComponentUuid(project.uuid());
-    db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
+    db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, project);
     db.commit();
     return dto;
   }
 
   public void deleteProjectPermissionFromAnyone(ComponentDto project, String permission) {
-    db.getDbClient().groupPermissionDao().delete(db.getSession(), permission, null, project.uuid());
+    db.getDbClient().groupPermissionDao().delete(db.getSession(), permission, null, project.uuid(), project);
     db.commit();
   }
 
@@ -257,7 +257,7 @@ public class UserDbTester {
       .setGroupUuid(group.getUuid())
       .setRole(permission)
       .setComponentUuid(project.uuid());
-    db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
+    db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, project);
     db.commit();
     return dto;
   }
@@ -292,7 +292,7 @@ public class UserDbTester {
   @Deprecated
   public UserPermissionDto insertPermissionOnUser(UserDto user, String permission) {
     UserPermissionDto dto = new UserPermissionDto(Uuids.create(), permission, user.getUuid(), null);
-    db.getDbClient().userPermissionDao().insert(db.getSession(), dto);
+    db.getDbClient().userPermissionDao().insert(db.getSession(), dto, null);
     db.commit();
     return dto;
   }
@@ -303,7 +303,7 @@ public class UserDbTester {
   }
 
   public void deletePermissionFromUser(ComponentDto project, UserDto user, String permission) {
-    db.getDbClient().userPermissionDao().deleteProjectPermission(db.getSession(), user.getUuid(), permission, project.uuid());
+    db.getDbClient().userPermissionDao().deleteProjectPermission(db.getSession(), user.getUuid(), permission, project.uuid(), project.name());
     db.commit();
   }
 
@@ -315,7 +315,7 @@ public class UserDbTester {
       "%s can't be granted on a public project", permission);
     checkArgument(project.getMainBranchProjectUuid() == null, "Permissions can't be granted on branches");
     UserPermissionDto dto = new UserPermissionDto(Uuids.create(), permission, user.getUuid(), project.uuid());
-    db.getDbClient().userPermissionDao().insert(db.getSession(), dto);
+    db.getDbClient().userPermissionDao().insert(db.getSession(), dto, project);
     db.commit();
     return dto;
   }
index 8da90478b944a580f97fa4c6a2fa0d18a999ef83..474e2b014f3039893c85500b147d4b4bfa134bb1 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.db.webhook;
 
 import java.util.Optional;
+import javax.annotation.Nullable;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.project.ProjectDto;
@@ -36,16 +37,16 @@ public class WebhookDbTester {
   }
 
   public WebhookDto insertGlobalWebhook() {
-    return insert(newGlobalWebhook());
+    return insert(newGlobalWebhook(), null);
   }
 
   public WebhookDto insertWebhook(ProjectDto project) {
-    return insert(newWebhook(project));
+    return insert(newWebhook(project), project.getName());
   }
 
-  public WebhookDto insert(WebhookDto dto) {
+  public WebhookDto insert(WebhookDto dto, @Nullable String projectName) {
     DbSession dbSession = dbTester.getSession();
-    dbTester.getDbClient().webhookDao().insert(dbSession, dto);
+    dbTester.getDbClient().webhookDao().insert(dbSession, dto, projectName);
     dbSession.commit();
     return dto;
   }
index b7dd62f460c6f7ce69610f9d67fb8c7fc189cbcd..eef87adac494a377442d0a0461161a58d05e8608 100644 (file)
@@ -49,7 +49,7 @@ public class CreateAuditTable extends DdlChange {
       .addPkColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
       .addColumn(newVarcharColumnBuilder("user_uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
       .addColumn(newVarcharColumnBuilder("user_login").setIsNullable(false).setLimit(255).build())
-      .addColumn(newVarcharColumnBuilder("category").setIsNullable(false).setLimit(20).build())
+      .addColumn(newVarcharColumnBuilder("category").setIsNullable(false).setLimit(25).build())
       .addColumn(newVarcharColumnBuilder("operation").setIsNullable(false).setLimit(50).build())
       .addColumn(newVarcharColumnBuilder("new_value").setIsNullable(true).setLimit(4000).build())
       .addColumn(createdAtColumn)
index 3ffabfa8af9cefbfd9f4c1e3ab238c415773aba2..6deb01b0806a5645c767ee19a85f09a343015df0 100644 (file)
@@ -41,7 +41,7 @@ public class FavoriteUpdater {
   /**
    * Set favorite to the logged in user. If no user, no action is done
    */
-  public void add(DbSession dbSession, ComponentDto componentDto, @Nullable String userUuid, boolean failIfTooManyFavorites) {
+  public void add(DbSession dbSession, ComponentDto componentDto, @Nullable String userUuid, @Nullable String userLogin, boolean failIfTooManyFavorites) {
     if (userUuid == null) {
       return;
     }
@@ -59,24 +59,28 @@ public class FavoriteUpdater {
       return;
     }
     dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto()
-      .setKey(PROP_FAVORITE_KEY)
-      .setComponentUuid(componentDto.uuid())
-      .setUserUuid(userUuid));
+        .setKey(PROP_FAVORITE_KEY)
+        .setComponentUuid(componentDto.uuid())
+        .setUserUuid(userUuid),
+      userLogin,
+      componentDto.name());
   }
 
   /**
    * Remove a favorite to the user.
+   *
    * @throws IllegalArgumentException if the component is not a favorite
    */
-  public void remove(DbSession dbSession, ComponentDto component, @Nullable String userUuid) {
+  public void remove(DbSession dbSession, ComponentDto component, @Nullable String userUuid, @Nullable String userLogin) {
     if (userUuid == null) {
       return;
     }
 
     int result = dbClient.propertiesDao().delete(dbSession, new PropertyDto()
-      .setKey(PROP_FAVORITE_KEY)
-      .setComponentUuid(component.uuid())
-      .setUserUuid(userUuid));
+        .setKey(PROP_FAVORITE_KEY)
+        .setComponentUuid(component.uuid())
+        .setUserUuid(userUuid),
+      userLogin, component.name());
     checkArgument(result == 1, "Component '%s' is not a favorite", component.getDbKey());
   }
 }
index 3f61a4d686adf51c6cd3ddafa4ae7fca599cb4bf..1831d917d267287c639eecc3d4cf61a8de3f634b 100644 (file)
@@ -50,7 +50,7 @@ public class FavoriteUpdaterTest {
     UserDto user = db.users().insertUser();
     assertNoFavorite(project, user);
 
-    underTest.add(dbSession, project, user.getUuid(), true);
+    underTest.add(dbSession, project, user.getUuid(), user.getLogin(), true);
 
     assertFavorite(project, user);
   }
@@ -59,7 +59,7 @@ public class FavoriteUpdaterTest {
   public void do_nothing_when_no_user() {
     ComponentDto project = db.components().insertPrivateProject();
 
-    underTest.add(dbSession, project, null, true);
+    underTest.add(dbSession, project, null, null,true);
 
     assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
       .setComponentUuid(project.uuid())
@@ -69,13 +69,13 @@ public class FavoriteUpdaterTest {
   @Test
   public void do_not_add_favorite_when_already_100_favorite_projects() {
     UserDto user = db.users().insertUser();
-    IntStream.rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid()));
+    IntStream.rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid(), user.getName()));
     assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
       .setUserUuid(user.getUuid())
       .build(), dbSession)).hasSize(100);
     ComponentDto project = db.components().insertPrivateProject();
 
-    underTest.add(dbSession, project, user.getUuid(), false);
+    underTest.add(dbSession, project, user.getUuid(), user.getLogin(), false);
 
     assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
       .setUserUuid(user.getUuid())
@@ -85,13 +85,14 @@ public class FavoriteUpdaterTest {
   @Test
   public void do_not_add_favorite_when_already_100_favorite_portfolios() {
     UserDto user = db.users().insertUser();
-    IntStream.rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid()));
+    IntStream.rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(),
+      user.getUuid(), user.getLogin()));
     assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
       .setUserUuid(user.getUuid())
       .build(), dbSession)).hasSize(100);
     ComponentDto project = db.components().insertPrivateProject();
 
-    underTest.add(dbSession, project, user.getUuid(), false);
+    underTest.add(dbSession, project, user.getUuid(), user.getLogin(), false);
 
     assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
       .setUserUuid(user.getUuid())
@@ -101,26 +102,27 @@ public class FavoriteUpdaterTest {
   @Test
   public void fail_when_more_than_100_projects_favorites() {
     UserDto user = db.users().insertUser();
-    IntStream.rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid()));
+    IntStream.rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(),
+      user.getUuid(), user.getLogin()));
     ComponentDto project = db.components().insertPrivateProject();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("You cannot have more than 100 favorites on components with qualifier 'TRK'");
 
-    underTest.add(dbSession, project, user.getUuid(), true);
+    underTest.add(dbSession, project, user.getUuid(), user.getLogin(), true);
   }
 
   @Test
   public void fail_when_adding_existing_favorite() {
     ComponentDto project = db.components().insertPrivateProject();
     UserDto user = db.users().insertUser();
-    underTest.add(dbSession, project, user.getUuid(), true);
+    underTest.add(dbSession, project, user.getUuid(), user.getLogin(), true);
     assertFavorite(project, user);
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage(String.format("Component '%s' is already a favorite", project.getKey()));
 
-    underTest.add(dbSession, project, user.getUuid(), true);
+    underTest.add(dbSession, project, user.getUuid(), user.getLogin(), true);
   }
 
   private void assertFavorite(ComponentDto project, UserDto user) {
index df727bdce2af7ffc79c8e2a4dfdc90b1731e7ca7..0851cd9b1ba6a4bc63d2854d9debc35e149d5570 100644 (file)
@@ -101,7 +101,8 @@ public class StartupMetadataProviderTest {
   }
 
   private void testLoadingFromDatabase(SonarRuntime runtime, boolean isStartupLeader) {
-    dbTester.properties().insertProperty(new PropertyDto().setKey(CoreProperties.SERVER_STARTTIME).setValue(formatDateTime(A_DATE)));
+    dbTester.properties().insertProperty(new PropertyDto().setKey(CoreProperties.SERVER_STARTTIME).setValue(formatDateTime(A_DATE)),
+      null, null);
     when(webServer.isStartupLeader()).thenReturn(isStartupLeader);
 
     StartupMetadata metadata = underTest.provide(system, runtime, webServer, dbTester.getDbClient());
index a971c864139d6ddc1b57ab61e591084d90e3ae2e..602ebb5a064c0ca7a04906686e421aad71ccd689 100644 (file)
@@ -63,8 +63,8 @@ public class AsynchronousWebHooksImplTest {
   @Test
   public void send_global_webhooks() {
     ComponentDto project = componentDbTester.insertPrivateProject();
-    webhookDbTester.insert(newGlobalWebhook().setName("First").setUrl("http://url1"));
-    webhookDbTester.insert(newGlobalWebhook().setName("Second").setUrl("http://url2"));
+    webhookDbTester.insert(newGlobalWebhook().setName("First").setUrl("http://url1"), null);
+    webhookDbTester.insert(newGlobalWebhook().setName("Second").setUrl("http://url2"), null);
 
     caller.enqueueSuccess(NOW, 200, 1_234);
     caller.enqueueFailure(NOW, new IOException("Fail to connect"));
index 46f0e0da5918008ee45db17a6140ee4e79990889..047e1ab047e3add910089634eec5e62707b162e4 100644 (file)
@@ -74,7 +74,7 @@ public class SynchronousWebHooksImplTest {
   @Test
   public void isEnabled_returns_true_if_one_valid_global_webhook() {
     ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
-    webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"));
+    webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"), projectDto.getName());
 
     assertThat(underTest.isEnabled(projectDto)).isTrue();
   }
@@ -82,7 +82,7 @@ public class SynchronousWebHooksImplTest {
   @Test
   public void isEnabled_returns_true_if_one_valid_project_webhook() {
     ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
-    webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"));
+    webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"), projectDto.getName());
 
     assertThat(underTest.isEnabled(projectDto)).isTrue();
   }
@@ -113,8 +113,8 @@ public class SynchronousWebHooksImplTest {
   @Test
   public void send_global_webhooks() {
     ComponentDto componentDto = componentDbTester.insertPrivateProject();
-    webhookDbTester.insert(newGlobalWebhook().setName("First").setUrl("http://url1"));
-    webhookDbTester.insert(newGlobalWebhook().setName("Second").setUrl("http://url2"));
+    webhookDbTester.insert(newGlobalWebhook().setName("First").setUrl("http://url1"), null);
+    webhookDbTester.insert(newGlobalWebhook().setName("Second").setUrl("http://url2"), null);
     caller.enqueueSuccess(NOW, 200, 1_234);
     caller.enqueueFailure(NOW, new IOException("Fail to connect"));
 
@@ -131,7 +131,7 @@ public class SynchronousWebHooksImplTest {
   @Test
   public void send_project_webhooks() {
     ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
-    webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"));
+    webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"), projectDto.getName());
     caller.enqueueSuccess(NOW, 200, 1_234);
 
     underTest.sendProjectAnalysisUpdate(new WebHooks.Analysis(projectDto.getUuid(), "1", "#1"), () -> mock, taskStatistics);
@@ -146,11 +146,11 @@ public class SynchronousWebHooksImplTest {
   @Test
   public void send_global_and_project_webhooks() {
     ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
-    webhookDbTester.insert(newWebhook(projectDto).setName("1First").setUrl("http://url1"));
-    webhookDbTester.insert(newWebhook(projectDto).setName("2Second").setUrl("http://url2"));
-    webhookDbTester.insert(newGlobalWebhook().setName("3Third").setUrl("http://url3"));
-    webhookDbTester.insert(newGlobalWebhook().setName("4Fourth").setUrl("http://url4"));
-    webhookDbTester.insert(newGlobalWebhook().setName("5Fifth").setUrl("http://url5"));
+    webhookDbTester.insert(newWebhook(projectDto).setName("1First").setUrl("http://url1"), projectDto.getName());
+    webhookDbTester.insert(newWebhook(projectDto).setName("2Second").setUrl("http://url2"), projectDto.getName());
+    webhookDbTester.insert(newGlobalWebhook().setName("3Third").setUrl("http://url3"), null);
+    webhookDbTester.insert(newGlobalWebhook().setName("4Fourth").setUrl("http://url4"), null);
+    webhookDbTester.insert(newGlobalWebhook().setName("5Fifth").setUrl("http://url5"), null);
     caller.enqueueSuccess(NOW, 200, 1_234);
     caller.enqueueFailure(NOW, new IOException("Fail to connect 1"));
     caller.enqueueFailure(NOW, new IOException("Fail to connect 2"));
index 494cec61a4daab17317c0c447a6ec27b44880f80..70e31993887f85dcaf87e67b58d2d18620df3359 100644 (file)
@@ -54,7 +54,7 @@ public class PluginConsentVerifier implements Startable {
       if (hasExternalPlugins && NOT_ACCEPTED == PluginRiskConsent.valueOf(property.getValue())) {
         addWarningInSonarDotLog();
         property.setValue(REQUIRED.name());
-        dbClient.propertiesDao().saveProperty(session, property);
+        dbClient.propertiesDao().saveProperty(session, property, null, null);
         session.commit();
       } else if (!hasExternalPlugins && REQUIRED == PluginRiskConsent.valueOf(property.getValue())) {
         dbClient.propertiesDao().deleteGlobalProperty(PLUGINS_RISK_CONSENT, session);
index 4b452708e60f7256133f7d8526b1d96dcd35245e..aabae7c3665373baab0342d9f24be91292b3f9fd 100644 (file)
@@ -46,6 +46,6 @@ public class ProjectDefaultVisibility {
   public void set(DbSession dbSession, Visibility visibility) {
     dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto()
       .setKey(PROJECTS_DEFAULT_VISIBILITY_PROPERTY_NAME)
-      .setValue(visibility.getLabel()));
+      .setValue(visibility.getLabel()), null, null);
   }
 }
index 1f4ca04f52c0f7602e5b1e63bc026757bbd74c9c..d0269c968910a34337850daa8bc4d9fdfe11fc66 100644 (file)
@@ -88,7 +88,7 @@ public class UserUpdaterUpdateTest {
       .setName("Marius2")
       .setEmail("marius2@mail.com")
       .setScmAccounts(singletonList("ma2")), u -> {
-      });
+    });
 
     UserDto updatedUser = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
     assertThat(updatedUser.isActive()).isTrue();
@@ -116,7 +116,7 @@ public class UserUpdaterUpdateTest {
       .setName("Marius2")
       .setEmail("marius2@email.com")
       .setExternalIdentity(new ExternalIdentity("github", "john", "ABCD")), u -> {
-      });
+    });
 
     UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
     assertThat(dto.getExternalId()).isEqualTo("ABCD");
@@ -134,7 +134,7 @@ public class UserUpdaterUpdateTest {
       .setName("Marius2")
       .setEmail("marius2@email.com")
       .setExternalIdentity(new ExternalIdentity("github", "john", "ABCD")), u -> {
-      });
+    });
 
     UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
     assertThat(dto.getExternalId()).isEqualTo("ABCD");
@@ -157,7 +157,7 @@ public class UserUpdaterUpdateTest {
       .setEmail("marius2@mail.com")
       .setPassword("password2")
       .setScmAccounts(asList("ma2", "", null)), u -> {
-      });
+    });
 
     UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
     assertThat(dto.getScmAccountsAsList()).containsOnly("ma2");
@@ -170,7 +170,7 @@ public class UserUpdaterUpdateTest {
 
     underTest.updateAndCommit(session, user, new UpdateUser()
       .setLogin("new_login"), u -> {
-      });
+    });
 
     assertThat(dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN)).isNull();
     UserDto userReloaded = dbClient.userDao().selectByUuid(session, user.getUuid());
@@ -194,7 +194,7 @@ public class UserUpdaterUpdateTest {
 
     underTest.updateAndCommit(session, user, new UpdateUser()
       .setLogin("new_login"), u -> {
-      });
+    });
 
     assertThat(dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN)).isNull();
     UserDto userReloaded = dbClient.userDao().selectByUuid(session, user.getUuid());
@@ -218,7 +218,7 @@ public class UserUpdaterUpdateTest {
 
     underTest.updateAndCommit(session, oldUser, new UpdateUser()
       .setLogin("new_login"), u -> {
-      });
+    });
 
     List<SearchHit> indexUsers = es.getDocuments(UserIndexDefinition.TYPE_USER);
     assertThat(indexUsers).hasSize(1);
@@ -233,16 +233,18 @@ public class UserUpdaterUpdateTest {
     ComponentDto project1 = db.components().insertPrivateProject();
     ComponentDto project2 = db.components().insertPrivateProject();
     ComponentDto anotherProject = db.components().insertPrivateProject();
-    db.properties().insertProperties(
+    db.properties().insertProperties(oldUser.getLogin(), project1.name(),
       new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()),
-      new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setComponentUuid(project1.uuid()),
-      new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setComponentUuid(project2.uuid()),
+      new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setComponentUuid(project1.uuid()));
+    db.properties().insertProperties(oldUser.getLogin(), project2.name(),
+      new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setComponentUuid(project2.uuid()));
+    db.properties().insertProperties(oldUser.getLogin(), anotherProject.name(),
       new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue("another login").setComponentUuid(anotherProject.uuid()));
     userIndexer.indexAll();
 
     underTest.updateAndCommit(session, oldUser, new UpdateUser()
       .setLogin("new_login"), u -> {
-      });
+    });
 
     assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setKey(DEFAULT_ISSUE_ASSIGNEE).build(), db.getSession()))
       .extracting(PropertyDto::getValue, PropertyDto::getComponentUuid)
@@ -263,7 +265,7 @@ public class UserUpdaterUpdateTest {
 
     underTest.updateAndCommit(session, user, new UpdateUser()
       .setName("Marius2"), u -> {
-      });
+    });
 
     UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
     assertThat(dto.getName()).isEqualTo("Marius2");
@@ -285,7 +287,7 @@ public class UserUpdaterUpdateTest {
 
     underTest.updateAndCommit(session, user, new UpdateUser()
       .setEmail("marius2@mail.com"), u -> {
-      });
+    });
 
     UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
     assertThat(dto.getEmail()).isEqualTo("marius2@mail.com");
@@ -307,7 +309,7 @@ public class UserUpdaterUpdateTest {
 
     underTest.updateAndCommit(session, user, new UpdateUser()
       .setScmAccounts(asList("ma2")), u -> {
-      });
+    });
 
     UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
     assertThat(dto.getScmAccountsAsList()).containsOnly("ma2");
@@ -327,7 +329,7 @@ public class UserUpdaterUpdateTest {
 
     underTest.updateAndCommit(session, user, new UpdateUser()
       .setScmAccounts(asList("ma", "marius33")), u -> {
-      });
+    });
 
     UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
     assertThat(dto.getScmAccountsAsList()).containsOnly("ma", "marius33");
@@ -341,7 +343,7 @@ public class UserUpdaterUpdateTest {
 
     underTest.updateAndCommit(session, user, new UpdateUser()
       .setScmAccounts(null), u -> {
-      });
+    });
 
     UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
     assertThat(dto.getScmAccounts()).isNull();
@@ -357,7 +359,7 @@ public class UserUpdaterUpdateTest {
 
     underTest.updateAndCommit(session, user, new UpdateUser()
       .setPassword("password2"), u -> {
-      });
+    });
 
     UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
     assertThat(dto.getSalt()).isNotEqualTo("salt");
@@ -380,7 +382,7 @@ public class UserUpdaterUpdateTest {
 
     underTest.updateAndCommit(session, user, new UpdateUser()
       .setPassword("password2"), u -> {
-      });
+    });
 
     UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
     assertThat(dto.getSalt()).isNotEqualTo("salt");
@@ -453,7 +455,7 @@ public class UserUpdaterUpdateTest {
       .setEmail(user.getEmail())
       .setScmAccounts(user.getScmAccountsAsList())
       .setExternalIdentity(new ExternalIdentity(user.getExternalIdentityProvider(), user.getExternalLogin(), user.getExternalId())), u -> {
-      });
+    });
 
     assertThat(dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN).getUpdatedAt()).isEqualTo(user.getUpdatedAt());
   }
@@ -470,7 +472,7 @@ public class UserUpdaterUpdateTest {
       .setEmail(user.getEmail())
       .setScmAccounts(asList("ma2", "ma1"))
       .setExternalIdentity(new ExternalIdentity(user.getExternalIdentityProvider(), user.getExternalLogin(), user.getExternalId())), u -> {
-      });
+    });
 
     assertThat(dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN).getUpdatedAt()).isEqualTo(user.getUpdatedAt());
   }
@@ -487,7 +489,7 @@ public class UserUpdaterUpdateTest {
       .setEmail("marius2@mail.com")
       .setPassword("password2")
       .setScmAccounts(asList("ma2")), u -> {
-      }, otherUser);
+    }, otherUser);
 
     assertThat(es.getIds(UserIndexDefinition.TYPE_USER)).containsExactlyInAnyOrder(user.getUuid(), otherUser.getUuid());
   }
@@ -527,7 +529,7 @@ public class UserUpdaterUpdateTest {
       .setEmail("marius2@mail.com")
       .setPassword("password2")
       .setScmAccounts(asList("ma2")), u -> {
-      });
+    });
 
     Multimap<String, String> groups = dbClient.groupMembershipDao().selectGroupsByLogins(session, asList(DEFAULT_LOGIN));
     assertThat(groups.get(DEFAULT_LOGIN).stream().anyMatch(g -> g.equals(defaultGroup.getName()))).isFalse();
@@ -548,7 +550,7 @@ public class UserUpdaterUpdateTest {
       .setEmail("marius2@mail.com")
       .setPassword("password2")
       .setScmAccounts(asList("ma2")), u -> {
-      });
+    });
 
     // Nothing as changed
     groups = dbClient.groupMembershipDao().selectGroupsByLogins(session, asList(DEFAULT_LOGIN));
index 24ad7777e7d69b0234bbff38721658f26f306ebd..f64d38a65e3fe553af236f4f195c7a179a347712 100644 (file)
@@ -72,7 +72,7 @@ public class PersistentSettings {
     if (value == null) {
       dbClient.propertiesDao().deleteGlobalProperty(key, dbSession);
     } else {
-      dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(value));
+      dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(value), null, null);
     }
     // refresh the cache of settings
     delegate.setProperty(key, value);
index 1ab380f5ba81ebd8d1afb979da7c1d45d3ba27e6..700f7819c1e8756553e046ead75eec9e24bd02d2 100644 (file)
@@ -139,7 +139,7 @@ public class ServerIdManager implements Startable {
   }
 
   private void persistServerId(DbSession dbSession, ServerId serverId) {
-    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(SERVER_ID).setValue(serverId.toString()));
+    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(SERVER_ID).setValue(serverId.toString()), null, null);
   }
 
   private void persistChecksum(DbSession dbSession, String checksump) {
index 075cdc36349aa9615afa1e513737d2ae82e3408d..9f9b3770c255c08fedd007d91de0f2afd8e15422 100644 (file)
@@ -114,7 +114,7 @@ public class RegisterPermissionTemplates implements Startable {
   }
 
   private void insertGroupPermission(DbSession dbSession, PermissionTemplateDto template, String permission, GroupDto group) {
-    dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getUuid(), group.getUuid(), permission);
+    dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getUuid(), group.getUuid(), permission, template.getName(), group.getName());
   }
 
 }
index a7ba1b6a1aa2ea12029abcef177e28d84e8b52af..003c972b70e67c716dad28a2eb20bcfbe2e65223 100644 (file)
@@ -236,8 +236,7 @@ public class ServerIdManagerTest {
     try {
       test(SERVER);
       fail("An ISE should have been raised");
-    }
-    catch (IllegalStateException e) {
+    } catch (IllegalStateException e) {
       assertThat(e.getMessage()).isEqualTo("Server ID is invalid");
       // no changes
       verifyDb(serverId, dbChecksum);
@@ -284,8 +283,7 @@ public class ServerIdManagerTest {
     try {
       test(SERVER);
       fail("An ISE should have been raised");
-    }
-    catch (IllegalStateException e) {
+    } catch (IllegalStateException e) {
       assertThat(e.getMessage()).isEqualTo("Server ID is invalid");
       // no changes
       verifyDb(serverId, dbChecksum);
@@ -294,10 +292,10 @@ public class ServerIdManagerTest {
 
   @DataProvider
   public static Object[][] allFormatsOfServerId() {
-    return new Object[][] {
-        {OLD_FORMAT_SERVER_ID},
-        {NO_DATABASE_ID_SERVER_ID},
-        {WITH_DATABASE_ID_SERVER_ID}
+    return new Object[][]{
+      {OLD_FORMAT_SERVER_ID},
+      {NO_DATABASE_ID_SERVER_ID},
+      {WITH_DATABASE_ID_SERVER_ID}
     };
   }
 
@@ -346,7 +344,8 @@ public class ServerIdManagerTest {
   }
 
   private void insertServerId(String serverId) {
-    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(CoreProperties.SERVER_ID).setValue(serverId));
+    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(CoreProperties.SERVER_ID).setValue(serverId),
+      null, null);
     dbSession.commit();
   }
 
index 6323c077bb4a434cb04efc4566e471e110cd801b..e49760e9ec7e125c7cf4556820a311e9800d7b57 100644 (file)
@@ -171,7 +171,7 @@ public class PermissionIndexerDaoTest {
         .setGroupUuid(group.getUuid())
         .setRole(USER)
         .setComponentUuid(project.uuid());
-      dbClient.groupPermissionDao().insert(dbSession, dto);
+      dbClient.groupPermissionDao().insert(dbSession, dto, project);
     }
     dbSession.commit();
 
index 3d66e0f1b5e1bbc1e4958dd929ad45cde2bebb84..6eca1df58b1515c22cc10c1e2e8944251eed5e49 100644 (file)
@@ -111,13 +111,13 @@ public class SetPatAction implements AlmIntegrationsWsAction {
       if (almPatDto.isPresent()) {
         AlmPatDto almPat = almPatDto.get();
         almPat.setPersonalAccessToken(resultingPat);
-        dbClient.almPatDao().update(dbSession, almPat);
+        dbClient.almPatDao().update(dbSession, almPat, userSession.getLogin(), almSetting.getKey());
       } else {
         AlmPatDto almPat = new AlmPatDto()
           .setPersonalAccessToken(resultingPat)
           .setAlmSettingUuid(almSetting.getUuid())
           .setUserUuid(userUuid);
-        dbClient.almPatDao().insert(dbSession, almPat);
+        dbClient.almPatDao().insert(dbSession, almPat, userSession.getLogin(), almSetting.getKey());
       }
       dbSession.commit();
     }
index ae2854cf85e3d451542eb0199e3a4c61e1d503e6..9fbc93982bda7b5ea9453dc3fd33df63db01abde 100644 (file)
@@ -20,9 +20,7 @@
 package org.sonar.server.almintegration.ws.azure;
 
 import com.google.common.annotations.VisibleForTesting;
-
 import java.util.Optional;
-
 import org.sonar.alm.client.azure.AzureDevOpsHttpClient;
 import org.sonar.alm.client.azure.GsonAzureRepo;
 import org.sonar.api.server.ws.Request;
@@ -137,6 +135,7 @@ public class ImportAzureProjectAction implements AlmIntegrationsWsAction {
         .setQualifier(PROJECT)
         .build(),
       userSession.isLoggedIn() ? userSession.getUuid() : null,
+      userSession.isLoggedIn() ? userSession.getLogin() : null,
       repo.getDefaultBranchName(),
       s -> {
       });
@@ -149,7 +148,7 @@ public class ImportAzureProjectAction implements AlmIntegrationsWsAction {
       .setAlmSlug(repo.getProject().getName())
       .setProjectUuid(componentDto.uuid())
       .setMonorepo(false);
-    dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto);
+    dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), componentDto.name());
   }
 
   @VisibleForTesting
index 6c69b4410c218f4e2f5420945071f9da801abf25..b3cb415e680003ef3fcc3376e200d07d91059c9a 100644 (file)
@@ -131,8 +131,9 @@ public class ImportBitbucketCloudRepoAction implements AlmIntegrationsWsAction {
       .setQualifier(PROJECT)
       .build();
     String userUuid = userSession.isLoggedIn() ? userSession.getUuid() : null;
+    String userLogin = userSession.isLoggedIn() ? userSession.getLogin() : null;
 
-    return componentUpdater.createWithoutCommit(dbSession, newProject, userUuid, defaultBranchName, p -> {
+    return componentUpdater.createWithoutCommit(dbSession, newProject, userUuid, userLogin, defaultBranchName, p -> {
     });
   }
 
@@ -143,7 +144,7 @@ public class ImportBitbucketCloudRepoAction implements AlmIntegrationsWsAction {
       .setAlmRepo(repo.getSlug())
       .setProjectUuid(componentDto.uuid())
       .setMonorepo(false);
-    dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto);
+    dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), componentDto.name());
   }
 
 }
index a1477a09e3dd8003bff7b8dcd965f7cadc6aca85..26c138ff67394d80137d052bd7edb765ed37d012 100644 (file)
@@ -148,8 +148,9 @@ public class ImportBitbucketServerProjectAction implements AlmIntegrationsWsActi
       .setQualifier(PROJECT)
       .build();
     String userUuid = userSession.isLoggedIn() ? userSession.getUuid() : null;
+    String userLogin = userSession.isLoggedIn() ? userSession.getLogin() : null;
 
-    return componentUpdater.createWithoutCommit(dbSession, newProject, userUuid, defaultBranchName, p -> {});
+    return componentUpdater.createWithoutCommit(dbSession, newProject, userUuid, userLogin, defaultBranchName, p -> {});
   }
 
   private void populatePRSetting(DbSession dbSession, Repository repo, ComponentDto componentDto, AlmSettingDto almSettingDto) {
@@ -159,7 +160,7 @@ public class ImportBitbucketServerProjectAction implements AlmIntegrationsWsActi
       .setAlmSlug(repo.getSlug())
       .setProjectUuid(componentDto.uuid())
       .setMonorepo(false);
-    dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto);
+    dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), componentDto.name());
   }
 
 }
index 3b093435d65f4689f4efcf8459b3ef94e03dcf4a..ce584b71a9d54c0d09c9e45796eefe0ca9716906 100644 (file)
@@ -137,7 +137,7 @@ public class ImportGithubProjectAction implements AlmIntegrationsWsAction {
       .setPrivate(visibility)
       .setQualifier(PROJECT)
       .build(),
-      userSession.getUuid(), mainBranchName, s -> {});
+      userSession.getUuid(), userSession.getLogin(), mainBranchName, s -> {});
   }
 
   static String getProjectKeyFromRepository(Repository repo) {
@@ -152,6 +152,6 @@ public class ImportGithubProjectAction implements AlmIntegrationsWsAction {
       .setProjectUuid(componentDto.uuid())
       .setSummaryCommentEnabled(true)
       .setMonorepo(false);
-    dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto);
+    dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), componentDto.name());
   }
 }
index f89ad82f3389cf93071136de17b6cebdc852dd6f..ec378fed13880a4011ddc12d41ffbdd0e60c31fe 100644 (file)
@@ -122,13 +122,13 @@ public class ListGithubOrganizationsAction implements AlmIntegrationsWsAction {
         if (almPatDto.isPresent()) {
           AlmPatDto almPat = almPatDto.get();
           almPat.setPersonalAccessToken(accessToken.getValue());
-          dbClient.almPatDao().update(dbSession, almPat);
+          dbClient.almPatDao().update(dbSession, almPat, userSession.getLogin(), almSettingDto.getKey());
         } else {
           AlmPatDto almPat = new AlmPatDto()
             .setPersonalAccessToken(accessToken.getValue())
             .setAlmSettingUuid(almSettingDto.getUuid())
             .setUserUuid(userUuid);
-          dbClient.almPatDao().insert(dbSession, almPat);
+          dbClient.almPatDao().insert(dbSession, almPat, userSession.getLogin(), almSettingDto.getKey());
         }
         dbSession.commit();
       } else {
index ae3629e87cd1581e800bd47f4c56ff0a8e058de6..6fcfcba5f0b2e8d4cde6230a1b93cf1de9768706 100644 (file)
@@ -124,11 +124,13 @@ public class ImportGitLabProjectAction implements AlmIntegrationsWsAction {
 
   private void populateMRSetting(DbSession dbSession, Long gitlabProjectId, ComponentDto componentDto, AlmSettingDto almSettingDto) {
     dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, new ProjectAlmSettingDto()
-      .setProjectUuid(componentDto.projectUuid())
-      .setAlmSettingUuid(almSettingDto.getUuid())
-      .setAlmRepo(gitlabProjectId.toString())
-      .setAlmSlug(null)
-      .setMonorepo(false));
+        .setProjectUuid(componentDto.projectUuid())
+        .setAlmSettingUuid(almSettingDto.getUuid())
+        .setAlmRepo(gitlabProjectId.toString())
+        .setAlmSlug(null)
+        .setMonorepo(false),
+      almSettingDto.getKey(),
+      componentDto.name());
   }
 
   private ComponentDto createProject(DbSession dbSession, Project gitlabProject, @Nullable String mainBranchName) {
@@ -136,12 +138,12 @@ public class ImportGitLabProjectAction implements AlmIntegrationsWsAction {
     String sqProjectKey = generateProjectKey(gitlabProject.getPathWithNamespace(), uuidFactory.create());
 
     return componentUpdater.createWithoutCommit(dbSession, newComponentBuilder()
-      .setKey(sqProjectKey)
-      .setName(gitlabProject.getName())
-      .setPrivate(visibility)
-      .setQualifier(PROJECT)
-      .build(),
-      userSession.getUuid(), mainBranchName, s -> {
+        .setKey(sqProjectKey)
+        .setName(gitlabProject.getName())
+        .setPrivate(visibility)
+        .setQualifier(PROJECT)
+        .build(),
+      userSession.getUuid(), userSession.getLogin(), mainBranchName, s -> {
       });
   }
 
index 423a0228a957d61de217b482127927178abfba84..a3ea90987e370cf52122621be8b1934cf736404e 100644 (file)
@@ -152,6 +152,7 @@ public class ReportSubmitter {
   private ComponentDto createProject(DbSession dbSession, BranchSupport.ComponentKey componentKey, @Nullable String projectName) {
     userSession.checkPermission(GlobalPermission.PROVISION_PROJECTS);
     String userUuid = userSession.getUuid();
+    String userName = userSession.getLogin();
 
     boolean wouldCurrentUserHaveScanPermission = permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(
       dbSession, userUuid, componentKey.getDbKey());
@@ -165,7 +166,7 @@ public class ReportSubmitter {
       .setQualifier(Qualifiers.PROJECT)
       .setPrivate(getDefaultVisibility(dbSession).isPrivate())
       .build();
-    return componentUpdater.createWithoutCommit(dbSession, newProject, userUuid, c -> {
+    return componentUpdater.createWithoutCommit(dbSession, newProject, userUuid, userName, c -> {
     });
   }
 
index 5a1c8a23c04e4ba968041bf141cf442b2db8bb78..14a7b65c791a365b99c0e7df821049a6df8627ae 100644 (file)
@@ -78,8 +78,8 @@ public class ComponentUpdater {
    * - Add component to favorite if the component has the 'Project Creators' permission
    * - Index component in es indexes
    */
-  public ComponentDto create(DbSession dbSession, NewComponent newComponent, @Nullable String userUuid) {
-    ComponentDto componentDto = createWithoutCommit(dbSession, newComponent, userUuid, c -> {
+  public ComponentDto create(DbSession dbSession, NewComponent newComponent, @Nullable String userUuid, @Nullable String userLogin) {
+    ComponentDto componentDto = createWithoutCommit(dbSession, newComponent, userUuid, userLogin, c -> {
     });
     commitAndIndex(dbSession, componentDto);
     return componentDto;
@@ -90,8 +90,8 @@ public class ComponentUpdater {
    * Don't forget to call commitAndIndex(...) when ready to commit.
    */
   public ComponentDto createWithoutCommit(DbSession dbSession, NewComponent newComponent,
-    @Nullable String userUuid, Consumer<ComponentDto> componentModifier) {
-    return createWithoutCommit(dbSession, newComponent, userUuid, null, componentModifier);
+    @Nullable String userUuid, @Nullable String userLogin,  Consumer<ComponentDto> componentModifier) {
+    return createWithoutCommit(dbSession, newComponent, userUuid, userLogin, null, componentModifier);
   }
 
   /**
@@ -99,14 +99,14 @@ public class ComponentUpdater {
    * Don't forget to call commitAndIndex(...) when ready to commit.
    */
   public ComponentDto createWithoutCommit(DbSession dbSession, NewComponent newComponent,
-    @Nullable String userUuid, @Nullable String mainBranchName,
+    @Nullable String userUuid, @Nullable String userLogin, @Nullable String mainBranchName,
     Consumer<ComponentDto> componentModifier) {
     checkKeyFormat(newComponent.qualifier(), newComponent.key());
     ComponentDto componentDto = createRootComponent(dbSession, newComponent, componentModifier);
     if (isRootProject(componentDto)) {
       createMainBranch(dbSession, componentDto.uuid(), mainBranchName);
     }
-    handlePermissionTemplate(dbSession, componentDto, userUuid);
+    handlePermissionTemplate(dbSession, componentDto, userUuid, userLogin);
     return componentDto;
   }
 
@@ -175,11 +175,11 @@ public class ComponentUpdater {
     dbClient.branchDao().upsert(session, branch);
   }
 
-  private void handlePermissionTemplate(DbSession dbSession, ComponentDto componentDto, @Nullable String userUuid) {
+  private void handlePermissionTemplate(DbSession dbSession, ComponentDto componentDto, @Nullable String userUuid, @Nullable String userLogin) {
     permissionTemplateService.applyDefault(dbSession, componentDto, userUuid);
     if (componentDto.qualifier().equals(PROJECT)
       && permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(dbSession, componentDto)) {
-      favoriteUpdater.add(dbSession, componentDto, userUuid, false);
+      favoriteUpdater.add(dbSession, componentDto, userUuid, userLogin, false);
     }
   }
 
index 5f9c5ff92533b371f5e5b2b6538d4b87b17063c5..4c87214d41cde37c305c0c4eef7717fc9c59ba0a 100644 (file)
@@ -96,7 +96,9 @@ public class AddAction implements FavoritesWsAction {
         userSession
           .checkLoggedIn()
           .checkComponentPermission(USER, componentDto);
-        favoriteUpdater.add(dbSession, componentDto, userSession.isLoggedIn() ? userSession.getUuid() : null, true);
+        String userUuid = userSession.isLoggedIn() ? userSession.getUuid() : null;
+        String userLogin = userSession.isLoggedIn() ? userSession.getLogin() : null;
+        favoriteUpdater.add(dbSession, componentDto, userUuid, userLogin, true);
         dbSession.commit();
       }
     };
index 8d61dc9669c0afd9b4a0f883e27274dd3478f41b..1fc8fff296205093f6461aa59bb38c1f45bf886e 100644 (file)
@@ -74,7 +74,9 @@ public class RemoveAction implements FavoritesWsAction {
       try (DbSession dbSession = dbClient.openSession(false)) {
         ComponentDto component = componentFinder.getByKey(dbSession, request.mandatoryParam(PARAM_COMPONENT));
         userSession.checkLoggedIn();
-        favoriteUpdater.remove(dbSession, component, userSession.isLoggedIn() ? userSession.getUuid() : null);
+        favoriteUpdater.remove(dbSession, component,
+          userSession.isLoggedIn() ? userSession.getUuid() : null,
+          userSession.isLoggedIn() ? userSession.getLogin() : null);
         dbSession.commit();
       }
     };
index 56d18ee79ad4835392a8bea0efc458ca6215680b..60779ed731b1c44043b2e457de0f64a621e320f5 100644 (file)
@@ -48,6 +48,7 @@ public class NotificationUpdater {
   public void add(DbSession dbSession, String channel, String dispatcher, UserDto user, @Nullable ComponentDto project) {
     String key = String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel);
     String projectUuid = project == null ? null : project.uuid();
+    String projectName = project == null ? null : project.name();
 
     List<PropertyDto> existingNotification = dbClient.propertiesDao().selectByQuery(
       PropertyQuery.builder()
@@ -65,7 +66,8 @@ public class NotificationUpdater {
       .setKey(key)
       .setUserUuid(user.getUuid())
       .setValue(PROP_NOTIFICATION_VALUE)
-      .setComponentUuid(projectUuid));
+      .setComponentUuid(projectUuid),
+      user.getLogin(), projectName);
   }
 
   /**
@@ -74,6 +76,7 @@ public class NotificationUpdater {
   public void remove(DbSession dbSession, String channel, String dispatcher, UserDto user, @Nullable ComponentDto project) {
     String key = String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel);
     String projectUuid = project == null ? null : project.uuid();
+    String projectName = project == null ? null : project.name();
 
     List<PropertyDto> existingNotification = dbClient.propertiesDao().selectByQuery(
       PropertyQuery.builder()
@@ -90,7 +93,7 @@ public class NotificationUpdater {
       .setKey(key)
       .setUserUuid(user.getUuid())
       .setValue(PROP_NOTIFICATION_VALUE)
-      .setComponentUuid(projectUuid));
+      .setComponentUuid(projectUuid), user.getLogin(), projectName);
   }
 
   private static Predicate<PropertyDto> notificationScope(@Nullable ComponentDto project) {
index 6e16d7a5bbecc84d89bc45ab7a7832528ade4504..b094b9e1a005e537d2dd52beee7c7d29edc618a7 100644 (file)
@@ -120,7 +120,7 @@ public class GroupPermissionChanger {
       .setRole(change.getPermission())
       .setGroupUuid(change.getGroupUuidOrAnyone().getUuid())
       .setComponentUuid(change.getProjectUuid());
-    dbClient.groupPermissionDao().insert(dbSession, addedDto);
+    dbClient.groupPermissionDao().insert(dbSession, addedDto, change.getProject());
     return true;
   }
 
@@ -137,7 +137,8 @@ public class GroupPermissionChanger {
     dbClient.groupPermissionDao().delete(dbSession,
       change.getPermission(),
       change.getGroupUuidOrAnyone().getUuid(),
-      change.getProjectUuid());
+      change.getProjectUuid(),
+      change.getProject());
     return true;
   }
 
index 59255b27ac4d7aea1a4c28d761d5008a681d243f..6b4f5fdcd80ef9228efbf64ebd67846c8d92a116 100644 (file)
@@ -126,8 +126,8 @@ public class PermissionTemplateService {
   }
 
   private void copyPermissions(DbSession dbSession, PermissionTemplateDto template, ComponentDto project, @Nullable String projectCreatorUserUuid) {
-    dbClient.groupPermissionDao().deleteByRootComponentUuid(dbSession, project.uuid());
-    dbClient.userPermissionDao().deleteProjectPermissions(dbSession, project.uuid());
+    dbClient.groupPermissionDao().deleteByRootComponentUuid(dbSession, project.uuid(), project.name());
+    dbClient.userPermissionDao().deleteProjectPermissions(dbSession, project.uuid(), project.name());
 
     List<PermissionTemplateUserDto> usersPermissions = dbClient.permissionTemplateDao().selectUserPermissionsByTemplateId(dbSession, template.getUuid());
     Map<String, String> userDtoMap = dbClient.userDao().selectByUuids(dbSession, usersPermissions.stream().map(PermissionTemplateUserDto::getUserUuid).collect(Collectors.toSet()))
@@ -137,7 +137,7 @@ public class PermissionTemplateService {
       .filter(up -> permissionValidForProject(project, up.getPermission()))
       .forEach(up -> {
         UserPermissionDto dto = new UserPermissionDto(uuidFactory.create(), up.getPermission(), userDtoMap.get(up.getUserUuid()), project.uuid());
-        dbClient.userPermissionDao().insert(dbSession, dto);
+        dbClient.userPermissionDao().insert(dbSession, dto, project);
       });
 
     List<PermissionTemplateGroupDto> groupsPermissions = dbClient.permissionTemplateDao().selectGroupPermissionsByTemplateUuid(dbSession, template.getUuid());
@@ -151,7 +151,7 @@ public class PermissionTemplateService {
           .setGroupUuid(isAnyone(gp.getGroupName()) ? null : gp.getGroupUuid())
           .setRole(gp.getPermission())
           .setComponentUuid(project.uuid());
-        dbClient.groupPermissionDao().insert(dbSession, dto);
+        dbClient.groupPermissionDao().insert(dbSession, dto, project);
       });
 
     List<PermissionTemplateCharacteristicDto> characteristics = dbClient.permissionTemplateCharacteristicDao().selectByTemplateUuids(dbSession, singletonList(template.getUuid()));
@@ -168,7 +168,7 @@ public class PermissionTemplateService {
         .filter(characteristic -> !permissionsForCurrentUserAlreadyInDb.contains(characteristic.getPermission()))
         .forEach(c -> {
           UserPermissionDto dto = new UserPermissionDto(uuidFactory.create(), c.getPermission(), userDto.getUuid(), project.uuid());
-          dbClient.userPermissionDao().insert(dbSession, dto);
+          dbClient.userPermissionDao().insert(dbSession, dto, project);
         });
     }
   }
index d5f1a0f6e903f9387db8e9660c21936daf2b7709..1a3de04965b24e431caa19b6adadad691427bf40 100644 (file)
@@ -98,7 +98,7 @@ public class UserPermissionChanger {
     }
     UserPermissionDto dto = new UserPermissionDto(uuidFactory.create(), change.getPermission(), change.getUserId().getUuid(),
       change.getProjectUuid());
-    dbClient.userPermissionDao().insert(dbSession, dto);
+    dbClient.userPermissionDao().insert(dbSession, dto, change.getProject());
     return true;
   }
 
@@ -108,8 +108,10 @@ public class UserPermissionChanger {
     }
     checkOtherAdminsExist(dbSession, change);
     String projectUuid = change.getProjectUuid();
+    String projectName = change.getProject() == null ? null : change.getProject().name();
     if (projectUuid != null) {
-      dbClient.userPermissionDao().deleteProjectPermission(dbSession, change.getUserId().getUuid(), change.getPermission(), projectUuid);
+      dbClient.userPermissionDao().deleteProjectPermission(dbSession, change.getUserId().getUuid(), change.getPermission(),
+        projectUuid, projectName);
     } else {
       dbClient.userPermissionDao().deleteGlobalPermission(dbSession, change.getUserId().getUuid(), change.getPermission());
     }
index bd6350003dc93eee77f72f6fb5a1b0c042eb6efe..84483e101659d3283b18f18f06ad5adf2765e711 100644 (file)
@@ -40,6 +40,7 @@ import static org.sonar.server.permission.ws.WsParameters.createGroupIdParameter
 import static org.sonar.server.permission.ws.WsParameters.createGroupNameParameter;
 import static org.sonar.server.permission.ws.WsParameters.createTemplateParameters;
 import static org.sonar.server.permission.ws.template.WsTemplateRef.fromRequest;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_NAME;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
 
 public class AddGroupToTemplateAction implements PermissionsWsAction {
@@ -86,7 +87,8 @@ public class AddGroupToTemplateAction implements PermissionsWsAction {
       checkGlobalAdmin(userSession);
 
       if (!groupAlreadyAdded(dbSession, template.getUuid(), permission, group)) {
-        dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getUuid(), group.getUuid(), permission);
+        dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getUuid(), group.getUuid(), permission,
+          template.getName(), request.param(PARAM_GROUP_NAME));
         dbSession.commit();
       }
     }
index 426f1c51baa6b42573fc930b7263347cf05d607f..e257f3c3d25b84d32b2837bfac96bce0104ef298 100644 (file)
@@ -99,7 +99,7 @@ public class AddProjectCreatorToTemplateAction implements PermissionsWsAction {
       Optional<PermissionTemplateCharacteristicDto> templatePermission = dbClient.permissionTemplateCharacteristicDao()
         .selectByPermissionAndTemplateId(dbSession, request.getPermission(), template.getUuid());
       if (templatePermission.isPresent()) {
-        updateTemplatePermission(dbSession, templatePermission.get());
+        updateTemplatePermission(dbSession, templatePermission.get(), template.getName());
       } else {
         addTemplatePermission(dbSession, request, template);
       }
@@ -109,20 +109,21 @@ public class AddProjectCreatorToTemplateAction implements PermissionsWsAction {
   private void addTemplatePermission(DbSession dbSession, AddProjectCreatorToTemplateRequest request, PermissionTemplateDto template) {
     long now = system.now();
     dbClient.permissionTemplateCharacteristicDao().insert(dbSession, new PermissionTemplateCharacteristicDto()
-      .setUuid(Uuids.create())
-      .setPermission(request.getPermission())
-      .setTemplateUuid(template.getUuid())
-      .setWithProjectCreator(true)
-      .setCreatedAt(now)
-      .setUpdatedAt(now));
+        .setUuid(Uuids.create())
+        .setPermission(request.getPermission())
+        .setTemplateUuid(template.getUuid())
+        .setWithProjectCreator(true)
+        .setCreatedAt(now)
+        .setUpdatedAt(now),
+      template.getName());
     dbSession.commit();
   }
 
-  private void updateTemplatePermission(DbSession dbSession, PermissionTemplateCharacteristicDto templatePermission) {
+  private void updateTemplatePermission(DbSession dbSession, PermissionTemplateCharacteristicDto templatePermission, String templateName) {
     PermissionTemplateCharacteristicDto targetTemplatePermission = templatePermission
       .setUpdatedAt(system.now())
       .setWithProjectCreator(true);
-    dbClient.permissionTemplateCharacteristicDao().update(dbSession, targetTemplatePermission);
+    dbClient.permissionTemplateCharacteristicDao().update(dbSession, targetTemplatePermission, templateName);
     dbSession.commit();
   }
 
index 5e02fe1b5ff82ac70ebfd6dfa888681e722f733f..2ee0e3bdd9944df423f285018c3d4da1699627f5 100644 (file)
@@ -98,7 +98,8 @@ public class AddUserToTemplateAction implements PermissionsWsAction {
       UserId user = wsSupport.findUser(dbSession, userLogin);
 
       if (!isUserAlreadyAdded(dbSession, template.getUuid(), userLogin, permission)) {
-        dbClient.permissionTemplateDao().insertUserPermission(dbSession, template.getUuid(), user.getUuid(), permission);
+        dbClient.permissionTemplateDao().insertUserPermission(dbSession, template.getUuid(), user.getUuid(), permission,
+          template.getName(), user.getLogin());
         dbSession.commit();
       }
     }
index 71260b0e0b7a2cd1fbbc21aba46542c8944066f2..674ab9d45023033be90569a53c618e4c85aa5084 100644 (file)
@@ -85,7 +85,7 @@ public class DeleteTemplateAction implements PermissionsWsAction {
       checkGlobalAdmin(userSession);
 
       checkTemplateUuidIsNotDefault(dbSession, template);
-      dbClient.permissionTemplateDao().deleteByUuid(dbSession, template.getUuid());
+      dbClient.permissionTemplateDao().deleteByUuid(dbSession, template.getUuid(), template.getName());
       dbSession.commit();
     }
   }
index e546862f07927078b782212b8f243cbba3724123..166f75b3652e78cb52e0bfe642f440bf5947183e 100644 (file)
@@ -36,6 +36,7 @@ import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobal
 import static org.sonar.server.permission.ws.WsParameters.createGroupIdParameter;
 import static org.sonar.server.permission.ws.WsParameters.createGroupNameParameter;
 import static org.sonar.server.permission.ws.WsParameters.createTemplateParameters;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_NAME;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
 
 public class RemoveGroupFromTemplateAction implements PermissionsWsAction {
@@ -78,7 +79,8 @@ public class RemoveGroupFromTemplateAction implements PermissionsWsAction {
       checkGlobalAdmin(userSession);
       GroupUuidOrAnyone group = wsSupport.findGroup(dbSession, request);
 
-      dbClient.permissionTemplateDao().deleteGroupPermission(dbSession, template.getUuid(), group.getUuid(), permission);
+      dbClient.permissionTemplateDao().deleteGroupPermission(dbSession, template.getUuid(), group.getUuid(), permission,
+        template.getName(), request.param(PARAM_GROUP_NAME));
       dbSession.commit();
     }
     response.noContent();
index 9b8defef1c9a838fe125edc860dd9c302ddbdf98..2adeeb358be5f5257c9f6b569820e5a529e7ff96 100644 (file)
@@ -97,15 +97,16 @@ public class RemoveProjectCreatorFromTemplateAction implements PermissionsWsActi
 
       PermissionTemplateCharacteristicDao dao = dbClient.permissionTemplateCharacteristicDao();
       dao.selectByPermissionAndTemplateId(dbSession, request.getPermission(), template.getUuid())
-        .ifPresent(permissionTemplateCharacteristicDto -> updateTemplateCharacteristic(dbSession, permissionTemplateCharacteristicDto));
+        .ifPresent(permissionTemplateCharacteristicDto -> updateTemplateCharacteristic(dbSession, permissionTemplateCharacteristicDto,
+          template.getName()));
     }
   }
 
-  private void updateTemplateCharacteristic(DbSession dbSession, PermissionTemplateCharacteristicDto templatePermission) {
+  private void updateTemplateCharacteristic(DbSession dbSession, PermissionTemplateCharacteristicDto templatePermission, String templateName) {
     PermissionTemplateCharacteristicDto targetTemplatePermission = templatePermission
       .setUpdatedAt(system.now())
       .setWithProjectCreator(false);
-    dbClient.permissionTemplateCharacteristicDao().update(dbSession, targetTemplatePermission);
+    dbClient.permissionTemplateCharacteristicDao().update(dbSession, targetTemplatePermission, templateName);
     dbSession.commit();
   }
 
index 5e3499ebdd43f8837180b0d551b94113f22c8ede..a8c5bc7df954f8461f08912260442614ecd00d17 100644 (file)
@@ -98,7 +98,7 @@ public class RemoveUserFromTemplateAction implements PermissionsWsAction {
 
       UserId user = wsSupport.findUser(dbSession, userLogin);
 
-      dbClient.permissionTemplateDao().deleteUserPermission(dbSession, template.getUuid(), user.getUuid(), permission);
+      dbClient.permissionTemplateDao().deleteUserPermission(dbSession, template.getUuid(), user.getUuid(), permission, template.getName(), user.getLogin());
       dbSession.commit();
     }
   }
index 089f50d55f2881b404be2a416058873cb1d6d949..6de38e799fe87b80eb56d5104accb831e9914512 100644 (file)
@@ -114,7 +114,8 @@ public class CreateAction implements ProjectsWsAction {
         .setPrivate(changeToPrivate)
         .setQualifier(PROJECT)
         .build(),
-        userSession.isLoggedIn() ? userSession.getUuid() : null);
+        userSession.isLoggedIn() ? userSession.getUuid() : null,
+        userSession.isLoggedIn() ? userSession.getLogin() : null);
       return toCreateResponse(componentDto);
     }
   }
index 3489b38c6051137e92fb23c4d1a288f50cf96867..97a1335980e8c5cd69aa3776b0f3cb777987b73a 100644 (file)
@@ -64,7 +64,7 @@ public class UpdateVisibilityAction implements ProjectsWsAction {
   private final Configuration configuration;
 
   public UpdateVisibilityAction(DbClient dbClient, ComponentFinder componentFinder, UserSession userSession,
-                                ProjectIndexers projectIndexers, UuidFactory uuidFactory, Configuration configuration) {
+    ProjectIndexers projectIndexers, UuidFactory uuidFactory, Configuration configuration) {
     this.dbClient = dbClient;
     this.componentFinder = componentFinder;
     this.userSession = userSession;
@@ -149,7 +149,7 @@ public class UpdateVisibilityAction implements ProjectsWsAction {
 
   private void updatePermissionsToPrivate(DbSession dbSession, ComponentDto component) {
     // delete project permissions for group AnyOne
-    dbClient.groupPermissionDao().deleteByRootComponentUuidAndGroupUuid(dbSession, component.uuid(), null);
+    dbClient.groupPermissionDao().deleteByRootComponentUuidAndGroupUuid(dbSession, component.uuid(), null, component.name());
     // grant UserRole.CODEVIEWER and UserRole.USER to any group or user with at least one permission on project
     PUBLIC_PERMISSIONS.forEach(permission -> {
       dbClient.groupPermissionDao().selectGroupUuidsWithPermissionOnProjectBut(dbSession, component.uuid(), permission)
@@ -160,23 +160,25 @@ public class UpdateVisibilityAction implements ProjectsWsAction {
   }
 
   private void insertProjectPermissionOnUser(DbSession dbSession, ComponentDto component, String permission, String userUuid) {
-    dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(Uuids.create(), permission, userUuid, component.uuid()));
+    dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(Uuids.create(), permission, userUuid, component.uuid()),
+      component);
   }
 
   private void insertProjectPermissionOnGroup(DbSession dbSession, ComponentDto component, String permission, String groupUuid) {
     dbClient.groupPermissionDao().insert(dbSession, new GroupPermissionDto()
-      .setUuid(uuidFactory.create())
-      .setComponentUuid(component.uuid())
-      .setGroupUuid(groupUuid)
-      .setRole(permission));
+        .setUuid(uuidFactory.create())
+        .setComponentUuid(component.uuid())
+        .setGroupUuid(groupUuid)
+        .setRole(permission),
+      component);
   }
 
   private void updatePermissionsToPublic(DbSession dbSession, ComponentDto component) {
     PUBLIC_PERMISSIONS.forEach(permission -> {
       // delete project group permission for UserRole.CODEVIEWER and UserRole.USER
-      dbClient.groupPermissionDao().deleteByRootComponentUuidAndPermission(dbSession, component.uuid(), permission);
+      dbClient.groupPermissionDao().deleteByRootComponentUuidAndPermission(dbSession, component.uuid(), permission, component.name());
       // delete project user permission for UserRole.CODEVIEWER and UserRole.USER
-      dbClient.userPermissionDao().deleteProjectPermissionOfAnyUser(dbSession, component.uuid(), permission);
+      dbClient.userPermissionDao().deleteProjectPermissionOfAnyUser(dbSession, component.uuid(), permission, component.name());
     });
   }
 
index 1a3b6b2c26069a3d49d24aa47000bf73d9779e4d..9bd81ab42197b5ecde0606547ba34106cd09e8df 100644 (file)
@@ -23,20 +23,33 @@ import org.sonar.api.config.internal.Settings;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
 import org.sonar.server.user.UserSession;
 import org.sonarqube.ws.Settings.GenerateSecretKeyWsResponse;
 
 import static org.sonar.server.ws.WsUtils.writeProtobuf;
 
 public class GenerateSecretKeyAction implements SettingsWsAction {
+  private final DbClient dbClient;
   private final Settings settings;
   private final UserSession userSession;
+  private AuditPersister auditPersister;
 
-  public GenerateSecretKeyAction(Settings settings, UserSession userSession) {
+  public GenerateSecretKeyAction(DbClient dbClient, Settings settings, UserSession userSession) {
+    this.dbClient = dbClient;
     this.settings = settings;
     this.userSession = userSession;
   }
 
+  public GenerateSecretKeyAction(DbClient dbClient, Settings settings, UserSession userSession, AuditPersister auditPersister) {
+    this.dbClient = dbClient;
+    this.settings = settings;
+    this.userSession = userSession;
+    this.auditPersister = auditPersister;
+  }
+
   @Override
   public void define(WebService.NewController context) {
     context.createAction("generate_secret_key")
@@ -53,5 +66,12 @@ public class GenerateSecretKeyAction implements SettingsWsAction {
     userSession.checkIsSystemAdministrator();
 
     writeProtobuf(GenerateSecretKeyWsResponse.newBuilder().setSecretKey(settings.getEncryption().generateRandomSecretKey()).build(), request, response);
+
+    if (auditPersister != null) {
+      try (DbSession dbSession = dbClient.openSession(false)) {
+        auditPersister.generateSecretKey(dbSession);
+        dbSession.commit();
+      }
+    }
   }
 }
index 3170aed7c4b1ecad5699a93d2675016c8af3cb60..a0a346b911cda853b922fce25dc327ba1dcb4af9 100644 (file)
@@ -94,13 +94,13 @@ public class SetAction implements SettingsWsAction {
   public void define(WebService.NewController context) {
     WebService.NewAction action = context.createAction("set")
       .setDescription("Update a setting value.<br>" +
-        "Either '%s' or '%s' must be provided.<br> " +
-        "The settings defined in conf/sonar.properties are read-only and can't be changed.<br/>" +
-        "Requires one of the following permissions: " +
-        "<ul>" +
-        "<li>'Administer System'</li>" +
-        "<li>'Administer' rights on the specified component</li>" +
-        "</ul>",
+          "Either '%s' or '%s' must be provided.<br> " +
+          "The settings defined in conf/sonar.properties are read-only and can't be changed.<br/>" +
+          "Requires one of the following permissions: " +
+          "<ul>" +
+          "<li>'Administer System'</li>" +
+          "<li>'Administer' rights on the specified component</li>" +
+          "</ul>",
         PARAM_VALUE, PARAM_VALUES)
       .setSince("6.1")
       .setChangelog(
@@ -145,6 +145,7 @@ public class SetAction implements SettingsWsAction {
 
   private void doHandle(DbSession dbSession, SetRequest request) {
     Optional<ComponentDto> component = searchComponent(dbSession, request);
+    String projectName = component.isPresent() ? component.get().name() : null;
     checkPermissions(component);
 
     PropertyDefinition definition = propertyDefinitions.get(request.getKey());
@@ -159,7 +160,7 @@ public class SetAction implements SettingsWsAction {
       validate(request);
       PropertyDto property = toProperty(request, component);
       value = property.getValue();
-      dbClient.propertiesDao().saveProperty(dbSession, property);
+      dbClient.propertiesDao().saveProperty(dbSession, property, null, projectName);
     }
 
     dbSession.commit();
@@ -176,15 +177,18 @@ public class SetAction implements SettingsWsAction {
     String inlinedFieldKeys = IntStream.of(fieldIds).mapToObj(String::valueOf).collect(COMMA_JOINER);
     String key = persistedKey(request);
     String componentUuid = component.isPresent() ? component.get().uuid() : null;
+    String componentName = component.isPresent() ? component.get().name() : null;
 
     deleteSettings(dbSession, component, key);
-    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(inlinedFieldKeys).setComponentUuid(componentUuid));
+    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(inlinedFieldKeys)
+      .setComponentUuid(componentUuid), null, componentName);
 
     List<String> fieldValues = request.getFieldValues();
     IntStream.of(fieldIds).boxed()
       .flatMap(i -> readOneFieldValues(fieldValues.get(i - 1), request.getKey()).entrySet().stream()
         .map(entry -> new KeyValue(key + "." + i + "." + entry.getKey(), entry.getValue())))
-      .forEach(keyValue -> dbClient.propertiesDao().saveProperty(dbSession, toFieldProperty(keyValue, componentUuid)));
+      .forEach(keyValue -> dbClient.propertiesDao().saveProperty(dbSession, toFieldProperty(keyValue, componentUuid),
+        null, componentName));
 
     return inlinedFieldKeys;
   }
index 28b395ebe3acfccc920ae4782f7836c2c6f62fb3..fe8f0973b1cbb1762d5e44898211225dd3667582 100644 (file)
@@ -75,7 +75,7 @@ public class SettingsUpdater {
 
   private void deleteSetting(DbSession dbSession, String settingKey, Optional<ComponentDto> componentDto) {
     if (componentDto.isPresent()) {
-      dbClient.propertiesDao().deleteProjectProperty(settingKey, componentDto.get().uuid(), dbSession);
+      dbClient.propertiesDao().deleteProjectProperty(settingKey, componentDto.get().uuid(), dbSession, componentDto.get().name());
     } else {
       dbClient.propertiesDao().deleteGlobalProperty(settingKey, dbSession);
     }
index 2b3af10c93bf493d4466d712b86ffc96990f0808..8961d3e418bb5dbf56fb335283af4ca9bc2ba403 100644 (file)
@@ -90,7 +90,7 @@ public class DeactivateAction implements UsersWsAction {
       dbClient.propertiesDao().deleteByQuery(dbSession, PropertyQuery.builder().setUserUuid(userUuid).build());
       dbClient.userGroupDao().deleteByUserUuid(dbSession, user);
       dbClient.userPermissionDao().deleteByUserUuid(dbSession, userUuid);
-      dbClient.permissionTemplateDao().deleteUserPermissionsByUserUuid(dbSession, userUuid);
+      dbClient.permissionTemplateDao().deleteUserPermissionsByUserUuid(dbSession, userUuid, user.getLogin());
       dbClient.qProfileEditUsersDao().deleteByUser(dbSession, user);
       dbClient.userPropertiesDao().deleteByUser(dbSession, user);
       dbClient.almPatDao().deleteByUser(dbSession, user);
index 3b7baca350f208431e78dfbac67963968e6aa245..a7b5891ad159266e588bcbcc6c32fd9df9a90b58 100644 (file)
@@ -95,7 +95,7 @@ public class DeleteAction implements UserGroupsWsAction {
   }
 
   private void removeFromPermissionTemplates(DbSession dbSession, GroupDto group) {
-    dbClient.permissionTemplateDao().deleteByGroup(dbSession, group.getUuid());
+    dbClient.permissionTemplateDao().deleteByGroup(dbSession, group.getUuid(), group.getName());
   }
 
   private void removeGroupMembers(DbSession dbSession, GroupDto group) {
index 3e0b2cf84ca81bf419d23541e8b22c0ed5dfabb9..ca96fd485d1e320ca31a55e5d63d28156011962f 100644 (file)
@@ -126,7 +126,8 @@ public class CreateAction implements WebhooksWsAction {
 
       webhookSupport.checkUrlPattern(url, "Url parameter with value '%s' is not a valid url", url);
       WebhookDto dto = doHandle(dbSession, projectDto, name, url, secret);
-      dbClient.webhookDao().insert(dbSession, dto);
+      String projectName = projectDto == null ? null : projectDto.getName();
+      dbClient.webhookDao().insert(dbSession, dto, projectName);
       dbSession.commit();
       writeResponse(request, response, dto);
     }
index 1ba37ccdd094fe0d2e17d2bc92f95af6c130cd60..5ea7c69c2ac629e6880f7a5e390b575de8224533 100644 (file)
@@ -94,7 +94,7 @@ public class DeleteAction implements WebhooksWsAction {
 
   private void deleteWebhook(DbSession dbSession, WebhookDto webhookDto) {
     dbClient.webhookDeliveryDao().deleteByWebhook(dbSession, webhookDto);
-    dbClient.webhookDao().delete(dbSession, webhookDto.getUuid());
+    dbClient.webhookDao().delete(dbSession, webhookDto.getUuid(), webhookDto.getName());
   }
 
 }
index d6b5cd87d5241893bb981204fe2c571a6e110072..19511535d4c82e52a0718e4ff85a6ce51e1c116b 100644 (file)
@@ -116,10 +116,10 @@ public class UpdateAction implements WebhooksWsAction {
       if (projectUuid != null) {
         ProjectDto projectDto = componentFinder.getProjectByUuid(dbSession, projectUuid);
         webhookSupport.checkPermission(projectDto);
-        updateWebhook(dbSession, webhookDto, name, url, secret);
+        updateWebhook(dbSession, webhookDto, name, url, secret, projectDto.getName());
       } else {
         webhookSupport.checkPermission();
-        updateWebhook(dbSession, webhookDto, name, url, secret);
+        updateWebhook(dbSession, webhookDto, name, url, secret, null);
       }
 
       dbSession.commit();
@@ -128,12 +128,12 @@ public class UpdateAction implements WebhooksWsAction {
     response.noContent();
   }
 
-  private void updateWebhook(DbSession dbSession, WebhookDto dto, String name, String url, @Nullable String secret) {
+  private void updateWebhook(DbSession dbSession, WebhookDto dto, String name, String url, @Nullable String secret, @Nullable String projectName) {
     dto
       .setName(name)
       .setUrl(url)
       .setSecret(secret);
-    dbClient.webhookDao().update(dbSession, dto);
+    dbClient.webhookDao().update(dbSession, dto, projectName);
   }
 
 }
index 28be2ab4c92336a93875c55e3743d6aa3286e272..1884443d3c876b2c2293de2f0b577b7478ae691f 100644 (file)
@@ -245,7 +245,7 @@ public class CheckPatActionTest {
     UserDto user = db.users().insertUser();
     userSession.logIn(user).addPermission(PROVISION_PROJECTS);
     AlmPatDto almPatDto = newAlmPatDto();
-    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
 
     TestRequest request = ws.newRequest().setParam("almSetting", "testKey");
     assertThatThrownBy(request::execute)
index 710f2df4ac74ba14587fa20a585063db3cbfda1a..8d7610b206be8fc14723b0520625918f1b93ec28 100644 (file)
@@ -211,7 +211,7 @@ public class ImportAzureProjectActionTest {
     UserDto user = db.users().insertUser();
     userSession.logIn(user).addPermission(PROVISION_PROJECTS);
     AlmPatDto almPatDto = newAlmPatDto();
-    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
 
     TestRequest request = ws.newRequest()
       .setParam("almSetting", "testKey");
index aca6f3e978c58b71ac56f0bec07938cf30afe481..c73e70b2e086a9d3c9809c1d38639947a94d62a8 100644 (file)
@@ -124,9 +124,9 @@ public class ListAzureProjectsActionTest {
 
   @Test
   public void fail_check_alm_setting_not_found() {
-    insertUser();
+    UserDto user = insertUser();
     AlmPatDto almPatDto = newAlmPatDto();
-    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
 
     TestRequest request = ws.newRequest()
       .setParam("almSetting", "testKey");
index 5b01fc6062a7e5fe931d257294b85a01c4294a3d..7918962abd5f6bb1abaa611658fff2bce064edae 100644 (file)
@@ -296,9 +296,9 @@ public class SearchAzureReposActionTest {
 
   @Test
   public void fail_check_pat_alm_setting_not_found() {
-    insertUser();
+    UserDto user = insertUser();
     AlmPatDto almPatDto = newAlmPatDto();
-    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
 
     TestRequest request = ws.newRequest()
       .setParam("almSetting", "testKey");
index 78af3c2c9a196a52b248c3c1f4aee1cab3efb9a4..918232dbee613d8ce7ef702773dba52c60da8d82 100644 (file)
@@ -187,7 +187,7 @@ public class ImportBitbucketCloudRepoActionTest {
     UserDto user = db.users().insertUser();
     userSession.logIn(user).addPermission(PROVISION_PROJECTS);
     AlmPatDto almPatDto = newAlmPatDto();
-    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
 
     TestRequest request = ws.newRequest()
       .setParam("almSetting", "testKey")
index 14175d4d25f4f52e831b89af7ceaa028513c1547..f6531353b11fba115b22a078432b8a3d3b363b83 100644 (file)
@@ -149,7 +149,7 @@ public class SearchBitbucketCloudReposActionTest {
     UserDto user = db.users().insertUser();
     userSession.logIn(user).addPermission(PROVISION_PROJECTS);
     AlmPatDto almPatDto = newAlmPatDto();
-    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
 
     TestRequest request = ws.newRequest().setParam("almSetting", "testKey");
 
index 62d0fca00f809abe32abc87936f701a6392015f1..d3cdd223bb68a5778142715ad9394d5e0d68a10d 100644 (file)
@@ -203,7 +203,7 @@ public class ImportBitbucketServerProjectActionTest {
     UserDto user = db.users().insertUser();
     userSession.logIn(user).addPermission(PROVISION_PROJECTS);
     AlmPatDto almPatDto = newAlmPatDto();
-    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("ALM Setting 'testKey' not found");
index 050ec5a410a489dbe70af90170301d86806d6e55..6fdd7f744972788433b50c4ac2969620c10447e1 100644 (file)
@@ -113,7 +113,7 @@ public class ListBitbucketServerProjectsActionTest {
     UserDto user = db.users().insertUser();
     userSession.logIn(user).addPermission(PROVISION_PROJECTS);
     AlmPatDto almPatDto = newAlmPatDto();
-    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
 
     TestRequest request = ws.newRequest()
       .setParam("almSetting", "testKey");
index d0c3907f2002e9a934ab8572de40a6d843c4e911..24748721ce03703a4659658d5660d0ce420e6bf8 100644 (file)
@@ -200,7 +200,7 @@ public class SearchBitbucketServerReposActionTest {
     UserDto user = db.users().insertUser();
     userSession.logIn(user).addPermission(PROVISION_PROJECTS);
     AlmPatDto almPatDto = newAlmPatDto();
-    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("ALM Setting 'testKey' not found");
index d1d728efa65dbb7cd1a8db3d028b2f05763baaed..0da6523ccf5186e917583d3768e05f662b441ccd 100644 (file)
@@ -197,7 +197,7 @@ public class SearchGitlabReposActionTest {
     UserDto user = db.users().insertUser();
     userSession.logIn(user).addPermission(PROVISION_PROJECTS);
     AlmPatDto almPatDto = newAlmPatDto();
-    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto);
+    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
 
     TestRequest request = ws.newRequest()
       .setParam("almSetting", "testKey");
index a774621fceec400ca78c64a4846ae8cb50f09f5f..e9cd6b598e050c05e5dd41b765d1bb45e696ffab 100644 (file)
@@ -183,7 +183,7 @@ public class BranchReportSubmitterTest {
     BranchSupport.ComponentKey componentKey = createComponentKeyOfBranch(createdBranch);
     when(branchSupportDelegate.createComponentKey(nonExistingProject.getDbKey(), randomCharacteristics))
       .thenReturn(componentKey);
-    when(componentUpdater.createWithoutCommit(any(), any(), eq(user.getUuid()), any()))
+    when(componentUpdater.createWithoutCommit(any(), any(), eq(user.getUuid()), eq(user.getLogin()), any()))
       .thenAnswer((Answer<ComponentDto>) invocation -> db.components().insertPrivateProject(nonExistingProject));
     when(branchSupportDelegate.createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingProject), any()))
       .thenReturn(createdBranch);
index a354afc7c0b3c866fee08d6e3a145075e4632dbe..538dc166710473ee4aa83ccc0fbc2dc7aac197e7 100644 (file)
@@ -202,7 +202,7 @@ public class ReportSubmitterTest {
   @Test
   public void do_no_add_favorite_when_already_100_favorite_projects_and_no_project_creator_permission_on_permission_template() {
     UserDto user = db.users().insertUser();
-    rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid()));
+    rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid(), user.getLogin()));
     userSession
       .logIn(user)
       .addPermission(GlobalPermission.SCAN)
index 670e087fc8d28822ffadc80700c367e2634ca616..c099512b97250743101eda9b12eebdb622d0c92c 100644 (file)
@@ -77,7 +77,7 @@ public class ComponentUpdaterTest {
       .setName(DEFAULT_PROJECT_NAME)
       .setPrivate(true)
       .build();
-    ComponentDto returned = underTest.create(db.getSession(), project, null);
+    ComponentDto returned = underTest.create(db.getSession(), project, null, null);
 
     ComponentDto loaded = db.getDbClient().componentDao().selectOrFailByUuid(db.getSession(), returned.uuid());
     assertThat(loaded.getDbKey()).isEqualTo(DEFAULT_PROJECT_KEY);
@@ -111,7 +111,7 @@ public class ComponentUpdaterTest {
       .setName(DEFAULT_PROJECT_NAME)
       .setPrivate(true)
       .build();
-    ComponentDto returned = underTest.create(db.getSession(), project, null);
+    ComponentDto returned = underTest.create(db.getSession(), project, null, null);
     ComponentDto loaded = db.getDbClient().componentDao().selectOrFailByUuid(db.getSession(), returned.uuid());
     assertThat(loaded.isPrivate()).isEqualTo(project.isPrivate());
   }
@@ -123,7 +123,7 @@ public class ComponentUpdaterTest {
       .setName(DEFAULT_PROJECT_NAME)
       .setPrivate(false)
       .build();
-    ComponentDto returned = underTest.create(db.getSession(), project, null);
+    ComponentDto returned = underTest.create(db.getSession(), project, null, null);
     ComponentDto loaded = db.getDbClient().componentDao().selectOrFailByUuid(db.getSession(), returned.uuid());
     assertThat(loaded.isPrivate()).isEqualTo(project.isPrivate());
   }
@@ -136,7 +136,7 @@ public class ComponentUpdaterTest {
       .setQualifier(VIEW)
       .build();
 
-    ComponentDto returned = underTest.create(db.getSession(), view, null);
+    ComponentDto returned = underTest.create(db.getSession(), view, null, null);
 
     ComponentDto loaded = db.getDbClient().componentDao().selectOrFailByUuid(db.getSession(), returned.uuid());
     assertThat(loaded.getDbKey()).isEqualTo("view-key");
@@ -155,7 +155,7 @@ public class ComponentUpdaterTest {
       .setQualifier(APP)
       .build();
 
-    ComponentDto returned = underTest.create(db.getSession(), application, null);
+    ComponentDto returned = underTest.create(db.getSession(), application, null, null);
 
     ComponentDto loaded = db.getDbClient().componentDao().selectOrFailByUuid(db.getSession(), returned.uuid());
     assertThat(loaded.getDbKey()).isEqualTo("app-key");
@@ -178,7 +178,7 @@ public class ComponentUpdaterTest {
       .setKey(DEFAULT_PROJECT_KEY)
       .setName(DEFAULT_PROJECT_NAME)
       .build();
-    ComponentDto dto = underTest.create(db.getSession(), project, userUuid);
+    ComponentDto dto = underTest.create(db.getSession(), project, userUuid, "user-login");
 
     verify(permissionTemplateService).applyDefault(db.getSession(), dto, userUuid);
   }
@@ -193,7 +193,7 @@ public class ComponentUpdaterTest {
     when(permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(any(DbSession.class), any(ComponentDto.class)))
       .thenReturn(true);
 
-    ComponentDto dto = underTest.create(db.getSession(), project, userDto.getUuid());
+    ComponentDto dto = underTest.create(db.getSession(), project, userDto.getUuid(), userDto.getLogin());
 
     assertThat(db.favorites().hasFavorite(dto, userDto.getUuid())).isTrue();
   }
@@ -201,7 +201,7 @@ public class ComponentUpdaterTest {
   @Test
   public void do_not_add_project_to_user_favorites_if_project_creator_is_defined_in_permission_template_and_already_100_favorites() {
     UserDto user = db.users().insertUser();
-    rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid()));
+    rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid(), user.getLogin()));
     NewComponent project = NewComponent.newComponentBuilder()
       .setKey(DEFAULT_PROJECT_KEY)
       .setName(DEFAULT_PROJECT_NAME)
@@ -211,7 +211,8 @@ public class ComponentUpdaterTest {
 
     ComponentDto dto = underTest.create(db.getSession(),
       project,
-      user.getUuid());
+      user.getUuid(),
+      user.getLogin());
 
     assertThat(db.favorites().hasFavorite(dto, user.getUuid())).isFalse();
   }
@@ -223,7 +224,7 @@ public class ComponentUpdaterTest {
         .setKey(DEFAULT_PROJECT_KEY)
         .setName(DEFAULT_PROJECT_NAME)
         .build(),
-      null);
+      null, null);
 
     assertThat(db.favorites().hasNoFavorite(project)).isTrue();
   }
@@ -235,7 +236,7 @@ public class ComponentUpdaterTest {
         .setKey(DEFAULT_PROJECT_KEY)
         .setName(DEFAULT_PROJECT_NAME)
         .build(),
-      null);
+      null, null);
 
     assertThat(db.favorites().hasNoFavorite(project)).isTrue();
   }
@@ -249,7 +250,7 @@ public class ComponentUpdaterTest {
       .setKey(existing.getDbKey())
       .setName(DEFAULT_PROJECT_NAME)
       .build();
-    assertThatThrownBy(() -> underTest.create(session, newComponent, null))
+    assertThatThrownBy(() -> underTest.create(session, newComponent, null, null))
       .isInstanceOf(BadRequestException.class)
       .hasMessage("Could not create Project, key already exists: " + existing.getDbKey());
   }
@@ -261,7 +262,7 @@ public class ComponentUpdaterTest {
       .setKey("1234")
       .setName(DEFAULT_PROJECT_NAME)
       .build();
-    assertThatThrownBy(() -> underTest.create(session, newComponent, null))
+    assertThatThrownBy(() -> underTest.create(session, newComponent, null, null))
       .isInstanceOf(BadRequestException.class)
       .hasMessageContaining("Malformed key for Project: '1234'");
   }
@@ -273,7 +274,7 @@ public class ComponentUpdaterTest {
       .setKey("roject%Key")
       .setName(DEFAULT_PROJECT_NAME)
       .build();
-    assertThatThrownBy(() -> underTest.create(session, newComponent, null))
+    assertThatThrownBy(() -> underTest.create(session, newComponent, null, null))
       .isInstanceOf(BadRequestException.class)
       .hasMessageContaining("Malformed key for Project: 'roject%Key'");
   }
index 12c2a44877addd066dce0d41eaf39c6d1b2e870f..634f5f7388133bbbfe329a69f387db8da7328162 100644 (file)
@@ -223,7 +223,7 @@ public class AppActionTest {
   public void component_is_favorite() {
     ComponentDto project = db.components().insertPrivateProject();
     userSession.logIn("john").addProjectPermission(USER, project);
-    db.favorites().add(project, userSession.getUuid());
+    db.favorites().add(project, userSession.getUuid(), userSession.getLogin());
 
     String result = ws.newRequest()
       .setParam("component", project.getKey())
index 6ad620d9f51cdc2099f4d4d8eb09dde9ba7e1e95..097969e1ad3a786ef6629dbc9a7c2ffe6fd8c570 100644 (file)
@@ -126,27 +126,27 @@ public class SearchProjectsActionTest {
 
   @DataProvider
   public static Object[][] rating_metric_keys() {
-    return new Object[][] {{SQALE_RATING_KEY}, {RELIABILITY_RATING_KEY}, {SECURITY_RATING_KEY}};
+    return new Object[][]{{SQALE_RATING_KEY}, {RELIABILITY_RATING_KEY}, {SECURITY_RATING_KEY}};
   }
 
   @DataProvider
   public static Object[][] new_rating_metric_keys() {
-    return new Object[][] {{NEW_MAINTAINABILITY_RATING_KEY}, {NEW_RELIABILITY_RATING_KEY}, {NEW_SECURITY_RATING_KEY}};
+    return new Object[][]{{NEW_MAINTAINABILITY_RATING_KEY}, {NEW_RELIABILITY_RATING_KEY}, {NEW_SECURITY_RATING_KEY}};
   }
 
   @DataProvider
   public static Object[][] component_qualifiers_for_valid_editions() {
-    return new Object[][] {
-      {new String[] {Qualifiers.PROJECT}, Edition.COMMUNITY},
-      {new String[] {Qualifiers.APP, Qualifiers.PROJECT}, Edition.DEVELOPER},
-      {new String[] {Qualifiers.APP, Qualifiers.PROJECT}, Edition.ENTERPRISE},
-      {new String[] {Qualifiers.APP, Qualifiers.PROJECT}, Edition.DATACENTER},
+    return new Object[][]{
+      {new String[]{Qualifiers.PROJECT}, Edition.COMMUNITY},
+      {new String[]{Qualifiers.APP, Qualifiers.PROJECT}, Edition.DEVELOPER},
+      {new String[]{Qualifiers.APP, Qualifiers.PROJECT}, Edition.ENTERPRISE},
+      {new String[]{Qualifiers.APP, Qualifiers.PROJECT}, Edition.DATACENTER},
     };
   }
 
   @DataProvider
   public static Object[][] community_or_developer_edition() {
-    return new Object[][] {
+    return new Object[][]{
       {Edition.COMMUNITY},
       {Edition.DEVELOPER},
     };
@@ -154,7 +154,7 @@ public class SearchProjectsActionTest {
 
   @DataProvider
   public static Object[][] enterprise_or_datacenter_edition() {
-    return new Object[][] {
+    return new Object[][]{
       {Edition.ENTERPRISE},
       {Edition.DATACENTER},
     };
@@ -558,7 +558,7 @@ public class SearchProjectsActionTest {
     Stream.of(javaProject, markDownProject).forEach(this::addFavourite);
     index();
 
-    addFavourite((String) null);
+    addFavourite(null, null);
 
     SearchProjectsWsResponse result = call(request.setFilter("isFavorite"));
 
@@ -1291,7 +1291,7 @@ public class SearchProjectsActionTest {
 
     List<Component> projects = call(request
       .setFilter("alert_status = WARN"))
-        .getComponentsList();
+      .getComponentsList();
 
     assertThat(projects)
       .extracting(Component::getKey)
@@ -1342,11 +1342,12 @@ public class SearchProjectsActionTest {
   }
 
   private void addFavourite(ComponentDto project) {
-    addFavourite(project.uuid());
+    addFavourite(project.uuid(), project.name());
   }
 
-  private void addFavourite(@Nullable String componentUuid) {
-    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("favourite").setComponentUuid(componentUuid).setUserUuid(userSession.getUuid()));
+  private void addFavourite(@Nullable String componentUuid, @Nullable String componentName) {
+    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("favourite")
+      .setComponentUuid(componentUuid).setUserUuid(userSession.getUuid()), userSession.getLogin(), componentName);
     dbSession.commit();
   }
 
index 24337a619205551f2b08a88727d8a5a48ad3c9cb..0f6a0c62f476a701ca229585c6390c17a816da4f 100644 (file)
@@ -70,8 +70,8 @@ public class RemoveActionTest {
   public void remove_a_favorite_project() {
     ComponentDto project = insertProjectAndPermissions();
     ComponentDto file = db.components().insertComponent(newFileDto(project));
-    db.favorites().add(project, user.getUuid());
-    db.favorites().add(file, user.getUuid());
+    db.favorites().add(project, user.getUuid(), user.getLogin());
+    db.favorites().add(file, user.getUuid(), user.getLogin());
 
     TestResponse result = call(PROJECT_KEY);
 
index 81653704d04f8e4b4f9cfe590b1c440264c1f089..87d3196b7ade3e1fae106934603799b870fdc46e 100644 (file)
@@ -54,6 +54,7 @@ import static org.sonarqube.ws.client.WsRequest.Method.POST;
 
 public class SearchActionTest {
   private String userUuid;
+  private String userLogin;
 
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
@@ -70,6 +71,7 @@ public class SearchActionTest {
     UserDto userDto = db.users().insertUser();
     userSession.logIn(userDto);
     userUuid = userDto.getUuid();
+    userLogin = userDto.getLogin();
   }
 
   @Test
@@ -104,7 +106,7 @@ public class SearchActionTest {
   public void filter_authorized_components() {
     addComponent(ComponentTesting.newPrivateProjectDto().setDbKey("K1"));
     ComponentDto unauthorizedProject = db.components().insertComponent(ComponentTesting.newPrivateProjectDto());
-    db.favorites().add(unauthorizedProject, userUuid);
+    db.favorites().add(unauthorizedProject, userUuid, userLogin);
 
     SearchResponse result = call();
 
@@ -117,7 +119,7 @@ public class SearchActionTest {
     IntStream.rangeClosed(1, 9)
       .forEach(i -> addComponent(ComponentTesting.newPrivateProjectDto().setDbKey("K" + i).setName("N" + i)));
     ComponentDto unauthorizedProject = db.components().insertComponent(ComponentTesting.newPrivateProjectDto());
-    db.favorites().add(unauthorizedProject, userUuid);
+    db.favorites().add(unauthorizedProject, userUuid, userLogin);
 
     SearchResponse result = call(2, 3);
 
@@ -133,7 +135,7 @@ public class SearchActionTest {
     addComponent(ComponentTesting.newPrivateProjectDto().setDbKey("K1"));
     ComponentDto otherUserFavorite = ComponentTesting.newPrivateProjectDto().setDbKey("K42");
     db.components().insertComponent(otherUserFavorite);
-    db.favorites().add(otherUserFavorite, "42");
+    db.favorites().add(otherUserFavorite, "42", userLogin);
     db.commit();
 
     SearchResponse result = call();
@@ -183,7 +185,7 @@ public class SearchActionTest {
 
   private void addComponent(ComponentDto component) {
     db.components().insertComponent(component);
-    db.favorites().add(component, userUuid);
+    db.favorites().add(component, userUuid, userLogin);
     db.commit();
     userSession.addProjectPermission(UserRole.USER, component);
   }
index 9c7ea76a89706979009068a880c500e64ac7c9fe..fae48ace40dc7a69ffdaea17553c8bfd98a5a903 100644 (file)
@@ -1398,7 +1398,8 @@ public class SearchActionTest {
         .setUuid(Uuids.createFast())
         .setGroupUuid(null)
         .setComponentUuid(project.uuid())
-        .setRole(permission));
+        .setRole(permission),
+      project);
     session.commit();
     userSession.logIn().addProjectPermission(permission, project);
   }
index 391cfa172d7d3b0ef2f6a81dd5c98ada2b9bc76d..e60064e7d8b48d1905f1558fde0daf3ff225b40c 100644 (file)
@@ -433,7 +433,7 @@ public class GroupPermissionChangerTest {
       .setGroupUuid(null)
       .setRole(perm)
       .setComponentUuid(privateProject.uuid());
-    db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
+    db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, privateProject);
     db.commit();
   }
 }
index f8bb924197e70fe87aa9ccea3511c960f15786a0..155ebd8829010bfb505d1679041868962e0629f8 100644 (file)
@@ -425,10 +425,10 @@ public class PermissionTemplateServiceTest {
     dbTester.users().insertMember(group, user);
     PermissionTemplateDto template = templateDb.insertTemplate();
     dbTester.permissionTemplates().setDefaultTemplates(template, null, null);
-    templateDb.addProjectCreatorToTemplate(template.getUuid(), SCAN.getKey());
-    templateDb.addUserToTemplate(template.getUuid(), user.getUuid(), UserRole.USER);
-    templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.CODEVIEWER);
-    templateDb.addGroupToTemplate(template.getUuid(), null, UserRole.ISSUE_ADMIN);
+    templateDb.addProjectCreatorToTemplate(template.getUuid(), SCAN.getKey(), template.getName());
+    templateDb.addUserToTemplate(template.getUuid(), user.getUuid(), UserRole.USER, template.getName(), user.getLogin());
+    templateDb.addGroupToTemplate(template.getUuid(), group.getUuid(), UserRole.CODEVIEWER, template.getName(), group.getName());
+    templateDb.addGroupToTemplate(template.getUuid(), null, UserRole.ISSUE_ADMIN, template.getName(), null);
 
     // authenticated user
     checkWouldUserHaveScanPermission(user.getUuid(), true);
index 40770cdac24ee11294ea60b4649c6a5dc03a9bdc..eb8e9ab2d33bf2881b3e523c30a3fa1cfc58d20e 100644 (file)
@@ -475,7 +475,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio
       .setGroupUuid(null)
       .setRole(perm)
       .setComponentUuid(project.uuid());
-    db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
+    db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, project);
     db.commit();
   }
 }
index ea1436148da9d65b5f0f1e9578d7d6163a56abe7..ae5b0f7672433a5e282154885ad4496b98fbb6c2 100644 (file)
@@ -89,7 +89,8 @@ public class AddProjectCreatorToTemplateActionTest extends BasePermissionWsTest<
         .setPermission(UserRole.USER)
         .setWithProjectCreator(false)
         .setCreatedAt(1_000_000_000L)
-        .setUpdatedAt(1_000_000_000L));
+        .setUpdatedAt(1_000_000_000L),
+      template.getName());
     db.commit();
     when(system.now()).thenReturn(3_000_000_000L);
 
index b4e66aa4f84360b47a50b0bdea7557149b549176..7449404ba26fb8ee87afa249446fb2aae7523a69 100644 (file)
@@ -214,12 +214,14 @@ public class ApplyTemplateActionTest extends BasePermissionWsTest<ApplyTemplateA
   }
 
   private void addUserToTemplate(UserDto user, PermissionTemplateDto permissionTemplate, String permission) {
-    db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), permissionTemplate.getUuid(), user.getUuid(), permission);
+    db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), permissionTemplate.getUuid(), user.getUuid(),
+      permission, permissionTemplate.getName(), user.getLogin());
     db.commit();
   }
 
   private void addGroupToTemplate(GroupDto group, PermissionTemplateDto permissionTemplate, String permission) {
-    db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), permissionTemplate.getUuid(), group.getUuid(), permission);
+    db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), permissionTemplate.getUuid(), group.getUuid(),
+      permission, permissionTemplate.getName(), group.getName());
     db.commit();
   }
 
index c07273b2346e20ab9dcf2759f3ac7416c13fc935..0eea5c1d9fe67b6573d55d9fe7e7939d2982c2ce 100644 (file)
@@ -334,12 +334,14 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT
   }
 
   private void addUserToTemplate(UserDto user, PermissionTemplateDto permissionTemplate, String permission) {
-    db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), permissionTemplate.getUuid(), user.getUuid(), permission);
+    db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), permissionTemplate.getUuid(), user.getUuid(),
+      permission, permissionTemplate.getName(), user.getLogin());
     db.commit();
   }
 
   private void addGroupToTemplate(GroupDto group, PermissionTemplateDto permissionTemplate, String permission) {
-    db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), permissionTemplate.getUuid(), group.getUuid(), permission);
+    db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), permissionTemplate.getUuid(), group.getUuid(),
+      permission, permissionTemplate.getName(), group.getName());
     db.commit();
   }
 
index 9005ae1f0e49266b0199ced4e5f72a776d4b98ee..bf7dc90294c82aef94982204ac1f19398c6bd22f 100644 (file)
@@ -228,8 +228,10 @@ public class DeleteTemplateActionTest {
     PermissionTemplateDto dto = db.permissionTemplates().insertTemplate();
     UserDto user = db.getDbClient().userDao().insert(db.getSession(), UserTesting.newUserDto().setActive(true));
     GroupDto group = db.getDbClient().groupDao().insert(db.getSession(), GroupTesting.newGroupDto());
-    db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), dto.getUuid(), user.getUuid(), UserRole.ADMIN);
-    db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), dto.getUuid(), group.getUuid(), UserRole.CODEVIEWER);
+    db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), dto.getUuid(), user.getUuid(), UserRole.ADMIN,
+      dto.getName(), user.getLogin());
+    db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), dto.getUuid(), group.getUuid(), UserRole.CODEVIEWER,
+      dto.getName(), group.getName());
     db.commit();
     return dto;
   }
index 552fd2b906770bf94f3838a64059f0b6d466d3c7..771a13ba858b1ca9742f1383f775f8cec195dc71 100644 (file)
@@ -74,7 +74,7 @@ public class RemoveGroupFromTemplateActionTest extends BasePermissionWsTest<Remo
 
     group = db.users().insertGroup("group-name");
     template = db.permissionTemplates().insertTemplate();
-    addGroupToTemplate(template, group.getUuid(), PERMISSION);
+    addGroupToTemplate(template, group.getUuid(), PERMISSION, group.getName());
   }
 
   @Test
@@ -127,7 +127,7 @@ public class RemoveGroupFromTemplateActionTest extends BasePermissionWsTest<Remo
 
   @Test
   public void remove_anyone_group_from_template() {
-    addGroupToTemplate(template, null, PERMISSION);
+    addGroupToTemplate(template, null, PERMISSION, null);
 
     newRequest(ANYONE, template.getUuid(), PERMISSION);
 
@@ -210,8 +210,9 @@ public class RemoveGroupFromTemplateActionTest extends BasePermissionWsTest<Remo
     request.execute();
   }
 
-  private void addGroupToTemplate(PermissionTemplateDto template, @Nullable String groupUuid, String permission) {
-    db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), template.getUuid(), groupUuid, permission);
+  private void addGroupToTemplate(PermissionTemplateDto template, @Nullable String groupUuid, String permission, String groupName) {
+    db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), template.getUuid(), groupUuid,
+      permission, template.getName(), groupName);
     db.commit();
   }
 
index e6f1367dafece13daf42cc3156d31813c20ff3c9..f05ebfebc9a4b611052af7dc6bd2aaeeccd42e69 100644 (file)
@@ -77,7 +77,8 @@ public class RemoveProjectCreatorFromTemplateActionTest extends BasePermissionWs
         .setPermission(UserRole.USER)
         .setWithProjectCreator(false)
         .setCreatedAt(1_000_000_000L)
-        .setUpdatedAt(1_000_000_000L));
+        .setUpdatedAt(1_000_000_000L),
+      template.getName());
     db.commit();
     when(system.now()).thenReturn(3_000_000_000L);
 
index 2a19380e7ba276fb39bcf5ddfa0280d153105ca2..6f6148157e9ff2097ec9a57e9e6164c5eae609c7 100644 (file)
@@ -219,7 +219,8 @@ public class RemoveUserFromTemplateActionTest extends BasePermissionWsTest<Remov
   }
 
   private void addUserToTemplate(UserDto user, PermissionTemplateDto template, String permission) {
-    db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), template.getUuid(), user.getUuid(), permission);
+    db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), template.getUuid(), user.getUuid(), permission,
+      template.getName(), user.getLogin());
     db.commit();
   }
 
index 70e9f21dc89ec22c9635db5008e2e7a70e856c41..b7c6f360a6a9825e6b4e02bb7c479fc2eaca3bef 100644 (file)
@@ -92,12 +92,12 @@ public class SearchTemplatesActionTest extends BasePermissionWsTest<SearchTempla
     GroupDto group2 = db.users().insertGroup();
     GroupDto group3 = db.users().insertGroup();
 
-    addUserToTemplate(projectTemplate.getUuid(), user1.getUuid(), UserRole.ISSUE_ADMIN);
-    addUserToTemplate(projectTemplate.getUuid(), user2.getUuid(), UserRole.ISSUE_ADMIN);
-    addUserToTemplate(projectTemplate.getUuid(), user3.getUuid(), UserRole.ISSUE_ADMIN);
-    addUserToTemplate(projectTemplate.getUuid(), user1.getUuid(), UserRole.CODEVIEWER);
-    addGroupToTemplate(projectTemplate.getUuid(), group1.getUuid(), UserRole.ADMIN);
-    addPermissionTemplateWithProjectCreator(projectTemplate.getUuid(), UserRole.ADMIN);
+    addUserToTemplate(projectTemplate.getUuid(), user1.getUuid(), UserRole.ISSUE_ADMIN, projectTemplate.getName(), user1.getLogin());
+    addUserToTemplate(projectTemplate.getUuid(), user2.getUuid(), UserRole.ISSUE_ADMIN, projectTemplate.getName(), user2.getLogin());
+    addUserToTemplate(projectTemplate.getUuid(), user3.getUuid(), UserRole.ISSUE_ADMIN, projectTemplate.getName(), user3.getLogin());
+    addUserToTemplate(projectTemplate.getUuid(), user1.getUuid(), UserRole.CODEVIEWER, projectTemplate.getName(), user1.getLogin());
+    addGroupToTemplate(projectTemplate.getUuid(), group1.getUuid(), UserRole.ADMIN, projectTemplate.getName(), group1.getName());
+    addPermissionTemplateWithProjectCreator(projectTemplate.getUuid(), UserRole.ADMIN, projectTemplate.getName());
 
     db.permissionTemplates().setDefaultTemplates(projectTemplate, null, null);
 
@@ -122,18 +122,18 @@ public class SearchTemplatesActionTest extends BasePermissionWsTest<SearchTempla
     GroupDto group2 = db.users().insertGroup();
     GroupDto group3 = db.users().insertGroup();
 
-    addUserToTemplate(projectTemplate.getUuid(), user1.getUuid(), UserRole.ISSUE_ADMIN);
-    addUserToTemplate(projectTemplate.getUuid(), user2.getUuid(), UserRole.ISSUE_ADMIN);
-    addUserToTemplate(projectTemplate.getUuid(), user3.getUuid(), UserRole.ISSUE_ADMIN);
-    addUserToTemplate(projectTemplate.getUuid(), user1.getUuid(), UserRole.CODEVIEWER);
-    addGroupToTemplate(projectTemplate.getUuid(), group1.getUuid(), UserRole.ADMIN);
-    addPermissionTemplateWithProjectCreator(projectTemplate.getUuid(), UserRole.ADMIN);
+    addUserToTemplate(projectTemplate.getUuid(), user1.getUuid(), UserRole.ISSUE_ADMIN, projectTemplate.getName(), user1.getLogin());
+    addUserToTemplate(projectTemplate.getUuid(), user2.getUuid(), UserRole.ISSUE_ADMIN, projectTemplate.getName(), user2.getLogin());
+    addUserToTemplate(projectTemplate.getUuid(), user3.getUuid(), UserRole.ISSUE_ADMIN, projectTemplate.getName(), user3.getLogin());
+    addUserToTemplate(projectTemplate.getUuid(), user1.getUuid(), UserRole.CODEVIEWER, projectTemplate.getName(), user1.getLogin());
+    addGroupToTemplate(projectTemplate.getUuid(), group1.getUuid(), UserRole.ADMIN, projectTemplate.getName(), group1.getName());
+    addPermissionTemplateWithProjectCreator(projectTemplate.getUuid(), UserRole.ADMIN, projectTemplate.getName());
 
-    addUserToTemplate(portfoliosTemplate.getUuid(), user1.getUuid(), UserRole.USER);
-    addUserToTemplate(portfoliosTemplate.getUuid(), user2.getUuid(), UserRole.USER);
-    addGroupToTemplate(portfoliosTemplate.getUuid(), group1.getUuid(), UserRole.ISSUE_ADMIN);
-    addGroupToTemplate(portfoliosTemplate.getUuid(), group2.getUuid(), UserRole.ISSUE_ADMIN);
-    addGroupToTemplate(portfoliosTemplate.getUuid(), group3.getUuid(), UserRole.ISSUE_ADMIN);
+    addUserToTemplate(portfoliosTemplate.getUuid(), user1.getUuid(), UserRole.USER, portfoliosTemplate.getName(), user1.getLogin());
+    addUserToTemplate(portfoliosTemplate.getUuid(), user2.getUuid(), UserRole.USER, portfoliosTemplate.getName(), user2.getLogin());
+    addGroupToTemplate(portfoliosTemplate.getUuid(), group1.getUuid(), UserRole.ISSUE_ADMIN, portfoliosTemplate.getName(), group1.getName());
+    addGroupToTemplate(portfoliosTemplate.getUuid(), group2.getUuid(), UserRole.ISSUE_ADMIN, portfoliosTemplate.getName(), group2.getName());
+    addGroupToTemplate(portfoliosTemplate.getUuid(), group3.getUuid(), UserRole.ISSUE_ADMIN, portfoliosTemplate.getName(), group3.getName());
 
     db.permissionTemplates().setDefaultTemplates(projectTemplate, applicationsTemplate, portfoliosTemplate);
 
@@ -352,24 +352,25 @@ public class SearchTemplatesActionTest extends BasePermissionWsTest<SearchTempla
     return insert;
   }
 
-  private void addGroupToTemplate(String templateUuid, @Nullable String groupUuid, String permission) {
-    dbClient.permissionTemplateDao().insertGroupPermission(db.getSession(), templateUuid, groupUuid, permission);
+  private void addGroupToTemplate(String templateUuid, @Nullable String groupUuid, String permission, String templateName, String groupName) {
+    dbClient.permissionTemplateDao().insertGroupPermission(db.getSession(), templateUuid, groupUuid, permission, templateName, groupName);
     db.getSession().commit();
   }
 
-  private void addUserToTemplate(String templateUuid, String userId, String permission) {
-    dbClient.permissionTemplateDao().insertUserPermission(db.getSession(), templateUuid, userId, permission);
+  private void addUserToTemplate(String templateUuid, String userId, String permission, String templateName, String userLogin) {
+    dbClient.permissionTemplateDao().insertUserPermission(db.getSession(), templateUuid, userId, permission, templateName, userLogin);
     db.getSession().commit();
   }
 
-  private void addPermissionTemplateWithProjectCreator(String templateUuid, String permission) {
+  private void addPermissionTemplateWithProjectCreator(String templateUuid, String permission, String templateName) {
     dbClient.permissionTemplateCharacteristicDao().insert(dbSession, new PermissionTemplateCharacteristicDto()
-      .setUuid(Uuids.createFast())
-      .setWithProjectCreator(true)
-      .setTemplateUuid(templateUuid)
-      .setPermission(permission)
-      .setCreatedAt(1_000_000_000L)
-      .setUpdatedAt(2_000_000_000L));
+        .setUuid(Uuids.createFast())
+        .setWithProjectCreator(true)
+        .setTemplateUuid(templateUuid)
+        .setPermission(permission)
+        .setCreatedAt(1_000_000_000L)
+        .setUpdatedAt(2_000_000_000L),
+      templateName);
     db.commit();
   }
 
index 6b30cad62e3c3848cdcf68758fff192f748eb2b0..75d640e20fe02000f036429eeae4cad48a296f03 100644 (file)
@@ -87,11 +87,11 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
     GroupDto userGroup = insertGroup("sonar-users", "Any new users created will automatically join this group");
 
     PermissionTemplateDto template = addTemplate();
-    addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), adminGroup.getUuid()));
-    addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), userGroup.getUuid()));
+    addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), adminGroup.getUuid()), template.getName());
+    addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), userGroup.getUuid()), template.getName());
     // Anyone group
-    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null));
-    addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), null));
+    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null), template.getName());
+    addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), null), template.getName());
     loginAsAdmin();
 
     String response = newRequest()
@@ -111,23 +111,23 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
     PermissionTemplateDto template = addTemplate();
 
     GroupDto group1 = db.users().insertGroup("group-1-name");
-    addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getUuid(), group1.getUuid()));
-    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group1.getUuid()));
+    addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getUuid(), group1.getUuid()), template.getName());
+    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group1.getUuid()), template.getName());
 
     GroupDto group2 = db.users().insertGroup("group-2-name");
-    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group2.getUuid()));
-    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getUuid()));
+    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group2.getUuid()), template.getName());
+    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getUuid()), template.getName());
 
     GroupDto group3 = db.users().insertGroup("group-3-name");
 
     // Anyone
-    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null));
-    addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), null));
+    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null), template.getName());
+    addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), null), template.getName());
 
     PermissionTemplateDto anotherTemplate = addTemplate();
     GroupDto group4 = db.users().insertGroup("group-4-name");
-    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group3.getUuid()));
-    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group4.getUuid()));
+    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group3.getUuid()), anotherTemplate.getName());
+    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group4.getUuid()), anotherTemplate.getName());
     loginAsAdmin();
 
     WsGroupsResponse response = newRequest()
@@ -146,19 +146,19 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
     PermissionTemplateDto template = addTemplate();
 
     GroupDto group1 = db.users().insertGroup("group-1-name");
-    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()));
-    addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getUuid(), group1.getUuid()));
+    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()), template.getName());
+    addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getUuid(), group1.getUuid()), template.getName());
 
     GroupDto group2 = db.users().insertGroup("group-2-name");
-    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getUuid()));
+    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getUuid()), template.getName());
 
     GroupDto group3 = db.users().insertGroup("group-3-name");
 
     // Anyone
-    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null));
+    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null), template.getName());
 
     PermissionTemplateDto anotherTemplate = addTemplate();
-    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group3.getUuid()));
+    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group3.getUuid()), anotherTemplate.getName());
     loginAsAdmin();
 
     WsGroupsResponse response = newRequest()
@@ -178,12 +178,12 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
     GroupDto group3 = db.users().insertGroup("group-3-name");
 
     PermissionTemplateDto template = addTemplate();
-    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()));
-    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getUuid()));
-    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null));
+    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()), template.getName());
+    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getUuid()), template.getName());
+    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null), template.getName());
 
     PermissionTemplateDto anotherTemplate = addTemplate();
-    addGroupToTemplate(newPermissionTemplateGroup(USER, anotherTemplate.getUuid(), group1.getUuid()));
+    addGroupToTemplate(newPermissionTemplateGroup(USER, anotherTemplate.getUuid(), group1.getUuid()), anotherTemplate.getName());
     loginAsAdmin();
 
     WsGroupsResponse response = newRequest()
@@ -197,9 +197,9 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
   public void search_with_pagination() {
     PermissionTemplateDto template = addTemplate();
     GroupDto group1 = db.users().insertGroup("group-1-name");
-    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()));
+    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()), template.getName());
     GroupDto group2 = db.users().insertGroup("group-2-name");
-    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group2.getUuid()));
+    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group2.getUuid()), template.getName());
     loginAsAdmin();
 
     WsGroupsResponse response = newRequest()
@@ -216,7 +216,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
   public void search_with_text_query() {
     PermissionTemplateDto template = addTemplate();
     GroupDto group1 = db.users().insertGroup("group-1-name");
-    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()));
+    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()), template.getName());
     GroupDto group2 = db.users().insertGroup("group-2-name");
     GroupDto group3 = db.users().insertGroup("group-3");
     loginAsAdmin();
@@ -252,7 +252,7 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
   public void search_with_text_query_return_anyone_group_even_when_no_permission_set() {
     PermissionTemplateDto template = addTemplate();
     GroupDto group = db.users().insertGroup("group");
-    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group.getUuid()));
+    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group.getUuid()), template.getName());
     loginAsAdmin();
 
     WsGroupsResponse response = newRequest()
@@ -366,8 +366,8 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
     return db.users().insertGroup(newGroupDto().setName(name).setDescription(description));
   }
 
-  private void addGroupToTemplate(PermissionTemplateGroupDto permissionTemplateGroup) {
-    db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), permissionTemplateGroup);
+  private void addGroupToTemplate(PermissionTemplateGroupDto permissionTemplateGroup, String templateName) {
+    db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), permissionTemplateGroup, templateName);
     db.commit();
   }
 
index a6ff1722cb1061ab39eea306d5b76a9fa5141b3c..899a6cf6ac472edbf9d6a4fb2b2c80cf6ea1ed00 100644 (file)
@@ -90,9 +90,9 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     UserDto user2 = insertUser(newUserDto().setLogin("george.orwell").setName("George Orwell").setEmail("george.orwell@1984.net"));
 
     PermissionTemplateDto template1 = addTemplate();
-    addUserToTemplate(newPermissionTemplateUser(CODEVIEWER, template1, user1));
-    addUserToTemplate(newPermissionTemplateUser(CODEVIEWER, template1, user2));
-    addUserToTemplate(newPermissionTemplateUser(ADMIN, template1, user2));
+    addUserToTemplate(newPermissionTemplateUser(CODEVIEWER, template1, user1), template1.getName());
+    addUserToTemplate(newPermissionTemplateUser(CODEVIEWER, template1, user2), template1.getName());
+    addUserToTemplate(newPermissionTemplateUser(ADMIN, template1, user2), template1.getName());
     loginAsAdmin();
 
     String result = newRequest(null, template1.getUuid()).execute().getInput();
@@ -108,13 +108,13 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
 
     PermissionTemplateDto template = addTemplate();
-    addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
-    addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
-    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1));
-    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
+    addUserToTemplate(newPermissionTemplateUser(USER, template, user1), template.getName());
+    addUserToTemplate(newPermissionTemplateUser(USER, template, user2), template.getName());
+    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1), template.getName());
+    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3), template.getName());
 
     PermissionTemplateDto anotherTemplate = addTemplate();
-    addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
+    addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1), anotherTemplate.getName());
 
     Permissions.UsersWsResponse response = newRequest(null, null)
       .setParam(PARAM_TEMPLATE_NAME, template.getName())
@@ -135,13 +135,13 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
 
     PermissionTemplateDto template = addTemplate();
-    addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
-    addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
-    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1));
-    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
+    addUserToTemplate(newPermissionTemplateUser(USER, template, user1), template.getName());
+    addUserToTemplate(newPermissionTemplateUser(USER, template, user2), template.getName());
+    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1), template.getName());
+    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3), template.getName());
 
     PermissionTemplateDto anotherTemplate = addTemplate();
-    addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
+    addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1), anotherTemplate.getName());
 
     Permissions.UsersWsResponse response = newRequest(null, null)
       .setParam(PARAM_TEMPLATE_NAME, template.getName())
@@ -158,13 +158,13 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
 
     PermissionTemplateDto template = addTemplate();
-    addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
-    addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
-    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1));
-    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
+    addUserToTemplate(newPermissionTemplateUser(USER, template, user1), template.getName());
+    addUserToTemplate(newPermissionTemplateUser(USER, template, user2), template.getName());
+    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1), template.getName());
+    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3), template.getName());
 
     PermissionTemplateDto anotherTemplate = addTemplate();
-    addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
+    addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1), anotherTemplate.getName());
 
     loginAsAdmin();
     Permissions.UsersWsResponse response = newRequest(USER, template.getUuid())
@@ -181,13 +181,13 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
 
     PermissionTemplateDto template = addTemplate();
-    addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
-    addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
-    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1));
-    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
+    addUserToTemplate(newPermissionTemplateUser(USER, template, user1), template.getName());
+    addUserToTemplate(newPermissionTemplateUser(USER, template, user2), template.getName());
+    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1), template.getName());
+    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3), template.getName());
 
     PermissionTemplateDto anotherTemplate = addTemplate();
-    addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
+    addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1), anotherTemplate.getName());
 
     loginAsAdmin();
     Permissions.UsersWsResponse response = newRequest(USER, null)
@@ -207,9 +207,9 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     UserDto user3 = insertUser(newUserDto().setLogin("login-1").setName("name-1"));
 
     PermissionTemplateDto template = addTemplate();
-    addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
-    addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
-    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
+    addUserToTemplate(newPermissionTemplateUser(USER, template, user1), template.getName());
+    addUserToTemplate(newPermissionTemplateUser(USER, template, user2), template.getName());
+    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3), template.getName());
 
     loginAsAdmin();
     Permissions.UsersWsResponse response = newRequest(null, null)
@@ -310,8 +310,9 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     return userDto;
   }
 
-  private void addUserToTemplate(PermissionTemplateUserDto dto) {
-    db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), dto.getTemplateUuid(), dto.getUserUuid(), dto.getPermission());
+  private void addUserToTemplate(PermissionTemplateUserDto dto, String templateName) {
+    db.getDbClient().permissionTemplateDao().insertUserPermission(db.getSession(), dto.getTemplateUuid(), dto.getUserUuid(),
+      dto.getPermission(), templateName, dto.getUserLogin());
     db.commit();
   }
 
index 1d263e841c9b42acd0609f0b20eb5e758d34b698..2de78c23b1dbef5b3be14a72cb47f605c969844f 100644 (file)
@@ -193,7 +193,7 @@ public class CreateActionTest {
   public void do_not_add_project_to_user_favorites_if_project_creator_is_defined_in_permission_template_and_already_100_favorites() {
     UserDto user = db.users().insertUser();
     when(permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(any(DbSession.class), any(ComponentDto.class))).thenReturn(true);
-    rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid()));
+    rangeClosed(1, 100).forEach(i -> db.favorites().add(db.components().insertPrivateProject(), user.getUuid(), user.getLogin()));
     userSession.logIn(user).addPermission(PROVISION_PROJECTS);
 
     ws.newRequest()
index cb290b192a257471d191b030fce881ea1163d171..59d95923983ce7e33891ecd8c2714c1ea3d54f3d 100644 (file)
@@ -611,7 +611,7 @@ public class UpdateVisibilityActionTest {
       .setGroupUuid(null)
       .setRole(permission)
       .setComponentUuid(component.uuid());
-    dbTester.getDbClient().groupPermissionDao().insert(dbTester.getSession(), dto);
+    dbTester.getDbClient().groupPermissionDao().insert(dbTester.getSession(), dto, component);
     dbTester.commit();
   }
 
@@ -621,13 +621,13 @@ public class UpdateVisibilityActionTest {
       .setGroupUuid(group.getUuid())
       .setRole(permission)
       .setComponentUuid(component.uuid());
-    dbTester.getDbClient().groupPermissionDao().insert(dbTester.getSession(), dto);
+    dbTester.getDbClient().groupPermissionDao().insert(dbTester.getSession(), dto, component);
     dbTester.commit();
   }
 
   private void unsafeInsertProjectPermissionOnUser(ComponentDto component, UserDto user, String permission) {
     UserPermissionDto dto = new UserPermissionDto(Uuids.create(), permission, user.getUuid(), component.uuid());
-    dbTester.getDbClient().userPermissionDao().insert(dbTester.getSession(), dto);
+    dbTester.getDbClient().userPermissionDao().insert(dbTester.getSession(), dto, component);
     dbTester.commit();
   }
 
index faeed01aeaba2aa83f08cc977638f494d3179a02..4f41d85c399cf875c66cebaa18805d329ef37e51 100644 (file)
@@ -30,6 +30,9 @@ import org.junit.rules.TemporaryFolder;
 import org.sonar.api.config.internal.Encryption;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbTester;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsActionTester;
@@ -44,10 +47,13 @@ public class GenerateSecretKeyActionTest {
   public UserSessionRule userSession = UserSessionRule.standalone().logIn().setSystemAdministrator();
   @Rule
   public TemporaryFolder temporaryFolder = new TemporaryFolder();
+  @Rule
+  public DbTester db = DbTester.create(System2.INSTANCE);
 
+  private DbClient dbClient = db.getDbClient();
   private MapSettings settings = new MapSettings();
   private Encryption encryption = settings.getEncryption();
-  private GenerateSecretKeyAction underTest = new GenerateSecretKeyAction(settings, userSession);
+  private GenerateSecretKeyAction underTest = new GenerateSecretKeyAction(dbClient, settings, userSession);
   private WsActionTester ws = new WsActionTester(underTest);
 
   @Test
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/GenerateSecretKeyActionWithPersisterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/GenerateSecretKeyActionWithPersisterTest.java
new file mode 100644 (file)
index 0000000..92726e1
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.setting.ws;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.config.internal.MapSettings;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.ws.WsActionTester;
+import org.sonarqube.ws.Settings.GenerateSecretKeyWsResponse;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class GenerateSecretKeyActionWithPersisterTest {
+  private final AuditPersister auditPersister = mock(AuditPersister.class);
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+  @Rule
+  public UserSessionRule userSession = UserSessionRule.standalone().logIn().setSystemAdministrator();
+  @Rule
+  public DbTester db = DbTester.create(System2.INSTANCE, auditPersister);
+
+  private DbClient dbClient = db.getDbClient();
+  private MapSettings settings = new MapSettings();
+  private GenerateSecretKeyAction underTest = new GenerateSecretKeyAction(dbClient, settings, userSession, auditPersister);
+  private WsActionTester ws = new WsActionTester(underTest);
+
+  @Test
+  public void generateValidSecretKeyIsPersisted() {
+    call();
+
+    verify(auditPersister).generateSecretKey(any());
+  }
+
+  private GenerateSecretKeyWsResponse call() {
+    return ws.newRequest()
+      .setMethod("GET")
+      .executeProtobuf(GenerateSecretKeyWsResponse.class);
+  }
+
+}
index bc7b58c8c14ec0286c5b4d5ab5f91c9738232b1b..bdda0be254971d039776cdb0f90568ea29851b80 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.setting.ws;
 
 import java.util.Random;
 import javax.annotation.Nullable;
-
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -97,7 +96,7 @@ public class ResetActionTest {
   public void remove_global_setting() {
     logInAsSystemAdministrator();
     definitions.addComponent(PropertyDefinition.builder("foo").build());
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
 
     executeRequestOnGlobalSetting("foo");
     assertGlobalPropertyDoesNotExist("foo");
@@ -106,7 +105,7 @@ public class ResetActionTest {
   @Test
   public void remove_global_setting_even_if_not_defined() {
     logInAsSystemAdministrator();
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
 
     executeRequestOnGlobalSetting("foo");
     assertGlobalPropertyDoesNotExist("foo");
@@ -116,7 +115,7 @@ public class ResetActionTest {
   public void remove_component_setting() {
     logInAsProjectAdmin();
     definitions.addComponent(PropertyDefinition.builder("foo").onQualifiers(PROJECT).build());
-    propertyDb.insertProperties(newComponentPropertyDto(project).setKey("foo").setValue("value"));
+    propertyDb.insertProperties(null, null, newComponentPropertyDto(project).setKey("foo").setValue("value"));
 
     executeRequestOnProjectSetting("foo");
     assertProjectPropertyDoesNotExist("foo");
@@ -125,7 +124,7 @@ public class ResetActionTest {
   @Test
   public void remove_component_setting_even_if_not_defined() {
     logInAsProjectAdmin();
-    propertyDb.insertProperties(newComponentPropertyDto(project).setKey("foo").setValue("value"));
+    propertyDb.insertProperties(null, null, newComponentPropertyDto(project).setKey("foo").setValue("value"));
 
     executeRequestOnProjectSetting("foo");
     assertProjectPropertyDoesNotExist("foo");
@@ -135,7 +134,7 @@ public class ResetActionTest {
   public void remove_hidden_setting() {
     logInAsSystemAdministrator();
     definitions.addComponent(PropertyDefinition.builder("foo").hidden().build());
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
 
     executeRequestOnGlobalSetting("foo");
     assertGlobalPropertyDoesNotExist("foo");
@@ -144,8 +143,8 @@ public class ResetActionTest {
   @Test
   public void ignore_project_setting_when_removing_global_setting() {
     logInAsSystemAdministrator();
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
-    propertyDb.insertProperties(newComponentPropertyDto(project).setKey("foo").setValue("value"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
+    propertyDb.insertProperties(null, project.name(), newComponentPropertyDto(project).setKey("foo").setValue("value"));
 
     executeRequestOnGlobalSetting("foo");
 
@@ -156,8 +155,8 @@ public class ResetActionTest {
   @Test
   public void ignore_global_setting_when_removing_project_setting() {
     logInAsProjectAdmin();
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
-    propertyDb.insertProperties(newComponentPropertyDto(project).setKey("foo").setValue("value"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
+    propertyDb.insertProperties(null, project.name(), newComponentPropertyDto(project).setKey("foo").setValue("value"));
 
     executeRequestOnProjectSetting("foo");
 
@@ -169,7 +168,7 @@ public class ResetActionTest {
   public void ignore_user_setting_when_removing_global_setting() {
     logInAsSystemAdministrator();
     UserDto user = dbClient.userDao().insert(dbSession, UserTesting.newUserDto());
-    propertyDb.insertProperties(newUserPropertyDto("foo", "one", user));
+    propertyDb.insertProperties(user.getLogin(), null, newUserPropertyDto("foo", "one", user));
 
     executeRequestOnGlobalSetting("foo");
     assertUserPropertyExists("foo", user);
@@ -179,7 +178,7 @@ public class ResetActionTest {
   public void ignore_user_setting_when_removing_project_setting() {
     logInAsProjectAdmin();
     UserDto user = dbClient.userDao().insert(dbSession, UserTesting.newUserDto());
-    propertyDb.insertProperties(newUserPropertyDto("foo", "one", user));
+    propertyDb.insertProperties(user.getLogin(), null, newUserPropertyDto("foo", "one", user));
 
     executeRequestOnProjectSetting("foo");
     assertUserPropertyExists("foo", user);
@@ -196,7 +195,7 @@ public class ResetActionTest {
   public void remove_setting_by_deprecated_key() {
     logInAsSystemAdministrator();
     definitions.addComponent(PropertyDefinition.builder("foo").deprecatedKey("old").build());
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
 
     executeRequestOnGlobalSetting("old");
     assertGlobalPropertyDoesNotExist("foo");
@@ -207,7 +206,7 @@ public class ResetActionTest {
     ComponentDto project = db.components().insertPublicProject();
     ComponentDto branch = db.components().insertProjectBranch(project);
     definitions.addComponent(PropertyDefinition.builder("foo").onQualifiers(PROJECT).build());
-    propertyDb.insertProperties(newComponentPropertyDto(branch).setKey("foo").setValue("value"));
+    propertyDb.insertProperties(null, branch.name(), newComponentPropertyDto(branch).setKey("foo").setValue("value"));
     userSession.logIn().addProjectPermission(ADMIN, project);
 
     ws.newRequest()
index 8e9e908bb272f44b82cfda709b05db58f92f1be2..234a84829e377a792aff02cc09f2cc4e5d405e96 100644 (file)
@@ -141,7 +141,7 @@ public class SetActionTest {
 
   @Test
   public void update_existing_global_setting() {
-    propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my value"));
+    propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my value"), null, null);
     assertGlobalSetting("my.key", "my value");
 
     callForGlobalSetting("my.key", "my new value");
@@ -152,7 +152,7 @@ public class SetActionTest {
 
   @Test
   public void persist_new_project_setting() {
-    propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"));
+    propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"), null, null);
     ComponentDto project = db.components().insertPrivateProject();
     logInAsProjectAdministrator(project);
 
@@ -175,9 +175,9 @@ public class SetActionTest {
 
   @Test
   public void update_existing_project_setting() {
-    propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"));
+    propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"), null, null);
     ComponentDto project = db.components().insertPrivateProject();
-    propertyDb.insertProperty(newComponentPropertyDto("my.key", "my project value", project));
+    propertyDb.insertProperty(newComponentPropertyDto("my.key", "my project value", project), project.name(), null);
     assertComponentSetting("my.key", "my project value", project.uuid());
     logInAsProjectAdministrator(project);
 
@@ -259,7 +259,7 @@ public class SetActionTest {
           .type(PropertyType.STRING)
           .build()))
       .build());
-    propertyDb.insertProperties(
+    propertyDb.insertProperties(null, null,
       newGlobalPropertyDto("my.key", "1,2,3,4"),
       newGlobalPropertyDto("my.key.1.firstField", "oldFirstValue"),
       newGlobalPropertyDto("my.key.1.secondField", "oldSecondValue"),
@@ -308,10 +308,11 @@ public class SetActionTest {
           .build()))
       .build());
     ComponentDto project = db.components().insertPrivateProject();
-    propertyDb.insertProperties(
+    propertyDb.insertProperties(null, null,
       newGlobalPropertyDto("my.key", "1"),
       newGlobalPropertyDto("my.key.1.firstField", "oldFirstValue"),
-      newGlobalPropertyDto("my.key.1.secondField", "oldSecondValue"),
+      newGlobalPropertyDto("my.key.1.secondField", "oldSecondValue"));
+    propertyDb.insertProperties(null, project.name(),
       newComponentPropertyDto("my.key", "1", project),
       newComponentPropertyDto("my.key.1.firstField", "componentFirstValue", project),
       newComponentPropertyDto("my.key.1.firstField", "componentSecondValue", project));
@@ -379,8 +380,8 @@ public class SetActionTest {
 
   @Test
   public void user_setting_is_not_updated() {
-    propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my user value").setUserUuid("42"));
-    propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"));
+    propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my user value").setUserUuid("42"), null, "user_login");
+    propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"), null, null);
 
     callForGlobalSetting("my.key", "my new global value");
 
index 55345e36c2f9fd83bb737f7e49846806f4527cc2..d9b9373c6f00a5ac06e5b90aab22e27a0041102e 100644 (file)
@@ -72,9 +72,9 @@ public class SettingsUpdaterTest {
   @Test
   public void delete_global_settings() {
     definitions.addComponent(PropertyDefinition.builder("foo").build());
-    propertyDb.insertProperties(newComponentPropertyDto(project).setKey("foo").setValue("value"));
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("bar").setValue("two"));
+    propertyDb.insertProperties(null, project.name(), newComponentPropertyDto(project).setKey("foo").setValue("value"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("bar").setValue("two"));
 
     underTest.deleteGlobalSettings(dbSession, "foo", "bar");
 
@@ -86,9 +86,9 @@ public class SettingsUpdaterTest {
   @Test
   public void delete_component_settings() {
     definitions.addComponent(PropertyDefinition.builder("foo").build());
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("value"));
-    propertyDb.insertProperties(newComponentPropertyDto(project).setKey("foo").setValue("one"));
-    propertyDb.insertProperties(newComponentPropertyDto(project).setKey("bar").setValue("two"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("value"));
+    propertyDb.insertProperties(null, project.name(), newComponentPropertyDto(project).setKey("foo").setValue("one"));
+    propertyDb.insertProperties(null, project.name(), newComponentPropertyDto(project).setKey("bar").setValue("two"));
 
     underTest.deleteComponentSettings(dbSession, project, "foo", "bar");
 
@@ -99,7 +99,7 @@ public class SettingsUpdaterTest {
 
   @Test
   public void does_not_fail_when_deleting_unknown_setting() {
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
 
     underTest.deleteGlobalSettings(dbSession, "unknown");
 
@@ -109,8 +109,8 @@ public class SettingsUpdaterTest {
   @Test
   public void does_not_delete_user_settings() {
     UserDto user = dbClient.userDao().insert(dbSession, UserTesting.newUserDto());
-    propertyDb.insertProperties(newUserPropertyDto("foo", "one", user));
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
+    propertyDb.insertProperties(user.getLogin(), null, newUserPropertyDto("foo", "one", user));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
 
     underTest.deleteGlobalSettings(dbSession, "foo");
 
@@ -126,7 +126,7 @@ public class SettingsUpdaterTest {
         PropertyFieldDefinition.build("key").name("Key").build(),
         PropertyFieldDefinition.build("size").name("Size").build()))
       .build());
-    propertyDb.insertProperties(
+    propertyDb.insertProperties(null, null,
       newGlobalPropertyDto().setKey("foo").setValue("1,2"),
       newGlobalPropertyDto().setKey("foo.1.key").setValue("key1"),
       newGlobalPropertyDto().setKey("foo.1.size").setValue("size1"),
@@ -149,7 +149,7 @@ public class SettingsUpdaterTest {
         PropertyFieldDefinition.build("key").name("Key").build(),
         PropertyFieldDefinition.build("size").name("Size").build()))
       .build());
-    propertyDb.insertProperties(
+    propertyDb.insertProperties(null, project.name(),
       newComponentPropertyDto(project).setKey("foo").setValue("1,2"),
       newComponentPropertyDto(project).setKey("foo.1.key").setValue("key1"),
       newComponentPropertyDto(project).setKey("foo.1.size").setValue("size1"),
@@ -172,7 +172,7 @@ public class SettingsUpdaterTest {
         PropertyFieldDefinition.build("key").name("Key").build(),
         PropertyFieldDefinition.build("size").name("Size").build()))
       .build());
-    propertyDb.insertProperties(
+    propertyDb.insertProperties(null, project.name(),
       newComponentPropertyDto(project).setKey("other").setValue("1,2"),
       newComponentPropertyDto(project).setKey("other.1.key").setValue("key1"));
 
@@ -215,9 +215,9 @@ public class SettingsUpdaterTest {
 
   private void assertUserPropertyExists(String key, UserDto user) {
     assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
-      .setKey(key)
-      .setUserUuid(user.getUuid())
-      .build(),
+        .setKey(key)
+        .setUserUuid(user.getUuid())
+        .build(),
       dbSession)).isNotEmpty();
   }
 }
index 263d14f3fae29f6a955154c30f0fff79ffe6830d..90d3aff90298cfbf0765821642cecd2b6cd0e373 100644 (file)
@@ -101,7 +101,7 @@ public class ValuesActionTest {
     definitions.addComponent(PropertyDefinition
       .builder("foo")
       .build());
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
 
     ValuesWsResponse result = executeRequestForGlobalProperties("foo");
 
@@ -124,7 +124,7 @@ public class ValuesActionTest {
     definitions.addComponent(PropertyDefinition.builder("global")
       .multiValues(true)
       .build());
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("global").setValue("three,four"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("global").setValue("three,four"));
 
     ValuesWsResponse result = executeRequestForGlobalProperties("default", "global");
     assertThat(result.getSettingsList()).hasSize(2);
@@ -142,7 +142,7 @@ public class ValuesActionTest {
   public void return_multi_value_with_coma() {
     logIn();
     definitions.addComponent(PropertyDefinition.builder("global").multiValues(true).build());
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("global").setValue("three,four%2Cfive"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("global").setValue("three,four%2Cfive"));
 
     ValuesWsResponse result = executeRequestForGlobalProperties("global");
 
@@ -211,7 +211,7 @@ public class ValuesActionTest {
   public void return_global_values() {
     logIn();
     definitions.addComponent(PropertyDefinition.builder("property").defaultValue("default").build());
-    propertyDb.insertProperties(
+    propertyDb.insertProperties(null, null,
       // The property is overriding default value
       newGlobalPropertyDto().setKey("property").setValue("one"));
 
@@ -226,8 +226,9 @@ public class ValuesActionTest {
     logInAsProjectUser();
     definitions.addComponent(
       PropertyDefinition.builder("property").defaultValue("default").onQualifiers(PROJECT).build());
-    propertyDb.insertProperties(
-      newGlobalPropertyDto().setKey("property").setValue("one"),
+    propertyDb.insertProperties(null, null,
+      newGlobalPropertyDto().setKey("property").setValue("one"));
+    propertyDb.insertProperties(null, project.name(),
       // The property is overriding global value
       newComponentPropertyDto(project).setKey("property").setValue("two"));
 
@@ -244,8 +245,9 @@ public class ValuesActionTest {
       PropertyDefinition.builder("global").build(),
       PropertyDefinition.builder("global.default").defaultValue("default").build(),
       PropertyDefinition.builder("project").onQualifiers(PROJECT).build()));
-    propertyDb.insertProperties(
-      newGlobalPropertyDto().setKey("global").setValue("one"),
+    propertyDb.insertProperties(null, null,
+      newGlobalPropertyDto().setKey("global").setValue("one"));
+    propertyDb.insertProperties(null, project.name(),
       newComponentPropertyDto(project).setKey("project").setValue("two"));
 
     ValuesWsResponse result = executeRequestForProjectProperties();
@@ -259,7 +261,7 @@ public class ValuesActionTest {
     logInAsProjectUser();
     definitions.addComponent(PropertyDefinition.builder("property").defaultValue("default").onQualifiers(PROJECT).build());
     // The property is not defined on project
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("property").setValue("one"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("property").setValue("one"));
 
     ValuesWsResponse result = executeRequestForProjectProperties("property");
 
@@ -270,7 +272,7 @@ public class ValuesActionTest {
   @Test
   public void return_values_even_if_no_property_definition() {
     logIn();
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("globalPropertyWithoutDefinition").setValue("value"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("globalPropertyWithoutDefinition").setValue("value"));
 
     ValuesWsResponse result = executeRequestForGlobalProperties("globalPropertyWithoutDefinition");
 
@@ -283,7 +285,7 @@ public class ValuesActionTest {
   @Test
   public void return_values_of_component_even_if_no_property_definition() {
     logInAsProjectUser();
-    propertyDb.insertProperties(
+    propertyDb.insertProperties(null, project.name(),
       newComponentPropertyDto(project).setKey("property").setValue("foo"));
 
     ValuesWsResponse response = executeRequestForComponentProperties(project, "property");
@@ -310,7 +312,7 @@ public class ValuesActionTest {
       .builder("foo")
       .defaultValue("default")
       .build());
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("bar").setValue(""));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("bar").setValue(""));
 
     ValuesWsResponse result = executeRequestForGlobalProperties("unknown");
 
@@ -322,8 +324,9 @@ public class ValuesActionTest {
     logInAsProjectUser();
     ComponentDto module = componentDb.insertComponent(newModuleDto(project));
     definitions.addComponent(PropertyDefinition.builder("property").defaultValue("default").onQualifiers(PROJECT, MODULE).build());
-    propertyDb.insertProperties(
-      newGlobalPropertyDto().setKey("property").setValue("one"),
+    propertyDb.insertProperties(null, null,
+      newGlobalPropertyDto().setKey("property").setValue("one"));
+    propertyDb.insertProperties(null, module.name(),
       // The property is overriding global value
       newComponentPropertyDto(module).setKey("property").setValue("two"));
 
@@ -342,9 +345,11 @@ public class ValuesActionTest {
       PropertyDefinition.builder("globalProperty").onQualifiers(PROJECT, MODULE).build(),
       PropertyDefinition.builder("projectProperty").onQualifiers(PROJECT, MODULE).build(),
       PropertyDefinition.builder("moduleProperty").onQualifiers(PROJECT, MODULE).build()));
-    propertyDb.insertProperties(
-      newGlobalPropertyDto().setKey("globalProperty").setValue("global"),
-      newComponentPropertyDto(project).setKey("projectProperty").setValue("project"),
+    propertyDb.insertProperties(null, null,
+      newGlobalPropertyDto().setKey("globalProperty").setValue("global"));
+    propertyDb.insertProperties(null, project.name(),
+      newComponentPropertyDto(project).setKey("projectProperty").setValue("project"));
+    propertyDb.insertProperties(null, module.name(),
       newComponentPropertyDto(module).setKey("moduleProperty").setValue("module"));
 
     ValuesWsResponse result = executeRequestForComponentProperties(module, "defaultProperty", "globalProperty", "projectProperty", "moduleProperty");
@@ -362,7 +367,7 @@ public class ValuesActionTest {
     definitions.addComponents(asList(
       PropertyDefinition.builder("defaultProperty").defaultValue("default").build(),
       PropertyDefinition.builder("globalProperty").build()));
-    propertyDb.insertProperties(
+    propertyDb.insertProperties(null, null,
       newGlobalPropertyDto().setKey("globalProperty").setValue("global"));
 
     ValuesWsResponse result = executeRequestForGlobalProperties("defaultProperty", "globalProperty");
@@ -379,9 +384,11 @@ public class ValuesActionTest {
     ComponentDto subModule = componentDb.insertComponent(newModuleDto(module));
     definitions.addComponents(asList(
       PropertyDefinition.builder("foo").defaultValue("default").onQualifiers(PROJECT, MODULE).build()));
-    propertyDb.insertProperties(
-      newGlobalPropertyDto().setKey("foo").setValue("global"),
-      newComponentPropertyDto(project).setKey("foo").setValue("project"),
+    propertyDb.insertProperties(null, null,
+      newGlobalPropertyDto().setKey("foo").setValue("global"));
+    propertyDb.insertProperties(null, project.name(),
+      newComponentPropertyDto(project).setKey("foo").setValue("project"));
+    propertyDb.insertProperties(null, module.name(),
       newComponentPropertyDto(module).setKey("foo").setValue("module"));
 
     assertParentValue(executeRequestForComponentProperties(subModule, "foo").getSettings(0), "module");
@@ -397,9 +404,11 @@ public class ValuesActionTest {
     ComponentDto subModule = componentDb.insertComponent(newModuleDto(module));
     definitions.addComponents(asList(
       PropertyDefinition.builder("foo").defaultValue("default1,default2").multiValues(true).onQualifiers(PROJECT, MODULE).build()));
-    propertyDb.insertProperties(
-      newGlobalPropertyDto().setKey("foo").setValue("global1,global2"),
-      newComponentPropertyDto(project).setKey("foo").setValue("project1,project2"),
+    propertyDb.insertProperties(null, null,
+      newGlobalPropertyDto().setKey("foo").setValue("global1,global2"));
+    propertyDb.insertProperties(null, project.name(),
+      newComponentPropertyDto(project).setKey("foo").setValue("project1,project2"));
+    propertyDb.insertProperties(null, module.name(),
       newComponentPropertyDto(module).setKey("foo").setValue("module1,module2"));
 
     assertParentValues(executeRequestForComponentProperties(subModule, "foo").getSettings(0), "module1", "module2");
@@ -446,7 +455,7 @@ public class ValuesActionTest {
           PropertyFieldDefinition.build("key").name("Key").build(),
           PropertyFieldDefinition.build("size").name("Size").build()))
         .build()));
-    propertyDb.insertProperties(
+    propertyDb.insertProperties(null, module.name(),
       newComponentPropertyDto(module).setKey("simple").setValue("module"),
       newComponentPropertyDto(module).setKey("multi").setValue("module1,module2"));
     propertyDb.insertPropertySet("set", module, ImmutableMap.of("key", "keyM1", "size", "sizeM1"));
@@ -460,8 +469,9 @@ public class ValuesActionTest {
   public void return_parent_value_when_no_definition() {
     logInAsProjectUser();
     ComponentDto module = componentDb.insertComponent(newModuleDto(project));
-    propertyDb.insertProperties(
-      newGlobalPropertyDto().setKey("foo").setValue("global"),
+    propertyDb.insertProperties(null, null,
+      newGlobalPropertyDto().setKey("foo").setValue("global"));
+    propertyDb.insertProperties(null, project.name(),
       newComponentPropertyDto(project).setKey("foo").setValue("project"));
 
     assertParentValue(executeRequestForComponentProperties(module, "foo").getSettings(0), "project");
@@ -476,7 +486,7 @@ public class ValuesActionTest {
       .builder("foo")
       .deprecatedKey("deprecated")
       .build());
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
 
     ValuesWsResponse result = executeRequestForGlobalProperties("deprecated");
 
@@ -491,7 +501,7 @@ public class ValuesActionTest {
     definitions.addComponents(asList(
       PropertyDefinition.builder("foo").build(),
       PropertyDefinition.builder("secret.secured").build()));
-    propertyDb.insertProperties(
+    propertyDb.insertProperties(null, null,
       newGlobalPropertyDto().setKey("foo").setValue("one"),
       newGlobalPropertyDto().setKey("secret.secured").setValue("password"));
 
@@ -522,7 +532,7 @@ public class ValuesActionTest {
     definitions.addComponents(asList(
       PropertyDefinition.builder("foo").build(),
       PropertyDefinition.builder("secret.secured").build()));
-    propertyDb.insertProperties(
+    propertyDb.insertProperties(null, null,
       newGlobalPropertyDto().setKey("foo").setValue("one"),
       newGlobalPropertyDto().setKey("secret.secured").setValue("password"));
 
@@ -540,9 +550,10 @@ public class ValuesActionTest {
       PropertyDefinition.builder("foo").onQualifiers(PROJECT).build(),
       PropertyDefinition.builder("global.secret.secured").build(),
       PropertyDefinition.builder("secret.secured").onQualifiers(PROJECT).build()));
-    propertyDb.insertProperties(
+    propertyDb.insertProperties(null, null,
+      newGlobalPropertyDto().setKey("global.secret.secured").setValue("very secret"));
+    propertyDb.insertProperties(null, project.name(),
       newComponentPropertyDto(project).setKey("foo").setValue("one"),
-      newGlobalPropertyDto().setKey("global.secret.secured").setValue("very secret"),
       newComponentPropertyDto(project).setKey("secret.secured").setValue("password"));
 
     ValuesWsResponse result = executeRequestForProjectProperties();
@@ -555,7 +566,7 @@ public class ValuesActionTest {
     userSession
       .addProjectPermission(USER, project)
       .addProjectPermission(SCAN_EXECUTION, project);
-    propertyDb.insertProperties(newComponentPropertyDto(project).setKey("not-defined.secured").setValue("123"));
+    propertyDb.insertProperties(null, project.name(), newComponentPropertyDto(project).setKey("not-defined.secured").setValue("123"));
 
     ValuesWsResponse result = executeRequestForProjectProperties("not-defined.secured");
 
@@ -568,7 +579,7 @@ public class ValuesActionTest {
     definitions.addComponents(asList(
       PropertyDefinition.builder("foo").build(),
       PropertyDefinition.builder("secret.secured").build()));
-    propertyDb.insertProperties(
+    propertyDb.insertProperties(null, null,
       newGlobalPropertyDto().setKey("foo").setValue("one"),
       newGlobalPropertyDto().setKey("secret.secured").setValue("password"));
 
@@ -584,9 +595,10 @@ public class ValuesActionTest {
       PropertyDefinition.builder("foo").onQualifiers(PROJECT).build(),
       PropertyDefinition.builder("global.secret.secured").build(),
       PropertyDefinition.builder("secret.secured").onQualifiers(PROJECT).build()));
-    propertyDb.insertProperties(
+    propertyDb.insertProperties(null, null,
+      newGlobalPropertyDto().setKey("global.secret.secured").setValue("very secret"));
+    propertyDb.insertProperties(null, project.name(),
       newComponentPropertyDto(project).setKey("foo").setValue("one"),
-      newGlobalPropertyDto().setKey("global.secret.secured").setValue("very secret"),
       newComponentPropertyDto(project).setKey("secret.secured").setValue("password"));
 
     ValuesWsResponse result = executeRequestForProjectProperties();
@@ -597,7 +609,7 @@ public class ValuesActionTest {
   @Test
   public void return_secured_settings_even_if_not_defined_when_project_admin() {
     logInAsProjectAdmin();
-    propertyDb.insertProperties(newComponentPropertyDto(project).setKey("not-defined.secured").setValue("123"));
+    propertyDb.insertProperties(null, project.name(), newComponentPropertyDto(project).setKey("not-defined.secured").setValue("123"));
 
     ValuesWsResponse result = executeRequestForProjectProperties("not-defined.secured");
 
@@ -627,7 +639,7 @@ public class ValuesActionTest {
     definitions.addComponents(asList(
       PropertyDefinition.builder("foo").build(),
       PropertyDefinition.builder("secret.secured").build()));
-    propertyDb.insertProperties(
+    propertyDb.insertProperties(null, null,
       newGlobalPropertyDto().setKey("foo").setValue("one"),
       newGlobalPropertyDto().setKey("secret.secured").setValue("password"));
 
@@ -642,7 +654,7 @@ public class ValuesActionTest {
     definitions.addComponents(asList(
       PropertyDefinition.builder("foo").onQualifiers(PROJECT).build(),
       PropertyDefinition.builder("secret.secured").onQualifiers(PROJECT).build()));
-    propertyDb.insertProperties(
+    propertyDb.insertProperties(null, project.name(),
       newComponentPropertyDto(project).setKey("foo").setValue("one"),
       newComponentPropertyDto(project).setKey("secret.secured").setValue("password"));
 
@@ -655,7 +667,7 @@ public class ValuesActionTest {
   public void return_additional_settings_specific_for_scanner_when_no_keys() {
     logInAsAdmin();
     definitions.addComponent(PropertyDefinition.builder("secret.secured").build());
-    propertyDb.insertProperties(
+    propertyDb.insertProperties(null, null,
       newGlobalPropertyDto().setKey("sonar.core.id").setValue("ID"),
       newGlobalPropertyDto().setKey("sonar.core.startTime").setValue("2017-01-01"));
 
@@ -670,7 +682,7 @@ public class ValuesActionTest {
     definitions.addComponent(PropertyDefinition
       .builder("foo")
       .build());
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("fi±∞…"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("fi±∞…"));
 
     ValuesWsResponse result = executeRequestForGlobalProperties("foo");
 
@@ -694,7 +706,7 @@ public class ValuesActionTest {
       .builder("foo")
       .deprecatedKey("deprecated")
       .build());
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("foo").setValue("one"));
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("'foo' and 'deprecated' cannot be used at the same time as they refer to the same setting");
@@ -724,7 +736,7 @@ public class ValuesActionTest {
       .builder("sonar.autogenerated")
       .multiValues(true)
       .build());
-    propertyDb.insertProperties(newGlobalPropertyDto().setKey("sonar.autogenerated").setValue("val1,val2,val3"));
+    propertyDb.insertProperties(null, null, newGlobalPropertyDto().setKey("sonar.autogenerated").setValue("val1,val2,val3"));
     definitions.addComponent(PropertyDefinition
       .builder("sonar.demo")
       .type(PropertyType.PROPERTY_SET)
@@ -787,7 +799,7 @@ public class ValuesActionTest {
     PropertyDefinition securedDef = PropertyDefinition.builder("my.password.secured").build();
     PropertyDefinition standardDef = PropertyDefinition.builder("my.property").build();
     definitions.addComponents(asList(securedDef, standardDef));
-    propertyDb.insertProperties(
+    propertyDb.insertProperties(null, null,
       newGlobalPropertyDto().setKey(securedDef.key()).setValue("securedValue"),
       newGlobalPropertyDto().setKey(standardDef.key()).setValue("standardValue"));
 
index fa84b71e1323a2f94256dad55556a073d79545a4..2fcea4cb5e428d864cc285736565fa12547f4ee1 100644 (file)
@@ -155,7 +155,8 @@ public class ComponentActionTest {
   public void return_component_info_with_favourite() {
     ComponentDto project = insertProject();
     UserDto user = db.users().insertUser("obiwan");
-    propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid()));
+    propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid()),
+      project.name(), user.getLogin());
     userSession.logIn(user).addProjectPermission(UserRole.USER, project);
     init();
 
@@ -167,7 +168,8 @@ public class ComponentActionTest {
     ComponentDto project = insertProject();
     ComponentDto branch = componentDbTester.insertProjectBranch(project, b -> b.setKey("feature1").setUuid("xyz"));
     UserDto user = db.users().insertUser("obiwan");
-    propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid()));
+    propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid()),
+      project.name(), user.getLogin());
     userSession.logIn(user).addProjectPermission(UserRole.USER, project);
     init();
 
@@ -622,7 +624,8 @@ public class ComponentActionTest {
     componentDbTester.insertSnapshot(analysis);
     when(resourceTypes.get(project.qualifier())).thenReturn(DefaultResourceTypes.get().getRootType());
     UserDto user = db.users().insertUser("obiwan");
-    propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid()));
+    propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid()),
+      project.name(), user.getLogin());
     addQualityProfiles(project,
       createQProfile("qp1", "Sonar Way Java", "java"),
       createQProfile("qp2", "Sonar Way Xoo", "xoo"));
index 985b02b1679ed051b1b652833483e5e220e1e424..8d98e05f7bbcdaf79939659cc582046094527836 100644 (file)
@@ -143,9 +143,9 @@ public class DeactivateActionTest {
     logInAsSystemAdministrator();
     UserDto user = db.users().insertUser();
     ComponentDto project = db.components().insertPrivateProject();
-    db.properties().insertProperty(newUserPropertyDto(user));
-    db.properties().insertProperty(newUserPropertyDto(user));
-    db.properties().insertProperty(newUserPropertyDto(user).setComponentUuid(project.uuid()));
+    db.properties().insertProperty(newUserPropertyDto(user), null, user.getLogin());
+    db.properties().insertProperty(newUserPropertyDto(user), null, user.getLogin());
+    db.properties().insertProperty(newUserPropertyDto(user).setComponentUuid(project.uuid()), project.name(), user.getLogin());
 
     deactivate(user.getLogin());
 
@@ -177,8 +177,8 @@ public class DeactivateActionTest {
     UserDto user = db.users().insertUser();
     PermissionTemplateDto template = db.permissionTemplates().insertTemplate();
     PermissionTemplateDto anotherTemplate = db.permissionTemplates().insertTemplate();
-    db.permissionTemplates().addUserToTemplate(template.getUuid(), user.getUuid(), USER);
-    db.permissionTemplates().addUserToTemplate(anotherTemplate.getUuid(), user.getUuid(), CODEVIEWER);
+    db.permissionTemplates().addUserToTemplate(template.getUuid(), user.getUuid(), USER, template.getName(), user.getLogin());
+    db.permissionTemplates().addUserToTemplate(anotherTemplate.getUuid(), user.getUuid(), CODEVIEWER, anotherTemplate.getName(), user.getLogin());
 
     deactivate(user.getLogin());
 
@@ -208,9 +208,12 @@ public class DeactivateActionTest {
     UserDto user = db.users().insertUser();
     ComponentDto project = db.components().insertPrivateProject();
     ComponentDto anotherProject = db.components().insertPrivateProject();
-    db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()).setComponentUuid(project.uuid()));
-    db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()).setComponentUuid(anotherProject.uuid()));
-    db.properties().insertProperty(new PropertyDto().setKey("other").setValue(user.getLogin()).setComponentUuid(anotherProject.uuid()));
+    db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin())
+      .setComponentUuid(project.uuid()), project.name(), user.getLogin());
+    db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin())
+      .setComponentUuid(anotherProject.uuid()), anotherProject.name(), user.getLogin());
+    db.properties().insertProperty(new PropertyDto().setKey("other").setValue(user.getLogin())
+      .setComponentUuid(anotherProject.uuid()), anotherProject.name(), user.getLogin());
 
     deactivate(user.getLogin());
 
@@ -372,7 +375,7 @@ public class DeactivateActionTest {
   @Test
   public void administrators_can_be_deactivated_if_there_are_still_other_administrators() {
     UserDto admin = createAdminUser();
-    ;
+
     UserDto anotherAdmin = createAdminUser();
     logInAsSystemAdministrator();
 
index d805dc2b53b6525dfdc49d65806bae72fd820665..c7d07c60ff42a253afcad78d3584354478447375 100644 (file)
@@ -153,7 +153,8 @@ public class DeleteActionTest {
     GroupDto group = db.users().insertGroup();
     PermissionTemplateDto template = db.getDbClient().permissionTemplateDao().insert(db.getSession(),
       PermissionTemplateTesting.newPermissionTemplateDto());
-    db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), template.getUuid(), group.getUuid(), "perm");
+    db.getDbClient().permissionTemplateDao().insertGroupPermission(db.getSession(), template.getUuid(), group.getUuid(), "perm",
+      template.getName(), group.getName());
     db.commit();
     loginAsAdmin();
     assertThat(db.countRowsOfTable("perm_templates_groups")).isEqualTo(1);
index 1c3b06850c492d8c080906923aec44cb2e604a98..d02a32acd2caf8d966dbb3aeb0eadd1eaed92f88 100644 (file)
@@ -97,11 +97,11 @@ public class ListActionTest {
 
   @Test
   public void list_webhooks_and_their_latest_delivery() {
-    WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa"));
+    WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa"), null);
     webhookDeliveryDbTester.insert(newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
     webhookDeliveryDbTester.insert(newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
 
-    WebhookDto webhook2 = webhookDbTester.insert(newGlobalWebhook("bbb"));
+    WebhookDto webhook2 = webhookDbTester.insert(newGlobalWebhook("bbb"), null);
     webhookDeliveryDbTester.insert(newDto("WH2-DELIVERY-1-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
     webhookDeliveryDbTester.insert(newDto("WH2-DELIVERY-2-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
 
@@ -125,8 +125,8 @@ public class ListActionTest {
 
   @Test
   public void list_webhooks_when_no_delivery() {
-    WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa"));
-    WebhookDto webhook2 = webhookDbTester.insert(newGlobalWebhook("bbb"));
+    WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa"), null);
+    WebhookDto webhook2 = webhookDbTester.insert(newGlobalWebhook("bbb"), null);
 
     userSession.logIn().addPermission(ADMINISTER);
 
@@ -148,10 +148,10 @@ public class ListActionTest {
   public void obfuscate_credentials_in_webhook_URLs() {
     String url = "http://foo:barouf@toto/bop";
     String expectedUrl = "http://***:******@toto/bop";
-    WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa", t -> t.setUrl(url)));
+    WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa", t -> t.setUrl(url)), null);
     webhookDeliveryDbTester.insert(newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
     webhookDeliveryDbTester.insert(newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
-    webhookDbTester.insert(newGlobalWebhook("bbb", t -> t.setUrl(url)));
+    webhookDbTester.insert(newGlobalWebhook("bbb", t -> t.setUrl(url)), null);
 
     userSession.logIn().addPermission(ADMINISTER);