2017-11-11 20:23:33 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Admin
|
|
|
|
class RolesController < BaseController
|
2022-07-05 02:41:40 +02:00
|
|
|
before_action :set_role, except: [:index, :new, :create]
|
2017-11-11 20:23:33 +01:00
|
|
|
|
2022-07-05 02:41:40 +02:00
|
|
|
def index
|
|
|
|
authorize :user_role, :index?
|
|
|
|
|
|
|
|
@roles = UserRole.order(position: :desc).page(params[:page])
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
authorize :user_role, :create?
|
|
|
|
|
|
|
|
@role = UserRole.new
|
|
|
|
end
|
|
|
|
|
2023-04-30 06:46:39 +02:00
|
|
|
def edit
|
|
|
|
authorize @role, :update?
|
|
|
|
end
|
|
|
|
|
2022-07-05 02:41:40 +02:00
|
|
|
def create
|
|
|
|
authorize :user_role, :create?
|
|
|
|
|
|
|
|
@role = UserRole.new(resource_params)
|
|
|
|
@role.current_account = current_account
|
|
|
|
|
|
|
|
if @role.save
|
2022-08-25 20:39:40 +02:00
|
|
|
log_action :create, @role
|
2022-07-05 02:41:40 +02:00
|
|
|
redirect_to admin_roles_path
|
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
authorize @role, :update?
|
|
|
|
|
|
|
|
@role.current_account = current_account
|
|
|
|
|
|
|
|
if @role.update(resource_params)
|
2022-08-25 20:39:40 +02:00
|
|
|
log_action :update, @role
|
2022-07-05 02:41:40 +02:00
|
|
|
redirect_to admin_roles_path
|
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
authorize @role, :destroy?
|
|
|
|
@role.destroy!
|
2022-08-25 20:39:40 +02:00
|
|
|
log_action :destroy, @role
|
2022-07-05 02:41:40 +02:00
|
|
|
redirect_to admin_roles_path
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_role
|
|
|
|
@role = UserRole.find(params[:id])
|
2017-11-11 20:23:33 +01:00
|
|
|
end
|
|
|
|
|
2022-07-05 02:41:40 +02:00
|
|
|
def resource_params
|
|
|
|
params.require(:user_role).permit(:name, :color, :highlighted, :position, permissions_as_keys: [])
|
2017-11-11 20:23:33 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|