]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4466 Added controller and pages to handle CRUD operations on permission templates
authorJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Mon, 8 Jul 2013 09:00:04 +0000 (11:00 +0200)
committerJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Mon, 8 Jul 2013 09:00:04 +0000 (11:00 +0200)
13 files changed:
plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
sonar-core/src/main/java/org/sonar/core/user/PermissionDao.java
sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateMapper.java
sonar-core/src/main/resources/org/sonar/core/user/PermissionTemplateMapper.xml
sonar-core/src/test/java/org/sonar/core/user/PermissionDaoTest.java
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/updatePermissionTemplate-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/updatePermissionTemplate.xml [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/permission_templates_controller.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_delete_form.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_permission_template_form.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/index.html.erb [new file with mode: 0644]
sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionTemplateServiceTest.java

index 74ff3af35cbbafb5e15a951c1e25da7b0634a28d..203475dae722247d5e5699be40e458088af13fc5 100644 (file)
@@ -2242,6 +2242,20 @@ projects_role.codeviewer=Role: Code Viewers
 projects_role.codeviewer.desc=Ability to view the source code of the project.
 
 
+#------------------------------------------------------------------------------
+#
+# PERMISSION TEMPLATES
+#
+#------------------------------------------------------------------------------
+permission_templates=Permission templates
+permission_template.new_template=New permission template
+permission_template.create_template=Create permission template
+permission_template.delete_confirm_title=Delete permission template
+permission_template.do_you_want_to_delete_template=Are you sure that you want to delete this permission template?
+permission_template.delete_template=Delete permission template
+permission_template.edit_template=Edit permission template
+
+
 #------------------------------------------------------------------------------
 #
 # ERRORS HANDLING
index 14deada2ff3f22d072b603a25f15f939c697ab16..2d1e499c6fc8eb3baf8c49b604a150bc310f6169 100644 (file)
@@ -110,6 +110,22 @@ public class PermissionDao implements TaskExtension, ServerExtension {
     }
   }
 
