1
0
Fork 0

Add class ApplicationPolicy::Context

This commit is contained in:
Alex Kotov 2019-09-12 03:28:45 +05:00
parent 141974d849
commit 3a1e4819a9
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
2 changed files with 27 additions and 7 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(

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