Add class ApplicationPolicy::Context
This commit is contained in:
parent
141974d849
commit
3a1e4819a9
2 changed files with 27 additions and 7 deletions
|
@ -21,7 +21,11 @@ private
|
|||
@current_account ||= current_user&.account
|
||||
end
|
||||
|
||||
alias pundit_user current_account
|
||||
def pundit_user
|
||||
@pundit_user ||= ApplicationPolicy::Context.new(
|
||||
account: current_account,
|
||||
)
|
||||
end
|
||||
|
||||
def set_raven_context
|
||||
Raven.user_context(
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ApplicationPolicy
|
||||
attr_reader :account, :record
|
||||
attr_reader :context, :record
|
||||
|
||||
def initialize(account, record)
|
||||
@account = account
|
||||
def initialize(context, record)
|
||||
@context = context
|
||||
@record = record
|
||||
end
|
||||
|
||||
|
@ -46,15 +46,19 @@ class ApplicationPolicy
|
|||
|
||||
private
|
||||
|
||||
def account
|
||||
context&.account
|
||||
end
|
||||
|
||||
def restricted?
|
||||
Rails.application.restricted?
|
||||
end
|
||||
|
||||
class Scope
|
||||
attr_reader :account, :scope
|
||||
attr_reader :context, :scope
|
||||
|
||||
def initialize(account, scope)
|
||||
@account = account
|
||||
def initialize(context, scope)
|
||||
@context = context
|
||||
@scope = scope
|
||||
end
|
||||
|
||||
|
@ -68,8 +72,20 @@ private
|
|||
|
||||
private
|
||||
|
||||
def account
|
||||
context&.account
|
||||
end
|
||||
|
||||
def restricted?
|
||||
Rails.application.restricted?
|
||||
end
|
||||
end
|
||||
|
||||
class Context
|
||||
attr_reader :account
|
||||
|
||||
def initialize(account:)
|
||||
@account = account
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue