diff options
author | Aurélien Poscia <aurelien.poscia@sonarsource.com> | 2024-08-21 15:23:44 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-08-23 20:02:33 +0000 |
commit | da3c7f5e086e4d9c84e966cba2b74c15e72c6426 (patch) | |
tree | 7426397f3db0486a8d40880fc678902d449ca7af /server/sonar-db-dao/src/main/java/org/sonar | |
parent | 11eed2c0e23bc971bcd5f5a3eb03de4c64733228 (diff) | |
download | sonarqube-da3c7f5e086e4d9c84e966cba2b74c15e72c6426.tar.gz sonarqube-da3c7f5e086e4d9c84e966cba2b74c15e72c6426.zip |
SONAR-22807 Adapt the BE to use the renamed table DEVOPS_PERMS_MAPPING
Diffstat (limited to 'server/sonar-db-dao/src/main/java/org/sonar')
10 files changed, 110 insertions, 96 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java index 26e1187218d..bb7b126d088 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java @@ -66,7 +66,7 @@ import org.sonar.db.property.InternalComponentPropertiesDao; import org.sonar.db.property.InternalPropertiesDao; import org.sonar.db.property.PropertiesDao; import org.sonar.db.provisioning.GithubOrganizationGroupDao; -import org.sonar.db.provisioning.GithubPermissionsMappingDao; +import org.sonar.db.provisioning.DevOpsPermissionsMappingDao; import org.sonar.db.purge.PurgeDao; import org.sonar.db.pushevent.PushEventDao; import org.sonar.db.qualitygate.ProjectQgateAssociationDao; @@ -127,13 +127,13 @@ public class DaoModule extends Module { ComponentDao.class, ComponentKeyUpdaterDao.class, DefaultQProfileDao.class, + DevOpsPermissionsMappingDao.class, DuplicationDao.class, EntityDao.class, EsQueueDao.class, EventDao.class, EventComponentChangeDao.class, GithubOrganizationGroupDao.class, - GithubPermissionsMappingDao.class, ExternalGroupDao.class, FileSourceDao.class, GroupDao.class, diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java index c336b040b8c..8f68429cbb0 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java @@ -66,7 +66,7 @@ import org.sonar.db.property.InternalComponentPropertiesDao; import org.sonar.db.property.InternalPropertiesDao; import org.sonar.db.property.PropertiesDao; import org.sonar.db.provisioning.GithubOrganizationGroupDao; -import org.sonar.db.provisioning.GithubPermissionsMappingDao; +import org.sonar.db.provisioning.DevOpsPermissionsMappingDao; import org.sonar.db.purge.PurgeDao; import org.sonar.db.pushevent.PushEventDao; import org.sonar.db.qualitygate.ProjectQgateAssociationDao; @@ -192,7 +192,7 @@ public class DbClient { private final ReportScheduleDao reportScheduleDao; private final ReportSubscriptionDao reportSubscriptionDao; private final GithubOrganizationGroupDao githubOrganizationGroupDao; - private final GithubPermissionsMappingDao githubPermissionsMappingDao; + private final DevOpsPermissionsMappingDao devopsPermissionsMappingDao; private final RuleChangeDao ruleChangeDao; private final ProjectExportDao projectExportDao; private final IssueFixedDao issueFixedDao; @@ -254,7 +254,7 @@ public class DbClient { metricDao = getDao(map, MetricDao.class); groupDao = getDao(map, GroupDao.class); githubOrganizationGroupDao = getDao(map, GithubOrganizationGroupDao.class); - githubPermissionsMappingDao = getDao(map, GithubPermissionsMappingDao.class); + devopsPermissionsMappingDao = getDao(map, DevOpsPermissionsMappingDao.class); externalGroupDao = getDao(map, ExternalGroupDao.class); ruleDao = getDao(map, RuleDao.class); ruleRepositoryDao = getDao(map, RuleRepositoryDao.class); @@ -513,8 +513,8 @@ public class DbClient { return githubOrganizationGroupDao; } - public GithubPermissionsMappingDao githubPermissionsMappingDao() { - return githubPermissionsMappingDao; + public DevOpsPermissionsMappingDao githubPermissionsMappingDao() { + return devopsPermissionsMappingDao; } public ExternalGroupDao externalGroupDao() { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java index 35162ba115e..e14f8adac8a 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java @@ -121,8 +121,8 @@ import org.sonar.db.property.PropertiesMapper; import org.sonar.db.property.ScrapPropertyDto; import org.sonar.db.provisioning.GithubOrganizationGroupDto; import org.sonar.db.provisioning.GithubOrganizationGroupMapper; -import org.sonar.db.provisioning.GithubPermissionsMappingDto; -import org.sonar.db.provisioning.GithubPermissionsMappingMapper; +import org.sonar.db.provisioning.DevOpsPermissionsMappingDto; +import org.sonar.db.provisioning.DevOpsPermissionsMappingMapper; import org.sonar.db.purge.PurgeMapper; import org.sonar.db.purge.PurgeableAnalysisDto; import org.sonar.db.pushevent.PushEventDto; @@ -208,12 +208,12 @@ public class MyBatis { confBuilder.loadAlias("AnticipatedTransition", AnticipatedTransitionDto.class); confBuilder.loadAlias("CeTaskCharacteristic", CeTaskCharacteristicDto.class); confBuilder.loadAlias("Component", ComponentDto.class); + confBuilder.loadAlias("DevOpsPermissionsMapping", DevOpsPermissionsMappingDto.class); confBuilder.loadAlias("DuplicationUnit", DuplicationUnitDto.class); confBuilder.loadAlias("Entity", EntityDto.class); confBuilder.loadAlias("Event", EventDto.class); confBuilder.loadAlias("ExternalGroup", ExternalGroupDto.class); confBuilder.loadAlias("GithubOrganizationGroup", GithubOrganizationGroupDto.class); - confBuilder.loadAlias("GithubPermissionsMapping", GithubPermissionsMappingDto.class); confBuilder.loadAlias("FilePathWithHash", FilePathWithHashDto.class); confBuilder.loadAlias("KeyWithUuid", KeyWithUuidDto.class); confBuilder.loadAlias("Group", GroupDto.class); @@ -292,7 +292,7 @@ public class MyBatis { EventMapper.class, EventComponentChangeMapper.class, GithubOrganizationGroupMapper.class, - GithubPermissionsMappingMapper.class, + DevOpsPermissionsMappingMapper.class, ExternalGroupMapper.class, FileSourceMapper.class, GroupMapper.class, diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/AuditPersister.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/AuditPersister.java index 25d0bcbf65d..5e6f11a95f4 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/AuditPersister.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/AuditPersister.java @@ -25,7 +25,7 @@ import org.sonar.db.audit.model.AbstractEditorNewValue; import org.sonar.db.audit.model.ComponentKeyNewValue; import org.sonar.db.audit.model.ComponentNewValue; import org.sonar.db.audit.model.DevOpsPlatformSettingNewValue; -import org.sonar.db.audit.model.GithubPermissionsMappingNewValue; +import org.sonar.db.audit.model.DevOpsPermissionsMappingNewValue; import org.sonar.db.audit.model.GroupPermissionNewValue; import org.sonar.db.audit.model.LicenseNewValue; import org.sonar.db.audit.model.PermissionTemplateNewValue; @@ -103,9 +103,9 @@ public interface AuditPersister { void deleteGroupFromPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue); - void addGithubPermissionsMapping(DbSession dbSession, GithubPermissionsMappingNewValue newValue); + void addDevOpsPermissionsMapping(DbSession dbSession, DevOpsPermissionsMappingNewValue newValue); - void deleteGithubPermissionsMapping(DbSession dbSession, GithubPermissionsMappingNewValue deletedValue); + void deleteDevOpsPermissionsMapping(DbSession dbSession, DevOpsPermissionsMappingNewValue deletedValue); void addQualityGateEditor(DbSession dbSession, AbstractEditorNewValue newValue); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/NoOpAuditPersister.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/NoOpAuditPersister.java index 2b6d448c295..6edae9decc8 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/NoOpAuditPersister.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/NoOpAuditPersister.java @@ -25,7 +25,7 @@ import org.sonar.db.audit.model.ComponentKeyNewValue; import org.sonar.db.audit.model.ComponentNewValue; import org.sonar.db.audit.model.DevOpsPlatformSettingNewValue; import org.sonar.db.audit.model.AbstractEditorNewValue; -import org.sonar.db.audit.model.GithubPermissionsMappingNewValue; +import org.sonar.db.audit.model.DevOpsPermissionsMappingNewValue; import org.sonar.db.audit.model.GroupPermissionNewValue; import org.sonar.db.audit.model.LicenseNewValue; import org.sonar.db.audit.model.PermissionTemplateNewValue; @@ -193,12 +193,12 @@ public class NoOpAuditPersister implements AuditPersister { } @Override - public void addGithubPermissionsMapping(DbSession dbSession, GithubPermissionsMappingNewValue newValue) { + public void addDevOpsPermissionsMapping(DbSession dbSession, DevOpsPermissionsMappingNewValue newValue) { // no op } @Override - public void deleteGithubPermissionsMapping(DbSession dbSession, GithubPermissionsMappingNewValue deletedValue) { + public void deleteDevOpsPermissionsMapping(DbSession dbSession, DevOpsPermissionsMappingNewValue deletedValue) { // no op } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GithubPermissionsMappingNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/DevOpsPermissionsMappingNewValue.java index 1b3b7dec67e..b7624791dcb 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GithubPermissionsMappingNewValue.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/DevOpsPermissionsMappingNewValue.java @@ -21,20 +21,22 @@ package org.sonar.db.audit.model; import com.google.common.annotations.VisibleForTesting; -public class GithubPermissionsMappingNewValue extends NewValue { +public class DevOpsPermissionsMappingNewValue extends NewValue { @VisibleForTesting public static final String ALL_PERMISSIONS = "all"; + private final String devOpsPlatform; private final String githubRole; private final String sonarqubePermission; - public GithubPermissionsMappingNewValue(String githubRole, String sonarqubePermission) { + public DevOpsPermissionsMappingNewValue(String devOpsPlatform, String githubRole, String sonarqubePermission) { + this.devOpsPlatform = devOpsPlatform; this.githubRole = githubRole; this.sonarqubePermission = sonarqubePermission; } - public static GithubPermissionsMappingNewValue withAllPermissions(String githubRole) { - return new GithubPermissionsMappingNewValue(githubRole, ALL_PERMISSIONS); + public static DevOpsPermissionsMappingNewValue withAllPermissions(String devOpsPlatform, String githubRole) { + return new DevOpsPermissionsMappingNewValue(devOpsPlatform, githubRole, ALL_PERMISSIONS); } @VisibleForTesting @@ -42,14 +44,21 @@ public class GithubPermissionsMappingNewValue extends NewValue { return githubRole; } + @VisibleForTesting public String getSonarqubePermission() { return sonarqubePermission; } + @VisibleForTesting + public String getDevOpsPlatform() { + return devOpsPlatform; + } + @Override public String toString() { StringBuilder sb = new StringBuilder("{"); - addField(sb, "\"githubRole\": ", this.githubRole, true); + addField(sb, "\"devOpsPlatform\": ", this.devOpsPlatform, true); + addField(sb, "\"devOpsRole\": ", this.githubRole, true); addField(sb, "\"sonarqubePermissions\": ", this.sonarqubePermission, true); endString(sb); return sb.toString(); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/DevOpsPermissionsMappingDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/DevOpsPermissionsMappingDao.java new file mode 100644 index 00000000000..c5737e62910 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/DevOpsPermissionsMappingDao.java @@ -0,0 +1,72 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.provisioning; + +import java.util.Set; +import org.sonar.db.Dao; +import org.sonar.db.DbSession; +import org.sonar.db.audit.AuditPersister; +import org.sonar.db.audit.model.DevOpsPermissionsMappingNewValue; + +public class DevOpsPermissionsMappingDao implements Dao { + + private final AuditPersister auditPersister; + + public DevOpsPermissionsMappingDao(AuditPersister auditPersister) { + this.auditPersister = auditPersister; + } + + public Set<DevOpsPermissionsMappingDto> findAll(DbSession dbSession, String devOpsPlatform) { + return mapper(dbSession).selectAll(devOpsPlatform); + } + + public Set<DevOpsPermissionsMappingDto> findAllForRole(DbSession dbSession, String devOpsPlatform, String role) { + return mapper(dbSession).selectAllForRole(devOpsPlatform, role); + } + + public void insert(DbSession dbSession, DevOpsPermissionsMappingDto devOpsPermissionsMappingDto) { + mapper(dbSession).insert(devOpsPermissionsMappingDto); + DevOpsPermissionsMappingNewValue newValueForAuditLogs = toNewValueForAuditLogs( + devOpsPermissionsMappingDto.devOpsPlatform(), + devOpsPermissionsMappingDto.role(), + devOpsPermissionsMappingDto.sonarqubePermission() + ); + auditPersister.addDevOpsPermissionsMapping(dbSession, newValueForAuditLogs); + } + + public void delete(DbSession dbSession, String devOpsPlatform, String role, String sonarqubePermission) { + mapper(dbSession).delete(devOpsPlatform, role, sonarqubePermission); + auditPersister.deleteDevOpsPermissionsMapping(dbSession, toNewValueForAuditLogs(devOpsPlatform, role, sonarqubePermission)); + } + + public void deleteAllPermissionsForRole(DbSession dbSession, String devOpsPlatform, String role) { + mapper(dbSession).deleteAllPermissionsForRole(devOpsPlatform, role); + auditPersister.deleteDevOpsPermissionsMapping(dbSession, DevOpsPermissionsMappingNewValue.withAllPermissions(devOpsPlatform, role)); + } + + private static DevOpsPermissionsMappingNewValue toNewValueForAuditLogs(String devOpsPlatform, String role, String sonarqubePermission) { + return new DevOpsPermissionsMappingNewValue(devOpsPlatform, role, sonarqubePermission); + } + + private static DevOpsPermissionsMappingMapper mapper(DbSession session) { + return session.getMapper(DevOpsPermissionsMappingMapper.class); + } + +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/DevOpsPermissionsMappingDto.java index 764e0aec5dd..09d7654a93e 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/DevOpsPermissionsMappingDto.java @@ -19,5 +19,5 @@ */ package org.sonar.db.provisioning; -public record GithubPermissionsMappingDto(String uuid, String githubRole, String sonarqubePermission) { +public record DevOpsPermissionsMappingDto(String uuid, String devOpsPlatform, String role, String sonarqubePermission) { } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/DevOpsPermissionsMappingMapper.java index 8faf4b9ef0b..afb6d2972f4 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/DevOpsPermissionsMappingMapper.java @@ -22,15 +22,15 @@ package org.sonar.db.provisioning; import java.util.Set; import org.apache.ibatis.annotations.Param; -public interface GithubPermissionsMappingMapper { +public interface DevOpsPermissionsMappingMapper { - Set<GithubPermissionsMappingDto> selectAll(); + Set<DevOpsPermissionsMappingDto> selectAll(@Param("devOpsPlatform") String devOpsPlatform); - Set<GithubPermissionsMappingDto> selectAllForGithubRole(String githubRole); + Set<DevOpsPermissionsMappingDto> selectAllForRole(@Param("devOpsPlatform") String devOpsPlatform, @Param("role") String role); - void insert(GithubPermissionsMappingDto githubPermissionsMappingDto); + void insert(DevOpsPermissionsMappingDto devOpsPermissionsMappingDto); - void delete(@Param("githubRole") String githubRole, @Param("sonarqubePermission") String sonarqubePermission); + void delete(@Param("devOpsPlatform") String devOpsPlatform, @Param("role") String role, @Param("sonarqubePermission") String sonarqubePermission); - void deleteAllPermissionsForRole(String githubRole); + void deleteAllPermissionsForRole(@Param("devOpsPlatform") String devOpsPlatform, @Param("role") String role); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingDao.java deleted file mode 100644 index 33496aaaaea..00000000000 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingDao.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.provisioning; - -import java.util.Set; -import org.sonar.db.Dao; -import org.sonar.db.DbSession; -import org.sonar.db.audit.AuditPersister; -import org.sonar.db.audit.model.GithubPermissionsMappingNewValue; - -public class GithubPermissionsMappingDao implements Dao { - - private final AuditPersister auditPersister; - - public GithubPermissionsMappingDao(AuditPersister auditPersister) { - this.auditPersister = auditPersister; - } - - public Set<GithubPermissionsMappingDto> findAll(DbSession dbSession) { - return mapper(dbSession).selectAll(); - } - - public Set<GithubPermissionsMappingDto> findAllForGithubRole(DbSession dbSession, String githubRole) { - return mapper(dbSession).selectAllForGithubRole(githubRole); - } - - public void insert(DbSession dbSession, GithubPermissionsMappingDto githubPermissionsMappingDto) { - mapper(dbSession).insert(githubPermissionsMappingDto); - auditPersister.addGithubPermissionsMapping(dbSession, toNewValueForAuditLogs(githubPermissionsMappingDto.githubRole(), githubPermissionsMappingDto.sonarqubePermission())); - } - - public void delete(DbSession dbSession, String githubRole, String sonarqubePermission) { - mapper(dbSession).delete(githubRole, sonarqubePermission); - auditPersister.deleteGithubPermissionsMapping(dbSession, toNewValueForAuditLogs(githubRole, sonarqubePermission)); - } - - public void deleteAllPermissionsForRole(DbSession dbSession, String githubRole) { - mapper(dbSession).deleteAllPermissionsForRole(githubRole); - auditPersister.deleteGithubPermissionsMapping(dbSession, GithubPermissionsMappingNewValue.withAllPermissions(githubRole)); - } - - private static GithubPermissionsMappingNewValue toNewValueForAuditLogs(String githubRole, String sonarqubePermission) { - return new GithubPermissionsMappingNewValue(githubRole, sonarqubePermission); - } - - private static GithubPermissionsMappingMapper mapper(DbSession session) { - return session.getMapper(GithubPermissionsMappingMapper.class); - } - -} |