aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-07-18 10:47:51 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-07-18 10:58:34 +0200
commit0dff22bda049bcb3f5fa8cb0bcb5d9ea8a80fe8c (patch)
tree02f202cdaa5c6688df91a732cab2d7ef3ba7bd18 /sonar-db
parent5b33c8da54067095015d560539ec70a188eaef42 (diff)
downloadsonarqube-0dff22bda049bcb3f5fa8cb0bcb5d9ea8a80fe8c.tar.gz
sonarqube-0dff22bda049bcb3f5fa8cb0bcb5d9ea8a80fe8c.zip
SONAR-7839 Return Anyone group even if it has no permission
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml8
-rw-r--r--sonar-db/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java11
2 files changed, 15 insertions, 4 deletions
diff --git a/sonar-db/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml b/sonar-db/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml
index 93adf4031ef..29b2475dfb1 100644
--- a/sonar-db/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml
@@ -220,14 +220,13 @@
<sql id="groupNamesByQueryAndTemplate">
FROM
- (SELECT g.id AS group_id, g.name AS name, ptg.permission_reference AS permission
+ (SELECT g.id AS group_id, g.name AS name, ptg.permission_reference AS permission, ptg.template_id AS templateId
FROM groups g
- LEFT JOIN perm_templates_groups ptg ON ptg.group_id=g.id AND ptg.template_id=#{templateId}
+ LEFT JOIN perm_templates_groups ptg ON ptg.group_id=g.id
UNION ALL
- SELECT 0 AS group_id, 'Anyone' AS name, ptg.permission_reference AS permission
+ SELECT 0 AS group_id, 'Anyone' AS name, ptg.permission_reference AS permission, ptg.template_id AS templateId
FROM perm_templates_groups ptg
<where>
- AND ptg.template_id=#{templateId}
<if test="query.withPermissionOnly()">
AND ptg.group_id IS NULL
</if>
@@ -239,6 +238,7 @@
</if>
<if test="query.withPermissionOnly()">
AND groups.permission IS NOT NULL
+ AND groups.templateId=#{templateId}
<if test="query.permission != null">
AND groups.permission=#{query.permission}
</if>
diff --git a/sonar-db/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java
index ac11218540b..ebd98b73cc5 100644
--- a/sonar-db/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java
@@ -184,6 +184,17 @@ public class GroupWithPermissionTemplateDaoTest {
}
@Test
+ public void select_group_names_by_query_and_template_returns_anyone() {
+ PermissionTemplateDto template = permissionTemplateDbTester.insertTemplate();
+
+ GroupDto group = groupDb.insertGroup(newGroupDto().setName("Group"));
+ PermissionTemplateDto otherTemplate = permissionTemplateDbTester.insertTemplate();
+ permissionTemplateDbTester.addGroupToTemplate(otherTemplate.getId(), group.getId(), USER);
+
+ assertThat(selectGroupNamesByQueryAndTemplate(builder().setSearchQuery("nyo").build(), template.getId())).containsExactly("Anyone");
+ }
+
+ @Test
public void count_group_names_by_query_and_template() {
GroupDto group1 = groupDb.insertGroup(newGroupDto().setName("Group-1"));
GroupDto group2 = groupDb.insertGroup(newGroupDto().setName("Group-2"));