]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8134 refactor SQL to check organization permission
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 14 Oct 2016 12:09:12 +0000 (14:09 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Sun, 16 Oct 2016 17:10:47 +0000 (19:10 +0200)
sonar-db/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml

index 0dbb5162cbfa0a5b3007cb457bbe97eef167e2b6..d819a2b2294216de2e017a66831c639910eda095 100644 (file)
@@ -6,11 +6,23 @@
   <select id="selectOrganizationPermissions" parameterType="map" resultType="string">
     select gr.role
     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.resource_id is null and
-    (gr.group_id is null or gr.group_id in (select gu.group_id from groups_users gu where gu.user_id=#{userId,jdbcType=BIGINT}))
+    gu.user_id=#{userId,jdbcType=BIGINT}
+
     union
+
+    select gr.role
+    from group_roles gr
+    where
+    gr.organization_uuid=#{organizationUuid,jdbcType=VARCHAR} and
+    gr.group_id is null and
+    gr.resource_id is null
+
+    union
+
     select ur.role
     from user_roles ur
     where
   <select id="selectRootComponentPermissions" parameterType="map" resultType="string">
     select gr.role
     from group_roles gr
+    inner join groups_users gu on gr.group_id=gu.group_id
     where
     gr.resource_id=#{rootComponentId,jdbcType=BIGINT} and
-    (gr.group_id is null or gr.group_id in (select gu.group_id from groups_users gu where gu.user_id=#{userId,jdbcType=BIGINT}))
+    gu.user_id=#{userId,jdbcType=BIGINT}
+
     union
+    select gr.role
+    from group_roles gr
+    where
+    gr.resource_id=#{rootComponentId,jdbcType=BIGINT} and
+    gr.group_id is null
+
+    union
+
     select ur.role
     from user_roles ur
     where