Update permission checking

This commit is contained in:
cryptogopher 2024-11-10 17:34:02 +01:00
parent 537cd18336
commit 817b1a4376
3 changed files with 29 additions and 7 deletions

View File

@ -1,11 +1,30 @@
class Default::UnitsController < ApplicationController class Default::UnitsController < ApplicationController
navigation_tab :units navigation_tab :units
before_action :find_unit, only: [:import, :export, :destroy]
before_action except: :index do before_action except: :index do
raise AccessForbidden unless current_user.at_least(:admin) case action_name.to_sym
when :import, :import_all
raise AccessForbidden unless current_user.at_least(:active)
else
raise AccessForbidden unless current_user.at_least(:admin)
end
end end
def index def index
@units = current_user.units.defaults_diff @units = current_user.units.defaults_diff
end end
def import
end
def import_all
end
def export
end
def destroy
end
end end

View File

@ -1,5 +1,5 @@
class UnitsController < ApplicationController class UnitsController < ApplicationController
before_action only: [:new] do before_action only: :new do
find_unit if params[:id].present? find_unit if params[:id].present?
end end
before_action :find_unit, only: [:edit, :update, :rebase, :destroy] before_action :find_unit, only: [:edit, :update, :rebase, :destroy]

View File

@ -2,11 +2,14 @@ class UsersController < ApplicationController
helper_method :allow_disguise? helper_method :allow_disguise?
before_action :find_user, only: [:show, :update, :disguise] before_action :find_user, only: [:show, :update, :disguise]
before_action except: :revert do
raise AccessForbidden unless current_user.at_least(:admin) before_action do
end case action_name.to_sym
before_action only: :revert do when :revert
raise AccessForbidden unless current_user_disguised? raise AccessForbidden unless current_user_disguised?
else
raise AccessForbidden unless current_user.at_least(:admin)
end
end end
def index def index