Class: Decidim::HomeActivitySearch

Inherits:
Searchlight::Search
  • Object
show all
Defined in:
decidim-core/app/services/decidim/home_activity_search.rb

Overview

A class to search for recent activity performed in a Decidim Organization. It will only return the `Decidim::ActionLog` rows that have an action as `created` or `published`.

This class is thought to be used in the `LastActivityCell` uniquely.

Instance Method Summary collapse

Instance Method Details

#base_queryObject

Needed by Searchlight, this is the base query that will be used to append other criteria to the search.


12
13
14
15
16
# File 'decidim-core/app/services/decidim/home_activity_search.rb', line 12

def base_query
  ActionLog
    .where(visibility: %w(public-only all))
    .where(organization: options.fetch(:organization))
end

#resource_typesObject

All the resource types that are eligible to be included as an activity.


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'decidim-core/app/services/decidim/home_activity_search.rb', line 34

def resource_types
  @resource_types ||= %w(
    Decidim::Accountability::Result
    Decidim::Blogs::Post
    Decidim::Comments::Comment
    Decidim::Consultations::Question
    Decidim::Debates::Debate
    Decidim::Meetings::Meeting
    Decidim::Proposals::Proposal
    Decidim::Surveys::Survey
    Decidim::Assembly
    Decidim::Consultation
    Decidim::Initiative
    Decidim::ParticipatoryProcess
  ).select do |klass|
    klass.safe_constantize.present?
  end
end

#runObject

Overwrites the default Searchlight run method since we want to return activities in an specific order but we need to set it at the end of the chain.


20
21
22
# File 'decidim-core/app/services/decidim/home_activity_search.rb', line 20

def run
  super.order(created_at: :desc)
end

#search_resource_typeObject

Adds a constrain to filter by resource type(s).


25
26
27
28
29
30
31
# File 'decidim-core/app/services/decidim/home_activity_search.rb', line 25

def search_resource_type
  if resource_types.include?(resource_type)
    scope_for(resource_type)
  else
    all_resources_scope
  end
end