</select>
<select id="selectByName" parameterType="String" resultType="PermissionTemplate">
- SELECT id, name, description, created_at AS createdAt, updated_at AS updatedAt
+ SELECT id, name, kee, description, created_at AS createdAt, updated_at AS updatedAt
FROM permission_templates
WHERE name = #{templateName}
</select>
<select id="selectAllPermissionTemplates" resultType="PermissionTemplate">
- SELECT id, name, description, created_at AS createdAt, updated_at AS updatedAt
+ SELECT id, name, kee, description, created_at AS createdAt, updated_at AS updatedAt
FROM permission_templates
</select>
assertThat(permissionTemplate).isNotNull();
assertThat(permissionTemplate.getName()).isEqualTo("my template");
+ assertThat(permissionTemplate.getKee()).isEqualTo("my_template_20130102_030405");
assertThat(permissionTemplate.getDescription()).isEqualTo("my description");
assertThat(permissionTemplate.getUsersPermissions()).hasSize(3);
assertThat(permissionTemplate.getUsersPermissions()).onProperty("userId").containsOnly(1L, 2L, 1L);
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_id() throws Exception {
+ public void should_select_permission_template_by_key() throws Exception {
setupData("selectPermissionTemplate");
PermissionTemplateDto permissionTemplate = permissionDao.selectTemplateByKey("my_template_20130102_030405");
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");
}
assertThat(permissionTemplates).hasSize(3);
assertThat(permissionTemplates).onProperty("id").containsOnly(1L, 2L, 3L);
assertThat(permissionTemplates).onProperty("name").containsOnly("template1", "template2", "template3");
+ assertThat(permissionTemplates).onProperty("kee").containsOnly("template1_20130102_030405", "template2_20130102_030405", "template3_20130102_030405");
assertThat(permissionTemplates).onProperty("description").containsOnly("description1", "description2", "description3");
}
<dataset>
- <permission_templates id="1" name="template1" kee="my_template_20130102_030405" description="description1" created_at="[null]" updated_at="[null]"/>
- <permission_templates id="2" name="template2" kee="my_template_20130102_030405" description="description2" created_at="[null]" updated_at="[null]"/>
- <permission_templates id="3" name="template3" kee="my_template_20130102_030405" description="description3" created_at="[null]" updated_at="[null]"/>
+ <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]"/>
+ <permission_templates id="3" name="template3" kee="template3_20130102_030405" description="description3" created_at="[null]" updated_at="[null]"/>
</dataset>
\ No newline at end of file
private final Long id;
private final String name;
+ private final String key;
private final String description;
private Multimap<String, PermissionTemplateUser> usersByPermission;
private Multimap<String, PermissionTemplateGroup> groupsByPermission;
- private PermissionTemplate(Long id, String name, String description) {
+ private PermissionTemplate(Long id, String name, String key, String description) {
this.id = id;
this.name = name;
+ this.key = key;
this.description = description;
usersByPermission = HashMultimap.create();
groupsByPermission = HashMultimap.create();
if(permissionTemplateDto == null) {
return null;
}
- PermissionTemplate permissionTemplate =
- new PermissionTemplate(permissionTemplateDto.getId(), permissionTemplateDto.getName(), permissionTemplateDto.getDescription());
+ PermissionTemplate permissionTemplate = new PermissionTemplate(
+ permissionTemplateDto.getId(), permissionTemplateDto.getName(), permissionTemplateDto.getKee(), permissionTemplateDto.getDescription());
List<PermissionTemplateUserDto> usersPermissions = permissionTemplateDto.getUsersPermissions();
if(usersPermissions != null) {
return description;
}
+ public String getKey() {
+ return key;
+ }
+
public List<PermissionTemplateUser> getUsersForPermission(String permission) {
return ImmutableList.copyOf(usersByPermission.get(permission));
}
} else {
GroupDto groupDto = userDao.selectGroupByName(groupName);
if(groupDto != null) {
- groupId = userDao.selectGroupByName(groupName).getId();
+ groupId = groupDto.getId();
} else {
throw new IllegalArgumentException("Cannot setup default permission for group: " + groupName);
}
templates_names.each do |template_name|
permission_template = Internal.permission_templates.selectPermissionTemplate(template_name)
@permission_templates << permission_template
- @permission_templates_options << [permission_template.name, permission_template.id.to_s]
+ @permission_templates_options << [permission_template.name, permission_template.key]
end
@root_qualifiers = get_root_qualifiers
#
def update_users_permissions
verify_post_request
- require_parameters :id, :name, :permission
+ require_parameters :name, :permission
@permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name])
#
def update_groups_permissions
verify_post_request
- require_parameters :id, :name, :permission
+ require_parameters :name, :permission
@permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name])
:id => "selectg-codeviewer-#{u permission_template.name}", :class => 'open-modal link-action', 'modal-width' => '760px' %>)
</td>
<td>
- <% if @default_templates.values.include?(permission_template.id.to_s)
- qualifier = @default_templates.invert[permission_template.id.to_s]
+ <% qualifiers = []
+ @default_templates.each_pair do |q, t|
+ qualifiers << q if t == permission_template.key
+ end
+ if qualifiers.length > 0
%>
- <%= image_tag 'tick.png', :id => "is_active_#{u permission_template.name}" %><span class="small gray">(Default for <%= message('qualifier.' + qualifier) %>)</span>
+ <%= image_tag 'tick.png', :id => "is_active_#{u permission_template.name}" %><span class="small gray">(Default for <%= qualifiers.collect {|q| message('qualifier.' + q)}.join(',') %>)</span>
<% end %>
</td>
<td align="right">
:id => "edit-template-#{u permission_template.name}", :class => 'open-modal link-action' %>
</td>
<td align="right">
- <% unless @default_templates.values.include?(permission_template.id.to_s) %>
+ <% 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' %>
<% end %>
PermissionTemplateDto permissionTemplateDto = new PermissionTemplateDto()
.setId(1L)
.setName("name")
+ .setKee("key")
.setDescription("description")
.setUsersPermissions(Lists.newArrayList(
new PermissionTemplateUserDto().setId(1L).setUserId(1L).setUserName("user1").setUserLogin("login1").setPermission("permission1"),
assertThat(permissionTemplate.getId()).isEqualTo(1L);
assertThat(permissionTemplate.getName()).isEqualTo("name");
+ assertThat(permissionTemplate.getKey()).isEqualTo("key");
assertThat(permissionTemplate.getDescription()).isEqualTo("description");
assertThat(permissionTemplate.getUsersForPermission("unmatchedPermission")).isEmpty();
assertThat(permissionTemplate.getUsersForPermission("permission1")).onProperty("userName").containsOnly("user1", "user2");