From 7e39e7ff590f355f898534988b46e7ac249bf280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marius=20B=C4=82LTEANU?= Date: Tue, 25 Jun 2024 21:44:41 +0200 Subject: [PATCH] Add bulk unlock users action. --- app/controllers/users_controller.rb | 18 +++++++++++++----- app/views/context_menus/users.html.erb | 4 ++++ config/routes.rb | 1 + 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 26e9151d9..d2ebd668d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -239,12 +239,11 @@ class UsersController < ApplicationController end def bulk_lock - @users = User.logged.where(id: params[:ids]).where.not(id: User.current) - (render_404; return) unless @users.any? + bulk_update_status(params[:ids], User::STATUS_LOCKED) + end - @users.update_all status: User::STATUS_LOCKED - flash[:notice] = l(:notice_successful_update) - redirect_to users_path + def bulk_unlock + bulk_update_status(params[:ids], User::STATUS_ACTIVE) end private @@ -261,4 +260,13 @@ class UsersController < ApplicationController rescue ActiveRecord::RecordNotFound render_404 end + + def bulk_update_status(user_ids, status) + users = User.logged.where(id: user_ids).where.not(id: User.current) + (render_404; return) unless users.any? + + users.update_all status: status + flash[:notice] = l(:notice_successful_update) + redirect_to users_path + end end diff --git a/app/views/context_menus/users.html.erb b/app/views/context_menus/users.html.erb index c47b55fd2..93fe061e6 100644 --- a/app/views/context_menus/users.html.erb +++ b/app/views/context_menus/users.html.erb @@ -25,6 +25,10 @@
  • <%= context_menu_link l(:button_lock), bulk_lock_users_path(ids: @users.map(&:id)), method: :post, class: 'icon icon-lock' %>
  • + <% else %> +
  • + <%= context_menu_link l(:button_unlock), bulk_unlock_users_path(ids: @users.map(&:id)), method: :post, class: 'icon icon-unlock' %> +
  • <% end %>
  • <%= context_menu_link l(:button_delete), diff --git a/config/routes.rb b/config/routes.rb index f7cc3ac14..563ffe1e2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -113,6 +113,7 @@ Rails.application.routes.draw do collection do delete 'bulk_destroy' post :bulk_lock + post :bulk_unlock end resources :memberships, :controller => 'principal_memberships' resources :email_addresses, :only => [:index, :create, :update, :destroy] -- 2.39.3 (Apple Git-146)