Add class ApplicationPolicy::Context
This commit is contained in:
parent
7a0f7e0a12
commit
b2c904418b
3 changed files with 21 additions and 9 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 id: current_user.id if user_signed_in?
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -41,14 +41,14 @@ class ApplicationPolicy
|
|||
# :nocov:
|
||||
|
||||
def policy(record)
|
||||
Pundit.policy account, record
|
||||
Pundit.policy context, record
|
||||
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
|
||||
|
||||
|
@ -60,4 +60,12 @@ class ApplicationPolicy
|
|||
|
||||
# :nocov:
|
||||
end
|
||||
|
||||
class Context
|
||||
attr_reader :account
|
||||
|
||||
def initialize(account:)
|
||||
@account = account
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
class PassportConfirmationPolicy < ApplicationPolicy
|
||||
def create?
|
||||
return false if record.passport.nil?
|
||||
return false if record.account != account
|
||||
return false if record.account != context.account
|
||||
|
||||
policy(record.passport).show?
|
||||
end
|
||||
|
|
Reference in a new issue