diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-08-26 11:26:50 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-08-26 11:26:58 +0200 |
commit | 08c2e6fd7e8a0d48b308ad13e1055dc82760617c (patch) | |
tree | 96f1f1cdeebde77d421aacaaf432e3e288f48685 /sonar-core | |
parent | 223299c1192266db9c4813faa37b5d10fba6f65f (diff) | |
download | sonarqube-08c2e6fd7e8a0d48b308ad13e1055dc82760617c.tar.gz sonarqube-08c2e6fd7e8a0d48b308ad13e1055dc82760617c.zip |
SONAR-4963 Return description in /permissions/search_groups
Diffstat (limited to 'sonar-core')
7 files changed, 42 insertions, 9 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/permission/GroupWithPermission.java b/sonar-core/src/main/java/org/sonar/core/permission/GroupWithPermission.java index d151084e4da..4ab0791a07a 100644 --- a/sonar-core/src/main/java/org/sonar/core/permission/GroupWithPermission.java +++ b/sonar-core/src/main/java/org/sonar/core/permission/GroupWithPermission.java @@ -23,9 +23,13 @@ package org.sonar.core.permission; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + public class GroupWithPermission { private String name; + private String description; private boolean hasPermission; public String name() { @@ -37,6 +41,16 @@ public class GroupWithPermission { return this; } + @CheckForNull + public String description() { + return description; + } + + public GroupWithPermission setDescription(@Nullable String description) { + this.description = description; + return this; + } + public boolean hasPermission() { return hasPermission; } diff --git a/sonar-core/src/main/java/org/sonar/core/permission/GroupWithPermissionDto.java b/sonar-core/src/main/java/org/sonar/core/permission/GroupWithPermissionDto.java index 2fba2f9301e..78d42099897 100644 --- a/sonar-core/src/main/java/org/sonar/core/permission/GroupWithPermissionDto.java +++ b/sonar-core/src/main/java/org/sonar/core/permission/GroupWithPermissionDto.java @@ -27,6 +27,7 @@ public class GroupWithPermissionDto { private String name; private String permission; + private String description; public String getName() { return name; @@ -47,9 +48,20 @@ public class GroupWithPermissionDto { return this; } + @CheckForNull + public String getDescription() { + return description; + } + + public GroupWithPermissionDto setDescription(@Nullable String description) { + this.description = description; + return this; + } + public GroupWithPermission toGroupWithPermission() { return new GroupWithPermission() .setName(name) + .setDescription(description) .hasPermission(permission != null); } } diff --git a/sonar-core/src/main/resources/org/sonar/core/permission/PermissionMapper.xml b/sonar-core/src/main/resources/org/sonar/core/permission/PermissionMapper.xml index 4b95b2be527..b3957662fa9 100644 --- a/sonar-core/src/main/resources/org/sonar/core/permission/PermissionMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/permission/PermissionMapper.xml @@ -31,8 +31,8 @@ </select> <select id="selectGroups" parameterType="map" resultType="GroupWithPermission"> - SELECT name, permission FROM - (SELECT g.name as name, group_role.role as permission + SELECT name, description, permission FROM + (SELECT g.name as name, g.description as description, group_role.role as permission FROM groups g LEFT JOIN group_roles group_role ON group_role.group_id=g.id AND group_role.role=#{query.permission} @@ -44,7 +44,7 @@ </if> UNION -- Add Anyone group permission - SELECT #{anyoneGroup} as name, group_role.role as permission + SELECT #{anyoneGroup} as name, NULL as description, group_role.role as permission FROM group_roles group_role <where> AND group_role.role=#{query.permission} diff --git a/sonar-core/src/test/java/org/sonar/core/permission/GroupWithPermissionDaoTest.java b/sonar-core/src/test/java/org/sonar/core/permission/GroupWithPermissionDaoTest.java index b1e8c3a34d0..18b495e3e0a 100644 --- a/sonar-core/src/test/java/org/sonar/core/permission/GroupWithPermissionDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/permission/GroupWithPermissionDaoTest.java @@ -49,18 +49,22 @@ public class GroupWithPermissionDaoTest extends AbstractDaoTestCase { GroupWithPermissionDto anyone = result.get(0); assertThat(anyone.getName()).isEqualTo("Anyone"); + assertThat(anyone.getDescription()).isNull(); assertThat(anyone.getPermission()).isNotNull(); GroupWithPermissionDto group1 = result.get(1); assertThat(group1.getName()).isEqualTo("sonar-administrators"); + assertThat(group1.getDescription()).isEqualTo("System administrators"); assertThat(group1.getPermission()).isNotNull(); GroupWithPermissionDto group2 = result.get(2); assertThat(group2.getName()).isEqualTo("sonar-reviewers"); + assertThat(group2.getDescription()).isEqualTo("Reviewers"); assertThat(group2.getPermission()).isNull(); GroupWithPermissionDto group3 = result.get(3); assertThat(group3.getName()).isEqualTo("sonar-users"); + assertThat(group3.getDescription()).isEqualTo("Any new users created will automatically join this group"); assertThat(group3.getPermission()).isNotNull(); } diff --git a/sonar-core/src/test/java/org/sonar/core/permission/GroupWithPermissionDtoTest.java b/sonar-core/src/test/java/org/sonar/core/permission/GroupWithPermissionDtoTest.java index a86a99d79bb..b04c08b794b 100644 --- a/sonar-core/src/test/java/org/sonar/core/permission/GroupWithPermissionDtoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/permission/GroupWithPermissionDtoTest.java @@ -30,10 +30,12 @@ public class GroupWithPermissionDtoTest { public void to_group_with_permission_having_permission() throws Exception { GroupWithPermission group = new GroupWithPermissionDto() .setName("users") + .setDescription("desc") .setPermission("user") .toGroupWithPermission(); assertThat(group.name()).isEqualTo("users"); + assertThat(group.description()).isEqualTo("desc"); assertThat(group.hasPermission()).isTrue(); } @@ -45,6 +47,7 @@ public class GroupWithPermissionDtoTest { .toGroupWithPermission(); assertThat(group.name()).isEqualTo("users"); + assertThat(group.description()).isNull(); assertThat(group.hasPermission()).isFalse(); } } diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/GroupWithPermissionDaoTest/groups_with_permissions.xml b/sonar-core/src/test/resources/org/sonar/core/permission/GroupWithPermissionDaoTest/groups_with_permissions.xml index 820e566dbdf..418d5e69fac 100644 --- a/sonar-core/src/test/resources/org/sonar/core/permission/GroupWithPermissionDaoTest/groups_with_permissions.xml +++ b/sonar-core/src/test/resources/org/sonar/core/permission/GroupWithPermissionDaoTest/groups_with_permissions.xml @@ -1,8 +1,8 @@ <dataset> - <groups id="200" name="sonar-administrators"/> - <groups id="201" name="sonar-users" /> - <groups id="202" name="sonar-reviewers" /> + <groups id="200" name="sonar-administrators" description="System administrators"/> + <groups id="201" name="sonar-users" description="Any new users created will automatically join this group"/> + <groups id="202" name="sonar-reviewers" description="Reviewers"/> <!-- Project permissions --> <group_roles id="1" group_id="200" resource_id="100" role="user"/> diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/GroupWithPermissionDaoTest/groups_with_permissions_should_be_sorted_by_group_name.xml b/sonar-core/src/test/resources/org/sonar/core/permission/GroupWithPermissionDaoTest/groups_with_permissions_should_be_sorted_by_group_name.xml index ba9d9acf297..10ab0e21e3f 100644 --- a/sonar-core/src/test/resources/org/sonar/core/permission/GroupWithPermissionDaoTest/groups_with_permissions_should_be_sorted_by_group_name.xml +++ b/sonar-core/src/test/resources/org/sonar/core/permission/GroupWithPermissionDaoTest/groups_with_permissions_should_be_sorted_by_group_name.xml @@ -1,8 +1,8 @@ <dataset> - <groups id="200" name="sonar-reviewers" /> - <groups id="201" name="sonar-users" /> - <groups id="202" name="sonar-administrators"/> + <groups id="200" name="sonar-reviewers" description="Reviewers"/> + <groups id="201" name="sonar-users" description="Any new users created will automatically join this group"/> + <groups id="202" name="sonar-administrators" description="System administrators"/> <!-- Project permissions --> <group_roles id="1" group_id="200" resource_id="100" role="user"/> |