From: Julien Lancelot Date: Tue, 12 Feb 2019 10:59:29 +0000 (+0100) Subject: SONARCLOUD-381 Create api/organization/sync_members X-Git-Tag: 7.7~117 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2847ce4e648a167335d675a3ba6e71b7b1b0f248;p=sonarqube.git SONARCLOUD-381 Create api/organization/sync_members * Rename organisation to organization in some SonarCloud directories/classes * Add WS api/organizations/sync_members * Get list of members from a GitHub organization * sync_members fails when members sync is disabled --- diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java index ea20cd1a87b..6cc176675f0 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java @@ -41,7 +41,7 @@ import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_ public class AuthorizationDao implements Dao { /** - * Loads all the permissions granted to logged-in user for the specified organization + * Loads all the permissions granted to user for the specified organization */ public Set selectOrganizationPermissions(DbSession dbSession, String organizationUuid, int userId) { return mapper(dbSession).selectOrganizationPermissions(organizationUuid, userId); @@ -94,6 +94,14 @@ public class AuthorizationDao implements Dao { return mapper(dbSession).countUsersWithGlobalPermissionExcludingUser(organizationUuid, permission, excludedUserId); } + /** + * The list of users who have the global permission. + * The anyone virtual group is not taken into account. + */ + public List selectUserIdsWithGlobalPermission(DbSession dbSession, String organizationUuid, String permission) { + return mapper(dbSession).selectUserIdsWithGlobalPermission(organizationUuid, permission); + } + /** * The number of users who will still have the permission if the user {@code userId} * is removed from group {@code groupId}. The anyone virtual group is not taken into account. diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java index 31fba10b72f..454bef1daf3 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java @@ -39,6 +39,8 @@ public interface AuthorizationMapper { int countUsersWithGlobalPermissionExcludingUser(@Param("organizationUuid") String organizationUuid, @Param("permission") String permission, @Param("excludedUserId") int excludedUserId); + List selectUserIdsWithGlobalPermission(@Param("organizationUuid") String organizationUuid, @Param("permission") String permission); + int countUsersWithGlobalPermissionExcludingGroupMember(@Param("organizationUuid") String organizationUuid, @Param("permission") String permission, @Param("groupId") int groupId, @Param("userId") int userId); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java index b1650456e53..7fe0e24e73d 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java @@ -173,6 +173,10 @@ public class UserDao implements Dao { return mapper(dbSession).selectByExternalIdAndIdentityProvider(externalId, externalIdentityProvider); } + public List selectByExternalIdsAndIdentityProvider(DbSession dbSession, Collection externalIds, String externalIdentityProvider) { + return executeLargeInputs(externalIds, e -> mapper(dbSession).selectByExternalIdsAndIdentityProvider(e, externalIdentityProvider)); + } + @CheckForNull public UserDto selectByExternalLoginAndIdentityProvider(DbSession dbSession, String externalLogin, String externalIdentityProvider) { return mapper(dbSession).selectByExternalLoginAndIdentityProvider(externalLogin, externalIdentityProvider); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java index dde13c8a06f..8f1a77c7b86 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java @@ -62,6 +62,9 @@ public interface UserMapper { @CheckForNull UserDto selectByExternalIdAndIdentityProvider(@Param("externalId") String externalId, @Param("externalIdentityProvider") String externalExternalIdentityProvider); + List selectByExternalIdsAndIdentityProvider(@Param("externalIds") List externalIds, @Param("externalIdentityProvider") String externalExternalIdentityProvider); + + @CheckForNull UserDto selectByExternalLoginAndIdentityProvider(@Param("externalLogin") String externalLogin, @Param("externalIdentityProvider") String externalExternalIdentityProvider); void scrollAll(ResultHandler handler); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml index 45fb21902cb..c0dfcd373e9 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml @@ -8,16 +8,16 @@ from group_roles gr inner join groups_users gu on gr.group_id=gu.group_id where - gr.organization_uuid=#{organizationUuid,jdbcType=VARCHAR} and + gr.organization_uuid=#{organizationUuid, jdbcType=VARCHAR} and gr.resource_id is null and - gu.user_id=#{userId,jdbcType=INTEGER} + gu.user_id=#{userId, jdbcType=INTEGER} union select gr.role from group_roles gr where - gr.organization_uuid=#{organizationUuid,jdbcType=VARCHAR} and + gr.organization_uuid=#{organizationUuid, jdbcType=VARCHAR} and gr.group_id is null and gr.resource_id is null @@ -26,8 +26,8 @@ select ur.role from user_roles ur where - ur.organization_uuid=#{organizationUuid,jdbcType=VARCHAR} and - ur.user_id=#{userId,jdbcType=INTEGER} + ur.organization_uuid=#{organizationUuid, jdbcType=VARCHAR} and + ur.user_id=#{userId, jdbcType=INTEGER} and ur.resource_id is null @@ -35,7 +35,7 @@ select gr.role from group_roles gr where - gr.organization_uuid=#{organizationUuid,jdbcType=VARCHAR} and + gr.organization_uuid=#{organizationUuid, jdbcType=VARCHAR} and gr.resource_id is null and gr.group_id is null @@ -47,20 +47,20 @@ from groups_users gu inner join group_roles gr on gr.group_id = gu.group_id where - gr.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and - gr.role = #{permission,jdbcType=VARCHAR} and + gr.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and + gr.role = #{permission, jdbcType=VARCHAR} and gr.resource_id is null and gr.group_id is not null and - gr.group_id != #{excludedGroupId,jdbcType=INTEGER} + gr.group_id != #{excludedGroupId, jdbcType=INTEGER} union select ur.user_id from user_roles ur where - ur.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and + ur.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and ur.resource_id is null and - ur.role = #{permission,jdbcType=VARCHAR} + ur.role = #{permission, jdbcType=VARCHAR} ) remaining @@ -71,24 +71,44 @@ from groups_users gu inner join group_roles gr on gr.group_id = gu.group_id where - gr.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and - gr.role = #{permission,jdbcType=VARCHAR} and + gr.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and + gr.role = #{permission, jdbcType=VARCHAR} and gr.resource_id is null and gr.group_id is not null and - gu.user_id != #{excludedUserId,jdbcType=INTEGER} + gu.user_id != #{excludedUserId, jdbcType=INTEGER} union select ur.user_id from user_roles ur where - ur.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and + ur.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and ur.resource_id is null and - ur.role = #{permission,jdbcType=VARCHAR} and - ur.user_id != #{excludedUserId,jdbcType=INTEGER} + ur.role = #{permission, jdbcType=VARCHAR} and + ur.user_id != #{excludedUserId, jdbcType=INTEGER} ) remaining + + @@ -120,8 +140,8 @@ from groups_users gu inner join group_roles gr on gr.group_id = gu.group_id where - gr.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and - gr.role = #{permission,jdbcType=VARCHAR} and + gr.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and + gr.role = #{permission, jdbcType=VARCHAR} and gr.resource_id is null and gr.group_id is not null @@ -130,10 +150,10 @@ select ur.user_id from user_roles ur where - ur.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and + ur.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} and ur.resource_id is null and - ur.role = #{permission,jdbcType=VARCHAR} and - ur.user_id != #{userId,jdbcType=INTEGER} + ur.role = #{permission, jdbcType=VARCHAR} and + ur.user_id != #{userId, jdbcType=INTEGER} ) remaining @@ -142,10 +162,10 @@ from group_roles gr inner join groups_users gu on gr.group_id = gu.group_id where - gr.role = #{permission,jdbcType=VARCHAR} and + gr.role = #{permission, jdbcType=VARCHAR} and gr.resource_id is null and gr.group_id is not null and - gu.user_id = #{userId,jdbcType=INTEGER} + gu.user_id = #{userId, jdbcType=INTEGER} union @@ -153,8 +173,8 @@ from user_roles ur where ur.resource_id is null and - ur.role = #{permission,jdbcType=VARCHAR} and - ur.user_id = #{userId,jdbcType=INTEGER} + ur.role = #{permission, jdbcType=VARCHAR} and + ur.user_id = #{userId, jdbcType=INTEGER} @@ -235,14 +255,14 @@ from projects p inner join group_roles gr on p.id = gr.resource_id where - gr.role = #{permission,jdbcType=VARCHAR} + gr.role = #{permission, jdbcType=VARCHAR} and (gr.group_id is null or exists ( select 1 from groups_users gu where gu.user_id = #{userId, jdbcType=INTEGER} and gr.group_id = gu.group_id) ) - and p.uuid in #{projectUuid,jdbcType=VARCHAR} + and p.uuid in #{projectUuid, jdbcType=VARCHAR} union @@ -250,9 +270,9 @@ from projects p inner join user_roles ur on p.id = ur.resource_id where - ur.role=#{permission,jdbcType=VARCHAR} - and ur.user_id=#{userId,jdbcType=INTEGER} - and p.uuid in #{projectUuid,jdbcType=VARCHAR} + ur.role=#{permission, jdbcType=VARCHAR} + and ur.user_id=#{userId, jdbcType=INTEGER} + and p.uuid in #{projectUuid, jdbcType=VARCHAR} union @@ -260,7 +280,7 @@ select p.uuid from projects p where - p.uuid in #{projectUuid,jdbcType=VARCHAR} + p.uuid in #{projectUuid, jdbcType=VARCHAR} and p.private = ${_false} @@ -270,9 +290,9 @@ from projects p inner join group_roles gr on p.id = gr.resource_id where - gr.role=#{permission,jdbcType=VARCHAR} + gr.role=#{permission, jdbcType=VARCHAR} and gr.group_id is null - and p.uuid in #{projectUuid,jdbcType=VARCHAR} + and p.uuid in #{projectUuid, jdbcType=VARCHAR} union @@ -280,7 +300,7 @@ select p.uuid from projects p where - p.uuid in #{projectUuid,jdbcType=VARCHAR} + p.uuid in #{projectUuid, jdbcType=VARCHAR} and p.private = ${_false} @@ -293,11 +313,11 @@ inner join group_roles gr on gr.group_id=gu.group_id where - gr.resource_id=#{componentId,jdbcType=BIGINT} - and gr.role=#{role,jdbcType=VARCHAR} + gr.resource_id=#{componentId, jdbcType=BIGINT} + and gr.role=#{role, jdbcType=VARCHAR} and gu.user_id in - #{id,jdbcType=BIGINT} + #{id, jdbcType=BIGINT} union @@ -307,11 +327,11 @@ from user_roles ur where - ur.resource_id=#{componentId,jdbcType=BIGINT} - and ur.role=#{role,jdbcType=VARCHAR} + ur.resource_id=#{componentId, jdbcType=BIGINT} + and ur.role=#{role, jdbcType=VARCHAR} and ur.user_id IN - #{id,jdbcType=BIGINT} + #{id, jdbcType=BIGINT} union @@ -323,7 +343,7 @@ where u.id in - #{id,jdbcType=BIGINT} + #{id, jdbcType=BIGINT} and exists ( select @@ -331,9 +351,9 @@ from projects p where - p.id =#{componentId,jdbcType=BIGINT} + p.id =#{componentId, jdbcType=BIGINT} and p.private = ${_false} - and #{role,jdbcType=VARCHAR} in ('user','codeviewer') + and #{role, jdbcType=VARCHAR} in ('user','codeviewer') ) @@ -342,9 +362,9 @@ from user_roles ur inner join projects p on p.id = ur.resource_id where - p.uuid = #{projectUuid,jdbcType=VARCHAR} and + p.uuid = #{projectUuid, jdbcType=VARCHAR} and p.organization_uuid = ur.organization_uuid and - ur.user_id = #{userId,jdbcType=BIGINT} + ur.user_id = #{userId, jdbcType=BIGINT} union @@ -353,9 +373,9 @@ inner join groups_users gu on gr.group_id = gu.group_id inner join projects p on p.id = gr.resource_id where - p.uuid = #{projectUuid,jdbcType=VARCHAR} and + p.uuid = #{projectUuid, jdbcType=VARCHAR} and p.organization_uuid = gr.organization_uuid and - gu.user_id = #{userId,jdbcType=BIGINT} + gu.user_id = #{userId, jdbcType=BIGINT} union @@ -374,7 +394,7 @@ inner join projects p on p.id = gr.resource_id where - p.uuid = #{projectUuid,jdbcType=VARCHAR} + p.uuid = #{projectUuid, jdbcType=VARCHAR} and p.organization_uuid = gr.organization_uuid and gr.group_id is null @@ -384,7 +404,7 @@ from user_roles ur inner join users u on u.id=ur.user_id where - ur.role=#{permission,jdbcType=VARCHAR} + ur.role=#{permission, jdbcType=VARCHAR} and ur.resource_id is null union @@ -394,7 +414,7 @@ inner join groups_users gu on gr.group_id = gu.group_id inner join users u on u.id=gu.user_id where - gr.role = #{permission,jdbcType=VARCHAR} and + gr.role = #{permission, jdbcType=VARCHAR} and gr.resource_id is null and gr.group_id is not null @@ -403,15 +423,15 @@ select u.login from users u where - u.login in #{login,jdbcType=VARCHAR} + u.login in #{login, jdbcType=VARCHAR} and ( exists ( select 1 from user_roles ur inner join projects p on p.id = ur.resource_id and p.organization_uuid = ur.organization_uuid where - p.kee = #{projectKey,jdbcType=VARCHAR} - and ur.role = #{permission,jdbcType=VARCHAR} + p.kee = #{projectKey, jdbcType=VARCHAR} + and ur.role = #{permission, jdbcType=VARCHAR} and ur.user_id = u.id ) or exists ( select 1 @@ -419,16 +439,16 @@ inner join group_roles gr on gr.resource_id = p.id and gr.organization_uuid = p.organization_uuid inner join groups_users gu on gu.group_id = gr.group_id where - p.kee = #{projectKey,jdbcType=VARCHAR} + p.kee = #{projectKey, jdbcType=VARCHAR} and gu.user_id = u.id - and gr.role = #{permission,jdbcType=VARCHAR} + and gr.role = #{permission, jdbcType=VARCHAR} ) or exists ( select 1 from projects p where - p.kee = #{projectKey,jdbcType=VARCHAR} + p.kee = #{projectKey, jdbcType=VARCHAR} and p.private = ${_false} ) diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml index 1a08f28b2bb..bf0ee3a5d81 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml @@ -32,14 +32,14 @@ SELECT FROM users u - WHERE u.uuid=#{uuid} + WHERE u.uuid=#{uuid, jdbcType=VARCHAR} @@ -82,7 +82,7 @@ FROM users u WHERE u.uuid in - #{uuid} + #{uuid, jdbcType=VARCHAR} @@ -98,7 +98,7 @@ FROM users u WHERE u.id in - #{id} + #{id, jdbcType=INTEGER} @@ -110,14 +110,14 @@ u.login IN - #{login} + #{login, jdbcType=VARCHAR} AND u.active=${_true} - AND (u.login LIKE #{searchTextSql} ESCAPE '/' OR u.name LIKE #{searchTextSql} ESCAPE '/') + AND (u.login LIKE #{searchTextSql, jdbcType=VARCHAR} ESCAPE '/' OR u.name LIKE #{searchTextSql, jdbcType=VARCHAR} ESCAPE '/') AND u.is_root = ${_true} @@ -141,14 +141,25 @@ SELECT FROM users u - WHERE u.external_id=#{externalId} AND u.external_identity_provider=#{externalIdentityProvider, jdbcType=VARCHAR} + WHERE u.external_id=#{externalId, jdbcType=VARCHAR} AND u.external_identity_provider=#{externalIdentityProvider, jdbcType=VARCHAR} + + +