Class: Decidim::InactiveUsersQuery

Inherits:
Query
  • Object
show all
Defined in:
app/queries/decidim/inactive_users_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Query

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

Constructor Details

#initialize(scope = Decidim::User.not_deleted) ⇒ InactiveUsersQuery

Returns a new instance of InactiveUsersQuery.



7
8
9
# File 'app/queries/decidim/inactive_users_query.rb', line 7

def initialize(scope = Decidim::User.not_deleted)
  @scope = scope
end

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



5
6
7
# File 'app/queries/decidim/inactive_users_query.rb', line 5

def scope
  @scope
end

Instance Method Details

#for_first_warning(cutoff_date) ⇒ Object



11
12
13
14
15
# File 'app/queries/decidim/inactive_users_query.rb', line 11

def for_first_warning(cutoff_date)
  scope
    .where("(current_sign_in_at <= :cutoff OR current_sign_in_at IS NULL) AND created_at <= :cutoff", cutoff: cutoff_date)
    .where.not("extended_data ? 'inactivity_notification'")
end

#for_last_warning(cutoff_date) ⇒ Object



17
18
19
20
21
22
# File 'app/queries/decidim/inactive_users_query.rb', line 17

def for_last_warning(cutoff_date)
  scope
    .where("(extended_data->'inactivity_notification'->>'notification_type') = 'first'")
    .where("(extended_data->'inactivity_notification'->>'sent_at')::timestamp <= ?", cutoff_date)
    .where("current_sign_in_at IS NULL OR current_sign_in_at <= (extended_data->'inactivity_notification'->>'sent_at')::timestamp")
end

#for_removal(cutoff_date) ⇒ Object



24
25
26
27
28
29
# File 'app/queries/decidim/inactive_users_query.rb', line 24

def for_removal(cutoff_date)
  scope
    .where("(extended_data->'inactivity_notification'->>'notification_type') = 'second'")
    .where("(extended_data->'inactivity_notification'->>'sent_at')::timestamp <= ?", cutoff_date)
    .where("current_sign_in_at IS NULL OR current_sign_in_at <= (extended_data->'inactivity_notification'->>'sent_at')::timestamp")
end