From 714cede3e2bd0d24d8db16b3a5abfad718c2d5bb Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 11 Sep 2017 04:19:16 +0200 Subject: [PATCH] Improved direct group assignment for agents. --- .../_ui_element/user_permission.coffee | 13 ++++- .../javascripts/app/models/group.coffee | 1 - .../app/views/generic/user_permission.jst.eco | 50 +------------------ .../generic/user_permission_group.jst.eco | 29 +++++++++++ 4 files changed, 41 insertions(+), 52 deletions(-) create mode 100644 app/assets/javascripts/app/views/generic/user_permission_group.jst.eco diff --git a/app/assets/javascripts/app/controllers/_ui_element/user_permission.coffee b/app/assets/javascripts/app/controllers/_ui_element/user_permission.coffee index 79cd7215e..2b89a3bd0 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/user_permission.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/user_permission.coffee @@ -67,9 +67,14 @@ class App.UiElement.user_permission item = $( App.view('generic/user_permission')( attribute: attribute roles: roles - groups: groups params: params rolesSelected: rolesSelected + ) ) + + item.find('.js-groups').html(App.view('generic/user_permission_group')( + attribute: attribute + groups: groups + params: params groupsSelected: groupsSelected hideGroups: hideGroups groupAccesses: App.Group.accesses() @@ -101,7 +106,11 @@ class App.UiElement.user_permission # if role with groups plugin is deselected, hide group selection if !checked - if rolesWithGroupPlugin[role_id] is 'group' + show = false + for role_id, group of rolesWithGroupPlugin + if item.find("[name=role_ids][value=#{role_id}]").prop('checked') + show = true + if !show item.find('.js-groupList').addClass('hidden') # select groups if only one is available diff --git a/app/assets/javascripts/app/models/group.coffee b/app/assets/javascripts/app/models/group.coffee index e58634828..2812b0b92 100644 --- a/app/assets/javascripts/app/models/group.coffee +++ b/app/assets/javascripts/app/models/group.coffee @@ -40,6 +40,5 @@ class App.Group extends App.Model read: 'Read' create: 'Create' change: 'Change' - delete: 'Delete' overview: 'Overview' full: 'Full' diff --git a/app/assets/javascripts/app/views/generic/user_permission.jst.eco b/app/assets/javascripts/app/views/generic/user_permission.jst.eco index 64569a55d..0f769be2f 100644 --- a/app/assets/javascripts/app/views/generic/user_permission.jst.eco +++ b/app/assets/javascripts/app/views/generic/user_permission.jst.eco @@ -1,18 +1,4 @@
-<% showGroups = false %> -<% for role in @roles: %> -<% if role.permissions: %> -<% for permission in role.permissions: %> -<% if _.contains(permission.preferences.plugin, 'groups'): %> -<% if showGroups is true: %> -<% showGroups = false %> -<% break %> -<% end %> -<% showGroups = true %> -<% end %> -<% end %> -<% end %> -<% end %> <% for role in @roles: %> - <% if role.permissions: %> - <% for permission in role.permissions: %> - <% if showGroups is true && _.contains(permission.preferences.plugin, 'groups'): %> -
- - - - <% for group in @groups: %> - <% permissions = [] %> - <% if @params.group_ids && @params.group_ids[group.id]: %> - <% permissions = @params.group_ids[group.id] %> - <% end %> - - - <% end %> -
<%- @T('Group') %> - <% for key, text of @groupAccesses: %> - <%- @T(text) %> - <% end %> -
- <%= group.displayName() %> - <% for key, text of @groupAccesses: %> - - - <% end %> -
-
- <% break %> - <% end %> - <% end %> - <% end %> <% end %> +
diff --git a/app/assets/javascripts/app/views/generic/user_permission_group.jst.eco b/app/assets/javascripts/app/views/generic/user_permission_group.jst.eco new file mode 100644 index 000000000..5da89be33 --- /dev/null +++ b/app/assets/javascripts/app/views/generic/user_permission_group.jst.eco @@ -0,0 +1,29 @@ +
+
+ + + + <% for group in @groups: %> + <% permissions = [] %> + <% if @params.group_ids && @params.group_ids[group.id]: %> + <% permissions = @params.group_ids[group.id] %> + <% end %> + + + <% end %> +
<%- @T('Group') %> + <% for key, text of @groupAccesses: %> + <%- @T(text) %> + <% end %> +
+ <%= group.displayName() %> + <% for key, text of @groupAccesses: %> + + + <% end %> +
+