Class: Pageflow::UserPolicy::Scope Private

Inherits:
Scope
  • Object
show all
Defined in:
app/policies/pageflow/user_policy.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, scope) ⇒ Scope

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Scope.



8
9
10
11
# File 'app/policies/pageflow/user_policy.rb', line 8

def initialize(user, scope)
  @user = user
  @scope = scope
end

Instance Attribute Details

#scopeObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



6
7
8
# File 'app/policies/pageflow/user_policy.rb', line 6

def scope
  @scope
end

#userObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



6
7
8
# File 'app/policies/pageflow/user_policy.rb', line 6

def user
  @user
end

Instance Method Details

#resolveObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/policies/pageflow/user_policy.rb', line 13

def resolve
  if user.admin?
    scope.all
  else
    manager_accounts_ids = AccountPolicy::Scope
                           .new(@user, Account).member_addable.map(&:id)

    scope.joins(:memberships)
         .where('pageflow_memberships.entity_type = \'Pageflow::Account\'')
         .where((manager_accounts_ids)).distinct
  end
end