Class: Decidim::Conferences::ConferencesWithUserRole

Inherits:
Query
  • Object
show all
Defined in:
decidim-conferences/app/queries/decidim/conferences/conferences_with_user_role.rb

Overview

A class used to find the Conferences that the given user has the specific role privilege.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Query

#cached_query, #each, #eager?, #exists?, merge, #none?, #relation?, #|

Constructor Details

#initialize(user, role = :any) ⇒ ConferencesWithUserRole

Initializes the class.

user - a User that needs to find which conferences can manage role - (optional) a Symbol to specify the role privilege



20
21
22
23
# File 'decidim-conferences/app/queries/decidim/conferences/conferences_with_user_role.rb', line 20

def initialize(user, role = :any)
  @user = user
  @role = role
end

Class Method Details

.for(user, role = :any) ⇒ Object

Syntactic sugar to initialize the class and return the queried objects.

user - a User that needs to find which conferences can manage role - (optional) a Symbol to specify the role privilege



12
13
14
# File 'decidim-conferences/app/queries/decidim/conferences/conferences_with_user_role.rb', line 12

def self.for(user, role = :any)
  new(user, role).query
end

Instance Method Details

#queryObject

Finds the Conferences that the given user has role privileges. If the special role ‘:any’ is provided it returns all conferences where the user has some kind of role privilege.

Returns an ActiveRecord::Relation.



30
31
32
33
34
35
# File 'decidim-conferences/app/queries/decidim/conferences/conferences_with_user_role.rb', line 30

def query
  # Admin users have all role privileges for all organization conferences
  return Conferences::OrganizationConferences.new(user.organization).query if user.admin?

  Conference.where(id: conference_ids)
end