1
0
Fork 0

Add class ApplicationPolicy::Context

This commit is contained in:
Alex Kotov 2018-12-02 16:04:30 +05:00
parent 7a0f7e0a12
commit b2c904418b
No known key found for this signature in database
GPG Key ID: 4E831250F47DE154
3 changed files with 21 additions and 9 deletions

View File

@ -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?

View File

@ -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

View File

@ -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