diff options
author | Jean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com> | 2013-07-11 17:19:51 +0200 |
---|---|---|
committer | Jean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com> | 2013-07-11 17:19:51 +0200 |
commit | 4c20d02a36d8da972e2983e4c02372285c76b153 (patch) | |
tree | 15fd9b44a897c53ef3ec6a9c0bb19a0549c57bf9 /sonar-core/src/main | |
parent | d217475442c8b463724626325f27ff5bfe06fc14 (diff) | |
download | sonarqube-4c20d02a36d8da972e2983e4c02372285c76b153.tar.gz sonarqube-4c20d02a36d8da972e2983e4c02372285c76b153.zip |
SONAR-4453 Added tests to cover permission template application
Diffstat (limited to 'sonar-core/src/main')
3 files changed, 28 insertions, 24 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/permission/ComponentPermissionFacade.java b/sonar-core/src/main/java/org/sonar/core/permission/ComponentPermissionFacade.java index 177a5c69f5f..e1dcb52b8d8 100644 --- a/sonar-core/src/main/java/org/sonar/core/permission/ComponentPermissionFacade.java +++ b/sonar-core/src/main/java/org/sonar/core/permission/ComponentPermissionFacade.java @@ -135,6 +135,7 @@ public class ComponentPermissionFacade implements TaskComponent, ServerComponent public void applyPermissionTemplate(Long templateId, Long resourceId) { SqlSession session = myBatis.openSession(); try { + removeAllPermissions(resourceId, session); PermissionTemplateDto permissionTemplate = getPermissionTemplate(templateId); List<PermissionTemplateUserDto> usersPermissions = permissionTemplate.getUsersPermissions(); if(usersPermissions != null) { @@ -146,7 +147,8 @@ public class ComponentPermissionFacade implements TaskComponent, ServerComponent List<PermissionTemplateGroupDto> groupsPermissions = permissionTemplate.getGroupsPermissions(); if(groupsPermissions != null) { for (PermissionTemplateGroupDto groupPermission : groupsPermissions) { - addGroupPermission(resourceId, groupPermission.getGroupName(), groupPermission.getPermission(), session); + String groupName = groupPermission.getGroupName() == null ? DefaultGroups.ANYONE : groupPermission.getGroupName(); + addGroupPermission(resourceId, groupName, groupPermission.getPermission(), session); } } session.commit(); diff --git a/sonar-core/src/main/resources/org/sonar/core/user/PermissionTemplateMapper.xml b/sonar-core/src/main/resources/org/sonar/core/user/PermissionTemplateMapper.xml index de84f3485bd..4e9dc2d47f0 100644 --- a/sonar-core/src/main/resources/org/sonar/core/user/PermissionTemplateMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/user/PermissionTemplateMapper.xml @@ -38,6 +38,7 @@ DELETE FROM perm_templates_users WHERE template_id = #{templateId} AND user_id = #{userId} + AND permission_reference = #{permission} </delete> <insert id="insertGroupPermission" parameterType="PermissionTemplateGroup"> @@ -48,6 +49,7 @@ <delete id="deleteGroupPermission" parameterType="PermissionTemplateGroup"> DELETE FROM perm_templates_groups WHERE template_id = #{templateId} + AND permission_reference = #{permission} AND <choose> <when test="groupId != null"> diff --git a/sonar-core/src/main/resources/org/sonar/core/user/UserMapper.xml b/sonar-core/src/main/resources/org/sonar/core/user/UserMapper.xml index 3b5f9003cb6..4b3a0ad0599 100644 --- a/sonar-core/src/main/resources/org/sonar/core/user/UserMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/user/UserMapper.xml @@ -14,89 +14,89 @@ </sql> <select id="selectUserByLogin" parameterType="string" resultType="User"> - select + SELECT <include refid="userColumns"/> - from users u where u.login=#{id} and u.active=${_true} + FROM users u WHERE u.login=#{id} AND u.active=${_true} </select> <select id="selectUsersByLogins" parameterType="map" resultType="User"> - select + SELECT <include refid="userColumns"/> - from users u where u.login in + FROM users u WHERE u.login IN <foreach item="login" index="index" collection="logins" open="(" separator="," close=")"> #{login} </foreach> </select> <select id="selectUsers" parameterType="map" resultType="User"> - select + SELECT <include refid="userColumns"/> - from users u + FROM users u <where> <if test="logins != null and logins.size() > 0"> - u.login in + u.login IN <foreach item="login" index="index" collection="logins" open="(" separator="," close=")"> #{login} </foreach> </if> <if test="includeDeactivated==false"> - and u.active=${_true} + AND u.active=${_true} </if> <if test="searchText != null"> - and (u.login like #{searchTextSql} escape '/' or u.name like #{searchTextSql} escape '/') + AND (u.login LIKE #{searchTextSql} ESCAPE '/' OR u.name LIKE #{searchTextSql} ESCAPE '/') </if> </where> - order by u.name + ORDER BY u.name </select> <select id="selectGroupByName" parameterType="string" resultType="Group"> - select id, name, description, created_at AS "createdAt", updated_at AS "updatedAt" - from groups where name=#{id} + SELECT id, name, description, created_at AS "createdAt", updated_at AS "updatedAt" + FROM groups WHERE name=#{id} </select> <delete id="removeUserFromGroups" parameterType="long"> - delete from groups_users where user_id=#{id} + DELETE FROM groups_users WHERE user_id=#{id} </delete> <delete id="deleteUserRoles" parameterType="long"> - delete from user_roles where user_id=#{id} + DELETE FROM user_roles WHERE user_id=#{id} </delete> <delete id="deleteUserProperties" parameterType="long"> - delete from properties where user_id=#{id} + DELETE FROM properties WHERE user_id=#{id} </delete> <delete id="deleteUserDashboards" parameterType="long"> - delete from dashboards where user_id=#{id} + DELETE FROM dashboards WHERE user_id=#{id} </delete> <delete id="deleteUserActiveDashboards" parameterType="long"> - delete from active_dashboards where user_id=#{id} + DELETE FROM active_dashboards WHERE user_id=#{id} </delete> <delete id="" parameterType="long"> - delete from user_roles where user_id=#{id} + DELETE FROM user_roles WHERE user_id=#{id} </delete> <delete id="deleteUserMeasureFilters" parameterType="long"> - delete from measure_filters where user_id=#{id} + DELETE FROM measure_filters WHERE user_id=#{id} </delete> <delete id="deleteUserMeasureFilterFavourites" parameterType="long"> - delete from measure_filter_favourites where user_id=#{id} + DELETE FROM measure_filter_favourites WHERE user_id=#{id} </delete> <delete id="deleteUserIssueFilters" parameterType="String"> - delete from issue_filters where user_login=#{id} + DELETE FROM issue_filters WHERE user_login=#{id} </delete> <delete id="deleteUserIssueFilterFavourites" parameterType="String"> - delete from issue_filter_favourites where user_login=#{id} + DELETE FROM issue_filter_favourites WHERE user_login=#{id} </delete> <update id="deactivateUser" parameterType="long"> - update users set active=${_false} where id=#{id} + UPDATE users SET active=${_false} WHERE id=#{id} </update> </mapper> |