Add customizable user roles (#18641)
* Add customizable user roles * Various fixes and improvements * Add migration for old settings and fix tootctl role management
This commit is contained in:
parent
1b4054256f
commit
44b2ee3485
187 changed files with 1945 additions and 1032 deletions
37
app/views/admin/roles/_form.html.haml
Normal file
37
app/views/admin/roles/_form.html.haml
Normal file
|
@ -0,0 +1,37 @@
|
|||
= simple_form_for @role, url: @role.new_record? ? admin_roles_path : admin_role_path(@role) do |f|
|
||||
= render 'shared/error_messages', object: @role
|
||||
|
||||
- if @role.everyone?
|
||||
.flash-message.info
|
||||
= t('admin.roles.everyone_full_description_html')
|
||||
- else
|
||||
.fields-group
|
||||
= f.input :name, wrapper: :with_label
|
||||
|
||||
.fields-group
|
||||
= f.input :position, wrapper: :with_label
|
||||
|
||||
.fields-group
|
||||
= f.input :color, wrapper: :with_label, input_html: { placeholder: '#000000' }
|
||||
|
||||
%hr.spacer/
|
||||
|
||||
.fields-group
|
||||
= f.input :highlighted, wrapper: :with_label
|
||||
|
||||
%hr.spacer/
|
||||
|
||||
.field-group
|
||||
.input.with_block_label
|
||||
%label= t('simple_form.labels.user_role.permissions_as_keys')
|
||||
%span.hint= t('simple_form.hints.user_role.permissions_as_keys')
|
||||
|
||||
- (@role.everyone? ? UserRole::Flags::CATEGORIES.slice(:invites) : UserRole::Flags::CATEGORIES).each do |category, permissions|
|
||||
%h4= t(category, scope: 'admin.roles.categories')
|
||||
|
||||
= f.input :permissions_as_keys, collection: permissions, wrapper: :with_block_label, include_blank: false, label_method: lambda { |privilege| safe_join([t("admin.roles.privileges.#{privilege}"), content_tag(:span, t("admin.roles.privileges.#{privilege}_description"), class: 'hint')]) }, required: false, as: :check_boxes, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li', label: false, hint: false
|
||||
|
||||
%hr.spacer/
|
||||
|
||||
.actions
|
||||
= f.button :button, @role.new_record? ? t('admin.roles.add_new') : t('generic.save_changes'), type: :submit
|
18
app/views/admin/roles/_role.html.haml
Normal file
18
app/views/admin/roles/_role.html.haml
Normal file
|
@ -0,0 +1,18 @@
|
|||
.announcements-list__item
|
||||
= link_to edit_admin_role_path(role), class: 'announcements-list__item__title' do
|
||||
%span.user-role{ class: "user-role-#{role.id}" }
|
||||
= fa_icon 'users fw'
|
||||
|
||||
- if role.everyone?
|
||||
= t('admin.roles.everyone')
|
||||
- else
|
||||
= role.name
|
||||
|
||||
.announcements-list__item__action-bar
|
||||
.announcements-list__item__meta
|
||||
- if role.everyone?
|
||||
= t('admin.roles.everyone_full_description_html')
|
||||
- else
|
||||
= link_to t('admin.roles.assigned_users', count: role.users.count), admin_accounts_path(role_id: role.id)
|
||||
•
|
||||
%abbr{ title: role.permissions_as_keys.map { |privilege| I18n.t("admin.roles.privileges.#{privilege}") }.join(', ') }= t('admin.roles.permissions_count', count: role.permissions_as_keys.size)
|
8
app/views/admin/roles/edit.html.haml
Normal file
8
app/views/admin/roles/edit.html.haml
Normal file
|
@ -0,0 +1,8 @@
|
|||
- content_for :page_title do
|
||||
= t('admin.roles.edit', name: @role.everyone? ? t('admin.roles.everyone') : @role.name)
|
||||
|
||||
- content_for :heading_actions do
|
||||
= link_to t('admin.roles.delete'), admin_role_path(@role), method: :delete, data: { confirm: t('admin.accounts.are_you_sure') }, class: 'button button--destructive' if can?(:destroy, @role)
|
||||
|
||||
= render partial: 'form'
|
||||
|
17
app/views/admin/roles/index.html.haml
Normal file
17
app/views/admin/roles/index.html.haml
Normal file
|
@ -0,0 +1,17 @@
|
|||
- content_for :page_title do
|
||||
= t('admin.roles.title')
|
||||
|
||||
- content_for :heading_actions do
|
||||
= link_to t('admin.roles.add_new'), new_admin_role_path, class: 'button' if can?(:create, :user_role)
|
||||
|
||||
%p= t('admin.roles.description_html')
|
||||
|
||||
%hr.spacer/
|
||||
|
||||
.applications-list
|
||||
= render partial: 'role', collection: @roles.select(&:everyone?)
|
||||
|
||||
%hr.spacer/
|
||||
|
||||
.applications-list
|
||||
= render partial: 'role', collection: @roles.reject(&:everyone?)
|
4
app/views/admin/roles/new.html.haml
Normal file
4
app/views/admin/roles/new.html.haml
Normal file
|
@ -0,0 +1,4 @@
|
|||
- content_for :page_title do
|
||||
= t('admin.roles.add_new')
|
||||
|
||||
= render partial: 'form'
|
Loading…
Add table
Add a link
Reference in a new issue