Class: Decidim::PublicActivities

Inherits:
LastActivity show all
Defined in:
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 activites :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.

:scopes - a collection of ‘Decidim::Scope`. It will return any activity that

took place in any of those scopes.

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.



26
27
28
29
30
31
32
33
# File 'app/queries/decidim/public_activities.rb', line 26

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

Instance Method Details

#queryObject



35
36
37
38
39
40
41
42
43
44
# File 'app/queries/decidim/public_activities.rb', line 35

def query
  query = base_query

  query = query.where(user: user) 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