Class: Decidim::ActivitySearch
- Inherits:
-
Searchlight::Search
- Object
- Searchlight::Search
- Decidim::ActivitySearch
- Defined in:
- app/services/decidim/activity_search.rb
Overview
A class to search for recent activity performed in a Decidim Organization. It is intended to be used in the user profile, to retrieve activity and timeline for that user.
It will return any action for a given resource, except ‘create` on resources that implement the `Decidim::Publicable` concern to avoid leaking private data.
Possible options:
:organization - the ‘Decidim::Organization` to scope to search. Required. :user - an optional `Decidim::USer` that performed the activites :follows - a collection of `Decidim::Follow` resources. It will return any
activity affecting any of these resources, performed by any of them or
contained in any of them as spaces.
:scopes - a collection of ‘Decidim::Scope`. It will return any activity that
took place in any of those scopes.
Instance Method Summary collapse
-
#base_query ⇒ Object
Needed by Searchlight, this is the base query that will be used to append other criteria to the search.
-
#resource_types ⇒ Object
All the resource types that are eligible to be included as an activity.
-
#run ⇒ Object
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.
-
#search_resource_type ⇒ Object
Adds a constrain to filter by resource type(s).
Instance Method Details
#base_query ⇒ Object
Needed by Searchlight, this is the base query that will be used to append other criteria to the search.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/services/decidim/activity_search.rb', line 24 def base_query query = ActionLog .where(visibility: %w(public-only all)) .where(organization: .fetch(:organization)) query = query.where(user: [:user]) if [:user] query = query.where(resource_type: [:resource_name]) if [:resource_name] query = filter_follows(query) query end |
#resource_types ⇒ Object
All the resource types that are eligible to be included as an activity.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/services/decidim/activity_search.rb', line 53 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 |
#run ⇒ Object
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.
39 40 41 |
# File 'app/services/decidim/activity_search.rb', line 39 def run super.order(created_at: :desc) end |
#search_resource_type ⇒ Object
Adds a constrain to filter by resource type(s).
44 45 46 47 48 49 50 |
# File 'app/services/decidim/activity_search.rb', line 44 def search_resource_type if resource_types.include?(resource_type) scope_for(resource_type) else all_resources_scope end end |