Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #892 from teganm/issue_3111

Issue 3111: Notify collection moderators when a new work is posted to the collection
  • Loading branch information...
commit 86ffef33bddf6ea9f632518ab4480346b03a9417 2 parents 41f76d9 + 6fe211b
@shalott shalott authored
View
19 app/mailers/collection_mailer.rb
@@ -0,0 +1,19 @@
+class CollectionMailer < ActionMailer::Base
+ include Resque::Mailer # see README in this directory
+
+ helper :application
+ helper :tags
+ helper :works
+
+ layout 'mailer'
+ default :from => ArchiveConfig.RETURN_ADDRESS
+
+ def item_added_notification(work_id, collection_id)
+ @creation = Work.find(work_id)
+ @collection = Collection.find(collection_id)
+ mail(
+ :to => @collection.email,
+ :subject => "[#{ArchiveConfig.APP_SHORT_NAME}] Work added to " + @collection.title.gsub("&gt;", ">").gsub("&lt;", "<")
+ )
+ end
+end
View
7 app/models/collection_item.rb
@@ -94,6 +94,13 @@ def update_work
work.save!
end
+ after_create :notify_of_association
+ def notify_of_association
+ if self.collection.collection_preference.email_notify && !self.collection.email.blank?
+ CollectionMailer.item_added_notification(self.work.id, self.collection.id).deliver
+ end
+ end
+
before_save :approve_automatically
def approve_automatically
if self.new_record?
View
9 app/views/collection_mailer/item_added_notification.html.erb
@@ -0,0 +1,9 @@
+<% @work = @creation.respond_to?(:work) ? @creation.work : @creation %>
+<% if @creation.is_a?(Work) %>
+ <p>
+ <%= @creation.pseuds.map{|p| p.byline}.to_sentence %> posted a <%= @work.backdate ? "backdated" : "new" %> work to your collection:
+ <%= raw simple_format(get_embed_link(@work)) %>
+ </p>
+<% end %>
+
+<p>You're receiving this email because you've chosen to be notified of new works added to your collection <%= link_to @collection.name, url_for(@collection) %>. Follow the link to change settings if you no longer wish to receive updates.</p>
View
2  app/views/collections/_form.html.erb
@@ -107,6 +107,8 @@
<dd>
<%= preference_form.label :show_random, ts("Show random works on the front page instead of the most recent") %>
</dd>
+ <dt><%= preference_form.check_box :email_notify %></dt>
+ <dd><%= preference_form.label :email_notify, ts("Send a message to the collection email when a work is added") %></dd>
<dt><%= label_tag :challenge_type, ts("Type of challenge, if any") %>:</dt>
<% type = @collection.challenge ? @collection.challenge.class.name : @challenge_type %>
<dd><%= select_tag :challenge_type, options_for_select(Collection::CHALLENGE_TYPE_OPTIONS, type) %></dd>
View
9 db/migrate/20120921094037_add_email_notifications_to_collection_preferences.rb
@@ -0,0 +1,9 @@
+class AddEmailNotificationsToCollectionPreferences < ActiveRecord::Migration
+ def self.up
+ add_column :collection_preferences, :email_notify, :boolean, :default => false, :null => false
+ end
+
+ def self.down
+ remove_column :collection_preferences, :email_notify
+ end
+end
View
2  features/collectible.feature
@@ -2,7 +2,7 @@
Feature: Collectible items
As a user
- I want to add various items to collections
+ I want to add my items to collections
Scenario: Add my work to a collection
Given I have a collection "Various Penguins"
View
13 features/collection_create.feature
@@ -4,7 +4,7 @@ Feature: Collection
As a humble user
I want to create a collection and post to it
-Scenario: Create a collection, post a work to it
+Scenario: Create a collection
Given I am logged in as "first_user"
When I post the work "Test work thingy"
@@ -17,6 +17,12 @@ Scenario: Create a collection, post a work to it
And I fill in "Introduction" with "Welcome to the collection"
And I fill in "FAQ" with "<dl><dt>What is this thing?</dt><dd>It's a collection</dd></dl>"
And I fill in "Rules" with "Be nice to people"
+ And I check the 1st checkbox with id matching "collection_collection_preference_attributes_moderated"
+ And I check the 1st checkbox with id matching "collection_collection_preference_attributes_closed"
+ And I check the 1st checkbox with id matching "collection_collection_preference_attributes_unrevealed"
+ And I check the 1st checkbox with id matching "collection_collection_preference_attributes_anonymous"
+ And I check the 1st checkbox with id matching "collection_collection_preference_attributes_show_random"
+ And I check the 1st checkbox with id matching "collection_collection_preference_attributes_email_notify"
And I submit
Then I should see "Collection was successfully created"
When I follow "Profile"
@@ -24,6 +30,11 @@ Scenario: Create a collection, post a work to it
And I should see "What is this thing?" within "#faq"
And I should see "It's a collection" within "#faq"
And I should see "Be nice to people" within "#rules"
+
+Scenario: Post to collection from the work edit page
+ Given I have the collection "My Collection Thing" with name "collection_thing"
+ And basic tags
+ And I am logged in as "first_user"
When I post the work "collect-y work"
And I go to first_user's user page
Then I should see "collect-y work"
View
46 features/collection_notification.feature
@@ -0,0 +1,46 @@
+@collections @works
+
+Feature: Collectible items email
+ As a moderator
+ I want to get notifications when items are added to my collection
+
+ Scenario: Work added to collection sends notification email
+ Given I am logged in as "first_user"
+ And all emails have been delivered
+ When I go to the collections page
+ When I follow "New Collection"
+ And I fill in "Display Title" with "Antarctic Penguins"
+ And I fill in "Collection Name" with "AntarcticPenguins"
+ And I fill in "Collection Email" with "test@archiveofourown.org"
+ And I check the 1st checkbox with id matching "collection_collection_preference_attributes_email_notify"
+ And I submit
+ Then I should see "Collection was successfully created"
+ When I go to the collections page
+ When I follow "New Collection"
+ And I fill in "Display Title" with "Polar Bears"
+ And I fill in "Collection Name" with "PolarBears"
+ And I fill in "Collection Email" with "test2@archiveofourown.org"
+ And I check the 1st checkbox with id matching "collection_collection_preference_attributes_email_notify"
+ And I submit
+ Then I should see "Collection was successfully created"
+ When I post the work "collect-y work"
+ And I go to first_user's user page
+ When I edit the work "collect-y work"
+ And I fill in "work_collection_names" with "AntarcticPenguins"
+ And I press "Preview"
+ Then I should see "Preview"
+ And I press "Update"
+ Then I should see "Work was successfully updated."
+ And I should see "collect-y work"
+ And I should see "Antarctic Penguins"
+ And 1 email should be delivered to test@archiveofourown.org
+ When I edit the work "collect-y work"
+ And I fill in "work_collection_names" with "AntarcticPenguins, PolarBears"
+ And I press "Preview"
+ Then I should see "Preview"
+ And I press "Update"
+ Then I should see "Work was successfully updated."
+ And I should see "collect-y work"
+ And I should see "Polar Bears"
+ And I should see "Antarctic Penguins"
+ And 1 email should be delivered to test2@archiveofourown.org
View
6 spec/models/work_spec.rb
@@ -95,6 +95,12 @@
@work.errors[:title].should_not be_empty
end
+ it "should send an email when added to collection" do
+ collection = Collection.new
+ collection.collection_preference = CollectionPreference.new
+ @work.add_to_collection(collection)
+
+ end
end
describe "new recipients virtual attribute" do
Please sign in to comment.
Something went wrong with that request. Please try again.