diff options
author | Jean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com> | 2013-07-04 17:47:28 +0200 |
---|---|---|
committer | Jean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com> | 2013-07-04 17:47:28 +0200 |
commit | a60604f5d250121fd594bb3d331a0f85fe889797 (patch) | |
tree | 61ed42fb477838861aa585032d7aa9655050efea /sonar-core | |
parent | c9cc6ba15aa9baaedb451ac3edab5a8dde9dec46 (diff) | |
download | sonarqube-a60604f5d250121fd594bb3d331a0f85fe889797.tar.gz sonarqube-a60604f5d250121fd594bb3d331a0f85fe889797.zip |
SONAR-4463 Renamed permission column and added DAO methods
Diffstat (limited to 'sonar-core')
18 files changed, 122 insertions, 25 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/user/Permission.java b/sonar-core/src/main/java/org/sonar/core/user/Permission.java index be5fb50a755..98bb97723a8 100644 --- a/sonar-core/src/main/java/org/sonar/core/user/Permission.java +++ b/sonar-core/src/main/java/org/sonar/core/user/Permission.java @@ -61,4 +61,7 @@ public class Permission { return allGlobal; } + public static boolean isValid(String permission) { + return allGlobal.containsKey(permission); + } } diff --git a/sonar-core/src/main/java/org/sonar/core/user/PermissionDao.java b/sonar-core/src/main/java/org/sonar/core/user/PermissionDao.java index 2e70595ec14..8e9bbf5d2de 100644 --- a/sonar-core/src/main/java/org/sonar/core/user/PermissionDao.java +++ b/sonar-core/src/main/java/org/sonar/core/user/PermissionDao.java @@ -37,6 +37,16 @@ public class PermissionDao implements TaskExtension, ServerExtension { this.myBatis = myBatis; } + public PermissionTemplateDto selectTemplateByName(String templateName) { + SqlSession session = myBatis.openSession(); + try { + PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); + return mapper.selectByName(templateName); + } finally { + MyBatis.closeQuietly(session); + } + } + public PermissionTemplateDto selectPermissionTemplate(String templateName) { PermissionTemplateDto permissionTemplate = null; SqlSession session = myBatis.openSession(); @@ -78,6 +88,19 @@ public class PermissionDao implements TaskExtension, ServerExtension { return permissionTemplate; } + public void deletePermissionTemplate(Long templateId) { + SqlSession session = myBatis.openSession(); + try { + PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); + mapper.deleteUsersPermissions(templateId); + mapper.deleteGroupsPermissions(templateId); + mapper.delete(templateId); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } + public void addUserPermission(Long templateId, Long userId, String permission) { PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto() .setTemplateId(templateId) diff --git a/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateMapper.java b/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateMapper.java index cc0f392e5d2..f3f3f85f884 100644 --- a/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateMapper.java @@ -27,6 +27,14 @@ public interface PermissionTemplateMapper { void insert(PermissionTemplateDto permissionTemplate); + void delete(Long templateId); + + void deleteUsersPermissions(Long templateId); + + void deleteGroupsPermissions(Long templateId); + + PermissionTemplateDto selectByName(String templateName); + PermissionTemplateDto selectTemplateUsersPermissions(String templateName); PermissionTemplateDto selectTemplateGroupsPermissions(String templateName); diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index 6bf00be3dbb..958224d5b56 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -544,7 +544,7 @@ CREATE TABLE "PERM_TEMPLATES_USERS" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "USER_ID" INTEGER NOT NULL, "TEMPLATE_ID" INTEGER NOT NULL, - "PERMISSION" VARCHAR(64) NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, "CREATED_AT" TIMESTAMP, "UPDATED_AT" TIMESTAMP ); @@ -553,7 +553,7 @@ CREATE TABLE "PERM_TEMPLATES_GROUPS" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "GROUP_ID" INTEGER, "TEMPLATE_ID" INTEGER NOT NULL, - "PERMISSION" VARCHAR(64) NOT NULL, + "PERMISSION_REFERENCE" VARCHAR(64) NOT NULL, "CREATED_AT" TIMESTAMP, "UPDATED_AT" TIMESTAMP ); 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 ee260ea609b..e01b01f683c 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 @@ -8,8 +8,23 @@ VALUES (#{name}, #{description}, #{createdAt}, #{updatedAt}) </insert> + <delete id="delete" parameterType="Long"> + DELETE FROM permission_templates + WHERE id = #{templateId} + </delete> + + <delete id="deleteUsersPermissions" parameterType="Long"> + DELETE FROM perm_templates_users + WHERE template_id = #{templateId} + </delete> + + <delete id="deleteGroupsPermissions" parameterType="Long"> + DELETE FROM perm_templates_groups + WHERE template_id = #{templateId} + </delete> + <insert id="insertUserPermission" parameterType="PermissionTemplateUser"> - INSERT INTO perm_templates_users (template_id, user_id, permission, created_at, updated_at) + INSERT INTO perm_templates_users (template_id, user_id, permission_reference, created_at, updated_at) VALUES (#{templateId}, #{userId}, #{permission}, #{createdAt}, #{updatedAt}) </insert> @@ -20,7 +35,7 @@ </delete> <insert id="insertGroupPermission" parameterType="PermissionTemplateGroup"> - INSERT INTO perm_templates_groups (template_id, group_id, permission, created_at, updated_at) + INSERT INTO perm_templates_groups (template_id, group_id, permission_reference, created_at, updated_at) VALUES (#{templateId}, #{groupId}, #{permission}, #{createdAt}, #{updatedAt}) </insert> @@ -38,6 +53,12 @@ </choose> </delete> + <select id="selectByName" parameterType="String" resultType="PermissionTemplate"> + SELECT id, name, description, created_at AS createdAt, updated_at AS updatedAt + FROM permission_templates + WHERE name = #{templateName} + </select> + <select id="selectAllPermissionTemplates" resultType="PermissionTemplate"> SELECT id, name, description, created_at AS createdAt, updated_at AS updatedAt FROM permission_templates @@ -50,7 +71,7 @@ pt.created_at AS template_created_at, pt.updated_at AS template_updated_at, ptu.id AS permission_template_user_id, - ptu.permission AS user_permission, + ptu.permission_reference AS user_permission, u.name AS user_name FROM permission_templates AS pt INNER JOIN perm_templates_users AS ptu ON ptu.template_id = pt.id @@ -65,7 +86,7 @@ pt.created_at AS template_created_at, pt.updated_at AS template_updated_at, ptg.id AS permission_template_group_id, - ptg.permission AS group_permission, + ptg.permission_reference AS group_permission, g.name AS group_name FROM permission_templates AS pt INNER JOIN perm_templates_groups AS ptg ON ptg.template_id = pt.id @@ -74,7 +95,7 @@ </select> <resultMap id="fullPermissionsTemplateResult" type="PermissionTemplate"> - <id property="id" column="template_id" /> + <id property="id" column="template_id"/> <result property="name" column="template_name"/> <result property="description" column="template_description"/> <result property="createdAt" column="template_created_at"/> diff --git a/sonar-core/src/test/java/org/sonar/core/user/PermissionDaoTest.java b/sonar-core/src/test/java/org/sonar/core/user/PermissionDaoTest.java index 205c9365cfb..01e0c6e4d4c 100644 --- a/sonar-core/src/test/java/org/sonar/core/user/PermissionDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/user/PermissionDaoTest.java @@ -63,6 +63,18 @@ public class PermissionDaoTest extends AbstractDaoTestCase { } @Test + public void should_permission_template_by_name() throws Exception { + setupData("selectPermissionTemplate"); + + PermissionTemplateDto permissionTemplate = permissionDao.selectTemplateByName("my template"); + + assertThat(permissionTemplate).isNotNull(); + assertThat(permissionTemplate.getId()).isEqualTo(1L); + assertThat(permissionTemplate.getName()).isEqualTo("my template"); + assertThat(permissionTemplate.getDescription()).isEqualTo("my description"); + } + + @Test public void should_select_all_permission_templates() throws Exception { setupData("selectAllPermissionTemplates"); @@ -75,6 +87,17 @@ public class PermissionDaoTest extends AbstractDaoTestCase { } @Test + public void should_delete_permission_template() throws Exception { + setupData("deletePermissionTemplate"); + + permissionDao.deletePermissionTemplate(1L); + + checkTable("deletePermissionTemplate", "permission_templates", "id", "name", "description"); + checkTable("deletePermissionTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission"); + checkTable("deletePermissionTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission"); + } + + @Test public void should_add_user_permission_to_template() throws Exception { setupData("addUserPermissionToTemplate"); permissionDao.addUserPermission(1L, 1L, "new_permission"); diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addGroupPermissionToTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addGroupPermissionToTemplate-result.xml index b7b0225d345..ae1db0b574e 100644 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addGroupPermissionToTemplate-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addGroupPermissionToTemplate-result.xml @@ -1,5 +1,5 @@ <dataset> <permission_templates id="1" name="my template" description="my description"/> <perm_templates_users/> - <perm_templates_groups id="1" template_id="1" group_id="1" permission="new_permission"/> + <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="new_permission"/> </dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addNullGroupPermissionToTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addNullGroupPermissionToTemplate-result.xml index fda5cefa69b..4fe3b439832 100644 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addNullGroupPermissionToTemplate-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addNullGroupPermissionToTemplate-result.xml @@ -1,5 +1,5 @@ <dataset> <permission_templates id="1" name="my template" description="my description"/> <perm_templates_users/> - <perm_templates_groups id="1" template_id="1" group_id="[null]" permission="new_permission"/> + <perm_templates_groups id="1" template_id="1" group_id="[null]" permission_reference="new_permission"/> </dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addUserPermissionToTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addUserPermissionToTemplate-result.xml index 3f243536113..8676d568d5e 100644 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addUserPermissionToTemplate-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addUserPermissionToTemplate-result.xml @@ -1,5 +1,5 @@ <dataset> <permission_templates id="1" name="my template" description="my description"/> - <perm_templates_users id="1" template_id="1" user_id="1" permission="new_permission"/> + <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="new_permission"/> <perm_templates_groups/> </dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/deletePermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/deletePermissionTemplate-result.xml new file mode 100644 index 00000000000..df9b962986d --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/deletePermissionTemplate-result.xml @@ -0,0 +1,7 @@ +<dataset> + <permission_templates id="2" name="other template" description="other description" created_at="[null]" updated_at="[null]"/> + + <perm_templates_users/> + + <perm_templates_groups/> +</dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/deletePermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/deletePermissionTemplate.xml new file mode 100644 index 00000000000..61c40436844 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/deletePermissionTemplate.xml @@ -0,0 +1,12 @@ +<dataset> + <permission_templates id="1" name="my template" description="my description" created_at="[null]" updated_at="[null]"/> + <permission_templates id="2" name="other template" description="other description" created_at="[null]" updated_at="[null]"/> + + <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="user_permission1"/> + <perm_templates_users id="2" template_id="1" user_id="2" permission_reference="user_permission1"/> + <perm_templates_users id="3" template_id="1" user_id="2" permission_reference="user_permission2"/> + + <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="group_permission1"/> + <perm_templates_groups id="2" template_id="1" group_id="2" permission_reference="group_permission1"/> + <perm_templates_groups id="3" template_id="1" group_id="[null]" permission_reference="group_permission2"/> +</dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate-result.xml index 1d43ca22fea..d2b04dcce89 100644 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate-result.xml @@ -1,5 +1,5 @@ <dataset> <permission_templates id="1" name="my template" description="my description"/> <perm_templates_users/> - <perm_templates_groups id="1" template_id="1" group_id="1" permission="remaining_permission"/> + <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission"/> </dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate.xml index 06e5322a5d3..2cb0ab460fd 100644 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate.xml +++ b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate.xml @@ -1,6 +1,6 @@ <dataset> <permission_templates id="1" name="my template" description="my description"/> <perm_templates_users/> - <perm_templates_groups id="1" template_id="1" group_id="1" permission="remaining_permission"/> - <perm_templates_groups id="2" template_id="1" group_id="2" permission="existing_permission"/> + <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission"/> + <perm_templates_groups id="2" template_id="1" group_id="2" permission_reference="existing_permission"/> </dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate-result.xml index 1d43ca22fea..d2b04dcce89 100644 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate-result.xml @@ -1,5 +1,5 @@ <dataset> <permission_templates id="1" name="my template" description="my description"/> <perm_templates_users/> - <perm_templates_groups id="1" template_id="1" group_id="1" permission="remaining_permission"/> + <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission"/> </dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate.xml index 095449a77b6..23bd158f3a1 100644 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate.xml +++ b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate.xml @@ -1,6 +1,6 @@ <dataset> <permission_templates id="1" name="my template" description="my description"/> <perm_templates_users/> - <perm_templates_groups id="1" template_id="1" group_id="1" permission="remaining_permission"/> - <perm_templates_groups id="2" template_id="1" group_id="[null]" permission="existing_permission"/> + <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission"/> + <perm_templates_groups id="2" template_id="1" group_id="[null]" permission_reference="existing_permission"/> </dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate-result.xml index 68bf04077f4..f4c500ba1ff 100644 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate-result.xml @@ -1,7 +1,7 @@ <dataset> <permission_templates id="1" name="my template" description="my description"/> - <perm_templates_users id="1" template_id="1" user_id="1" permission="remaining_permission"/> + <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="remaining_permission"/> <perm_templates_groups/> </dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate.xml index 69427d2d3bf..219c1f07286 100644 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate.xml +++ b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate.xml @@ -1,8 +1,8 @@ <dataset> <permission_templates id="1" name="my template" description="my description"/> - <perm_templates_users id="1" template_id="1" user_id="1" permission="remaining_permission"/> - <perm_templates_users id="2" template_id="1" user_id="2" permission="existing_permission"/> + <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="remaining_permission"/> + <perm_templates_users id="2" template_id="1" user_id="2" permission_reference="existing_permission"/> <perm_templates_groups/> </dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectPermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectPermissionTemplate.xml index 0de01c53486..91b6e9744eb 100644 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectPermissionTemplate.xml +++ b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectPermissionTemplate.xml @@ -1,16 +1,16 @@ <dataset> <permission_templates id="1" name="my template" description="my description" created_at="[null]" updated_at="[null]"/> - <perm_templates_users id="1" template_id="1" user_id="1" permission="user_permission1"/> - <perm_templates_users id="2" template_id="1" user_id="2" permission="user_permission1"/> - <perm_templates_users id="3" template_id="1" user_id="2" permission="user_permission2"/> + <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="user_permission1"/> + <perm_templates_users id="2" template_id="1" user_id="2" permission_reference="user_permission1"/> + <perm_templates_users id="3" template_id="1" user_id="2" permission_reference="user_permission2"/> <users id="1" login="user1" name="user1" /> <users id="2" login="user2" name="user2" /> - <perm_templates_groups id="1" template_id="1" group_id="1" permission="group_permission1"/> - <perm_templates_groups id="2" template_id="1" group_id="2" permission="group_permission1"/> - <perm_templates_groups id="3" template_id="1" group_id="[null]" permission="group_permission2"/> + <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="group_permission1"/> + <perm_templates_groups id="2" template_id="1" group_id="2" permission_reference="group_permission1"/> + <perm_templates_groups id="3" template_id="1" group_id="[null]" permission_reference="group_permission2"/> <groups id="1" name="group1"/> <groups id="2" name="group2"/> |