From 464dd4266bdc433805010b5dca428f4cb75c2a81 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Fri, 31 Jul 2026 15:55:43 +0200 Subject: Group user accounts by role Replaces the two-way admin/user split with four groups ordered by capability: administration, Redaktion, editors, alumni. alumni takes precedence over capability in role_group, so a retired admin appears at the bottom rather than the top. Forms now offer the three roles as checkboxes rather than a single admin checkbox, with a trailing hidden blank so an empty set can be posted, and user_params permits roles only for admins. Three create buttons prefill the common combinations. --- app/views/users/_user.html.erb | 13 +++++++--- app/views/users/edit.html.erb | 14 +++++++++-- app/views/users/index.html.erb | 55 +++++++++++++++++++++++------------------- app/views/users/new.html.erb | 14 +++++++++-- app/views/users/show.html.erb | 6 +++-- 5 files changed, 67 insertions(+), 35 deletions(-) (limited to 'app/views') diff --git a/app/views/users/_user.html.erb b/app/views/users/_user.html.erb index 9c6466a2..04884be8 100644 --- a/app/views/users/_user.html.erb +++ b/app/views/users/_user.html.erb @@ -1,11 +1,16 @@ <% users.each do |user| %> <%= user.login %> - <%= link_to "show", user_path(user) %> - <% if current_user.admin? || current_user == user %> - - <%= link_to "edit", edit_user_path(user) %> + + <% if user.roles.any? %> + <%= user.role_labels.join(", ") %> + <% else %> + <%= t(".no_roles") %> + <% end %> + <%= link_to t("admin.common.show"), user_path(user) %> + <% if current_user.admin? || current_user == user %> + <%= link_to t("admin.common.edit"), edit_user_path(user) %> <%= button_to user_path(user), method: :delete, form: { data: { confirm: t(".confirm_destroy", :login => user.login) }, class: 'button_to destructive' } do %> diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 9df93815..ad2e0891 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -21,8 +21,18 @@
<%= f.password_field :password_confirmation, :autocomplete => "new-password" %>
<% if current_user.admin? %> -
<%= t("users.labels.admin") %>
-
<%= f.check_box :admin %>
+
<%= t("users.labels.roles") %>
+
+ <% User::ROLES.each do |role| %> + + <% end %> + <%= hidden_field_tag "user[roles][]", "" %> +
<% end %>
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 0a003cb1..854811a2 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,27 +1,32 @@ -

<%= t(".admins") %>

-<%= link_to new_user_path(admin: true), class: 'action_button' do %> - <%= icon("plus", library: "tabler", "aria-hidden": true) %> <%= t(".create_admin") %> -<% end %> - - - - - - - - <%= render :partial => "user", :locals => {:users => @users[:admin] ||= []} %> -
<%= t("users.labels.login") %>
+

<%= t(".title") %>

+ +

+ <% UsersController::ROLE_PRESETS.each_key do |preset| %> + <%= link_to new_user_path(:preset => preset), class: 'action_button' do %> + <%= icon("plus", library: "tabler", "aria-hidden": true) %> + <%= t(".create_#{preset}") %> + <% end %> + <% end %> +

-

<%= t(".users") %>

-<%= link_to new_user_path, class: 'action_button' do %> - <%= icon("plus", library: "tabler", "aria-hidden": true) %> <%= t(".create_user") %> +<% UsersController::GROUP_ORDER.each do |group| %> + <% members = @users[group] || [] %> +

"> + <%= t(".group_#{group}") %> + <%= members.size %> +

+ <% if members.any? %> + "> + + + + + + + + <%= render :partial => "user", :locals => { :users => members } %> +
<%= t("users.labels.login") %><%= t("users.labels.roles") %>
+ <% else %> +

<%= t(".group_empty") %>

+ <% end %> <% end %> - - - - - - - - <%= render :partial => "user", :locals => {:users => @users[:user] ||= []} %> -
<%= t("users.labels.login") %>
diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 776e6e96..8d99fd92 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -21,8 +21,18 @@
<%= t("users.labels.confirm") %>
<%= f.password_field :password_confirmation %>
-
<%= t("users.labels.admin") %>
-
<%= f.check_box :admin %>
+
<%= t("users.labels.roles") %>
+
+ <% User::ROLES.each do |role| %> + + <% end %> + <%= hidden_field_tag "user[roles][]", "" %> +
<%= f.submit t("admin.common.create") %>
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 44976800..a320e53e 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -19,7 +19,9 @@
<%= t("users.labels.email") %>
<%= @user.email %>
-
<%= t("users.labels.admin") %>
-
<%= @user.admin ? t("admin.common.yes") : t("admin.common.no") %>
+
<%= t("users.labels.roles") %>
+
+ <%= @user.roles.any? ? @user.role_labels.join(", ") : t("users.no_roles") %> +
-- cgit v1.3