Class: Decidim::PublicActivities

Inherits:
LastActivity show all
Defined in:
decidim-core/app/queries/decidim/public_activities.rb

Overview

This query finds the public ActionLog entries that can be shown in the participant views of the application within a Decidim Organization. It is intended to be used in the user profile, to retrieve activity and timeline for that user.

This will create the base query for the activities but the resulting query needs to be scoped with either with_resource_type or with_new_resource_type in order to avoid leaking private data.

Possible options:

:resource_name - an optional name for a resource for searching only that

type of resources.

:user - an optional Decidim::User that performed the activities :current_user - an optional Decidim::User for defining whether to show the

private log entries that relate to the current user.

: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.

Direct Known Subclasses

OwnActivities

Instance Method Summary collapse

Methods inherited from Query

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

Constructor Details

#initialize(organization, options = {}) ⇒ PublicActivities

Returns a new instance of PublicActivities.



24
25
26
27
28
29
30
# File 'decidim-core/app/queries/decidim/public_activities.rb', line 24

def initialize(organization, options = {})
  @organization = organization
  @resource_name = options[:resource_name]
  @user = options[:user]
  @current_user = options[:current_user]
  @follows = options[:follows]
end

Instance Method Details

#queryObject



32
33
34
35
36
37
38
39
40
41
# File 'decidim-core/app/queries/decidim/public_activities.rb', line 32

def query
  query = base_query

  query = query.where(user_id: user.id, user_type: user.class.name) if user
  query = query.where(resource_type: resource_name) if resource_name.present?

  query = filter_follows(query)
  query = filter_moderated(query)
  filter_spaces(query)
end