Class: Pageflow::AccountRoleQuery

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

Overview

Query users for their role on accounts based on role

Defined Under Namespace

Classes: Scope

Instance Method Summary collapse

Constructor Details

#initialize(user, account) ⇒ AccountRoleQuery

Create query that can be used for role comparisons

Parameters:

  • user (User)

    Required. Membership user to check.

  • account (Pageflow::Account)

    Required. Membership entity to check.



47
48
49
50
# File 'app/models/pageflow/account_role_query.rb', line 47

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

Instance Method Details

#has_at_least_role?(role) ⇒ Boolean

Return true if there is a membership with at least role for user/account

Parameters:

  • role (String)

    Required. Minimum role that we compare against.

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
# File 'app/models/pageflow/account_role_query.rb', line 58

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