From 522c74b001f7f6f610978d8076c6403d995cb784 Mon Sep 17 00:00:00 2001 From: Jacek Date: Mon, 21 Nov 2022 11:45:35 +0100 Subject: [PATCH] MMF-2745 Default permission improvements --- build.gradle | 2 +- .../db/permission/GroupPermissionDao.java | 8 + .../db/permission/GroupPermissionMapper.java | 4 + .../db/permission/GroupPermissionMapper.xml | 31 ++++ .../db/permission/GroupPermissionDaoTest.java | 59 +++++++ .../version/v00/PopulateInitialSchema.java | 4 +- .../db/migration/version/v98/DbVersion98.java | 1 + .../v98/UpsertSonarUsersDescription.java | 40 +++++ .../v00/PopulateInitialSchemaTest.java | 6 +- .../v98/UpsertSonarUsersDescriptionTest.java | 79 +++++++++ .../schema.sql | 9 ++ .../main/js/apps/groups/components/List.tsx | 1 + .../__snapshots__/List-test.tsx.snap | 5 + .../shared/components/GroupHolder.tsx | 10 +- .../db/CheckAnyonePermissionsAtStartup.java | 75 +++++++++ .../CheckAnyonePermissionsAtStartupTest.java | 152 ++++++++++++++++++ .../server/permission/ws/groups-example.json | 2 +- .../ws/template/template_groups-example.json | 2 +- .../ws/template/TemplateGroupsActionTest.java | 2 +- .../platformlevel/PlatformLevel4.java | 3 +- .../resources/org/sonar/l10n/core.properties | 2 +- 21 files changed, 485 insertions(+), 12 deletions(-) create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/UpsertSonarUsersDescription.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/UpsertSonarUsersDescriptionTest.java create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v98/UpsertSonarUsersDescriptionTest/schema.sql create mode 100644 server/sonar-webserver-core/src/main/java/org/sonar/server/platform/db/CheckAnyonePermissionsAtStartup.java create mode 100644 server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/CheckAnyonePermissionsAtStartupTest.java diff --git a/build.gradle b/build.gradle index 6313a872b1e..726da0b4fe6 100644 --- a/build.gradle +++ b/build.gradle @@ -340,7 +340,7 @@ subprojects { dependency 'org.postgresql:postgresql:42.5.0' dependency 'org.reflections:reflections:0.10.2' dependency 'org.simpleframework:simple:5.1.6' - dependency 'org.sonarsource.orchestrator:sonar-orchestrator:3.39.0.167' + dependency 'org.sonarsource.orchestrator:sonar-orchestrator:3.40.0.183' dependency 'org.sonarsource.update-center:sonar-update-center-common:1.29.0.1000' dependency('org.springframework:spring-context:5.3.23') { exclude 'commons-logging:commons-logging' diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java index c23b174baee..3de87b133e1 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java @@ -73,6 +73,14 @@ public class GroupPermissionDao implements Dao { return executeLargeInputs(groupUuids, groups -> mapper(dbSession).selectByGroupUuids(groups, projectUuid)); } + public List selectProjectKeysWithAnyonePermissions(DbSession dbSession, int max) { + return mapper(dbSession).selectProjectKeysWithAnyonePermissions(max); + } + + public int countProjectsWithAnyonePermissions(DbSession dbSession) { + return mapper(dbSession).countProjectsWithAnyonePermissions(); + } + /** * Select global and project permissions of a given group (Anyone group is NOT supported) * Each row returns a {@link GroupPermissionDto} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java index a97740da6af..bcb9705b655 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java @@ -37,6 +37,10 @@ public interface GroupPermissionMapper { void groupsCountByProjectUuidAndPermission(Map parameters, ResultHandler resultHandler); + List selectProjectKeysWithAnyonePermissions(int max); + + int countProjectsWithAnyonePermissions(); + void insert(GroupPermissionDto dto); int delete(@Param("permission") String permission, @Nullable @Param("groupUuid") String groupUuid, @Nullable @Param("rootComponentUuid") String rootComponentUuid); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml index 1ce169e2918..d062673b736 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml @@ -39,6 +39,37 @@ groups.componentUuid + + + + + + + + + +