Project

General

Profile

Feature #40913 » 0001-Add-bulk-unlock-users-action.patch

Marius BĂLTEANU, 2024-06-25 21:45

View differences:

app/controllers/users_controller.rb
239 239
  end
240 240

  
241 241
  def bulk_lock
242
    @users = User.logged.where(id: params[:ids]).where.not(id: User.current)
243
    (render_404; return) unless @users.any?
242
    bulk_update_status(params[:ids], User::STATUS_LOCKED)
243
  end
244 244

  
245
    @users.update_all status: User::STATUS_LOCKED
246
    flash[:notice] = l(:notice_successful_update)
247
    redirect_to users_path
245
  def bulk_unlock
246
    bulk_update_status(params[:ids], User::STATUS_ACTIVE)
248 247
  end
249 248

  
250 249
  private
......
261 260
  rescue ActiveRecord::RecordNotFound
262 261
    render_404
263 262
  end
263

  
264
  def bulk_update_status(user_ids, status)
265
    users = User.logged.where(id: user_ids).where.not(id: User.current)
266
    (render_404; return) unless users.any?
267

  
268
    users.update_all status: status
269
    flash[:notice] = l(:notice_successful_update)
270
    redirect_to users_path
271
  end
264 272
end
app/views/context_menus/users.html.erb
25 25
      <li>
26 26
        <%= context_menu_link l(:button_lock), bulk_lock_users_path(ids: @users.map(&:id)), method: :post, class: 'icon icon-lock' %>
27 27
      </li>
28
    <% else %>
29
      <li>
30
        <%= context_menu_link l(:button_unlock), bulk_unlock_users_path(ids: @users.map(&:id)), method: :post, class: 'icon icon-unlock' %>
31
      </li>
28 32
    <% end %>
29 33
    <li>
30 34
      <%= context_menu_link l(:button_delete),
config/routes.rb
113 113
    collection do
114 114
      delete 'bulk_destroy'
115 115
      post :bulk_lock
116
      post :bulk_unlock
116 117
    end
117 118
    resources :memberships, :controller => 'principal_memberships'
118 119
    resources :email_addresses, :only => [:index, :create, :update, :destroy]
(3-3/3)