+  public void updatePermissionTemplate(Long templateId, String templateName, @Nullable String description) {
+    PermissionTemplateDto permissionTemplate = new PermissionTemplateDto()
+      .setId(templateId)
+      .setName(templateName)
+      .setDescription(description)
+      .setUpdatedAt(now());
+    SqlSession session = myBatis.openSession();
+    try {
+      PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
+      mapper.update(permissionTemplate);
+      session.commit();
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
   public void addUserPermission(Long templateId, Long userId, String permission) {
     PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto()
       .setTemplateId(templateId)
index f3f3f85f884fcc11432150091461040d252062b9..124492f07a52818b981b54d9212c6a3ed2ea05e1 100644 (file)
@@ -27,6 +27,8 @@ public interface PermissionTemplateMapper {
 
   void insert(PermissionTemplateDto permissionTemplate);
 
+  void update(PermissionTemplateDto permissionTemplate);
+
   void delete(Long templateId);
 
   void deleteUsersPermissions(Long templateId);
index 0cabe293958a455f697f93a353f3c3d1f9f1ab84..d07c5232aabc3ffa20bca47b0a4cf1726bfb1647 100644 (file)
@@ -8,6 +8,12 @@
     VALUES (#{name}, #{description}, #{createdAt}, #{updatedAt})
   </insert>
 
+  <update id="update" parameterType="PermissionTemplate">
+    UPDATE permission_templates
+    SET name = #{name}, description = #{description}, updated_at = #{updatedAt}
+    WHERE id = #{id}
+  </update>
+
   <delete id="delete" parameterType="Long">
     DELETE FROM permission_templates
     WHERE id = #{templateId}
index de5aef22b0a4638f5e3d5f8c43fc865ae9a26d6f..dba245bb5a8b0a1b9b23381ac14a2be48fea2367 100644 (file)
@@ -75,7 +75,7 @@ public class PermissionDaoTest extends AbstractDaoTestCase {
   }
 
   @Test
-  public void should_permission_template_by_name() throws Exception {
+  public void should_select_permission_template_by_name() throws Exception {
     setupData("selectPermissionTemplate");
 
     PermissionTemplateDto permissionTemplate = permissionDao.selectTemplateByName("my template");
@@ -98,6 +98,15 @@ public class PermissionDaoTest extends AbstractDaoTestCase {
     assertThat(permissionTemplates).onProperty("description").containsOnly("description1", "description2", "description3");
   }
 
+  @Test
+  public void should_update_permission_template() throws Exception {
+    setupData("updatePermissionTemplate");
+
+    permissionDao.updatePermissionTemplate(1L, "new_name", "new_description");
+
+    checkTable("updatePermissionTemplate", "permission_templates", "id", "name", "description");
+  }
+
   @Test
   public void should_delete_permission_template() throws Exception {
     setupData("deletePermissionTemplate");
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/updatePermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/updatePermissionTemplate-result.xml
new file mode 100644 (file)
index 0000000..c29fef8
--- /dev/null
@@ -0,0 +1,4 @@
+<dataset>
+  <permission_templates id="1" name="new_name" description="new_description" created_at="[null]" updated_at="[null]"/>
+  <permission_templates id="2" name="template2" description="description2" created_at="[null]" updated_at="[null]"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/updatePermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/updatePermissionTemplate.xml
new file mode 100644 (file)
index 0000000..ef9d2a2
--- /dev/null
@@ -0,0 +1,4 @@
+<dataset>
+  <permission_templates id="1" name="template1" description="description1" created_at="[null]" updated_at="[null]"/>
+  <permission_templates id="2" name="template2" description="description2" created_at="[null]" updated_at="[null]"/>
+</dataset>
\ No newline at end of file
index 7854a6bd12aa0acccebab65a0af8fbdac538c144..f56429a6861f83a72e695a22dbaa31a0e80fce15 100644 (file)
@@ -24,11 +24,14 @@ import com.google.common.collect.Lists;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.ServerComponent;
-import org.sonar.core.user.*;
+import org.sonar.core.user.PermissionDao;
+import org.sonar.core.user.PermissionTemplateDto;
+import org.sonar.core.user.UserDao;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ServerErrorException;
 
 import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
 import java.util.List;
 
 /**
@@ -65,9 +68,9 @@ public class InternalPermissionTemplateService implements ServerComponent {
     return permissionTemplates;
   }
 
-  public PermissionTemplate createPermissionTemplate(String name, String description) {
+  public PermissionTemplate createPermissionTemplate(String name, @Nullable String description) {
     PermissionTemplateUpdater.checkUserCredentials();
-    checkThatTemplateNameIsUnique(name);
+    validateTemplateName(null, name);
     PermissionTemplateDto permissionTemplateDto = permissionDao.createPermissionTemplate(name, description);
     if(permissionTemplateDto.getId() == null) {
       String errorMsg = "Template creation failed";
@@ -77,16 +80,15 @@ public class InternalPermissionTemplateService implements ServerComponent {
     return PermissionTemplate.create(permissionTemplateDto);
   }
 
-  public void deletePermissionTemplate(String templateName) {
+  public void updatePermissionTemplate(Long templateId, String newName, @Nullable String newDescription) {
     PermissionTemplateUpdater.checkUserCredentials();
-    PermissionTemplateDto permissionTemplateDto = permissionDao.selectTemplateByName(templateName);
-    if(permissionTemplateDto == null) {
-      String errorMsg = "Unknown template:" + templateName;
-      LOG.error(errorMsg);
-      throw new BadRequestException(errorMsg);
-    } else {
-      permissionDao.deletePermissionTemplate(permissionTemplateDto.getId());
-    }
+    validateTemplateName(templateId, newName);
+    permissionDao.updatePermissionTemplate(templateId, newName, newDescription);
+  }
+
+  public void deletePermissionTemplate(Long templateId) {
+    PermissionTemplateUpdater.checkUserCredentials();
+    permissionDao.deletePermissionTemplate(templateId);
   }
 
   public void addUserPermission(String templateName, String permission, final String userLogin) {
@@ -133,11 +135,16 @@ public class InternalPermissionTemplateService implements ServerComponent {
     updater.executeUpdate();
   }
 
-  private void checkThatTemplateNameIsUnique(String name) {
+  private void validateTemplateName(Long templateId, String templateName) {
+    if(templateName == null) {
+      String errorMsg = "The name field is mandatory";
+      LOG.error(errorMsg);
+      throw new BadRequestException(errorMsg);
+    }
     List<PermissionTemplateDto> existingTemplates = permissionDao.selectAllPermissionTemplates();
     if(existingTemplates != null) {
       for (PermissionTemplateDto existingTemplate : existingTemplates) {
-        if(existingTemplate.getName().equals(name)) {
+        if((templateId == null || templateId != existingTemplate.getId()) && (existingTemplate.getName().equals(templateName))) {
           String errorMsg = "A template with that name already exists";
           LOG.error(errorMsg);
           throw new BadRequestException(errorMsg);
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
new file mode 100644 (file)
index 0000000..60b25cd
--- /dev/null
@@ -0,0 +1,91 @@
+#
+# 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.
+#
+
+#
+# @since 3.7
+#
+# Note : do NOT use @template as an instance variable
+# as it is a reserved variable in Rails
+#
+class PermissionTemplatesController < ApplicationController
+
+  SECTION=Navigation::SECTION_CONFIGURATION
+
+  before_filter :admin_required
+
+  #
+  # GET
+  #
+  def index
+    @permission_templates = Internal.permission_templates.selectAllPermissionTemplates
+  end
+
+  def edit_users
+  end
+
+  def edit_groups
+  end
+
+  def create_form
+    render :partial => 'permission_templates/permission_template_form',
+           :locals => {:form_action => 'create', :message_title => 'new_template', :message_submit => 'create_template'}
+  end
+
+  #
+  # POST
+  #
+  def create
+    verify_post_request
+    @permission_template = Internal.permission_templates.createPermissionTemplate(params[:name], params[:description])
+    redirect_to :action => 'index'
+  end
+
+  def edit_form
+    @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name])
+    render :partial => 'permission_templates/permission_template_form',
+           :locals => {:form_action => 'edit', :message_title => 'edit_template', :message_submit => 'edit_template'}
+  end
+
+  #
+  # POST
+  #
+  def edit
+    verify_post_request
+    require_parameters :id, :name
+    Internal.permission_templates.updatePermissionTemplate(params[:id].to_i, params[:name], params[:description])
+    redirect_to :action => 'index'
+  end
+
+  def delete_form
+    @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name])
+    render :partial => 'permission_templates/delete_form'
+  end
+
+  #
+  # POST
+  #
+  def delete
+    verify_post_request
+    require_parameters :id
+    Internal.permission_templates.deletePermissionTemplate(params[:id].to_i)
+    redirect_to :action => 'index'
+  end
+
+end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_delete_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_delete_form.html.erb
new file mode 100644 (file)
index 0000000..e373a37
--- /dev/null
@@ -0,0 +1,25 @@
+<form id="delete-template-form" method="post" action="<%= ApplicationController.root_context -%>/permission_templates/delete">
+  <input type="hidden" name="id" value="<%= @permission_template.id -%>">
+  <fieldset>
+    <div class="modal-head">
+      <h2><%= message 'permission_template.delete_confirm_title' -%></h2>
+    </div>
+    <div class="modal-body">
+      <div id="permission-template-error" class="permission-template error errors" style="display:none;" />
+      <div class="info">
+        <img src="<%= ApplicationController.root_context -%>/images/information.png" style="vertical-align: text-bottom"/>
+        <%= message 'permission_template.do_you_want_to_delete_template' -%>
+      </div>
+    </div>
+    <div class="modal-foot">
+      <input type="submit" value="<%= message 'permission_template.delete_template' -%>" id="confirm-submit"/>
+      <a href="#" onclick="return closeModalWindow()" id="confirm-cancel"><%= h message('cancel') -%></a>
+    </div>
+  </fieldset>
+</form>
+
+<script>
+  $j("#delete-template-form").modalForm({success: function (data) {
+    window.location.reload();
+  }});
+</script>
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
new file mode 100644 (file)
index 0000000..a2203f7
--- /dev/null
@@ -0,0 +1,40 @@
+<form id="permission-template-form" method="post" action="<%= ApplicationController.root_context -%>/permission_templates/<%= form_action %>">
+  <% if form_action == 'edit' %>
+    <input type="hidden" name="id" value="<%= @permission_template.id -%>">
+  <% end %>
+  <fieldset>
+    <div class="modal-head">
+      <h2><%= message("permission_template.#{message_title}") -%></h2>
+    </div>
+    <div class="modal-body">
+      <div id="permission-template-error" class="permission-template error errors" style="display:none;" />
+      <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"/>
+      </div>
+      <div class="modal-field">
+        <label for="description"><%= h message('description') -%></label>
+        <input id="description" name="description" type="text" size="50" maxlength="4000" value="<%= @permission_template ? @permission_template.description : '' -%>"/>
+      </div>
+    </div>
+    <div class="modal-foot">
+      <input type="submit" value="<%= h message("permission_template.#{message_submit}") -%>" id="submit-permission-template-<%= form_action %>"/>
+      <a href="#" onclick="return closeModalWindow()" id="cancel-edit-template"><%= h message('cancel') -%></a>
+    </div>
+  </fieldset>
+</form>
+
+<script>
+  $j("#permission-template-form").modalForm({
+    success: function (data) {
+      window.location.reload();
+    },
+    error: function (xhr, textStatus, errorThrown) {
+      var htmlClass = 'permission-template';
+      $j('input[id^="submit-permission-template"]').removeAttr('disabled');
+      $j('.' + htmlClass + '.errors').show();
+      $j('.' + htmlClass + '.errors').html(xhr.responseText);
+    }
+  });
+</script>
+
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/index.html.erb
new file mode 100644 (file)
index 0000000..9c20a58
--- /dev/null
@@ -0,0 +1,72 @@
+<div class="line-block">
+  <ul style="float: right" class="horizontal">
+    <li class="marginleft10 add">
+      <a id="create-link-permission-template" href="permission_templates/create_form" class="open-modal link-action"><%= message('create') -%></a>
+    </li>
+  </ul>
+  <h1><%= message('permission_templates') -%></h1>
+</div>
+
+<table class="data width100" id="permission-templates">
+  <thead>
+  <tr>
+    <th class="left" width="20%"><%= message('name') -%></th>
+    <th class="left" colspan="3"></th>
+    <th class="right" width="5%" colspan="2"><%= message('operations') -%></th>
+  </tr>
+  </thead>
+
+  <tbody>
+  <% if @permission_templates.empty? %>
+    <tr class="even">
+      <td colspan="4" align="left"><%= message('no_results') %></td>
+    </tr>
+  <% end %>
+  <% @permission_templates.each do |permission_template| %>
+    <tr class="<%= cycle('even', 'odd') -%>">
+      <td valign="top"><b><%= h permission_template.name %></b><br/>
+        <span class="small gray"><%= h permission_template.description -%></span>
+      </td>
+      <td valign="top">
+        <%
+           users=Api::Utils.insensitive_sort(permission_template.getUsersForPermission('admin'))
+           groups=Api::Utils.insensitive_sort(permission_template.getGroupsForPermission('admin'))
+        %>
+        <span id="u-admin-<%= u permission_template.name -%>"><%= users.join(', ') %></span>
+        (<a href="<%= ApplicationController.root_context -%>/permission_templates/edit_users?redirect=projects&role=admin&resource=<%= permission_template.id -%>" class="link-action" id="selectu-admin-<%= u permission_template.name -%>">select users</a>)<br/>
+        <span id="g-admin-<%= u permission_template.name -%>"><%= groups.join(', ') %></span>
+        (<a href="<%= ApplicationController.root_context -%>/permission_templates/edit_groups?redirect=projects&role=admin&resource=<%= permission_template.id -%>&q=<%= u params[:q] -%>&qualifier=<%= @qualifier -%>&page=<%= params[:page] -%>" class="link-action" id="selectg-admin-<%= u permission_template.name -%>">select groups</a>)
+      </td>
+      <td valign="top">
+        <%
+           users=Api::Utils.insensitive_sort(permission_template.getUsersForPermission('user'))
+           groups=Api::Utils.insensitive_sort(permission_template.getGroupsForPermission('groups'))
+        %>
+        <span id="u-user-<%= u permission_template.name -%>"><%= users.join(', ') %></span>
+        (<a href="<%= ApplicationController.root_context -%>/roles/edit_users?redirect=projects&role=user&resource=<%= permission_template.id -%>&q=<%= u params[:q] -%>&qualifier=<%= @qualifier -%>&page=<%= params[:page] -%>" class="link-action" id="selectu-user-<%= u permission_template.name -%>">select users</a>)<br/>
+        <span id="g-user-<%= u permission_template.name -%>"><%= groups.join(', ') %></span>
+        (<a href="<%= ApplicationController.root_context -%>/roles/edit_groups?redirect=projects&role=user&resource=<%= permission_template.id -%>&q=<%= u params[:q] -%>&qualifier=<%= @qualifier -%>&page=<%= params[:page] -%>" class="link-action" id="selectg-user-<%= u permission_template.name -%>">select groups</a>)
+      </td>
+      <td valign="top">
+        <%
+           users=Api::Utils.insensitive_sort(permission_template.getUsersForPermission('codeviewer'))
+           groups=Api::Utils.insensitive_sort(permission_template.getGroupsForPermission('codeviewer'))
+        %>
+        <span id="u-codeviewer-<%= u permission_template.name -%>"><%= users.join(', ') %></span>
+        (<a href="<%= ApplicationController.root_context -%>/roles/edit_users?redirect=projects&role=codeviewer&resource=<%= permission_template.id -%>&q=<%= u params[:q] -%>&qualifier=<%= @qualifier -%>&page=<%= params[:page] -%>" class="link-action" id="selectu-codeviewer-<%= u permission_template.name -%>">select users</a>)<br/>
+        <span id="g-codeviewer-<%= u permission_template.name -%>"><%= groups.join(', ') %></span>
+        (<a href="<%= ApplicationController.root_context -%>/roles/edit_groups?redirect=projects&role=codeviewer&resource=<%= permission_template.id -%>&q=<%= u params[:q] -%>&qualifier=<%= @qualifier -%>&page=<%= params[:page] -%>" class="link-action" id="selectg-codeviewer-<%= u permission_template.name -%>">select groups</a>)
+      </td>
+      <td align="right">
+        <%= link_to message('edit'), {:action => :edit_form, :name => permission_template.name},
+                    :id => "edit-template-#{u permission_template.name}", :class => 'open-modal link-action' %>
+      </td>
+      <td align="right">
+        <%= link_to message('delete'), {:action => :delete_form, :name => permission_template.name},
+                    :id => "delete-template-#{u permission_template.name}", :class => 'open-modal link-action' %>
+      </td>
+    </tr>
+  <%
+     end %>
+  </tbody>
+</table>
index 5ade294c424a773c116f35db149fd981cc105cf2..a119ce86cc8c46314d86fa3190724858194a7261 100644 (file)
@@ -83,21 +83,11 @@ public class InternalPermissionTemplateServiceTest {
   public void should_delete_permission_template() throws Exception {
     when(permissionDao.selectTemplateByName(DEFAULT_NAME)).thenReturn(DEFAULT_TEMPLATE);
 
-    permissionTemplateService.deletePermissionTemplate(DEFAULT_NAME);
+    permissionTemplateService.deletePermissionTemplate(1L);
 
     verify(permissionDao, times(1)).deletePermissionTemplate(1L);
   }
 
-  @Test
-  public void should_validate_template_name_on_deletion() throws Exception {
-    expected.expect(BadRequestException.class);
-    expected.expectMessage("Unknown template:");
-
-    when(permissionDao.selectTemplateByName(DEFAULT_NAME)).thenReturn(null);
-
-    permissionTemplateService.deletePermissionTemplate(DEFAULT_NAME);
-  }
-
   @Test
   public void should_retrieve_permission_template() throws Exception {
 
@@ -149,6 +139,41 @@ public class InternalPermissionTemplateServiceTest {
     assertThat(templates).onProperty("description").containsOnly("template1", "template2");
   }
 
+  @Test
+  public void should_update_permission_template() throws Exception {
+
+    permissionTemplateService.updatePermissionTemplate(1L, "new_name", "new_description");
+
+    verify(permissionDao).updatePermissionTemplate(1L, "new_name", "new_description");
+  }
+
+  @Test
+  public void should_validate_template_name_on_update_if_applicable() throws Exception {
+    expected.expect(BadRequestException.class);
+    expected.expectMessage("A template with that name already exists");
+
+    PermissionTemplateDto template1 =
+      new PermissionTemplateDto().setId(1L).setName("template1").setDescription("template1");
+    PermissionTemplateDto template2 =
+      new PermissionTemplateDto().setId(2L).setName("template2").setDescription("template2");
+    when(permissionDao.selectAllPermissionTemplates()).thenReturn(Lists.newArrayList(template1, template2));
+
+    permissionTemplateService.updatePermissionTemplate(1L, "template2", "template1");
+  }
+
+  @Test
+  public void should_skip_name_validation_where_not_applicable() throws Exception {
+    PermissionTemplateDto template1 =
+      new PermissionTemplateDto().setId(1L).setName("template1").setDescription("template1");
+    PermissionTemplateDto template2 =
+      new PermissionTemplateDto().setId(2L).setName("template2").setDescription("template2");
+    when(permissionDao.selectAllPermissionTemplates()).thenReturn(Lists.newArrayList(template1, template2));
+
+    permissionTemplateService.updatePermissionTemplate(1L, "template1", "new_description");
+
+    verify(permissionDao).updatePermissionTemplate(1L, "template1", "new_description");
+  }
+
   @Test
   public void should_add_user_permission() throws Exception {
     UserDto userDto = new UserDto().setId(1L).setLogin("user").setName("user");