Class: Pageflow::FolderPolicy::Scope

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, scope) ⇒ Scope

Returns a new instance of Scope.



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

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

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



4
5
6
# File 'app/policies/pageflow/folder_policy.rb', line 4

def scope
  @scope
end

#userObject (readonly)

Returns the value of attribute user.



4
5
6
# File 'app/policies/pageflow/folder_policy.rb', line 4

def user
  @user
end

Instance Method Details

#resolveObject



11
12
13
14
15
16
17
18
19
# File 'app/policies/pageflow/folder_policy.rb', line 11

def resolve
  if user.admin?
    scope.all
  else
    scope.where('account_id IN (?) OR id IN (?)',
                accounts_where_user_is_at_least_previewer(user).map(&:id),
                user.entries.map(&:folder_id))
  end
end