Class: Pageflow::EntryRoleQuery

Inherits:
ApplicationQuery show all
Defined in:
app/models/pageflow/entry_role_query.rb

Defined Under Namespace

Classes: Scope

Instance Method Summary collapse

Constructor Details

#initialize(user, entry) ⇒ EntryRoleQuery

Returns a new instance of EntryRoleQuery.



94
95
96
97
# File 'app/models/pageflow/entry_role_query.rb', line 94

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

Instance Method Details

#has_at_least_account_role?(role) ⇒ Boolean

Returns:

  • (Boolean)


109
110
111
112
113
114
# File 'app/models/pageflow/entry_role_query.rb', line 109

def (role)
  @user
    .memberships
    .where(role: Roles.at_least(role), entity: @entry.)
    .any?
end

#has_at_least_role?(role) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
102
103
104
105
106
107
# File 'app/models/pageflow/entry_role_query.rb', line 99

def has_at_least_role?(role)
  @user
    .memberships
    .where(role: Roles.at_least(role))
    .where("(entity_id = :entry_id AND entity_type = 'Pageflow::Entry') OR " \
           "(entity_id = :account_id AND entity_type = 'Pageflow::Account')",
           entry_id: @entry.id, account_id: @entry..id)
    .any?
end