Class: Decidim::Newsletter

Inherits:
ApplicationRecord show all
Includes:
Loggable, Traceable, TranslatableResource
Defined in:
app/models/decidim/newsletter.rb

Overview

This model holds all the data needed to send a newsletter.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.log_presenter_class_for(_log) ⇒ Object



18
19
20
# File 'app/models/decidim/newsletter.rb', line 18

def self.log_presenter_class_for(_log)
  Decidim::AdminLog::NewsletterPresenter
end

Instance Method Details

#notifications_settings_url(**kwargs) ⇒ Object



63
64
65
# File 'app/models/decidim/newsletter.rb', line 63

def notifications_settings_url(**kwargs)
  proxy_url(__method__, **kwargs)
end

#organization_official_urlObject



71
72
73
74
75
# File 'app/models/decidim/newsletter.rb', line 71

def organization_official_url
  return "#" unless sent?

  organization.official_url || proxy_url(:root_url)
end

#sended_to_all_users?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/models/decidim/newsletter.rb', line 37

def sended_to_all_users?
  extended_data["send_to_all_users"]
end

#sended_to_followers?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/decidim/newsletter.rb', line 41

def sended_to_followers?
  extended_data["send_to_followers"]
end

#sended_to_participants?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/models/decidim/newsletter.rb', line 45

def sended_to_participants?
  extended_data["send_to_participants"]
end

#sended_to_partipatory_spacesObject



49
50
51
# File 'app/models/decidim/newsletter.rb', line 49

def sended_to_partipatory_spaces
  extended_data["participatory_space_types"]
end

#sent?Boolean

Returns true if this newsletter was already sent.

Returns a Boolean.

Returns:

  • (Boolean)


25
26
27
# File 'app/models/decidim/newsletter.rb', line 25

def sent?
  sent_at.present?
end

#sent_scopesObject



33
34
35
# File 'app/models/decidim/newsletter.rb', line 33

def sent_scopes
  @sent_scopes ||= organization.scopes.where(id: sent_scopes_ids)
end

#sent_scopes_idsObject



29
30
31
# File 'app/models/decidim/newsletter.rb', line 29

def sent_scopes_ids
  extended_data["scope_ids"] || []
end

#templateObject



53
54
55
56
57
# File 'app/models/decidim/newsletter.rb', line 53

def template
  @template ||= Decidim::ContentBlock
                .for_scope(:newsletter_template, organization: organization)
                .find_by(scoped_resource_id: id)
end

#unsubscribe_newsletters_url(**kwargs) ⇒ Object



67
68
69
# File 'app/models/decidim/newsletter.rb', line 67

def unsubscribe_newsletters_url(**kwargs)
  proxy_url(__method__, **kwargs)
end

#url(**kwargs) ⇒ Object



59
60
61
# File 'app/models/decidim/newsletter.rb', line 59

def url(**kwargs)
  proxy_url(:newsletter_url, id: id, **kwargs)
end