From 6c334f9290e0a5f42b4b128919d4c25b5d20ce58 Mon Sep 17 00:00:00 2001 From: Jacek Date: Mon, 20 Apr 2020 14:47:21 +0200 Subject: [PATCH] SONAR-13221 change PK to uuid of PERMISSION_TEMPLATES table * change template_id to template_uuid for PERM_TEMPLATES_GROUPS, PERM_TEMPLATES_USERS, PERM_TPL_CHARACTERISTICS --- .../CountByTemplateAndPermissionDto.java | 10 +- .../PermissionTemplateCharacteristicDao.java | 8 +- .../PermissionTemplateCharacteristicDto.java | 10 +- ...ermissionTemplateCharacteristicMapper.java | 8 +- .../template/PermissionTemplateDao.java | 111 +++++----- .../template/PermissionTemplateDto.java | 27 --- .../template/PermissionTemplateGroupDto.java | 10 +- .../template/PermissionTemplateMapper.java | 34 +-- .../template/PermissionTemplateUserDto.java | 10 +- ...PermissionTemplateCharacteristicMapper.xml | 30 +-- .../template/PermissionTemplateMapper.xml | 126 +++++------ server/sonar-db-dao/src/schema/schema-sq.ddl | 21 +- .../GroupWithPermissionTemplateDaoTest.java | 82 ++++---- ...rmissionTemplateCharacteristicDaoTest.java | 60 +++--- .../template/PermissionTemplateDaoTest.java | 196 +++++++++--------- .../UserWithPermissionTemplateDaoTest.java | 40 ++-- .../template/PermissionTemplateDbTester.java | 20 +- .../db/migration/version/v83/DbVersion83.java | 55 +++++ ...nUuidColumnOfPermissionTemplatesTable.java | 38 ++++ .../AddUuidColumnToPermissionTemplates.java | 31 +++ ...ropIdColumnOfPermissionTemplatesTable.java | 31 +++ ...opKeeColumnOfPermissionTemplatesTable.java | 37 ++++ ...yOnIdColumnOfPermissionTemplatesTable.java | 32 +++ ...rmissionTemplateUuidColumnNotNullable.java | 31 +++ .../PopulatePermissionTemplatesUuid.java | 58 ++++++ ...mplateUuidColumnToPermTemplatesGroups.java | 50 +++++ ...ateIdColumnOfPermTemplatesGroupsTable.java | 37 ++++ ...esGroupsTemplateUuidColumnNotNullable.java | 50 +++++ ...PermTemplatesGroupsTemplateUuidColumn.java | 49 +++++ ...emplateUuidColumnToPermTemplatesUsers.java | 50 +++++ ...lateIdColumnOfPermTemplatesUsersTable.java | 37 ++++ ...tesUsersTemplateUuidColumnNotNullable.java | 50 +++++ ...ePermTemplatesUsersTemplateUuidColumn.java | 49 +++++ ...ateUuidColumnToPermTplCharacteristics.java | 50 +++++ ...yColumnsOfPermTplCharacteristicsTable.java | 67 ++++++ ...IdColumnOfPermTplCharacteristicsTable.java | 37 ++++ ...yColumnsOfPermTplCharacteristicsTable.java | 52 +++++ ...eristicsTemplateUuidColumnNotNullable.java | 50 +++++ ...mTplCharacteristicsTemplateUuidColumn.java | 49 +++++ ...dColumnOfPermissionTemplatesTableTest.java | 52 +++++ ...ddUuidColumnToPermissionTemplatesTest.java | 68 ++++++ ...dColumnOfPermissionTemplatesTableTest.java | 52 +++++ ...eColumnOfPermissionTemplatesTableTest.java | 52 +++++ ...dColumnOfPermissionTemplatesTableTest.java | 56 +++++ ...sionTemplateUuidColumnNotNullableTest.java | 44 ++++ .../PopulatePermissionTemplatesUuidTest.java | 87 ++++++++ ...teUuidColumnToPermTemplatesGroupsTest.java | 66 ++++++ ...dColumnOfPermTemplatesGroupsTableTest.java | 52 +++++ ...oupsTemplateUuidColumnNotNullableTest.java | 44 ++++ ...TemplatesGroupsTemplateUuidColumnTest.java | 116 +++++++++++ ...ateUuidColumnToPermTemplatesUsersTest.java | 68 ++++++ ...IdColumnOfPermTemplatesUsersTableTest.java | 52 +++++ ...sersTemplateUuidColumnNotNullableTest.java | 44 ++++ ...mTemplatesUsersTemplateUuidColumnTest.java | 117 +++++++++++ ...uidColumnToPermTplCharacteristicsTest.java | 70 +++++++ ...umnsOfPermTplCharacteristicsTableTest.java | 52 +++++ ...lumnOfPermTplCharacteristicsTableTest.java | 52 +++++ ...umnsOfPermTplCharacteristicsTableTest.java | 52 +++++ ...ticsTemplateUuidColumnNotNullableTest.java | 44 ++++ ...CharacteristicsTemplateUuidColumnTest.java | 118 +++++++++++ .../schema.sql | 12 ++ .../schema.sql | 11 + .../schema.sql | 12 ++ .../schema.sql | 11 + .../schema.sql | 12 ++ .../schema.sql | 12 ++ .../schema.sql | 12 ++ .../schema.sql | 9 + .../schema.sql | 10 + .../schema.sql | 10 + .../schema.sql | 23 ++ .../schema.sql | 9 + .../schema.sql | 10 + .../schema.sql | 10 + .../schema.sql | 23 ++ .../schema.sql | 10 + .../schema.sql | 11 + .../schema.sql | 11 + .../schema.sql | 11 + .../schema.sql | 11 + .../schema.sql | 24 +++ .../organization/OrganisationSupport.java | 2 +- .../organization/OrganizationUpdaterImpl.java | 2 +- .../organization/MemberUpdaterTest.java | 10 +- .../OrganizationUpdaterImplTest.java | 4 +- .../startup/RegisterPermissionTemplates.java | 7 +- .../RegisterPermissionTemplatesTest.java | 2 +- .../permission/PermissionTemplateService.java | 13 +- .../ws/template/AddGroupToTemplateAction.java | 12 +- .../AddProjectCreatorToTemplateAction.java | 6 +- .../ws/template/AddUserToTemplateAction.java | 8 +- .../ws/template/DeleteTemplateAction.java | 9 +- .../RemoveGroupFromTemplateAction.java | 4 +- ...emoveProjectCreatorFromTemplateAction.java | 4 +- .../RemoveUserFromTemplateAction.java | 4 +- .../ws/template/SearchTemplatesAction.java | 59 +++--- .../ws/template/SearchTemplatesData.java | 48 ++--- .../ws/template/TemplateGroupsAction.java | 8 +- .../ws/template/TemplateUsersAction.java | 6 +- .../ws/template/UpdateTemplateAction.java | 11 +- .../organization/ws/CreateActionTest.java | 4 +- .../PermissionTemplateServiceTest.java | 8 +- .../AddGroupToTemplateActionTest.java | 2 +- ...AddProjectCreatorToTemplateActionTest.java | 15 +- .../template/AddUserToTemplateActionTest.java | 2 +- .../ws/template/ApplyTemplateActionTest.java | 4 +- .../template/BulkApplyTemplateActionTest.java | 4 +- .../ws/template/DeleteTemplateActionTest.java | 4 +- .../RemoveGroupFromTemplateActionTest.java | 4 +- ...eProjectCreatorFromTemplateActionTest.java | 10 +- .../RemoveUserFromTemplateActionTest.java | 6 +- .../template/SearchTemplatesActionTest.java | 65 +++--- .../ws/template/SearchTemplatesDataTest.java | 12 +- .../ws/template/TemplateGroupsActionTest.java | 58 +++--- .../ws/template/TemplateUsersActionTest.java | 4 +- .../server/user/ws/DeactivateActionTest.java | 9 +- .../usergroups/ws/DeleteActionTest.java | 2 +- 117 files changed, 3226 insertions(+), 621 deletions(-) create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/AddPrimaryKeyOnUuidColumnOfPermissionTemplatesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/AddUuidColumnToPermissionTemplates.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/DropIdColumnOfPermissionTemplatesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/DropKeeColumnOfPermissionTemplatesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/DropPrimaryKeyOnIdColumnOfPermissionTemplatesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/MakePermissionTemplateUuidColumnNotNullable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/PopulatePermissionTemplatesUuid.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesgroups/AddTemplateUuidColumnToPermTemplatesGroups.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesgroups/DropTemplateIdColumnOfPermTemplatesGroupsTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesgroups/MakePermTemplatesGroupsTemplateUuidColumnNotNullable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesgroups/PopulatePermTemplatesGroupsTemplateUuidColumn.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesusers/AddTemplateUuidColumnToPermTemplatesUsers.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesusers/DropTemplateIdColumnOfPermTemplatesUsersTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesusers/MakePermTemplatesUsersTemplateUuidColumnNotNullable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesusers/PopulatePermTemplatesUsersTemplateUuidColumn.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtplcharacteristics/AddTemplateUuidColumnToPermTplCharacteristics.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtplcharacteristics/AddUniqueIndexOnTemplateUuidAndPermissionKeyColumnsOfPermTplCharacteristicsTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtplcharacteristics/DropTemplateIdColumnOfPermTplCharacteristicsTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtplcharacteristics/DropUniqueIndexOnTemplateIdAndPermissionKeyColumnsOfPermTplCharacteristicsTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtplcharacteristics/MakePermTplCharacteristicsTemplateUuidColumnNotNullable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtplcharacteristics/PopulatePermTplCharacteristicsTemplateUuidColumn.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/AddPrimaryKeyOnUuidColumnOfPermissionTemplatesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/AddUuidColumnToPermissionTemplatesTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/DropIdColumnOfPermissionTemplatesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/DropKeeColumnOfPermissionTemplatesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/DropPrimaryKeyOnIdColumnOfPermissionTemplatesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/MakePermissionTemplateUuidColumnNotNullableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/PopulatePermissionTemplatesUuidTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesgroups/AddTemplateUuidColumnToPermTemplatesGroupsTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesgroups/DropTemplateIdColumnOfPermTemplatesGroupsTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesgroups/MakePermTemplatesGroupsTemplateUuidColumnNotNullableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesgroups/PopulatePermTemplatesGroupsTemplateUuidColumnTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesusers/AddTemplateUuidColumnToPermTemplatesUsersTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesusers/DropTemplateIdColumnOfPermTemplatesUsersTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesusers/MakePermTemplatesUsersTemplateUuidColumnNotNullableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesusers/PopulatePermTemplatesUsersTemplateUuidColumnTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtplcharacteristics/AddTemplateUuidColumnToPermTplCharacteristicsTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtplcharacteristics/AddUniqueIndexOnTemplateUuidAndPermissionKeyColumnsOfPermTplCharacteristicsTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtplcharacteristics/DropTemplateIdColumnOfPermTplCharacteristicsTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtplcharacteristics/DropUniqueIndexOnTemplateIdAndPermissionKeyColumnsOfPermTplCharacteristicsTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtplcharacteristics/MakePermTplCharacteristicsTemplateUuidColumnNotNullableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtplcharacteristics/PopulatePermTplCharacteristicsTemplateUuidColumnTest.java create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/AddPrimaryKeyOnUuidColumnOfPermissionTemplatesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/AddUuidColumnToPermissionTemplatesTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/DropIdColumnOfPermissionTemplatesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/DropKeeColumnOfPermissionTemplatesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/DropPrimaryKeyOnIdColumnOfPermissionTemplatesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/MakePermissionTemplateUuidColumnNotNullableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/PopulatePermissionTemplatesUuidTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesgroups/AddTemplateUuidColumnToPermTemplatesGroupsTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesgroups/DropTemplateIdColumnOfPermTemplatesGroupsTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesgroups/MakePermTemplatesGroupsTemplateUuidColumnNotNullableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesgroups/PopulatePermTemplatesGroupsTemplateUuidColumnTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesusers/AddTemplateUuidColumnToPermTemplatesUsersTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesusers/DropTemplateIdColumnOfPermTemplatesUsersTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesusers/MakePermTemplatesUsersTemplateUuidColumnNotNullableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtemplatesusers/PopulatePermTemplatesUsersTemplateUuidColumnTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtplcharacteristics/AddTemplateUuidColumnToPermTplCharacteristicsTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtplcharacteristics/AddUniqueIndexOnTemplateUuidAndPermissionKeyColumnsOfPermTplCharacteristicsTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtplcharacteristics/DropTemplateIdColumnOfPermTplCharacteristicsTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtplcharacteristics/DropUniqueIndexOnTemplateIdAndPermissionKeyColumnsOfPermTplCharacteristicsTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtplcharacteristics/MakePermTplCharacteristicsTemplateUuidColumnNotNullableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/permissiontemplates/fk/permtplcharacteristics/PopulatePermTplCharacteristicsTemplateUuidColumnTest/schema.sql diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/CountByTemplateAndPermissionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/CountByTemplateAndPermissionDto.java index f9f0e4ee694..8b3901039b6 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/CountByTemplateAndPermissionDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/CountByTemplateAndPermissionDto.java @@ -20,16 +20,16 @@ package org.sonar.db.permission.template; public class CountByTemplateAndPermissionDto { - private long templateId; + private String templateUuid; private String permission; private int count; - public long getTemplateId() { - return templateId; + public String getTemplateUuid() { + return templateUuid; } - public void setTemplateId(long templateId) { - this.templateId = templateId; + public void setTemplateUuid(String templateUuid) { + this.templateUuid = templateUuid; } public String getPermission() { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicDao.java index 34466e48748..b117ac1f9ca 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicDao.java @@ -30,12 +30,12 @@ import static org.sonar.db.DatabaseUtils.executeLargeInputs; public class PermissionTemplateCharacteristicDao implements Dao { - public List selectByTemplateIds(DbSession dbSession, List templateIds) { - return executeLargeInputs(templateIds, partitionOfTemplateIds -> mapper(dbSession).selectByTemplateIds(partitionOfTemplateIds)); + public List selectByTemplateUuids(DbSession dbSession, List templateUuids) { + return executeLargeInputs(templateUuids, partitionOfTemplateUuids -> mapper(dbSession).selectByTemplateUuids(partitionOfTemplateUuids)); } - public Optional selectByPermissionAndTemplateId(DbSession dbSession, String permission, long templateId) { - PermissionTemplateCharacteristicDto dto = mapper(dbSession).selectByPermissionAndTemplateId(permission, templateId); + public Optional selectByPermissionAndTemplateId(DbSession dbSession, String permission, String templateUuid) { + PermissionTemplateCharacteristicDto dto = mapper(dbSession).selectByPermissionAndTemplateUuid(permission, templateUuid); return Optional.ofNullable(dto); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicDto.java index d3ac1eb6320..1ab6541b7b6 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicDto.java @@ -26,7 +26,7 @@ public class PermissionTemplateCharacteristicDto { private static final int MAX_PERMISSION_KEY_LENGTH = 64; private String uuid; - private long templateId; + private String templateUuid; private String permission; private boolean withProjectCreator; private long createdAt; @@ -41,12 +41,12 @@ public class PermissionTemplateCharacteristicDto { return this; } - public long getTemplateId() { - return templateId; + public String getTemplateUuid() { + return templateUuid; } - public PermissionTemplateCharacteristicDto setTemplateId(long templateId) { - this.templateId = templateId; + public PermissionTemplateCharacteristicDto setTemplateUuid(String templateUuid) { + this.templateUuid = templateUuid; return this; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicMapper.java index f6dae36b590..ff7997c7e5e 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateCharacteristicMapper.java @@ -26,15 +26,15 @@ public interface PermissionTemplateCharacteristicMapper { PermissionTemplateCharacteristicDto selectByUuid(@Param("uuid") String uuid); - List selectByTemplateIds(@Param("templateIds") List templateId); + List selectByTemplateUuids(@Param("templateUuids") List templateUuids); - PermissionTemplateCharacteristicDto selectByPermissionAndTemplateId(@Param("permission") String permission, @Param("templateId") long templateId); + PermissionTemplateCharacteristicDto selectByPermissionAndTemplateUuid(@Param("permission") String permission, @Param("templateUuid") String templateUuid); void insert(PermissionTemplateCharacteristicDto templatePermissionDto); void update(PermissionTemplateCharacteristicDto templatePermissionDto); - void deleteByTemplateId(long id); + void deleteByTemplateUuid(String uuid); - void deleteByTemplateIds(@Param("templateIds") List subList); + void deleteByTemplateUuids(@Param("templateUuids") List subList); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java index 31c810c5874..e5c621d8493 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java @@ -30,7 +30,7 @@ import javax.annotation.Nullable; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; import org.sonar.api.utils.System2; -import org.sonar.core.util.Uuids; +import org.sonar.core.util.UuidFactory; import org.sonar.db.Dao; import org.sonar.db.DbSession; import org.sonar.db.permission.CountPerProjectPermission; @@ -46,51 +46,53 @@ public class PermissionTemplateDao implements Dao { private static final String ANYONE_GROUP_PARAMETER = "anyoneGroup"; private final System2 system; + private final UuidFactory uuidFactory; - public PermissionTemplateDao(System2 system) { + public PermissionTemplateDao(UuidFactory uuidFactory, System2 system) { + this.uuidFactory = uuidFactory; this.system = system; } /** * @return a paginated list of user logins. */ - public List selectUserLoginsByQueryAndTemplate(DbSession session, PermissionQuery query, long templateId) { - return mapper(session).selectUserLoginsByQueryAndTemplate(query, templateId, new RowBounds(query.getPageOffset(), query.getPageSize())); + public List selectUserLoginsByQueryAndTemplate(DbSession session, PermissionQuery query, String templateUuid) { + return mapper(session).selectUserLoginsByQueryAndTemplate(query, templateUuid, new RowBounds(query.getPageOffset(), query.getPageSize())); } - public int countUserLoginsByQueryAndTemplate(DbSession session, PermissionQuery query, long templateId) { - return mapper(session).countUserLoginsByQueryAndTemplate(query, templateId); + public int countUserLoginsByQueryAndTemplate(DbSession session, PermissionQuery query, String templateUuid) { + return mapper(session).countUserLoginsByQueryAndTemplate(query, templateUuid); } - public List selectUserPermissionsByTemplateIdAndUserLogins(DbSession dbSession, long templateId, List logins) { - return executeLargeInputs(logins, l -> mapper(dbSession).selectUserPermissionsByTemplateIdAndUserLogins(templateId, l)); + public List selectUserPermissionsByTemplateIdAndUserLogins(DbSession dbSession, String templateUuid, List logins) { + return executeLargeInputs(logins, l -> mapper(dbSession).selectUserPermissionsByTemplateUuidAndUserLogins(templateUuid, l)); } - public List selectUserPermissionsByTemplateId(DbSession dbSession, long templateId) { - return mapper(dbSession).selectUserPermissionsByTemplateIdAndUserLogins(templateId, Collections.emptyList()); + public List selectUserPermissionsByTemplateId(DbSession dbSession, String templateUuid) { + return mapper(dbSession).selectUserPermissionsByTemplateUuidAndUserLogins(templateUuid, Collections.emptyList()); } - public List selectGroupNamesByQueryAndTemplate(DbSession session, PermissionQuery query, long templateId) { - return mapper(session).selectGroupNamesByQueryAndTemplate(templateId, query, new RowBounds(query.getPageOffset(), query.getPageSize())); + public List selectGroupNamesByQueryAndTemplate(DbSession session, PermissionQuery query, String templateUuid) { + return mapper(session).selectGroupNamesByQueryAndTemplate(templateUuid, query, new RowBounds(query.getPageOffset(), query.getPageSize())); } - public int countGroupNamesByQueryAndTemplate(DbSession session, PermissionQuery query, String organizationUuid, long templateId) { - return mapper(session).countGroupNamesByQueryAndTemplate(organizationUuid, query, templateId); + public int countGroupNamesByQueryAndTemplate(DbSession session, PermissionQuery query, String organizationUuid, String templateUuid) { + return mapper(session).countGroupNamesByQueryAndTemplate(organizationUuid, query, templateUuid); } - public List selectGroupPermissionsByTemplateIdAndGroupNames(DbSession dbSession, long templateId, List groups) { - return executeLargeInputs(groups, g -> mapper(dbSession).selectGroupPermissionsByTemplateIdAndGroupNames(templateId, g)); + public List selectGroupPermissionsByTemplateIdAndGroupNames(DbSession dbSession, String templateUuid, List groups) { + return executeLargeInputs(groups, g -> mapper(dbSession).selectGroupPermissionsByTemplateUuidAndGroupNames(templateUuid, g)); } - public List selectGroupPermissionsByTemplateId(DbSession dbSession, long templateId) { - return mapper(dbSession).selectGroupPermissionsByTemplateIdAndGroupNames(templateId, Collections.emptyList()); + public List selectGroupPermissionsByTemplateUuid(DbSession dbSession, String templateUuid) { + return mapper(dbSession).selectGroupPermissionsByTemplateUuidAndGroupNames(templateUuid, Collections.emptyList()); } /** * @return {@code true} if template contains groups that are granted with {@code permission}, else {@code false} */ - public boolean hasGroupsWithPermission(DbSession dbSession, long templateId, String permission, @Nullable Integer groupId) { - return mapper(dbSession).countGroupsWithPermission(templateId, permission, groupId) > 0; + public boolean hasGroupsWithPermission(DbSession dbSession, String templateUuid, String permission, @Nullable Integer groupId) { + return mapper(dbSession).countGroupsWithPermission(templateUuid, permission, groupId) > 0; } @CheckForNull @@ -109,6 +111,9 @@ public class PermissionTemplateDao implements Dao { } public PermissionTemplateDto insert(DbSession session, PermissionTemplateDto dto) { + if (dto.getUuid() == null) { + dto.setUuid(uuidFactory.create()); + } mapper(session).insert(dto); return dto; } @@ -116,29 +121,29 @@ public class PermissionTemplateDao implements Dao { /** * Each row returns a #{@link CountPerProjectPermission} */ - public void usersCountByTemplateIdAndPermission(DbSession dbSession, List templateIds, ResultHandler resultHandler) { + public void usersCountByTemplateUuidAndPermission(DbSession dbSession, List templateUuids, ResultHandler resultHandler) { Map parameters = new HashMap<>(1); executeLargeInputsWithoutOutput( - templateIds, - partitionedTemplateIds -> { - parameters.put("templateIds", partitionedTemplateIds); - mapper(dbSession).usersCountByTemplateIdAndPermission(parameters, resultHandler); + templateUuids, + partitionedTemplateUuids -> { + parameters.put("templateUuids", partitionedTemplateUuids); + mapper(dbSession).usersCountByTemplateUuidAndPermission(parameters, resultHandler); }); } /** * Each row returns a #{@link CountPerProjectPermission} */ - public void groupsCountByTemplateIdAndPermission(DbSession dbSession, List templateIds, ResultHandler resultHandler) { + public void groupsCountByTemplateUuidAndPermission(DbSession dbSession, List templateUuids, ResultHandler resultHandler) { Map parameters = new HashMap<>(2); parameters.put(ANYONE_GROUP_PARAMETER, ANYONE); executeLargeInputsWithoutOutput( - templateIds, - partitionedTemplateIds -> { - parameters.put("templateIds", partitionedTemplateIds); - mapper(dbSession).groupsCountByTemplateIdAndPermission(parameters, resultHandler); + templateUuids, + partitionedTemplateUuids -> { + parameters.put("templateUuids", partitionedTemplateUuids); + mapper(dbSession).groupsCountByTemplateUuidAndPermission(parameters, resultHandler); }); } @@ -146,12 +151,12 @@ public class PermissionTemplateDao implements Dao { return mapper(dbSession).selectAllGroupPermissionTemplatesByGroupId(groupId); } - public void deleteById(DbSession session, long templateId) { + public void deleteByUuid(DbSession session, String templateUuid) { PermissionTemplateMapper mapper = mapper(session); - mapper.deleteUserPermissionsByTemplateId(templateId); - mapper.deleteGroupPermissionsByTemplateId(templateId); - session.getMapper(PermissionTemplateCharacteristicMapper.class).deleteByTemplateId(templateId); - mapper.deleteById(templateId); + mapper.deleteUserPermissionsByTemplateUuid(templateUuid); + mapper.deleteGroupPermissionsByTemplateUuid(templateUuid); + session.getMapper(PermissionTemplateCharacteristicMapper.class).deleteByTemplateUuid(templateUuid); + mapper.deleteByUuid(templateUuid); } public PermissionTemplateDto update(DbSession session, PermissionTemplateDto permissionTemplate) { @@ -159,10 +164,10 @@ public class PermissionTemplateDao implements Dao { return permissionTemplate; } - public void insertUserPermission(DbSession session, Long templateId, Integer userId, String permission) { + public void insertUserPermission(DbSession session, String templateUuid, Integer userId, String permission) { PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto() - .setUuid(Uuids.create()) - .setTemplateId(templateId) + .setUuid(uuidFactory.create()) + .setTemplateUuid(templateUuid) .setUserId(userId) .setPermission(permission) .setCreatedAt(now()) @@ -172,9 +177,9 @@ public class PermissionTemplateDao implements Dao { session.commit(); } - public void deleteUserPermission(DbSession session, Long templateId, Integer userId, String permission) { + public void deleteUserPermission(DbSession session, String templateUuid, Integer userId, String permission) { PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto() - .setTemplateId(templateId) + .setTemplateUuid(templateUuid) .setPermission(permission) .setUserId(userId); mapper(session).deleteUserPermission(permissionTemplateUser); @@ -189,10 +194,10 @@ public class PermissionTemplateDao implements Dao { mapper(dbSession).deleteUserPermissionsByUserId(userId); } - public void insertGroupPermission(DbSession session, long templateId, @Nullable Integer groupId, String permission) { + public void insertGroupPermission(DbSession session, String templateUuid, @Nullable Integer groupId, String permission) { PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto() - .setUuid(Uuids.create()) - .setTemplateId(templateId) + .setUuid(uuidFactory.create()) + .setTemplateUuid(templateUuid) .setPermission(permission) .setGroupId(groupId) .setCreatedAt(now()) @@ -204,9 +209,9 @@ public class PermissionTemplateDao implements Dao { mapper(session).insertGroupPermission(permissionTemplateGroup); } - public void deleteGroupPermission(DbSession session, Long templateId, @Nullable Integer groupId, String permission) { + public void deleteGroupPermission(DbSession session, String templateUuid, @Nullable Integer groupId, String permission) { PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto() - .setTemplateId(templateId) + .setTemplateUuid(templateUuid) .setPermission(permission) .setGroupId(groupId); mapper(session).deleteGroupPermission(permissionTemplateGroup); @@ -217,8 +222,8 @@ public class PermissionTemplateDao implements Dao { return mapper(dbSession).selectByName(organizationUuid, name.toUpperCase(Locale.ENGLISH)); } - public List selectPotentialPermissionsByUserIdAndTemplateId(DbSession dbSession, @Nullable Integer currentUserId, long templateId) { - return mapper(dbSession).selectPotentialPermissionsByUserIdAndTemplateId(currentUserId, templateId); + public List selectPotentialPermissionsByUserIdAndTemplateUuid(DbSession dbSession, @Nullable Integer currentUserId, String templateUuid) { + return mapper(dbSession).selectPotentialPermissionsByUserIdAndTemplateUuid(currentUserId, templateUuid); } /** @@ -239,12 +244,12 @@ public class PermissionTemplateDao implements Dao { public void deleteByOrganization(DbSession dbSession, String organizationUuid) { PermissionTemplateMapper templateMapper = mapper(dbSession); PermissionTemplateCharacteristicMapper templateCharacteristicMapper = dbSession.getMapper(PermissionTemplateCharacteristicMapper.class); - List templateIds = templateMapper.selectTemplateIdsByOrganization(organizationUuid); - executeLargeInputsWithoutOutput(templateIds, subList -> { - templateCharacteristicMapper.deleteByTemplateIds(subList); - templateMapper.deleteGroupPermissionsByTemplateIds(subList); - templateMapper.deleteUserPermissionsByTemplateIds(subList); - templateMapper.deleteByIds(subList); + List templateUuids = templateMapper.selectTemplateUuidsByOrganization(organizationUuid); + executeLargeInputsWithoutOutput(templateUuids, subList -> { + templateCharacteristicMapper.deleteByTemplateUuids(subList); + templateMapper.deleteGroupPermissionsByTemplateUuids(subList); + templateMapper.deleteUserPermissionsByTemplateUuids(subList); + templateMapper.deleteByUuids(subList); }); } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDto.java index be22f57031d..53f1f054244 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDto.java @@ -25,7 +25,6 @@ import javax.annotation.Nullable; public class PermissionTemplateDto { - private Long id; private String name; private String organizationUuid; private String uuid; @@ -34,15 +33,6 @@ public class PermissionTemplateDto { private Date createdAt; private Date updatedAt; - public Long getId() { - return id; - } - - public PermissionTemplateDto setId(Long id) { - this.id = id; - return this; - } - public String getOrganizationUuid() { return organizationUuid; } @@ -61,23 +51,6 @@ public class PermissionTemplateDto { return this; } - /** - * @deprecated since 5.2 use {@link #getUuid()} - */ - @Deprecated - public String getKee() { - return uuid; - } - - /** - * @deprecated since 5.2 use {@link #setUuid(String)} - */ - @Deprecated - public PermissionTemplateDto setKee(String kee) { - this.uuid = kee; - return this; - } - /** * @since 5.2 the kee column is a proper uuid. Before that it was build on the name + timestamp */ diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java index 50a623f7d78..4c3e5acf6d0 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java @@ -24,7 +24,7 @@ import javax.annotation.Nullable; public class PermissionTemplateGroupDto { private String uuid; - private Long templateId; + private String templateUuid; private Integer groupId; private String permission; private String groupName; @@ -40,12 +40,12 @@ public class PermissionTemplateGroupDto { return this; } - public Long getTemplateId() { - return templateId; + public String getTemplateUuid() { + return templateUuid; } - public PermissionTemplateGroupDto setTemplateId(Long templateId) { - this.templateId = templateId; + public PermissionTemplateGroupDto setTemplateUuid(String templateUuid) { + this.templateUuid = templateUuid; return this; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java index 6ade9607e32..d5c6383890d 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java @@ -36,13 +36,13 @@ public interface PermissionTemplateMapper { void update(PermissionTemplateDto permissionTemplate); - void deleteById(long templateId); + void deleteByUuid(String templateUuid); - void deleteByIds(@Param("templateIds") List templateIds); + void deleteByUuids(@Param("templateUuids") List templateUuids); - void deleteUserPermissionsByTemplateId(long templateId); + void deleteUserPermissionsByTemplateUuid(String templateUuid); - void deleteUserPermissionsByTemplateIds(@Param("templateIds") List templateIds); + void deleteUserPermissionsByTemplateUuids(@Param("templateUuids") List templateUuids); void deleteUserPermissionsByOrganization(@Param("organizationUuid") String organizationUuid, @Param("userId") int userId); @@ -50,17 +50,17 @@ public interface PermissionTemplateMapper { void deleteUserPermission(PermissionTemplateUserDto permissionTemplateUser); - void deleteGroupPermissionsByTemplateId(long templateId); + void deleteGroupPermissionsByTemplateUuid(String templateUuid); - void deleteGroupPermissionsByTemplateIds(@Param("templateIds") List templateIds); + void deleteGroupPermissionsByTemplateUuids(@Param("templateUuids") List templateUuids); void deleteGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup); PermissionTemplateDto selectByUuid(String templateUuid); - List selectUserPermissionsByTemplateIdAndUserLogins(@Param("templateId") long templateId, @Param("logins") List logins); + List selectUserPermissionsByTemplateUuidAndUserLogins(@Param("templateUuid") String templateUuid, @Param("logins") List logins); - List selectGroupPermissionsByTemplateIdAndGroupNames(@Param("templateId") long templateId, @Param("groups") List groups); + List selectGroupPermissionsByTemplateUuidAndGroupNames(@Param("templateUuid") String templateUuid, @Param("groups") List groups); void insertUserPermission(PermissionTemplateUserDto permissionTemplateUser); @@ -70,25 +70,25 @@ public interface PermissionTemplateMapper { PermissionTemplateDto selectByName(@Param("organizationUuid") String organizationUuid, @Param("name") String name); - List selectUserLoginsByQueryAndTemplate(@Param("query") PermissionQuery query, @Param("templateId") long templateId, RowBounds rowBounds); + List selectUserLoginsByQueryAndTemplate(@Param("query") PermissionQuery query, @Param("templateUuid") String templateUuid, RowBounds rowBounds); - int countUserLoginsByQueryAndTemplate(@Param("query") PermissionQuery query, @Param("templateId") long templateId); + int countUserLoginsByQueryAndTemplate(@Param("query") PermissionQuery query, @Param("templateUuid") String templateUuid); - List selectGroupNamesByQueryAndTemplate(@Param("templateId") long templateId, @Param("query") PermissionQuery query, RowBounds rowBounds); + List selectGroupNamesByQueryAndTemplate(@Param("templateUuid") String templateUuid, @Param("query") PermissionQuery query, RowBounds rowBounds); - int countGroupNamesByQueryAndTemplate(@Param("organizationUuid") String organizationUuid, @Param("query") PermissionQuery query, @Param("templateId") long templateId); + int countGroupNamesByQueryAndTemplate(@Param("organizationUuid") String organizationUuid, @Param("query") PermissionQuery query, @Param("templateUuid") String templateUuid); List selectAll(@Param("organizationUuid") String organizationUuid, @Nullable @Param("upperCaseNameLikeSql") String upperCaseNameLikeSql); - void usersCountByTemplateIdAndPermission(Map parameters, ResultHandler resultHandler); + void usersCountByTemplateUuidAndPermission(Map parameters, ResultHandler resultHandler); - void groupsCountByTemplateIdAndPermission(Map parameters, ResultHandler resultHandler); + void groupsCountByTemplateUuidAndPermission(Map parameters, ResultHandler resultHandler); - List selectPotentialPermissionsByUserIdAndTemplateId(@Param("userId") @Nullable Integer currentUserId, @Param("templateId") long templateId); + List selectPotentialPermissionsByUserIdAndTemplateUuid(@Param("userId") @Nullable Integer currentUserId, @Param("templateUuid") String templateUuid); - int countGroupsWithPermission(@Param("templateId") long templateId, @Param("permission") String permission, @Nullable @Param("groupId") Integer groupId); + int countGroupsWithPermission(@Param("templateUuid") String templateUuid, @Param("permission") String permission, @Nullable @Param("groupId") Integer groupId); - List selectTemplateIdsByOrganization(@Param("organizationUuid") String organizationUuid); + List selectTemplateUuidsByOrganization(@Param("organizationUuid") String organizationUuid); List selectAllGroupPermissionTemplatesByGroupId(@Param("groupId") Long groupId); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateUserDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateUserDto.java index 1980c0d6ea2..1dc469d693a 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateUserDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateUserDto.java @@ -23,7 +23,7 @@ import java.util.Date; public class PermissionTemplateUserDto { private String uuid; - private Long templateId; + private String templateUuid; private Integer userId; private String permission; private String userName; @@ -40,12 +40,12 @@ public class PermissionTemplateUserDto { return this; } - public Long getTemplateId() { - return templateId; + public String getTemplateUuid() { + return templateUuid; } - public PermissionTemplateUserDto setTemplateId(Long templateId) { - this.templateId = templateId; + public PermissionTemplateUserDto setTemplateUuid(String templateUuid) { + this.templateUuid = templateUuid; return this; } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateCharacteristicMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateCharacteristicMapper.xml index 74a4f86561b..0e9a0f6ce45 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateCharacteristicMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateCharacteristicMapper.xml @@ -3,7 +3,7 @@ ptc.uuid, - ptc.template_id as templateId, + ptc.template_uuid as templateUuid, ptc.permission_key as permission, ptc.with_project_creator as withProjectCreator, ptc.created_at as createdAt, @@ -17,30 +17,30 @@ where ptc.uuid=#{uuid,jdbcType=VARCHAR} - select from perm_tpl_characteristics ptc where - ptc.template_id in - - #{templateId} + ptc.template_uuid in + + #{templateUuid} order by ptc.created_at - select from perm_tpl_characteristics ptc - where ptc.template_id=#{templateId} + where ptc.template_uuid=#{templateUuid} and ptc.permission_key=#{permission} order by ptc.created_at - insert into perm_tpl_characteristics(uuid, template_id, permission_key, with_project_creator, created_at, updated_at) - values(#{uuid, jdbcType=VARCHAR}, #{templateId, jdbcType=BIGINT}, #{permission, jdbcType=VARCHAR}, + insert into perm_tpl_characteristics(uuid, template_uuid, permission_key, with_project_creator, created_at, updated_at) + values(#{uuid, jdbcType=VARCHAR}, #{templateUuid, jdbcType=VARCHAR}, #{permission, jdbcType=VARCHAR}, #{withProjectCreator, jdbcType=BOOLEAN}, #{createdAt, jdbcType=BIGINT}, #{updatedAt, jdbcType=BIGINT}) @@ -51,18 +51,18 @@ where uuid=#{uuid} - + DELETE FROM perm_tpl_characteristics - WHERE template_id = #{permissionTemplateId} + WHERE template_uuid = #{permissionTemplateId} - + delete from perm_tpl_characteristics where - template_id in - - #{templateId} + template_uuid in + + #{templateUuid} diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml index a2d84f79c21..6c3707b102a 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml @@ -3,12 +3,12 @@ - - INSERT INTO permission_templates (organization_uuid, name, kee, description, key_pattern, created_at, updated_at) + + INSERT INTO permission_templates (organization_uuid, name, uuid, description, key_pattern, created_at, updated_at) VALUES ( #{organizationUuid,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, - #{kee,jdbcType=VARCHAR}, + #{uuid,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{keyPattern,jdbcType=VARCHAR}, #{createdAt}, @@ -18,42 +18,42 @@ UPDATE permission_templates SET name = #{name}, description = #{description}, key_pattern = #{keyPattern}, updated_at = #{updatedAt} - WHERE id = #{id} + WHERE uuid = #{uuid} - + DELETE FROM permission_templates - WHERE id = #{templateId} + WHERE uuid = #{uuid} - + delete from permission_templates where - id in - #{templateId,jdbcType=BIGINT} + uuid in + #{uuid,jdbcType=BIGINT} - + delete from perm_templates_users where - template_id = #{templateId,jdbcType=BIGINT} + template_uuid = #{templateUuid,jdbcType=VARCHAR} - + delete from perm_templates_users where - template_id in - #{templateId,jdbcType=BIGINT} + template_uuid in + #{templateUuid,jdbcType=BIGINT} DELETE FROM perm_templates_users - WHERE template_id = #{templateId} + WHERE template_uuid = #{templateUuid} AND user_id = #{userId} AND permission_reference = #{permission} @@ -62,7 +62,7 @@ delete from perm_templates_users where user_id = #{userId,jdbcType=INTEGER} - and template_id in (select id from permission_templates where organization_uuid=#{organizationUuid,jdbcType=VARCHAR}) + and template_uuid in (select uuid from permission_templates where organization_uuid=#{organizationUuid,jdbcType=VARCHAR}) @@ -71,25 +71,25 @@ user_id = #{userId,jdbcType=INTEGER} - + delete from perm_templates_groups where - template_id = #{templateId,jdbcType=BIGINT} + template_uuid = #{templateUuid,jdbcType=VARCHAR} - + delete from perm_templates_groups where - template_id in - #{templateId,jdbcType=BIGINT} + template_uuid in + #{templateUuid,jdbcType=VARCHAR} DELETE FROM perm_templates_groups - WHERE template_id = #{templateId} + WHERE template_uuid = #{templateUuid} AND permission_reference = #{permission} AND @@ -103,15 +103,15 @@ - INSERT INTO perm_templates_users (uuid, template_id, user_id, permission_reference, created_at, updated_at) - VALUES (#{uuid}, #{templateId}, #{userId}, #{permission}, #{createdAt}, #{updatedAt}) + INSERT INTO perm_templates_users (uuid, template_uuid, user_id, permission_reference, created_at, updated_at) + VALUES (#{uuid}, #{templateUuid}, #{userId}, #{permission}, #{createdAt}, #{updatedAt}) - INSERT INTO perm_templates_groups (uuid, template_id, group_id, permission_reference, created_at, updated_at) + INSERT INTO perm_templates_groups (uuid, template_uuid, group_id, permission_reference, created_at, updated_at) VALUES ( #{uuid,jdbcType=VARCHAR}, - #{templateId,jdbcType=BIGINT}, + #{templateUuid,jdbcType=VARCHAR}, #{groupId,jdbcType=INTEGER}, #{permission,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP}, @@ -141,7 +141,7 @@ FROM users u LEFT JOIN perm_templates_users ptu ON ptu.user_id=u.id - AND ptu.template_id=#{templateId} + AND ptu.template_uuid=#{templateUuid} INNER JOIN organization_members om ON u.id=om.user_id AND om.organization_uuid=#{query.organizationUuid} @@ -178,11 +178,11 @@ g.id AS group_id, g.name AS name, ptg.permission_reference AS permission, - ptg.template_id AS templateId + ptg.template_uuid AS templateUuid FROM groups g LEFT JOIN perm_templates_groups ptg ON ptg.group_id=g.id - AND ptg.template_id=#{templateId} + AND ptg.template_uuid=#{templateUuid} where g.organization_uuid=#{query.organizationUuid,jdbcType=VARCHAR} UNION ALL @@ -190,10 +190,10 @@ 0 AS group_id, 'Anyone' AS name, ptg.permission_reference AS permission, - ptg.template_id AS templateId + ptg.template_uuid AS templateUuid FROM groups g LEFT JOIN perm_templates_groups ptg ON - ptg.template_id=#{templateId} + ptg.template_uuid=#{templateUuid} g.organization_uuid=#{query.organizationUuid,jdbcType=VARCHAR} @@ -207,7 +207,7 @@ AND groups.permission IS NOT NULL - AND groups.templateId=#{templateId} + AND groups.templateUuid=#{templateUuid} AND groups.permission=#{query.permission} @@ -216,14 +216,14 @@ - id, organization_uuid as organizationUuid, name, kee, description, key_pattern AS keyPattern, created_at AS createdAt, updated_at AS updatedAt + organization_uuid as organizationUuid, name, uuid, description, key_pattern AS keyPattern, created_at AS createdAt, updated_at AS updatedAt + - SELECT sub.uuid, - sub.templateId, + sub.templateUuid, sub.permission, sub.groupId, sub.groupName, @@ -285,7 +285,7 @@ FROM ( SELECT ptg.uuid, - ptg.template_id as templateId, + ptg.template_uuid as templateUuid, ptg.permission_reference AS permission, ptg.group_id AS groupId, g.name AS groupName, @@ -297,7 +297,7 @@ UNION ALL SELECT ptg.uuid, - ptg.template_id as templateId, + ptg.template_uuid as templateUuid, ptg.permission_reference AS permission, 0 AS groupId, 'Anyone' AS groupName, @@ -307,7 +307,7 @@ WHERE ptg.group_id IS NULL ) sub - sub.templateId=#{templateId} + sub.templateUuid=#{templateUuid} AND sub.groupName IN #{group} @@ -316,14 +316,14 @@ - -- from template users select ptu.permission_reference as permission_key from perm_templates_users ptu and ptu.user_id=#{userId} - and ptu.template_id=#{templateId} + and ptu.template_uuid=#{templateUuid} UNION -- from template groups except anyone group @@ -332,7 +332,7 @@ inner join groups_users gu on ptg.group_id = gu.group_id and gu.user_id=#{userId} - and ptg.template_id=#{templateId} + and ptg.template_uuid=#{templateUuid} UNION -- from template characteristics @@ -340,60 +340,60 @@ from perm_tpl_characteristics ptc and with_project_creator = ${_true} - and ptc.template_id = #{templateId} + and ptc.template_uuid = #{templateUuid} UNION -- from anyone group select ptg.permission_reference as permission_key from perm_templates_groups ptg - where ptg.template_id=#{templateId} + where ptg.template_uuid=#{templateUuid} and ptg.group_id IS NULL - - - select - id + uuid from permission_templates where @@ -416,7 +416,7 @@