diff options
20 files changed, 120 insertions, 51 deletions
diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index 83a2315b177..72837e8c75f 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -2380,6 +2380,7 @@ permission_template.edit_permissions=Edit Permissions: {0} permission_template.update_permissions=Save permission_template.no_results=No template to display permission_template.set_default_templates=Set Default Templates +permission_template.key_pattern=Project key pattern #------------------------------------------------------------------------------ diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDao.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDao.java index ac6341a3bf0..a320ba0fb79 100644 --- a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDao.java +++ b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDao.java @@ -79,11 +79,11 @@ public class PermissionTemplateDao implements TaskComponent, ServerComponent { PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); permissionTemplate = mapper.selectByName(templateName); PermissionTemplateDto templateUsersPermissions = mapper.selectTemplateUsersPermissions(templateName); - if(templateUsersPermissions != null) { + if (templateUsersPermissions != null) { permissionTemplate.setUsersPermissions(templateUsersPermissions.getUsersPermissions()); } PermissionTemplateDto templateGroupsPermissions = mapper.selectTemplateGroupsPermissions(templateName); - if(templateGroupsPermissions != null) { + if (templateGroupsPermissions != null) { permissionTemplate.setGroupsByPermission(templateGroupsPermissions.getGroupsPermissions()); } } finally { @@ -102,12 +102,13 @@ public class PermissionTemplateDao implements TaskComponent, ServerComponent { } } - public PermissionTemplateDto createPermissionTemplate(String templateName, @Nullable String description) { + public PermissionTemplateDto createPermissionTemplate(String templateName, @Nullable String description, @Nullable String keyPattern) { Date creationDate = now(); PermissionTemplateDto permissionTemplate = new PermissionTemplateDto() .setName(templateName) .setKee(generateTemplateKee(templateName, creationDate)) .setDescription(description) + .setKeyPattern(keyPattern) .setCreatedAt(creationDate) .setUpdatedAt(creationDate); SqlSession session = myBatis.openSession(); @@ -134,11 +135,12 @@ public class PermissionTemplateDao implements TaskComponent, ServerComponent { } } - public void updatePermissionTemplate(Long templateId, String templateName, @Nullable String description) { + public void updatePermissionTemplate(Long templateId, String templateName, @Nullable String description, @Nullable String keyPattern) { PermissionTemplateDto permissionTemplate = new PermissionTemplateDto() .setId(templateId) .setName(templateName) .setDescription(description) + .setKeyPattern(keyPattern) .setUpdatedAt(now()); SqlSession session = myBatis.openSession(); try { @@ -215,7 +217,7 @@ public class PermissionTemplateDao implements TaskComponent, ServerComponent { } private String generateTemplateKee(String name, Date timeStamp) { - if(PermissionTemplateDto.DEFAULT.getName().equals(name)) { + if (PermissionTemplateDto.DEFAULT.getName().equals(name)) { return PermissionTemplateDto.DEFAULT.getKee(); } String normalizedName = Normalizer.normalize(name, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "").replace(" ", "_"); diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDto.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDto.java index a68a60557aa..70c2a525218 100644 --- a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDto.java +++ b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDto.java @@ -22,6 +22,7 @@ package org.sonar.core.permission; import javax.annotation.CheckForNull; import javax.annotation.Nullable; + import java.util.Date; import java.util.List; @@ -36,6 +37,7 @@ public class PermissionTemplateDto { private String name; private String kee; private String description; + private String keyPattern; private List<PermissionTemplateUserDto> usersPermissions; private List<PermissionTemplateGroupDto> groupsPermissions; private Date createdAt; @@ -79,6 +81,16 @@ public class PermissionTemplateDto { } @CheckForNull + public String getKeyPattern() { + return keyPattern; + } + + public PermissionTemplateDto setKeyPattern(@Nullable String regexp) { + this.keyPattern = regexp; + return this; + } + + @CheckForNull public List<PermissionTemplateUserDto> getUsersPermissions() { return usersPermissions; } diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index caa95eeab07..845d94b5c6f 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -33,7 +33,7 @@ import java.util.List; */ public class DatabaseVersion implements BatchComponent, ServerComponent { - public static final int LAST_VERSION = 464; + public static final int LAST_VERSION = 465; public static enum Status { UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL diff --git a/sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml b/sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml index 7293920ebe2..29af09a54c0 100644 --- a/sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml @@ -4,13 +4,13 @@ <mapper namespace="org.sonar.core.permission.PermissionTemplateMapper"> <insert id="insert" parameterType="PermissionTemplate" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> - INSERT INTO permission_templates (name, kee, description, created_at, updated_at) - VALUES (#{name}, #{kee}, #{description}, #{createdAt}, #{updatedAt}) + INSERT INTO permission_templates (name, kee, description, key_pattern, created_at, updated_at) + VALUES (#{name}, #{kee}, #{description}, #{keyPattern}, #{createdAt}, #{updatedAt}) </insert> <update id="update" parameterType="PermissionTemplate"> UPDATE permission_templates - SET name = #{name}, description = #{description}, updated_at = #{updatedAt} + SET name = #{name}, description = #{description}, key_pattern = #{keyPattern}, updated_at = #{updatedAt} WHERE id = #{id} </update> @@ -62,19 +62,19 @@ </delete> <select id="selectByKey" parameterType="String" resultType="PermissionTemplate"> - SELECT id, name, kee, description, created_at AS createdAt, updated_at AS updatedAt + SELECT id, name, kee, description, key_pattern AS keyPattern, created_at AS createdAt, updated_at AS updatedAt FROM permission_templates WHERE kee = #{kee} </select> <select id="selectByName" parameterType="String" resultType="PermissionTemplate"> - SELECT id, name, kee, description, created_at AS createdAt, updated_at AS updatedAt + SELECT id, name, kee, description, key_pattern AS keyPattern, created_at AS createdAt, updated_at AS updatedAt FROM permission_templates WHERE name = #{templateName} </select> <select id="selectAllPermissionTemplates" resultType="PermissionTemplate"> - SELECT id, name, kee, description, created_at AS createdAt, updated_at AS updatedAt + SELECT id, name, kee, description, key_pattern AS keyPattern, created_at AS createdAt, updated_at AS updatedAt FROM permission_templates </select> @@ -82,6 +82,7 @@ SELECT pt.id AS template_id, pt.name AS template_name, pt.description AS template_description, + pt.key_pattern AS template_key_pattern, pt.created_at AS template_created_at, pt.updated_at AS template_updated_at, ptu.id AS permission_template_user_id, @@ -99,6 +100,7 @@ SELECT pt.id AS template_id, pt.name AS template_name, pt.description AS template_description, + pt.key_pattern AS template_key_pattern, pt.created_at AS template_created_at, pt.updated_at AS template_updated_at, ptg.id AS permission_template_group_id, @@ -116,6 +118,7 @@ <id property="id" column="template_id"/> <result property="name" column="template_name"/> <result property="description" column="template_description"/> + <result property="keyPattern" column="template_key_pattern"/> <result property="createdAt" column="template_created_at"/> <result property="updatedAt" column="template_updated_at"/> <collection property="usersPermissions" ofType="PermissionTemplateUser"> diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index 7c25b9f59fb..ece45fc06e8 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -188,6 +188,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('461'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('462'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('463'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('464'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('465'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; 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 d10f1505036..8f6ee44a95b 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 @@ -525,6 +525,7 @@ CREATE TABLE "PERMISSION_TEMPLATES" ( "NAME" VARCHAR(100) NOT NULL, "KEE" VARCHAR(100) NOT NULL, "DESCRIPTION" VARCHAR(4000), + "KEY_PATTERN" VARCHAR(500), "CREATED_AT" TIMESTAMP, "UPDATED_AT" TIMESTAMP ); diff --git a/sonar-core/src/test/java/org/sonar/core/permission/PermissionTemplateDaoTest.java b/sonar-core/src/test/java/org/sonar/core/permission/PermissionTemplateDaoTest.java index c98ad095713..652ecfca7d1 100644 --- a/sonar-core/src/test/java/org/sonar/core/permission/PermissionTemplateDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/permission/PermissionTemplateDaoTest.java @@ -33,7 +33,10 @@ import java.util.Date; import java.util.List; import static org.fest.assertions.Assertions.assertThat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.stub; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class PermissionTemplateDaoTest extends AbstractDaoTestCase { @@ -52,7 +55,7 @@ public class PermissionTemplateDaoTest extends AbstractDaoTestCase { @Test public void should_create_permission_template() throws Exception { setupData("createPermissionTemplate"); - PermissionTemplateDto permissionTemplate = permissionTemplateDao.createPermissionTemplate("my template", "my description"); + PermissionTemplateDto permissionTemplate = permissionTemplateDao.createPermissionTemplate("my template", "my description", "myregexp"); assertThat(permissionTemplate).isNotNull(); assertThat(permissionTemplate.getId()).isEqualTo(1L); checkTable("createPermissionTemplate", "permission_templates", "id", "name", "kee", "description"); @@ -61,7 +64,7 @@ public class PermissionTemplateDaoTest extends AbstractDaoTestCase { @Test public void should_normalize_kee_on_template_creation() throws Exception { setupData("createNonAsciiPermissionTemplate"); - PermissionTemplateDto permissionTemplate = permissionTemplateDao.createPermissionTemplate("Môü Gnô Gnèçàß", "my description"); + PermissionTemplateDto permissionTemplate = permissionTemplateDao.createPermissionTemplate("Môü Gnô Gnèçàß", "my description", null); assertThat(permissionTemplate).isNotNull(); assertThat(permissionTemplate.getId()).isEqualTo(1L); checkTable("createNonAsciiPermissionTemplate", "permission_templates", "id", "name", "kee", "description"); @@ -79,7 +82,7 @@ public class PermissionTemplateDaoTest extends AbstractDaoTestCase { when(myBatis.openSession()).thenReturn(session); permissionTemplateDao = new PermissionTemplateDao(myBatis, dateProvider); - PermissionTemplateDto permissionTemplate = permissionTemplateDao.createPermissionTemplate(PermissionTemplateDto.DEFAULT.getName(), null); + PermissionTemplateDto permissionTemplate = permissionTemplateDao.createPermissionTemplate(PermissionTemplateDto.DEFAULT.getName(), null, null); verify(mapper).insert(permissionTemplate); verify(session).commit(); @@ -162,7 +165,7 @@ public class PermissionTemplateDaoTest extends AbstractDaoTestCase { public void should_update_permission_template() throws Exception { setupData("updatePermissionTemplate"); - permissionTemplateDao.updatePermissionTemplate(1L, "new_name", "new_description"); + permissionTemplateDao.updatePermissionTemplate(1L, "new_name", "new_description", "new_regexp"); checkTable("updatePermissionTemplate", "permission_templates", "id", "name", "kee", "description"); } diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/createNonAsciiPermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/createNonAsciiPermissionTemplate-result.xml index d80de102071..68023c5eb8e 100644 --- a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/createNonAsciiPermissionTemplate-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/createNonAsciiPermissionTemplate-result.xml @@ -1,3 +1,3 @@ <dataset> - <permission_templates id="1" name="Môü Gnô Gnèçàß" kee="mou_gno_gneca_20130102_010405" description="my description"/> -</dataset>
\ No newline at end of file + <permission_templates id="1" name="Môü Gnô Gnèçàß" kee="mou_gno_gneca_20130102_010405" description="my description" key_pattern="[null]"/> +</dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/createPermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/createPermissionTemplate-result.xml index 0c2bd559342..4e0f6a0565c 100644 --- a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/createPermissionTemplate-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/createPermissionTemplate-result.xml @@ -1,3 +1,3 @@ <dataset> - <permission_templates id="1" name="my template" kee="my_template_20130102_010405" description="my description"/> -</dataset>
\ No newline at end of file + <permission_templates id="1" name="my template" kee="my_template_20130102_010405" description="my description" key_pattern="myregexp"/> +</dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/updatePermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/updatePermissionTemplate-result.xml index 6f25f75defe..864e0c9be19 100644 --- a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/updatePermissionTemplate-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/updatePermissionTemplate-result.xml @@ -1,4 +1,4 @@ <dataset> - <permission_templates id="1" name="new_name" kee="template1_20130102_030405" description="new_description" created_at="[null]" updated_at="[null]"/> - <permission_templates id="2" name="template2" kee="template2_20130102_030405" description="description2" created_at="[null]" updated_at="[null]"/> -</dataset>
\ No newline at end of file + <permission_templates id="1" name="new_name" kee="template1_20130102_030405" description="new_description" key_pattern="new_regexp" created_at="[null]" updated_at="[null]"/> + <permission_templates id="2" name="template2" kee="template2_20130102_030405" description="description2" key_pattern="barregexp" created_at="[null]" updated_at="[null]"/> +</dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/updatePermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/updatePermissionTemplate.xml index 2c056af7153..b461c1c9c3b 100644 --- a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/updatePermissionTemplate.xml +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/updatePermissionTemplate.xml @@ -1,4 +1,4 @@ <dataset> - <permission_templates id="1" name="template1" kee="template1_20130102_030405" description="description1" created_at="[null]" updated_at="[null]"/> - <permission_templates id="2" name="template2" kee="template2_20130102_030405" description="description2" created_at="[null]" updated_at="[null]"/> -</dataset>
\ No newline at end of file + <permission_templates id="1" name="template1" kee="template1_20130102_030405" description="description1" key_pattern="fooregexp" created_at="[null]" updated_at="[null]"/> + <permission_templates id="2" name="template2" kee="template2_20130102_030405" description="description2" key_pattern="barregexp" created_at="[null]" updated_at="[null]"/> +</dataset> diff --git a/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java b/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java index 72e8d89a7a5..7692449d6d7 100644 --- a/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java +++ b/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java @@ -77,10 +77,10 @@ public class InternalPermissionTemplateService implements ServerComponent { return permissionTemplates; } - public PermissionTemplate createPermissionTemplate(String name, @Nullable String description) { + public PermissionTemplate createPermissionTemplate(String name, @Nullable String description, @Nullable String keyPattern) { PermissionTemplateUpdater.checkSystemAdminUser(); validateTemplateName(null, name); - PermissionTemplateDto permissionTemplateDto = permissionTemplateDao.createPermissionTemplate(name, description); + PermissionTemplateDto permissionTemplateDto = permissionTemplateDao.createPermissionTemplate(name, description, keyPattern); if (permissionTemplateDto.getId() == null) { String errorMsg = "Template creation failed"; LOG.error(errorMsg); @@ -89,10 +89,10 @@ public class InternalPermissionTemplateService implements ServerComponent { return PermissionTemplate.create(permissionTemplateDto); } - public void updatePermissionTemplate(Long templateId, String newName, @Nullable String newDescription) { + public void updatePermissionTemplate(Long templateId, String newName, @Nullable String newDescription, @Nullable String newKeyPattern) { PermissionTemplateUpdater.checkSystemAdminUser(); validateTemplateName(templateId, newName); - permissionTemplateDao.updatePermissionTemplate(templateId, newName, newDescription); + permissionTemplateDao.updatePermissionTemplate(templateId, newName, newDescription, newKeyPattern); } public void deletePermissionTemplate(Long templateId) { diff --git a/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplate.java b/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplate.java index 0d6bbf66fe4..9f98ddf7c62 100644 --- a/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplate.java +++ b/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplate.java @@ -27,7 +27,9 @@ import org.sonar.core.permission.PermissionTemplateDto; import org.sonar.core.permission.PermissionTemplateGroupDto; import org.sonar.core.permission.PermissionTemplateUserDto; +import javax.annotation.CheckForNull; import javax.annotation.Nullable; + import java.util.List; public class PermissionTemplate { @@ -36,27 +38,30 @@ public class PermissionTemplate { private final String name; private final String key; private final String description; + private final String keyPattern; private Multimap<String, PermissionTemplateUser> usersByPermission; private Multimap<String, PermissionTemplateGroup> groupsByPermission; - private PermissionTemplate(Long id, String name, String key, String description) { + private PermissionTemplate(Long id, String name, String key, @Nullable String description, @Nullable String keyPattern) { this.id = id; this.name = name; this.key = key; this.description = description; + this.keyPattern = keyPattern; usersByPermission = HashMultimap.create(); groupsByPermission = HashMultimap.create(); } public static PermissionTemplate create(@Nullable PermissionTemplateDto permissionTemplateDto) { - if(permissionTemplateDto == null) { + if (permissionTemplateDto == null) { return null; } PermissionTemplate permissionTemplate = new PermissionTemplate( - permissionTemplateDto.getId(), permissionTemplateDto.getName(), permissionTemplateDto.getKee(), permissionTemplateDto.getDescription()); + permissionTemplateDto.getId(), permissionTemplateDto.getName(), permissionTemplateDto.getKee(), permissionTemplateDto.getDescription(), + permissionTemplateDto.getKeyPattern()); List<PermissionTemplateUserDto> usersPermissions = permissionTemplateDto.getUsersPermissions(); - if(usersPermissions != null) { + if (usersPermissions != null) { for (PermissionTemplateUserDto userPermission : usersPermissions) { permissionTemplate.registerUserPermission(permissionTemplateDto.getId(), userPermission.getUserId(), userPermission.getUserName(), userPermission.getUserLogin(), userPermission.getPermission()); @@ -64,7 +69,7 @@ public class PermissionTemplate { } List<PermissionTemplateGroupDto> groupsPermissions = permissionTemplateDto.getGroupsPermissions(); - if(groupsPermissions != null) { + if (groupsPermissions != null) { for (PermissionTemplateGroupDto groupPermission : groupsPermissions) { permissionTemplate.registerGroupPermission(groupPermission.getPermission(), permissionTemplateDto.getId(), groupPermission.getGroupId(), groupPermission.getGroupName()); @@ -81,6 +86,7 @@ public class PermissionTemplate { return name; } + @CheckForNull public String getDescription() { return description; } @@ -89,6 +95,11 @@ public class PermissionTemplate { return key; } + @CheckForNull + public String getKeyPattern() { + return keyPattern; + } + public List<PermissionTemplateUser> getUsersForPermission(String permission) { return ImmutableList.copyOf(usersByPermission.get(permission)); } diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java index 3d16ede9cce..8be2fbea9aa 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java @@ -79,7 +79,7 @@ public class RegisterPermissionTemplates { private void insertDefaultTemplate(String templateName) { PermissionTemplateDto defaultPermissionTemplate = permissionTemplateDao - .createPermissionTemplate(templateName, PermissionTemplateDto.DEFAULT.getDescription()); + .createPermissionTemplate(templateName, PermissionTemplateDto.DEFAULT.getDescription(), null); addGroupPermission(defaultPermissionTemplate, UserRole.ADMIN, DefaultGroups.ADMINISTRATORS); addGroupPermission(defaultPermissionTemplate, UserRole.ISSUE_ADMIN, DefaultGroups.ADMINISTRATORS); addGroupPermission(defaultPermissionTemplate, UserRole.USER, DefaultGroups.ANYONE); diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/permission_templates_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/permission_templates_controller.rb index 6a0c388d1ef..e8171c9796f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/permission_templates_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/permission_templates_controller.rb @@ -137,7 +137,7 @@ class PermissionTemplatesController < ApplicationController # def create verify_post_request - @permission_template = Internal.permission_templates.createPermissionTemplate(params[:name], params[:description]) + @permission_template = Internal.permission_templates.createPermissionTemplate(params[:name], params[:description], params[:pattern]) redirect_to :action => 'index' end @@ -156,7 +156,7 @@ class PermissionTemplatesController < ApplicationController def edit verify_post_request require_parameters :id, :name - Internal.permission_templates.updatePermissionTemplate(params[:id].to_i, params[:name], params[:description]) + Internal.permission_templates.updatePermissionTemplate(params[:id].to_i, params[:name], params[:description], params[:pattern]) redirect_to :action => 'index' end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_permission_template_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_permission_template_form.html.erb index 3679f47f8d4..0a66c2c336f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_permission_template_form.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_permission_template_form.html.erb @@ -10,12 +10,16 @@ <div class="modal-error"/> <div class="modal-field"> <label for="name"><%= h message('name') -%> <em class="mandatory">*</em></label> - <input id="name" name="name" type="text" size="50" maxlength="256" value="<%= @permission_template ? @permission_template.name : '' -%>" autofocus="autofocus"/> + <input id="name" name="name" type="text" maxlength="256" value="<%= @permission_template ? @permission_template.name : '' -%>" autofocus="autofocus" style="width: 330px;"/> </div> <div class="modal-field"> <label for="description"><%= h message('description') -%></label> <textarea id="description" name="description" maxlength="4000" rows="10" style="width: 330px;"><%= @permission_template ? @permission_template.description : '' -%></textarea> </div> + <div class="modal-field"> + <label for="keyPattern"><%= h message('permission_template.key_pattern') -%></label> + <input id="keyPattern" name="pattern" type="text" maxlength="500" value="<%= @permission_template ? @permission_template.keyPattern : '' -%>" style="width: 330px;"/> + </div> </div> <div class="modal-foot"> <input type="submit" value="<%= h message("permission_template.#{message_submit}") -%>" id="submit-permission-template-<%= form_action %>"/> diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/465_add_perm_template_key_pattern_column.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/465_add_perm_template_key_pattern_column.rb new file mode 100644 index 00000000000..43046904cc0 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/465_add_perm_template_key_pattern_column.rb @@ -0,0 +1,31 @@ +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2008-2013 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# SonarQube is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# Sonar 4.1 +# + +class AddPermTemplateKeyPatternColumn < ActiveRecord::Migration + + def self.up + add_column 'permission_templates', :key_pattern, :string, :null => true, :limit => 500 + end + +end diff --git a/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionTemplateServiceTest.java b/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionTemplateServiceTest.java index 42f5b9971ba..843ad84d3ed 100644 --- a/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionTemplateServiceTest.java +++ b/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionTemplateServiceTest.java @@ -78,9 +78,9 @@ public class InternalPermissionTemplateServiceTest { @Test public void should_create_permission_template() throws Exception { - when(permissionTemplateDao.createPermissionTemplate(DEFAULT_NAME, DEFAULT_DESC)).thenReturn(DEFAULT_TEMPLATE); + when(permissionTemplateDao.createPermissionTemplate(DEFAULT_NAME, DEFAULT_DESC, null)).thenReturn(DEFAULT_TEMPLATE); - PermissionTemplate permissionTemplate = permissionTemplateService.createPermissionTemplate(DEFAULT_NAME, DEFAULT_DESC); + PermissionTemplate permissionTemplate = permissionTemplateService.createPermissionTemplate(DEFAULT_NAME, DEFAULT_DESC, null); assertThat(permissionTemplate.getId()).isEqualTo(1L); assertThat(permissionTemplate.getName()).isEqualTo(DEFAULT_NAME); @@ -94,7 +94,7 @@ public class InternalPermissionTemplateServiceTest { when(permissionTemplateDao.selectAllPermissionTemplates()).thenReturn(Lists.newArrayList(DEFAULT_TEMPLATE)); - permissionTemplateService.createPermissionTemplate(DEFAULT_NAME, DEFAULT_DESC); + permissionTemplateService.createPermissionTemplate(DEFAULT_NAME, DEFAULT_DESC, null); } @Test @@ -102,7 +102,7 @@ public class InternalPermissionTemplateServiceTest { expected.expect(BadRequestException.class); expected.expectMessage("Name can't be blank"); - permissionTemplateService.createPermissionTemplate("", DEFAULT_DESC); + permissionTemplateService.createPermissionTemplate("", DEFAULT_DESC, null); } @Test @@ -189,9 +189,9 @@ public class InternalPermissionTemplateServiceTest { @Test public void should_update_permission_template() throws Exception { - permissionTemplateService.updatePermissionTemplate(1L, "new_name", "new_description"); + permissionTemplateService.updatePermissionTemplate(1L, "new_name", "new_description", null); - verify(permissionTemplateDao).updatePermissionTemplate(1L, "new_name", "new_description"); + verify(permissionTemplateDao).updatePermissionTemplate(1L, "new_name", "new_description", null); } @Test @@ -205,7 +205,7 @@ public class InternalPermissionTemplateServiceTest { new PermissionTemplateDto().setId(2L).setName("template2").setDescription("template2"); when(permissionTemplateDao.selectAllPermissionTemplates()).thenReturn(Lists.newArrayList(template1, template2)); - permissionTemplateService.updatePermissionTemplate(1L, "template2", "template1"); + permissionTemplateService.updatePermissionTemplate(1L, "template2", "template1", null); } @Test @@ -216,9 +216,9 @@ public class InternalPermissionTemplateServiceTest { new PermissionTemplateDto().setId(2L).setName("template2").setDescription("template2"); when(permissionTemplateDao.selectAllPermissionTemplates()).thenReturn(Lists.newArrayList(template1, template2)); - permissionTemplateService.updatePermissionTemplate(1L, "template1", "new_description"); + permissionTemplateService.updatePermissionTemplate(1L, "template1", "new_description", null); - verify(permissionTemplateDao).updatePermissionTemplate(1L, "template1", "new_description"); + verify(permissionTemplateDao).updatePermissionTemplate(1L, "template1", "new_description", null); } @Test diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterPermissionTemplatesTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterPermissionTemplatesTest.java index 0dd078f8547..ec28c3e1cd8 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterPermissionTemplatesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterPermissionTemplatesTest.java @@ -66,7 +66,7 @@ public class RegisterPermissionTemplatesTest { when(loadedTemplateDao.countByTypeAndKey(LoadedTemplateDto.PERMISSION_TEMPLATE_TYPE, PermissionTemplateDto.DEFAULT.getKee())) .thenReturn(0); - when(permissionTemplateDao.createPermissionTemplate(PermissionTemplateDto.DEFAULT.getName(), PermissionTemplateDto.DEFAULT.getDescription())) + when(permissionTemplateDao.createPermissionTemplate(PermissionTemplateDto.DEFAULT.getName(), PermissionTemplateDto.DEFAULT.getDescription(), null)) .thenReturn(permissionTemplate); when(userDao.selectGroupByName(DefaultGroups.ADMINISTRATORS)).thenReturn(new GroupDto().setId(1L)); when(userDao.selectGroupByName(DefaultGroups.USERS)).thenReturn(new GroupDto().setId(2L)); @@ -75,7 +75,7 @@ public class RegisterPermissionTemplatesTest { initializer.start(); verify(loadedTemplateDao).insert(argThat(Matches.template(expectedTemplate))); - verify(permissionTemplateDao).createPermissionTemplate(PermissionTemplateDto.DEFAULT.getName(), PermissionTemplateDto.DEFAULT.getDescription()); + verify(permissionTemplateDao).createPermissionTemplate(PermissionTemplateDto.DEFAULT.getName(), PermissionTemplateDto.DEFAULT.getDescription(), null); verify(permissionTemplateDao).addGroupPermission(1L, 1L, UserRole.ADMIN); verify(permissionTemplateDao).addGroupPermission(1L, 1L, UserRole.ISSUE_ADMIN); verify(permissionTemplateDao).addGroupPermission(1L, null, UserRole.USER); |