Class: Decidim::ParticipatoryProcessesWithUserRole

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

Overview

A class used to find the ParticipatoryProcesses 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) ⇒ ParticipatoryProcessesWithUserRole

Initializes the class.

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



19
20
21
22
# File 'decidim-core/app/queries/decidim/participatory_processes_with_user_role.rb', line 19

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 processes can manage role - (optional) a Symbol to specify the role privilege



11
12
13
# File 'decidim-core/app/queries/decidim/participatory_processes_with_user_role.rb', line 11

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

Instance Method Details

#queryObject

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

Returns an ActiveRecord::Relation.



29
30
31
32
33
34
# File 'decidim-core/app/queries/decidim/participatory_processes_with_user_role.rb', line 29

def query
  # Admin users have all role privileges for all organization processes
  return ParticipatoryProcesses::OrganizationParticipatoryProcesses.new(user.organization).query if user.admin?

  ParticipatoryProcess.where(id: process_ids)
end