alchemy_crm 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +10 -11
- data/alchemy_crm.gemspec +21 -21
- data/app/assets/javascripts/alchemy_crm/alchemy_crm.base.js +54 -54
- data/app/assets/stylesheets/alchemy_crm/base.css.scss +199 -199
- data/app/controllers/alchemy_crm/admin/base_controller.rb +5 -5
- data/app/controllers/alchemy_crm/admin/contact_groups_controller.rb +15 -15
- data/app/controllers/alchemy_crm/admin/contacts_controller.rb +95 -95
- data/app/controllers/alchemy_crm/admin/deliveries_controller.rb +66 -66
- data/app/controllers/alchemy_crm/admin/elements_controller_extension.rb +23 -23
- data/app/controllers/alchemy_crm/admin/mailings_controller.rb +44 -44
- data/app/controllers/alchemy_crm/admin/newsletters_controller.rb +16 -16
- data/app/controllers/alchemy_crm/admin/tags_controller.rb +60 -59
- data/app/controllers/alchemy_crm/base_controller.rb +3 -3
- data/app/controllers/alchemy_crm/contacts_controller.rb +88 -88
- data/app/controllers/alchemy_crm/mailings_controller.rb +16 -16
- data/app/controllers/alchemy_crm/recipients_controller.rb +30 -30
- data/app/controllers/alchemy_crm/subscriptions_controller.rb +54 -54
- data/app/helpers/alchemy/pages_helper_extension.rb +14 -14
- data/app/helpers/alchemy_crm/admin/base_helper.rb +8 -8
- data/app/helpers/alchemy_crm/mailings_helper.rb +175 -175
- data/app/mailers/alchemy_crm/bounce_receiver.rb +9 -9
- data/app/mailers/alchemy_crm/contacts_mailer.rb +21 -21
- data/app/mailers/alchemy_crm/mailings_mailer.rb +46 -46
- data/app/mailers/alchemy_crm/subscriptions_mailer.rb +12 -12
- data/app/models/alchemy/essence_element_teaser.rb +14 -14
- data/app/models/alchemy_crm/contact.rb +260 -260
- data/app/models/alchemy_crm/contact_group.rb +15 -15
- data/app/models/alchemy_crm/contact_group_filter.rb +17 -17
- data/app/models/alchemy_crm/delivery.rb +54 -54
- data/app/models/alchemy_crm/element_extension.rb +23 -23
- data/app/models/alchemy_crm/mailing.rb +90 -90
- data/app/models/alchemy_crm/newsletter.rb +33 -33
- data/app/models/alchemy_crm/reaction.rb +5 -5
- data/app/models/alchemy_crm/recipient.rb +46 -46
- data/app/models/alchemy_crm/subscription.rb +4 -4
- data/app/views/alchemy/admin/elements/fill.js.erb +11 -11
- data/app/views/alchemy/elements/_newsletter_article_view.html.erb +14 -14
- data/app/views/alchemy/elements/_newsletter_greeting_view.html.erb +9 -9
- data/app/views/alchemy/elements/_newsletter_signout_form_view.html.erb +18 -18
- data/app/views/alchemy/elements/_newsletter_signup_form_view.html.erb +62 -62
- data/app/views/alchemy/essences/_essence_element_teaser_editor.html.erb +29 -29
- data/app/views/alchemy/newsletter_layouts/_standard.html.erb +37 -37
- data/app/views/alchemy_crm/admin/contact_groups/_contact_group.html.erb +30 -30
- data/app/views/alchemy_crm/admin/contact_groups/_filter.html.erb +28 -28
- data/app/views/alchemy_crm/admin/contact_groups/_form.html.erb +45 -45
- data/app/views/alchemy_crm/admin/contact_groups/_tag.html.erb +4 -4
- data/app/views/alchemy_crm/admin/contact_groups/add_filter.js.erb +7 -7
- data/app/views/alchemy_crm/admin/contact_groups/index.html.erb +28 -28
- data/app/views/alchemy_crm/admin/contacts/_contact.html.erb +42 -42
- data/app/views/alchemy_crm/admin/contacts/_form.html.erb +76 -76
- data/app/views/alchemy_crm/admin/contacts/import.html.erb +27 -27
- data/app/views/alchemy_crm/admin/contacts/index.html.erb +39 -39
- data/app/views/alchemy_crm/admin/contacts/vcf_import_result.html.erb +24 -24
- data/app/views/alchemy_crm/admin/deliveries/_delivery.html.erb +30 -30
- data/app/views/alchemy_crm/admin/deliveries/_form.html.erb +61 -61
- data/app/views/alchemy_crm/admin/deliveries/_recipient.html.erb +36 -36
- data/app/views/alchemy_crm/admin/deliveries/index.html.erb +21 -21
- data/app/views/alchemy_crm/admin/deliveries/show.html.erb +61 -61
- data/app/views/alchemy_crm/admin/elements/teasables.html.erb +53 -53
- data/app/views/alchemy_crm/admin/mailings/_form.html.erb +41 -41
- data/app/views/alchemy_crm/admin/mailings/_mailing.html.erb +73 -73
- data/app/views/alchemy_crm/admin/mailings/edit_content.html.erb +170 -170
- data/app/views/alchemy_crm/admin/mailings/import_result.html.erb +18 -18
- data/app/views/alchemy_crm/admin/mailings/index.html.erb +25 -25
- data/app/views/alchemy_crm/admin/newsletters/_form.html.erb +52 -52
- data/app/views/alchemy_crm/admin/newsletters/_tag_with_radiobutton.html.erb +5 -5
- data/app/views/alchemy_crm/admin/newsletters/index.html.erb +29 -29
- data/app/views/alchemy_crm/admin/newsletters/new.html.erb +4 -4
- data/app/views/alchemy_crm/admin/tags/_radio_tag.html.erb +4 -4
- data/app/views/alchemy_crm/admin/tags/_tag.html.erb +30 -30
- data/app/views/alchemy_crm/admin/tags/edit.html.erb +32 -32
- data/app/views/alchemy_crm/admin/tags/index.html.erb +23 -23
- data/app/views/alchemy_crm/admin/tags/new.html.erb +14 -14
- data/app/views/alchemy_crm/contacts_mailer/signout_mail.html.erb +6 -6
- data/app/views/alchemy_crm/contacts_mailer/signout_mail.text.erb +2 -2
- data/app/views/alchemy_crm/contacts_mailer/signup_mail.html.erb +9 -9
- data/app/views/alchemy_crm/contacts_mailer/signup_mail.text.erb +2 -2
- data/app/views/alchemy_crm/mailings_mailer/verification_mail.html.erb +9 -9
- data/app/views/alchemy_crm/subscriptions/index.html.erb +4 -4
- data/app/views/alchemy_crm/subscriptions_mailer/overview_mail.html.erb +25 -25
- data/app/views/alchemy_crm/subscriptions_mailer/overview_mail.text.erb +2 -2
- data/app/views/csv_magic/import_errors.html.erb +23 -23
- data/app/views/csv_magic/mapper.html.erb +46 -46
- data/app/views/layouts/alchemy_crm/mailings.html.erb +177 -177
- data/config/initializers/assets.rb +2 -2
- data/config/locales/alchemy_crm.de.yml +1 -1
- data/config/locales/alchemy_crm.en.yml +1 -0
- data/config/locales/localized_country_select.de.rb +260 -260
- data/config/locales/localized_country_select.en.rb +274 -274
- data/config/routes.rb +67 -67
- data/db/migrate/20111104125306_remove_sent_mailing_pdf_id_from_sent_mailings.rb +1 -1
- data/db/migrate/20111124145923_namespace_alchemy_crm_models.rb +13 -13
- data/db/migrate/20120307160721_rename_alchemy_crm_recipients_sent_mailing_id.rb +3 -3
- data/db/migrate/20120320103412_add_indexes_to_alchemy_crm_sha1_columns.rb +3 -3
- data/db/migrate/20120327174301_add_more_indexes_to_alchemy_crm_tables.rb +10 -10
- data/lib/alchemy_crm.rb +15 -15
- data/lib/alchemy_crm/bounced_delivery.rb +38 -38
- data/lib/alchemy_crm/config.rb +25 -25
- data/lib/alchemy_crm/engine.rb +31 -31
- data/lib/alchemy_crm/i18n_helpers.rb +28 -28
- data/lib/alchemy_crm/newsletter_layout.rb +28 -28
- data/lib/alchemy_crm/seeder.rb +26 -26
- data/lib/alchemy_crm/version.rb +1 -1
- data/lib/generators/alchemy_crm/scaffold/files/newsletters.html.erb +19 -19
- data/lib/generators/alchemy_crm/scaffold/scaffold_generator.rb +2 -2
- data/lib/tasks/alchemy_crm.rake +22 -22
- data/lib/tasks/routes.rake +25 -25
- data/spec/config_spec.rb +24 -24
- data/spec/controllers/alchemy_crm/contacts_controller_spec.rb +147 -147
- data/spec/controllers/alchemy_crm/mailings_controller_spec.rb +62 -62
- data/spec/controllers/alchemy_crm/recipients_controller_spec.rb +109 -109
- data/spec/helpers/alchemy_crm/mailings_helper_spec.rb +165 -165
- data/spec/mailers/alchemy_crm/contacts_mailer_spec.rb +84 -84
- data/spec/mailers/alchemy_crm/mailings_mailer_spec.rb +29 -29
- data/spec/models/alchemy_crm/contact_group_spec.rb +25 -25
- data/spec/models/alchemy_crm/contact_spec.rb +71 -71
- data/spec/models/alchemy_crm/delivery_spec.rb +43 -39
- data/spec/models/alchemy_crm/mailing_spec.rb +46 -42
- data/spec/models/alchemy_crm/newsletter_spec.rb +29 -29
- data/spec/spec_helper.rb +36 -36
- metadata +6 -8
- data/rails/init.rb +0 -1
- data/recipes/alchemy-mailings-capistrano-tasks.rb +0 -12
@@ -1,26 +1,26 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
module AlchemyCrm
|
3
|
-
|
3
|
+
class ContactGroup < ActiveRecord::Base
|
4
4
|
|
5
|
-
|
5
|
+
acts_as_taggable_on :contact_tags
|
6
6
|
|
7
|
-
|
7
|
+
has_many :filters, :dependent => :destroy, :class_name => "AlchemyCrm::ContactGroupFilter"
|
8
8
|
|
9
|
-
|
9
|
+
validates_presence_of :name
|
10
10
|
|
11
|
-
|
11
|
+
accepts_nested_attributes_for :filters, :allow_destroy => true
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
def contacts
|
14
|
+
Contact.tagged_with(self.contact_tags, :any => true).where(filters_sql_string)
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
def filters_sql_string
|
18
|
+
filters.map(&:sql_string).join(' AND ')
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
def humanized_name
|
22
|
+
"#{self.name} (#{self.contacts.length})"
|
23
|
+
end
|
24
24
|
|
25
|
-
|
25
|
+
end
|
26
26
|
end
|
@@ -1,26 +1,26 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
module AlchemyCrm
|
3
|
-
|
3
|
+
class ContactGroupFilter < ActiveRecord::Base
|
4
4
|
|
5
|
-
|
5
|
+
belongs_to :contact_group
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
OPERATORS = [
|
8
|
+
[::I18n.t(:like, :scope => 'alchemy_crm.contact_group_filter_operators', :default => 'Contains'), "LIKE"],
|
9
|
+
[::I18n.t(:not_like, :scope => 'alchemy_crm.contact_group_filter_operators', :default => 'Contains not'), "NOT LIKE"],
|
10
|
+
[::I18n.t(:equals, :scope => 'alchemy_crm.contact_group_filter_operators', :default => 'Equals'), "="],
|
11
|
+
[::I18n.t(:equals_not, :scope => 'alchemy_crm.contact_group_filter_operators', :default => 'Equals not'), "!="]
|
12
|
+
]
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def sql_string
|
15
|
+
return "" if column.blank? || operator.blank? || prepared_value.blank?
|
16
|
+
"`#{Contact.table_name}`.`#{column}` #{operator} '#{prepared_value}'"
|
17
|
+
end
|
18
18
|
|
19
|
-
|
19
|
+
private
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
def prepared_value
|
22
|
+
operator =~ /LIKE/ ? "%#{value}%" : "#{value}"
|
23
|
+
end
|
24
24
|
|
25
|
-
|
25
|
+
end
|
26
26
|
end
|
@@ -1,57 +1,57 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
module AlchemyCrm
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
3
|
+
class Delivery < ActiveRecord::Base
|
4
|
+
|
5
|
+
attr_accessor :chunk_delay
|
6
|
+
|
7
|
+
belongs_to :mailing
|
8
|
+
has_many :recipients, :dependent => :destroy
|
9
|
+
|
10
|
+
after_create :recipients_from_mailing_contacts
|
11
|
+
|
12
|
+
scope :delivered, where("`alchemy_crm_deliveries`.`delivered_at` IS NOT NULL")
|
13
|
+
scope :pending, where("`alchemy_crm_deliveries`.`delivered_at` IS NULL")
|
14
|
+
|
15
|
+
def delivered?
|
16
|
+
!self.delivered_at.nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
# Sending mails in chunks.
|
20
|
+
def send_chunks(options={})
|
21
|
+
raise "No Mailing Given" if mailing.blank?
|
22
|
+
@chunk_delay = 0
|
23
|
+
recipients.each_slice(self.class.settings(:send_mails_in_chunks_of)) do |recipients_chunk|
|
24
|
+
send_mail_chunk(recipients_chunk, options)
|
25
|
+
@chunk_delay += 1
|
26
|
+
end
|
27
|
+
update_attribute(:delivered_at, Time.now)
|
28
|
+
end
|
29
|
+
handle_asynchronously :send_chunks, :run_at => proc { |m| m.deliver_at || Time.now }
|
30
|
+
|
31
|
+
# Send the mail chunk via delayed_job and waiting some time before next is enqueued
|
32
|
+
def send_mail_chunk(recipients_chunk, options)
|
33
|
+
recipients_chunk.each do |recipient|
|
34
|
+
mail = MailingsMailer.build(mailing, recipient, options).deliver
|
35
|
+
recipient.update_attribute(:message_id, mail.message_id)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
handle_asynchronously :send_mail_chunk, :run_at => proc { |m| (m.chunk_delay * m.class.settings(:send_mail_chunks_every)).minutes.from_now }
|
39
|
+
|
40
|
+
def self.settings(name)
|
41
|
+
AlchemyCrm::Config.get(name)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def recipients_from_mailing_contacts
|
47
|
+
raise "No Mailing Given" if mailing.blank?
|
48
|
+
mailing.contacts_not_having_email_yet.each do |contact|
|
49
|
+
recipients << Recipient.create!(
|
50
|
+
:email => contact.email,
|
51
|
+
:contact => contact
|
52
|
+
)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
57
|
end
|
@@ -1,28 +1,28 @@
|
|
1
1
|
# Extending Alchemys Element model
|
2
2
|
Alchemy::Element.class_eval do
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
4
|
+
def update_from_element(source, url)
|
5
|
+
self.contents.each do |content|
|
6
|
+
source_content = source.contents.find_by_name(content.name)
|
7
|
+
if !source_content.blank? && source_content.essence_type == content.essence_type
|
8
|
+
case content.essence_type
|
9
|
+
when "Alchemy::EssenceText"
|
10
|
+
content.essence.body = source_content.essence.body
|
11
|
+
when "Alchemy::EssenceRichtext"
|
12
|
+
content.essence.body = source_content.essence.body
|
13
|
+
when "Alchemy::EssencePicture"
|
14
|
+
content.essence.picture_id = source_content.essence.picture_id
|
15
|
+
when "Alchemy::EssenceAttachment"
|
16
|
+
content.essence.attachment_id = source_content.essence.attachment_id
|
17
|
+
end
|
18
|
+
content.essence.save
|
19
|
+
end
|
20
|
+
end
|
21
|
+
teaser = self.contents.where(:essence_type => "Alchemy::EssenceElementTeaser").first
|
22
|
+
if !teaser.essence.blank?
|
23
|
+
teaser.essence.url = url
|
24
|
+
teaser.essence.save
|
25
|
+
end
|
26
|
+
end
|
27
27
|
|
28
28
|
end
|
@@ -1,93 +1,93 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
module AlchemyCrm
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
3
|
+
class Mailing < ActiveRecord::Base
|
4
|
+
|
5
|
+
MAILING_PAGE_LAYOUT_PREFIX = "newsletter_layout_"
|
6
|
+
|
7
|
+
belongs_to :page, :dependent => :destroy, :class_name => 'Alchemy::Page'
|
8
|
+
has_many :deliveries, :dependent => :destroy
|
9
|
+
has_many :recipients, :through => :deliveries
|
10
|
+
belongs_to :newsletter
|
11
|
+
|
12
|
+
validates_presence_of :name
|
13
|
+
validates_presence_of :newsletter_id, :on => :create
|
14
|
+
|
15
|
+
before_create :set_sha1
|
16
|
+
after_create :create_page
|
17
|
+
|
18
|
+
# Returns all contacts found via newsletter.
|
19
|
+
def newsletter_contacts
|
20
|
+
return [] if newsletter.blank?
|
21
|
+
newsletter.contacts
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns all contacts found via newsletter contacts and additional email addresses.
|
25
|
+
def contacts
|
26
|
+
(newsletter_contacts + contacts_from_additional_email_addresses).uniq
|
27
|
+
end
|
28
|
+
|
29
|
+
def contacts_count
|
30
|
+
return 0 if contacts.blank?
|
31
|
+
contacts.count
|
32
|
+
end
|
33
|
+
|
34
|
+
def contacts_not_having_email_yet
|
35
|
+
return contacts if recipients.empty?
|
36
|
+
contacts.select { |c| !recipients.collect(&:email).include?(c.email) }
|
37
|
+
end
|
38
|
+
|
39
|
+
# Returns a list of all email addresses for contacts that have not got any email yet.
|
40
|
+
def emails
|
41
|
+
contacts_not_having_email_yet.collect(&:email)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Return a list of email addresses from additional_email_addresses field.
|
45
|
+
def additional_emails
|
46
|
+
return [] if additional_email_addresses.blank?
|
47
|
+
additional_email_addresses.gsub(/\s/,'').split(',').uniq
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns a list of contacts found or initialized by email address from additional_email_addresses field.
|
51
|
+
def contacts_from_additional_email_addresses
|
52
|
+
additional_emails.collect{ |email| Contact.find_or_initialize_by_email(:email => email) }
|
53
|
+
end
|
54
|
+
|
55
|
+
# Makes a copy of another mailing.
|
56
|
+
def self.copy(id)
|
57
|
+
source = self.find(id)
|
58
|
+
new(source.attributes.merge(
|
59
|
+
"name" => "#{source.name} (#{::I18n.t(:copy, :scope => :alchemy_crm, :default => 'Copy')})"
|
60
|
+
).except("id", "updated_at", "created_at", "sha1", "salt", "page_id"))
|
61
|
+
end
|
62
|
+
|
63
|
+
def next_pending_delivery
|
64
|
+
deliveries.pending.first
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def create_page
|
70
|
+
mailing_root = Alchemy::Page.find_by_name('Alchemy CRM Rootpage')
|
71
|
+
raise "Alchemy CRM root page not found. Did you seed the database?" if mailing_root.blank?
|
72
|
+
mailing_page = Alchemy::Page.new(
|
73
|
+
:name => "Mailing #{name}",
|
74
|
+
:sitemap => false,
|
75
|
+
:page_layout => newsletter.layout,
|
76
|
+
:language => Alchemy::Language.get_default,
|
77
|
+
:parent_id => mailing_root.id
|
78
|
+
)
|
79
|
+
if mailing_page.save
|
80
|
+
self.page = mailing_page
|
81
|
+
save
|
82
|
+
else
|
83
|
+
raise "Error while creating mailing page: #{mailing_page.errors.full_messages.join(' ')}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def set_sha1
|
88
|
+
self.salt = [Array.new(6){rand(256).chr}.join].pack("m")[0..7]
|
89
|
+
self.sha1 = Digest::SHA1.hexdigest(Time.now.to_i.to_s + salt)
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
93
|
end
|
@@ -1,48 +1,48 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
module AlchemyCrm
|
3
|
-
|
3
|
+
class Newsletter < ActiveRecord::Base
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
has_and_belongs_to_many :contact_groups, :join_table => 'alchemy_contact_groups_newsletters'
|
6
|
+
has_many :mailings
|
7
|
+
has_many :subscriptions
|
8
|
+
has_many :subscribers, :through => :subscriptions, :uniq => true, :source => :contact
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
validates_presence_of :name
|
11
|
+
validates_presence_of :layout
|
12
12
|
|
13
|
-
|
13
|
+
before_destroy :can_delete_mailings?
|
14
14
|
|
15
|
-
|
15
|
+
scope :subscribables, where(:public => true)
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
def contacts
|
18
|
+
(verified_contact_group_contacts + verified_subscribers).uniq
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
def contacts_count
|
22
|
+
return 0 if contacts.blank?
|
23
|
+
contacts.length
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
# get all uniq contacts from my contact groups
|
27
|
+
def verified_contact_group_contacts
|
28
|
+
contact_groups.collect { |contact_group| contact_group.contacts.available }.flatten.uniq
|
29
|
+
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
def humanized_name
|
32
|
+
"#{name} (#{contacts_count})"
|
33
|
+
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
def verified_subscribers
|
36
|
+
subscribers.available.includes(:subscriptions).where(:alchemy_crm_subscriptions => {:verified => true, :wants => true})
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
def can_delete_mailings?
|
40
|
+
raise "Cannot delete Newsletter because of referencing Mailings with IDs (#{mailings.collect(&:id).join(", ")})" if(mailings.length != 0)
|
41
|
+
end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
def layout_name
|
44
|
+
NewsletterLayout.display_name_for(layout)
|
45
|
+
end
|
46
46
|
|
47
|
-
|
47
|
+
end
|
48
48
|
end
|