Class: Decidim::Initiatives::Admin::ManageableInitiatives

Inherits:
Query
  • Object
show all
Defined in:
app/queries/decidim/initiatives/admin/manageable_initiatives.rb

Overview

Class that retrieves manageable initiatives for the given user. Regular users will get only their initiatives. Administrators will retrieve all initiatives.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ ManageableInitiatives

Initializes the class.

user - Decidim::User



20
21
22
# File 'app/queries/decidim/initiatives/admin/manageable_initiatives.rb', line 20

def initialize(user)
  @user = user
end

Class Method Details

.for(user) ⇒ Object

Syntactic sugar to initialize the class and return the queried objects

user - Decidim::User



13
14
15
# File 'app/queries/decidim/initiatives/admin/manageable_initiatives.rb', line 13

def self.for(user)
  new(user).query
end

Instance Method Details

#queryObject

Retrieves all initiatives / Initiatives created by the user.



25
26
27
28
29
# File 'app/queries/decidim/initiatives/admin/manageable_initiatives.rb', line 25

def query
  return Initiative.where(organization: @user.organization) if @user.admin?

  Initiative.where(id: InitiativesCreated.by(@user) + InitiativesPromoted.by(@user))
end