trabajo-afectivo/app/policies/pundit_policy.rb
2022-01-01 14:38:12 +01:00

34 lines
609 B
Ruby

# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
module PunditPolicy
attr_reader :user, :custom_exception
def initialize(user, context)
@user = user
user_required! if user_required?
initialize_context(context)
end
def user_required?
true
end
def user_required!
return if user
raise Exceptions::Forbidden, __('Authentication required')
end
private
def not_authorized(details = nil)
if details
details = "Not authorized (#{details})!"
end
@custom_exception = Exceptions::Forbidden.new(details)
false
end
end