Skip to content
This repository was archived by the owner on Apr 14, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/mailers/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
5 changes: 5 additions & 0 deletions app/views/admin/sites/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<%= f.text_field :name %>
</div>

<div class="para">
<%= f.label :user_notification_email %><br />
<%= f.text_field :user_notification_email %>
</div>

<div class="para">
<%= f.label :url, 'URL (optional unless moderating with Akismet)' %><br />
<%= f.text_field :url %>
Expand Down
6 changes: 6 additions & 0 deletions app/views/mailer/comment_posted_for_users.text.erb
Original file line number Diff line number Diff line change
@@ -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 %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUserNotificationEmailToSites < ActiveRecord::Migration
def change
add_column :sites, :user_notification_email, :string, :default => ""
end
end
19 changes: 11 additions & 8 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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|
Expand Down