summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2013-12-05 17:16:52 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2013-12-05 17:21:09 +0100
commit50673979b7ce6b337e9b87d3a4e0cd74a5789bc6 (patch)
tree0c2827410dd4f0d218a3410df20d48a2db445e53
parent0229a6a9e46062d0795e1086468b1d6e2d48c257 (diff)
downloadsonarqube-50673979b7ce6b337e9b87d3a4e0cd74a5789bc6.tar.gz
sonarqube-50673979b7ce6b337e9b87d3a4e0cd74a5789bc6.zip
SONAR-4941 Replace usage of template name by template key
-rw-r--r--sonar-core/src/main/java/org/sonar/core/permission/PermissionFacade.java8
-rw-r--r--sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDao.java19
-rw-r--r--sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateMapper.java6
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml10
-rw-r--r--sonar-core/src/test/java/org/sonar/core/permission/PermissionFacadeTest.java6
-rw-r--r--sonar-core/src/test/java/org/sonar/core/permission/PermissionTemplateDaoTest.java22
-rw-r--r--sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java20
-rw-r--r--sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateUpdater.java14
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/permission_templates_controller.rb30
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_edit_groups.html.erb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_edit_users.html.erb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/index.html.erb22
-rw-r--r--sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionTemplateServiceTest.java48
-rw-r--r--sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateUpdaterTest.java12
14 files changed, 91 insertions, 130 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionFacade.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionFacade.java
index 1391310b5c7..670a4db7385 100644
--- a/sonar-core/src/main/java/org/sonar/core/permission/PermissionFacade.java
+++ b/sonar-core/src/main/java/org/sonar/core/permission/PermissionFacade.java
@@ -30,11 +30,7 @@ import org.sonar.api.task.TaskComponent;
import org.sonar.core.persistence.MyBatis;
import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceDto;
-import org.sonar.core.user.GroupDto;
-import org.sonar.core.user.GroupRoleDto;
-import org.sonar.core.user.RoleDao;
-import org.sonar.core.user.UserDao;
-import org.sonar.core.user.UserRoleDto;
+import org.sonar.core.user.*;
import javax.annotation.Nullable;
@@ -163,7 +159,7 @@ public class PermissionFacade implements TaskComponent, ServerComponent {
if (permissionTemplateDto == null) {
throw new IllegalArgumentException("Could not retrieve permission template with key " + templateKey);
}
- PermissionTemplateDto templateWithPermissions = permissionTemplateDao.selectPermissionTemplate(permissionTemplateDto.getName());
+ PermissionTemplateDto templateWithPermissions = permissionTemplateDao.selectPermissionTemplate(permissionTemplateDto.getKee());
if (templateWithPermissions == null) {
throw new IllegalArgumentException("Could not retrieve permissions for template with key " + templateKey);
}
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 72262d4052b..300d7579fe7 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
@@ -75,17 +75,6 @@ public class PermissionTemplateDao implements TaskComponent, ServerComponent {
}
@CheckForNull
- public PermissionTemplateDto selectTemplateByName(String templateName) {
- SqlSession session = myBatis.openSession();
- try {
- PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
- return mapper.selectByName(templateName);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- @CheckForNull
public PermissionTemplateDto selectTemplateByKey(String templateKey) {
SqlSession session = myBatis.openSession();
try {
@@ -97,17 +86,17 @@ public class PermissionTemplateDao implements TaskComponent, ServerComponent {
}
@CheckForNull
- public PermissionTemplateDto selectPermissionTemplate(String templateName) {
+ public PermissionTemplateDto selectPermissionTemplate(String templateKey) {
PermissionTemplateDto permissionTemplate = null;
SqlSession session = myBatis.openSession();
try {
PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
- permissionTemplate = mapper.selectByName(templateName);
- PermissionTemplateDto templateUsersPermissions = mapper.selectTemplateUsersPermissions(templateName);
+ permissionTemplate = mapper.selectByKey(templateKey);
+ PermissionTemplateDto templateUsersPermissions = mapper.selectTemplateUsersPermissions(templateKey);
if (templateUsersPermissions != null) {
permissionTemplate.setUsersPermissions(templateUsersPermissions.getUsersPermissions());
}
- PermissionTemplateDto templateGroupsPermissions = mapper.selectTemplateGroupsPermissions(templateName);
+ PermissionTemplateDto templateGroupsPermissions = mapper.selectTemplateGroupsPermissions(templateKey);
if (templateGroupsPermissions != null) {
permissionTemplate.setGroupsByPermission(templateGroupsPermissions.getGroupsPermissions());
}
diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateMapper.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateMapper.java
index 68073023046..c115e289050 100644
--- a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateMapper.java
@@ -35,13 +35,11 @@ public interface PermissionTemplateMapper {
void deleteGroupsPermissions(Long templateId);
- PermissionTemplateDto selectByName(String templateName);
-
PermissionTemplateDto selectByKey(String templateKey);
- PermissionTemplateDto selectTemplateUsersPermissions(String templateName);
+ PermissionTemplateDto selectTemplateUsersPermissions(String templateKey);
- PermissionTemplateDto selectTemplateGroupsPermissions(String templateName);
+ PermissionTemplateDto selectTemplateGroupsPermissions(String templateKey);
void insertUserPermission(PermissionTemplateUserDto permissionTemplateUser);
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 7cf029510c1..f6461371b30 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
@@ -89,12 +89,6 @@
WHERE kee = #{kee}
</select>
- <select id="selectByName" parameterType="String" resultType="PermissionTemplate">
- 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, key_pattern AS keyPattern, created_at AS createdAt, updated_at AS updatedAt
FROM permission_templates
@@ -115,7 +109,7 @@
FROM permission_templates pt
INNER JOIN perm_templates_users ptu ON ptu.template_id = pt.id
INNER JOIN users u ON u.id = ptu.user_id AND u.active = ${_true}
- WHERE pt.name = #{templateName}
+ WHERE pt.kee = #{templateKey}
</select>
<select id="selectTemplateGroupsPermissions" parameterType="String" resultMap="fullPermissionsTemplateResult">
@@ -132,7 +126,7 @@
FROM permission_templates pt
INNER JOIN perm_templates_groups ptg ON ptg.template_id = pt.id
LEFT OUTER JOIN groups g ON g.id = ptg.group_id
- WHERE pt.name = #{templateName}
+ WHERE pt.kee = #{templateKey}
AND (g.name IS NOT NULL OR ptg.group_id IS NULL)
</select>
diff --git a/sonar-core/src/test/java/org/sonar/core/permission/PermissionFacadeTest.java b/sonar-core/src/test/java/org/sonar/core/permission/PermissionFacadeTest.java
index c64e2bfedea..93bd6cfa44f 100644
--- a/sonar-core/src/test/java/org/sonar/core/permission/PermissionFacadeTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/permission/PermissionFacadeTest.java
@@ -160,11 +160,11 @@ public class PermissionFacadeTest extends AbstractDaoTestCase {
@Test
public void should_retrieve_permission_template() throws Exception {
- PermissionTemplateDto permissionTemplateDto = new PermissionTemplateDto().setName("Test template");
- PermissionTemplateDto templateWithPermissions = new PermissionTemplateDto();
+ PermissionTemplateDto permissionTemplateDto = new PermissionTemplateDto().setName("Test template").setKee("test_template");
+ PermissionTemplateDto templateWithPermissions = new PermissionTemplateDto().setKee("test_template");
permissionTemplateDao = mock(PermissionTemplateDao.class);
when(permissionTemplateDao.selectTemplateByKey("test_template")).thenReturn(permissionTemplateDto);
- when(permissionTemplateDao.selectPermissionTemplate("Test template")).thenReturn(templateWithPermissions);
+ when(permissionTemplateDao.selectPermissionTemplate("test_template")).thenReturn(templateWithPermissions);
permissionFacade = new PermissionFacade(null, null, null, null, permissionTemplateDao, null);
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 652ecfca7d1..53daae1c564 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,10 +33,7 @@ import java.util.Date;
import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.stub;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
public class PermissionTemplateDaoTest extends AbstractDaoTestCase {
@@ -93,7 +90,7 @@ public class PermissionTemplateDaoTest extends AbstractDaoTestCase {
@Test
public void should_select_permission_template() throws Exception {
setupData("selectPermissionTemplate");
- PermissionTemplateDto permissionTemplate = permissionTemplateDao.selectPermissionTemplate("my template");
+ PermissionTemplateDto permissionTemplate = permissionTemplateDao.selectPermissionTemplate("my_template_20130102_030405");
assertThat(permissionTemplate).isNotNull();
assertThat(permissionTemplate.getName()).isEqualTo("my template");
@@ -113,7 +110,7 @@ public class PermissionTemplateDaoTest extends AbstractDaoTestCase {
@Test
public void should_select_empty_permission_template() throws Exception {
setupData("selectEmptyPermissionTemplate");
- PermissionTemplateDto permissionTemplate = permissionTemplateDao.selectPermissionTemplate("my template");
+ PermissionTemplateDto permissionTemplate = permissionTemplateDao.selectPermissionTemplate("my_template_20130102_030405");
assertThat(permissionTemplate).isNotNull();
assertThat(permissionTemplate.getName()).isEqualTo("my template");
@@ -123,19 +120,6 @@ public class PermissionTemplateDaoTest extends AbstractDaoTestCase {
}
@Test
- public void should_select_permission_template_by_name() throws Exception {
- setupData("selectPermissionTemplate");
-
- PermissionTemplateDto permissionTemplate = permissionTemplateDao.selectTemplateByName("my template");
-
- assertThat(permissionTemplate).isNotNull();
- assertThat(permissionTemplate.getId()).isEqualTo(1L);
- assertThat(permissionTemplate.getName()).isEqualTo("my template");
- assertThat(permissionTemplate.getKee()).isEqualTo("my_template_20130102_030405");
- assertThat(permissionTemplate.getDescription()).isEqualTo("my description");
- }
-
- @Test
public void should_select_permission_template_by_key() throws Exception {
setupData("selectPermissionTemplate");
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 c8ba6ecd719..da382dfeefc 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
@@ -61,9 +61,9 @@ public class InternalPermissionTemplateService implements ServerComponent {
}
@CheckForNull
- public PermissionTemplate selectPermissionTemplate(String templateName) {
+ public PermissionTemplate selectPermissionTemplate(String templateKey) {
PermissionTemplateUpdater.checkSystemAdminUser();
- PermissionTemplateDto permissionTemplateDto = permissionTemplateDao.selectPermissionTemplate(templateName);
+ PermissionTemplateDto permissionTemplateDto = permissionTemplateDao.selectPermissionTemplate(templateKey);
return PermissionTemplate.create(permissionTemplateDto);
}
@@ -108,8 +108,8 @@ public class InternalPermissionTemplateService implements ServerComponent {
permissionTemplateDao.deletePermissionTemplate(templateId);
}
- public void addUserPermission(String templateName, String permission, String userLogin) {
- PermissionTemplateUpdater updater = new PermissionTemplateUpdater(templateName, permission, userLogin, permissionTemplateDao, userDao) {
+ public void addUserPermission(String templateKey, String permission, String userLogin) {
+ PermissionTemplateUpdater updater = new PermissionTemplateUpdater(templateKey, permission, userLogin, permissionTemplateDao, userDao) {
@Override
protected void doExecute(Long templateId, String permission) {
Long userId = getUserId();
@@ -119,8 +119,8 @@ public class InternalPermissionTemplateService implements ServerComponent {
updater.executeUpdate();
}
- public void removeUserPermission(String templateName, String permission, String userLogin) {
- PermissionTemplateUpdater updater = new PermissionTemplateUpdater(templateName, permission, userLogin, permissionTemplateDao, userDao) {
+ public void removeUserPermission(String templateKey, String permission, String userLogin) {
+ PermissionTemplateUpdater updater = new PermissionTemplateUpdater(templateKey, permission, userLogin, permissionTemplateDao, userDao) {
@Override
protected void doExecute(Long templateId, String permission) {
Long userId = getUserId();
@@ -130,8 +130,8 @@ public class InternalPermissionTemplateService implements ServerComponent {
updater.executeUpdate();
}
- public void addGroupPermission(String templateName, String permission, String groupName) {
- PermissionTemplateUpdater updater = new PermissionTemplateUpdater(templateName, permission, groupName, permissionTemplateDao, userDao) {
+ public void addGroupPermission(String templateKey, String permission, String groupName) {
+ PermissionTemplateUpdater updater = new PermissionTemplateUpdater(templateKey, permission, groupName, permissionTemplateDao, userDao) {
@Override
protected void doExecute(Long templateId, String permission) {
Long groupId = getGroupId();
@@ -141,8 +141,8 @@ public class InternalPermissionTemplateService implements ServerComponent {
updater.executeUpdate();
}
- public void removeGroupPermission(String templateName, String permission, String groupName) {
- PermissionTemplateUpdater updater = new PermissionTemplateUpdater(templateName, permission, groupName, permissionTemplateDao, userDao) {
+ public void removeGroupPermission(String templateKey, String permission, String groupName) {
+ PermissionTemplateUpdater updater = new PermissionTemplateUpdater(templateKey, permission, groupName, permissionTemplateDao, userDao) {
@Override
protected void doExecute(Long templateId, String permission) {
Long groupId = getGroupId();
diff --git a/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateUpdater.java b/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateUpdater.java
index 021bcdbde7b..022692a29ee 100644
--- a/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateUpdater.java
+++ b/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateUpdater.java
@@ -37,14 +37,14 @@ import javax.annotation.Nullable;
abstract class PermissionTemplateUpdater {
- private final String templateName;
+ private final String templateKey;
private final String permission;
private final String updatedReference;
private final PermissionTemplateDao permissionTemplateDao;
private final UserDao userDao;
- PermissionTemplateUpdater(String templateName, String permission, String updatedReference, PermissionTemplateDao permissionTemplateDao, UserDao userDao) {
- this.templateName = templateName;
+ PermissionTemplateUpdater(String templateKey, String permission, String updatedReference, PermissionTemplateDao permissionTemplateDao, UserDao userDao) {
+ this.templateKey = templateKey;
this.permission = permission;
this.updatedReference = updatedReference;
this.permissionTemplateDao = permissionTemplateDao;
@@ -53,7 +53,7 @@ abstract class PermissionTemplateUpdater {
void executeUpdate() {
checkSystemAdminUser();
- Long templateId = getTemplateId(templateName);
+ Long templateId = getTemplateId(templateKey);
validatePermission(permission);
doExecute(templateId, permission);
}
@@ -101,10 +101,10 @@ abstract class PermissionTemplateUpdater {
}
}
- private Long getTemplateId(String name) {
- PermissionTemplateDto permissionTemplateDto = permissionTemplateDao.selectTemplateByName(name);
+ private Long getTemplateId(String key) {
+ PermissionTemplateDto permissionTemplateDto = permissionTemplateDao.selectTemplateByKey(key);
if (permissionTemplateDto == null) {
- throw new BadRequestException("Unknown template: " + name);
+ throw new BadRequestException("Unknown template: " + key);
}
return permissionTemplateDto.getId();
}
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 a9fcf669e14..0e138f5bac4 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
@@ -73,7 +73,7 @@ class PermissionTemplatesController < ApplicationController
#
def edit_users
@permission = params[:permission]
- @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name])
+ @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:key])
@users_with_permission = @permission_template.getUsersForPermission(params[:permission]).collect {|u| [u.userName, u.userLogin]}
@users_without_permission = all_users.each.collect {|u| [u.name, u.login]} - @users_with_permission
@@ -85,7 +85,7 @@ class PermissionTemplatesController < ApplicationController
#
def edit_groups
@permission = params[:permission]
- @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name])
+ @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:key])
@groups_with_permission = @permission_template.getGroupsForPermission(params[:permission]).collect {|g| [group_ref(g.groupName), group_ref(g.groupName)]}
@groups_without_permission = all_groups.each.collect {|g| g.nil? ? ['Anyone', 'Anyone'] : [g.name, g.name]} - @groups_with_permission
@@ -97,9 +97,9 @@ class PermissionTemplatesController < ApplicationController
#
def update_users_permissions
verify_post_request
- require_parameters :name, :permission
+ require_parameters :key, :permission
- @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name])
+ @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:key])
selected_users = params[:users] || []
@@ -110,11 +110,11 @@ class PermissionTemplatesController < ApplicationController
demoted_users = previous_users_with_permission - new_users_with_permission
promoted_users.each do |user|
- Internal.permission_templates.addUserPermission(params[:name], params[:permission], user[1])
+ Internal.permission_templates.addUserPermission(params[:key], params[:permission], user[1])
end
demoted_users.each do |user|
- Internal.permission_templates.removeUserPermission(params[:name], params[:permission], user[1])
+ Internal.permission_templates.removeUserPermission(params[:key], params[:permission], user[1])
end
redirect_to :action => 'index'
@@ -125,9 +125,9 @@ class PermissionTemplatesController < ApplicationController
#
def update_groups_permissions
verify_post_request
- require_parameters :name, :permission
+ require_parameters :key, :permission
- @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name])
+ @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:key])
selected_groups = params[:groups] || []
@@ -138,11 +138,11 @@ class PermissionTemplatesController < ApplicationController
demoted_groups = previous_groups_with_permission - new_groups_with_permission
promoted_groups.each do |group|
- Internal.permission_templates.addGroupPermission(params[:name], params[:permission], group[1])
+ Internal.permission_templates.addGroupPermission(params[:key], params[:permission], group[1])
end
demoted_groups.each do |group|
- Internal.permission_templates.removeGroupPermission(params[:name], params[:permission], group[1])
+ Internal.permission_templates.removeGroupPermission(params[:key], params[:permission], group[1])
end
redirect_to :action => 'index'
@@ -169,7 +169,7 @@ class PermissionTemplatesController < ApplicationController
# GET (modal form)
#
def edit_form
- @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name])
+ @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:key])
render :partial => 'permission_templates/permission_template_form',
:locals => {:form_action => 'edit', :message_title => 'edit_template', :message_submit => 'update_template'}
end
@@ -188,7 +188,7 @@ class PermissionTemplatesController < ApplicationController
# GET (modal form)
#
def delete_form
- @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name])
+ @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:key])
render :partial => 'permission_templates/delete_form'
end
@@ -247,10 +247,10 @@ class PermissionTemplatesController < ApplicationController
end
def get_templates_and_permissions(permission_templates)
- templates_names = permission_templates.collect {|t| t.name}
+ templates_keys = permission_templates.collect {|t| t.key}
permission_templates = []
- templates_names.each do |template_name|
- permission_templates << Internal.permission_templates.selectPermissionTemplate(template_name)
+ templates_keys.each do |template_key|
+ permission_templates << Internal.permission_templates.selectPermissionTemplate(template_key)
end
permission_templates.sort_by {|t| t.name.downcase}
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_edit_groups.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_edit_groups.html.erb
index adc6dd84b3b..dc5afb4028c 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_edit_groups.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_edit_groups.html.erb
@@ -1,6 +1,6 @@
<form id="permission-template-form" method="post" action="<%= ApplicationController.root_context -%>/permission_templates/update_groups_permissions">
<input type="hidden" name="id" value="<%= @permission_template.id -%>">
- <input type="hidden" name="name" value="<%= @permission_template.name -%>">
+ <input type="hidden" name="key" value="<%= @permission_template.key -%>">
<input type="hidden" name="permission" value="<%= @permission -%>"/>
<fieldset>
<div class="modal-head">
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_edit_users.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_edit_users.html.erb
index be35ff88538..48f94171689 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_edit_users.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_edit_users.html.erb
@@ -1,6 +1,6 @@
<form id="permission-template-form" method="post" action="<%= ApplicationController.root_context -%>/permission_templates/update_users_permissions">
<input type="hidden" name="id" value="<%= @permission_template.id -%>">
- <input type="hidden" name="name" value="<%= @permission_template.name -%>">
+ <input type="hidden" name="key" value="<%= @permission_template.key -%>">
<input type="hidden" name="permission" value="<%= @permission -%>"/>
<fieldset>
<div class="modal-head">
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
index 5423fef7552..ee5f3b17d68 100644
--- 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
@@ -56,16 +56,16 @@
users=Api::Utils.insensitive_sort(permission_template.getUsersForPermission(permission).collect {|u| u.userName})
groups=Api::Utils.insensitive_sort(permission_template.getGroupsForPermission(permission).collect {|g| g.groupName.blank? ? 'Anyone' : g.groupName})
%>
- <span id="u-<%= permission -%>-<%= u permission_template.name -%>"><%= users.join(', ') %></span>
- (<%= link_to message('select users'), {:action => :edit_users, :name => permission_template.name, :permission => permission},
- :id => "select-u-#{permission}-#{u permission_template.name}", :class => 'open-modal link-action nowrap', 'modal-width' => '780px' %>)<br/>
- <span id="g-<%= permission -%>-<%= u permission_template.name -%>"><%= groups.join(', ') %></span>
- (<%= link_to message('select groups'), {:action => :edit_groups, :name => permission_template.name, :permission => permission},
- :id => "select-g-#{permission}-#{u permission_template.name}", :class => 'open-modal link-action nowrap', 'modal-width' => '780px' %>)<br/>
+ <span id="u-<%= permission -%>-<%= u permission_template.key -%>"><%= users.join(', ') %></span>
+ (<%= link_to message('select users'), {:action => :edit_users, :key => permission_template.key, :permission => permission},
+ :id => "select-u-#{permission}-#{u permission_template.key}", :class => 'open-modal link-action nowrap', 'modal-width' => '780px' %>)<br/>
+ <span id="g-<%= permission -%>-<%= u permission_template.key -%>"><%= groups.join(', ') %></span>
+ (<%= link_to message('select groups'), {:action => :edit_groups, :key => permission_template.key, :permission => permission},
+ :id => "select-g-#{permission}-#{u permission_template.key}", :class => 'open-modal link-action nowrap', 'modal-width' => '780px' %>)<br/>
</td>
<% end %>
<td>
- <span id="<%= "key-pattern-#{u permission_template.name}" %>">
+ <span id="<%= "key-pattern-#{u permission_template.key}" %>">
<%= permission_template.key_pattern -%>
</span>
<% qualifiers = []
@@ -81,13 +81,13 @@
<% end %>
</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' %>
+ <%= link_to message('edit'), {:action => :edit_form, :key => permission_template.key},
+ :id => "edit-template-#{u permission_template.key}", :class => 'open-modal link-action' %>
</td>
<td align="right">
<% unless @default_templates.values.include?(permission_template.key) %>
- <%= link_to message('delete'), {:action => :delete_form, :name => permission_template.name},
- :id => "delete-template-#{u permission_template.name}", :class => 'open-modal link-action link-red' %>
+ <%= link_to message('delete'), {:action => :delete_form, :key => permission_template.key},
+ :id => "delete-template-#{u permission_template.key}", :class => 'open-modal link-action link-red' %>
<% end %>
</td>
</tr>
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 3b9426dd07f..280dae44e72 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
@@ -46,12 +46,12 @@ import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
public class InternalPermissionTemplateServiceTest {
- private static final String DEFAULT_NAME = "my template";
+ private static final String DEFAULT_KEY = "my_template";
private static final String DEFAULT_DESC = "my description";
private static final String DEFAULT_PATTERN = "com.foo.(.*)";
private static final String DEFAULT_PERMISSION = UserRole.USER;
private static final PermissionTemplateDto DEFAULT_TEMPLATE =
- new PermissionTemplateDto().setId(1L).setName(DEFAULT_NAME).setDescription(DEFAULT_DESC).setKeyPattern(DEFAULT_PATTERN);
+ new PermissionTemplateDto().setId(1L).setName(DEFAULT_KEY).setDescription(DEFAULT_DESC).setKeyPattern(DEFAULT_PATTERN);
@Mock
PermissionTemplateDao permissionTemplateDao;
@@ -93,12 +93,12 @@ public class InternalPermissionTemplateServiceTest {
@Test
public void should_create_permission_template() throws Exception {
- when(permissionTemplateDao.createPermissionTemplate(DEFAULT_NAME, DEFAULT_DESC, DEFAULT_PATTERN)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.createPermissionTemplate(DEFAULT_KEY, DEFAULT_DESC, DEFAULT_PATTERN)).thenReturn(DEFAULT_TEMPLATE);
- PermissionTemplate permissionTemplate = service.createPermissionTemplate(DEFAULT_NAME, DEFAULT_DESC, DEFAULT_PATTERN);
+ PermissionTemplate permissionTemplate = service.createPermissionTemplate(DEFAULT_KEY, DEFAULT_DESC, DEFAULT_PATTERN);
assertThat(permissionTemplate.getId()).isEqualTo(1L);
- assertThat(permissionTemplate.getName()).isEqualTo(DEFAULT_NAME);
+ assertThat(permissionTemplate.getName()).isEqualTo(DEFAULT_KEY);
assertThat(permissionTemplate.getDescription()).isEqualTo(DEFAULT_DESC);
assertThat(permissionTemplate.getKeyPattern()).isEqualTo(DEFAULT_PATTERN);
}
@@ -110,7 +110,7 @@ public class InternalPermissionTemplateServiceTest {
when(permissionTemplateDao.selectAllPermissionTemplates()).thenReturn(Lists.newArrayList(DEFAULT_TEMPLATE));
- service.createPermissionTemplate(DEFAULT_NAME, DEFAULT_DESC, null);
+ service.createPermissionTemplate(DEFAULT_KEY, DEFAULT_DESC, null);
}
@Test
@@ -126,12 +126,12 @@ public class InternalPermissionTemplateServiceTest {
expected.expect(BadRequestException.class);
expected.expectMessage("Invalid pattern: [azerty. Should be a valid Java regular expression.");
- service.createPermissionTemplate(DEFAULT_NAME, DEFAULT_DESC, "[azerty");
+ service.createPermissionTemplate(DEFAULT_KEY, DEFAULT_DESC, "[azerty");
}
@Test
public void should_delete_permission_template() throws Exception {
- when(permissionTemplateDao.selectTemplateByName(DEFAULT_NAME)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.selectTemplateByKey(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
service.deletePermissionTemplate(1L);
@@ -257,9 +257,9 @@ public class InternalPermissionTemplateServiceTest {
public void should_add_user_permission() throws Exception {
UserDto userDto = new UserDto().setId(1L).setLogin("user").setName("user");
when(userDao.selectActiveUserByLogin("user")).thenReturn(userDto);
- when(permissionTemplateDao.selectTemplateByName(DEFAULT_NAME)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.selectTemplateByKey(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
- service.addUserPermission(DEFAULT_NAME, DEFAULT_PERMISSION, "user");
+ service.addUserPermission(DEFAULT_KEY, DEFAULT_PERMISSION, "user");
verify(permissionTemplateDao, times(1)).addUserPermission(1L, 1L, DEFAULT_PERMISSION);
}
@@ -269,19 +269,19 @@ public class InternalPermissionTemplateServiceTest {
expected.expect(BadRequestException.class);
expected.expectMessage("Unknown user:");
- when(permissionTemplateDao.selectTemplateByName(DEFAULT_NAME)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.selectTemplateByKey(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
when(userDao.selectActiveUserByLogin("unknown")).thenReturn(null);
- service.addUserPermission(DEFAULT_NAME, DEFAULT_PERMISSION, "unknown");
+ service.addUserPermission(DEFAULT_KEY, DEFAULT_PERMISSION, "unknown");
}
@Test
public void should_remove_user_permission() throws Exception {
UserDto userDto = new UserDto().setId(1L).setLogin("user").setName("user");
when(userDao.selectActiveUserByLogin("user")).thenReturn(userDto);
- when(permissionTemplateDao.selectTemplateByName(DEFAULT_NAME)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.selectTemplateByKey(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
- service.removeUserPermission(DEFAULT_NAME, DEFAULT_PERMISSION, "user");
+ service.removeUserPermission(DEFAULT_KEY, DEFAULT_PERMISSION, "user");
verify(permissionTemplateDao, times(1)).removeUserPermission(1L, 1L, DEFAULT_PERMISSION);
}
@@ -290,9 +290,9 @@ public class InternalPermissionTemplateServiceTest {
public void should_add_group_permission() throws Exception {
GroupDto groupDto = new GroupDto().setId(1L).setName("group");
when(userDao.selectGroupByName("group")).thenReturn(groupDto);
- when(permissionTemplateDao.selectTemplateByName(DEFAULT_NAME)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.selectTemplateByKey(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
- service.addGroupPermission(DEFAULT_NAME, DEFAULT_PERMISSION, "group");
+ service.addGroupPermission(DEFAULT_KEY, DEFAULT_PERMISSION, "group");
verify(permissionTemplateDao, times(1)).addGroupPermission(1L, 1L, DEFAULT_PERMISSION);
}
@@ -302,28 +302,28 @@ public class InternalPermissionTemplateServiceTest {
expected.expect(BadRequestException.class);
expected.expectMessage("Unknown group:");
- when(permissionTemplateDao.selectTemplateByName(DEFAULT_NAME)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.selectTemplateByKey(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
when(userDao.selectGroupByName("unknown")).thenReturn(null);
- service.addGroupPermission(DEFAULT_NAME, DEFAULT_PERMISSION, "unknown");
+ service.addGroupPermission(DEFAULT_KEY, DEFAULT_PERMISSION, "unknown");
}
@Test
public void should_remove_group_permission() throws Exception {
GroupDto groupDto = new GroupDto().setId(1L).setName("group");
when(userDao.selectGroupByName("group")).thenReturn(groupDto);
- when(permissionTemplateDao.selectTemplateByName(DEFAULT_NAME)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.selectTemplateByKey(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
- service.removeGroupPermission(DEFAULT_NAME, DEFAULT_PERMISSION, "group");
+ service.removeGroupPermission(DEFAULT_KEY, DEFAULT_PERMISSION, "group");
verify(permissionTemplateDao, times(1)).removeGroupPermission(1L, 1L, DEFAULT_PERMISSION);
}
@Test
public void should_add_permission_to_anyone_group() throws Exception {
- when(permissionTemplateDao.selectTemplateByName(DEFAULT_NAME)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.selectTemplateByKey(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
- service.addGroupPermission(DEFAULT_NAME, DEFAULT_PERMISSION, "Anyone");
+ service.addGroupPermission(DEFAULT_KEY, DEFAULT_PERMISSION, "Anyone");
verify(permissionTemplateDao).addGroupPermission(1L, null, DEFAULT_PERMISSION);
verifyZeroInteractions(userDao);
@@ -331,9 +331,9 @@ public class InternalPermissionTemplateServiceTest {
@Test
public void should_remove_permission_from_anyone_group() throws Exception {
- when(permissionTemplateDao.selectTemplateByName(DEFAULT_NAME)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.selectTemplateByKey(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
- service.removeGroupPermission(DEFAULT_NAME, DEFAULT_PERMISSION, "Anyone");
+ service.removeGroupPermission(DEFAULT_KEY, DEFAULT_PERMISSION, "Anyone");
verify(permissionTemplateDao).removeGroupPermission(1L, null, DEFAULT_PERMISSION);
verifyZeroInteractions(userDao);
diff --git a/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateUpdaterTest.java b/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateUpdaterTest.java
index f9803ecb41a..8b3c267047c 100644
--- a/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateUpdaterTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateUpdaterTest.java
@@ -60,10 +60,10 @@ public class PermissionTemplateUpdaterTest {
public void should_execute_on_valid_parameters() throws Exception {
final PermissionTemplateDao permissionTemplateDao = mock(PermissionTemplateDao.class);
- when(permissionTemplateDao.selectTemplateByName("my template")).thenReturn(new PermissionTemplateDto().setId(1L));
+ when(permissionTemplateDao.selectTemplateByKey("my_template")).thenReturn(new PermissionTemplateDto().setId(1L));
PermissionTemplateUpdater updater =
- new PermissionTemplateUpdater("my template", UserRole.USER, "user", permissionTemplateDao, userDao) {
+ new PermissionTemplateUpdater("my_template", UserRole.USER, "user", permissionTemplateDao, userDao) {
@Override
void doExecute(Long templateId, String permission) {
permissionTemplateDao.addUserPermission(1L, 1L, UserRole.USER);
@@ -80,10 +80,10 @@ public class PermissionTemplateUpdaterTest {
expected.expectMessage("Unknown template:");
final PermissionTemplateDao permissionTemplateDao = mock(PermissionTemplateDao.class);
- when(permissionTemplateDao.selectTemplateByName("my template")).thenReturn(null);
+ when(permissionTemplateDao.selectTemplateByKey("my_template")).thenReturn(null);
PermissionTemplateUpdater updater =
- new PermissionTemplateUpdater("my template", UserRole.USER, "user", permissionTemplateDao, userDao) {
+ new PermissionTemplateUpdater("my_template", UserRole.USER, "user", permissionTemplateDao, userDao) {
@Override
void doExecute(Long templateId, String permission) {
}
@@ -97,10 +97,10 @@ public class PermissionTemplateUpdaterTest {
expected.expectMessage("Invalid permission:");
final PermissionTemplateDao permissionTemplateDao = mock(PermissionTemplateDao.class);
- when(permissionTemplateDao.selectTemplateByName("my template")).thenReturn(new PermissionTemplateDto().setId(1L));
+ when(permissionTemplateDao.selectTemplateByKey("my_template")).thenReturn(new PermissionTemplateDto().setId(1L));
PermissionTemplateUpdater updater =
- new PermissionTemplateUpdater("my template", "invalid", "user", permissionTemplateDao, userDao) {
+ new PermissionTemplateUpdater("my_template", "invalid", "user", permissionTemplateDao, userDao) {
@Override
void doExecute(Long templateId, String permission) {
}