diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb
index 43fb6ef7..9a1c46a1 100644
--- a/app/mailers/mailer.rb
+++ b/app/mailers/mailer.rb
@@ -4,9 +4,15 @@ class Mailer < ActionMailer::Base
default_url_options[:protocol] = uri.scheme
default_url_options[:host] = uri.host
- def comment_posted(comment)
+ def comment_posted_for_moderators(comment)
@site = comment.site
@comment = comment
mail(:to => comment.site.user.email, :subject => "New comment posted")
end
+
+ def comment_posted_for_users(comment)
+ @site = comment.site
+ @comment = comment
+ mail(:to => comment.site.user_notification_email, :subject => "New comment posted")
+ end
end
diff --git a/app/models/comment.rb b/app/models/comment.rb
index 9bfb5d51..7da8e089 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -20,6 +20,7 @@ class AkismetError < StandardError
before_create :set_moderation_status
after_create :update_topic_timestamp
after_create :notify_moderators
+ after_create :notify_users
def site
topic.site
@@ -124,6 +125,10 @@ def update_topic_timestamp
end
def notify_moderators
- Mailer.comment_posted(self).deliver
+ Mailer.comment_posted_for_moderators(self).deliver
+ end
+
+ def notify_users
+ Mailer.comment_posted_for_users(self).deliver
end
end
diff --git a/app/models/site.rb b/app/models/site.rb
index 14f16b92..42fe0303 100644
--- a/app/models/site.rb
+++ b/app/models/site.rb
@@ -14,7 +14,7 @@ class Site < ActiveRecord::Base
before_validation :nullify_blank_fields
attr_accessible :name, :url, :moderation_method, :akismet_key
- attr_accessible :user, :user_id, :name, :key, :url,
+ attr_accessible :user, :user_id, :name, :key, :url, :user_notification_email,
:moderation_method, :akismet_key, :as => :admin
default_value_for(:key) { SecureRandom.hex(20).to_i(16).to_s(36) }
diff --git a/app/views/admin/sites/_form.html.erb b/app/views/admin/sites/_form.html.erb
index cf08d2c4..5889d75f 100644
--- a/app/views/admin/sites/_form.html.erb
+++ b/app/views/admin/sites/_form.html.erb
@@ -16,6 +16,11 @@
<%= f.text_field :name %>
+
+ <%= f.label :user_notification_email %>
+ <%= f.text_field :user_notification_email %>
+
+
<%= f.label :url, 'URL (optional unless moderating with Akismet)' %>
<%= f.text_field :url %>
diff --git a/app/views/mailer/comment_posted.text.erb b/app/views/mailer/comment_posted_for_moderators.text.erb
similarity index 100%
rename from app/views/mailer/comment_posted.text.erb
rename to app/views/mailer/comment_posted_for_moderators.text.erb
diff --git a/app/views/mailer/comment_posted_for_users.text.erb b/app/views/mailer/comment_posted_for_users.text.erb
new file mode 100644
index 00000000..844545bb
--- /dev/null
+++ b/app/views/mailer/comment_posted_for_users.text.erb
@@ -0,0 +1,6 @@
+# A new comment has been posted on "<%= @site.name %>"
+
+Topic : <%= @comment.topic.title %> (<%= @comment.topic.url %>#juvia-comment-<%= @comment.id %>)
+Name : <%= @comment.author_name || 'Anonymous' %>
+Contents:
+<%= @comment.content %>
diff --git a/db/migrate/20140914031238_add_user_notification_email_to_sites.rb b/db/migrate/20140914031238_add_user_notification_email_to_sites.rb
new file mode 100644
index 00000000..929f137d
--- /dev/null
+++ b/db/migrate/20140914031238_add_user_notification_email_to_sites.rb
@@ -0,0 +1,5 @@
+class AddUserNotificationEmailToSites < ActiveRecord::Migration
+ def change
+ add_column :sites, :user_notification_email, :string, :default => ""
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 53510f22..43737ba7 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110804201102) do
+ActiveRecord::Schema.define(:version => 20140914031238) do
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
@@ -27,17 +27,20 @@
end
create_table "sites", :force => true do |t|
- t.integer "user_id", :null => false
- t.string "key", :null => false
- t.string "name", :null => false
+ t.integer "user_id", :null => false
+ t.string "key", :null => false
+ t.string "name", :null => false
t.string "url"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
- t.integer "moderation_method", :default => 0, :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.integer "moderation_method", :default => 0, :null => false
t.string "akismet_key"
+ t.string "user_notification_email", :default => ""
t.index ["key"], :name => "index_sites_on_key", :unique => true
+ t.index ["user_id"], :name => "fk__sites_user_id"
t.index ["user_id"], :name => "index_sites_on_user_id"
- t.foreign_key ["user_id"], "users", ["id"], :on_update => :cascade, :on_delete => :cascade, :name => "sites_ibfk_1"
+ t.index ["user_id"], :name => "ltered_sites_user_id"
+ t.foreign_key ["user_id"], "users", ["id"], :on_update => :no_action, :on_delete => :no_action, :name => "fk_sites_user_id"
end
create_table "topics", :force => true do |t|