Sha256: 7102d952515164ee19757260f68c3895b16151187f37bf949545163752757ee2

Contents?: true

Size: 1.28 KB

Versions: 10

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module Renalware
  class Admin::UsersController < BaseController
    include Renalware::Concerns::Pageable

    def index
      query = params.fetch(:q, {})
      query[:s] ||= "family_name"
      search = User
        .includes(:roles)
        .where.not(username: :systemuser)
        .ransack(query)
      users = search.result(distinct: true).page(page).per(per_page)
      authorize users
      render locals: { users: users, user_search: search }
    end

    def edit
      load_user
    end

    def update
      load_user

      if update_user.call(update_params)
        redirect_to admin_users_path,
                    notice: t(".success", model_name: "user")
      else
        flash.now[:error] = t(".failed", model_name: "user")
        render :edit
      end
    end

    private

    def load_user
      @user = User.find(params[:id])
      authorize @user
    end

    def update_params
      roles = Array(Role.fetch(role_ids))
      user_params.merge(roles: roles)
    end

    def user_params
      params.require(:user).permit(:approved, :unexpire, :telephone, role_ids: [])
    end

    def role_ids
      (user_params[:role_ids] || []).reject(&:blank?)
    end

    def update_user
      @update_user ||= System::UpdateUser.new(@user)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
renalware-core-2.0.121 app/controllers/renalware/admin/users_controller.rb
renalware-core-2.0.120 app/controllers/renalware/admin/users_controller.rb
renalware-core-2.0.119 app/controllers/renalware/admin/users_controller.rb
renalware-core-2.0.118 app/controllers/renalware/admin/users_controller.rb
renalware-core-2.0.117 app/controllers/renalware/admin/users_controller.rb
renalware-core-2.0.116 app/controllers/renalware/admin/users_controller.rb
renalware-core-2.0.115 app/controllers/renalware/admin/users_controller.rb
renalware-core-2.0.113 app/controllers/renalware/admin/users_controller.rb
renalware-core-2.0.112 app/controllers/renalware/admin/users_controller.rb
renalware-core-2.0.111 app/controllers/renalware/admin/users_controller.rb