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.



74
75
76
77
# File 'app/models/pageflow/entry_role_query.rb', line 74

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

Instance Method Details

#has_at_least_account_role?(role) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
92
93
94
# File 'app/models/pageflow/entry_role_query.rb', line 89

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

#has_at_least_role?(role) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
83
84
85
86
87
# File 'app/models/pageflow/entry_role_query.rb', line 79

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