Permalink
Browse files

Merge pull request #587 from elzj/issue-2997-series-subscription

Issue 2997: Adding series subscriptions
  • Loading branch information...
2 parents 59bcba4 + 1b351ca commit 5aaa66f0e8e2329a9d17b592173ee733d4972f93 @shalott shalott committed Apr 20, 2012
@@ -68,7 +68,7 @@ def show
if current_user.respond_to?(:subscriptions)
@subscription = current_user.subscriptions.where(:subscribable_id => @work.id,
:subscribable_type => 'Work').first ||
- current_user.subscriptions.build
+ current_user.subscriptions.build(:subscribable => @work)
end
# TEMPORARY hack-like thing to fix the fact that chaptered works weren't hit-counted or added to history at all
@@ -13,7 +13,7 @@ def show
if current_user.respond_to?(:subscriptions)
@subscription = current_user.subscriptions.where(:subscribable_id => @user.id,
:subscribable_type => 'User').first ||
- current_user.subscriptions.build
+ current_user.subscriptions.build(:subscribable => @user)
end
end
@@ -69,7 +69,7 @@ def show
if current_user.respond_to?(:subscriptions)
@subscription = current_user.subscriptions.where(:subscribable_id => @user.id,
:subscribable_type => 'User').first ||
- current_user.subscriptions.build
+ current_user.subscriptions.build(:subscribable => @user)
end
end
@@ -50,6 +50,11 @@ def show
@serial_works = @series.serial_works.find(:all, :include => :work, :conditions => ['works.posted = ?', true], :order => :position).select{|sw| sw.work.visible(User.current_user)}
# sets the page title with the data for the series
@page_title = @series.unrevealed? ? ts("Mystery Series") : get_page_title(@series.allfandoms.collect(&:name).join(', '), @series.anonymous? ? ts("Anonymous") : @series.allpseuds.collect(&:byline).join(', '), @series.title)
+ if current_user.respond_to?(:subscriptions)
+ @subscription = current_user.subscriptions.where(:subscribable_id => @series.id,
+ :subscribable_type => 'Series').first ||
+ current_user.subscriptions.build(:subscribable => @series)
+ end
end
# GET /series/new
@@ -100,7 +100,7 @@ def show
if current_user.respond_to?(:subscriptions)
@subscription = current_user.subscriptions.where(:subscribable_id => @user.id,
:subscribable_type => 'User').first ||
- current_user.subscriptions.build
+ current_user.subscriptions.build(:subscribable => @user)
end
end
@@ -209,7 +209,7 @@ def show
if current_user.respond_to?(:subscriptions)
@subscription = current_user.subscriptions.where(:subscribable_id => @work.id,
:subscribable_type => 'Work').first ||
- current_user.subscriptions.build
+ current_user.subscriptions.build(:subscribable => @work)
end
@page_title = @work.unrevealed? ? ts("Mystery Work") :
View
@@ -58,19 +58,9 @@ def subscription_notification(user_id, subscription_id, creation_id, creation_cl
user = User.find(user_id)
@subscription = Subscription.find(subscription_id)
@creation = creation_class_name.constantize.find(creation_id)
- if @subscription.subscribable_type == 'User'
- subject_text = "#{@subscription.name} has posted "
- if creation_class_name == 'Chapter'
- subject_text << "Chapter #{@creation.position} of \"#{@creation.work.title}\""
- elsif creation_class_name == 'Work'
- subject_text << "\"#{@creation.title}\""
- end
- else
- subject_text = "Subscription Notice for #{@subscription.name}"
- end
mail(
:to => user.email,
- :subject => "[#{ArchiveConfig.APP_NAME}] #{subject_text}"
+ :subject => "[#{ArchiveConfig.APP_NAME}] #{@subscription.subject_text(@creation)}"
)
end
View
@@ -2,15 +2,17 @@ class Subscription < ActiveRecord::Base
belongs_to :user
belongs_to :subscribable, :polymorphic => true
- validates_presence_of :user
+ validates_presence_of :user, :subscribable_id, :subscribable_type
# Get the subscriptions associated with this work
# currently: users subscribed to work, users subscribed to creator of work
scope :for_work, lambda {|work|
where(["(subscribable_id = ? AND subscribable_type = 'Work')
- OR (subscribable_id IN (?) AND subscribable_type = 'User')",
+ OR (subscribable_id IN (?) AND subscribable_type = 'User')
+ OR (subscribable_id IN (?) AND subscribable_type = 'Series')",
work.id,
- work.pseuds.value_of(:user_id)]).
+ work.pseuds.value_of(:user_id),
+ work.series.value_of(:id)]).
group(:user_id)
}
@@ -25,4 +27,16 @@ def name
end
end
+ def subject_text(creation)
+ authors = creation.pseuds.map{ |p| p.byline }.to_sentence
+ if creation.is_a?(Chapter)
+ "#{creation.work.title} by #{authors} has been updated"
+ elsif subscribable_type == 'User'
+ "#{self.name} has posted #{creation.title}"
+ elsif subscribable_type == 'Series'
+ verb = creation.pseuds.length > 1 ? 'have' : 'has'
+ "#{authors} #{verb} updated the '#{self.name}' series"
+ end
+ end
+
end
@@ -10,6 +10,11 @@
<!--subnav-->
<% if logged_in? %>
<ul class="navigation actions" role="navigation">
+ <% if @subscription %>
+ <li>
+ <%= render :partial => 'subscriptions/form', :locals => { :subscription => @subscription } %>
+ </li>
+ <% end %>
<% @bookmark ||= bookmark_if_exists(@series) %>
<li><%= link_to (@bookmark ? ts("Edit Series Bookmark") : ts("Bookmark Series")), "#bookmark-form", :class => "bookmark_form_placement_open" %></li>
<% if is_author_of?(@series) %>
@@ -0,0 +1,13 @@
+<% if current_user && subscription %>
+ <% if subscription.new_record? %>
+ <%= form_for [current_user, subscription] do |f| %>
+ <%= f.hidden_field :subscribable_id %>
+ <%= f.hidden_field :subscribable_type %>
+ <%= f.submit ts("Subscribe") %>
+ <% end %>
+ <% else %>
+ <%= form_for [current_user, subscription], :html => {:method => :delete} do |f| %>
+ <%= f.submit ts("Unsubscribe") %>
+ <% end %>
+ <% end %>
+<% end %>
@@ -10,6 +10,10 @@
<% @subscriptions.each do |subscription| %>
<dt>
<%= link_to(subscription.name, subscription.subscribable) %>
+ (<%= subscription.subscribable_type %>)
+ <% if %w(Work Series).include?(subscription.subscribable_type) %>
+ <%= ts("by %{names}", :names => byline(subscription.subscribable)).html_safe %>
+ <% end %>
</dt>
<dd>
<%= form_for [current_user, subscription], :html => {:method => :delete} do |f| %>
@@ -10,18 +10,10 @@
<% unless @user == current_user %>
<li><%= link_to_help "coming-soon", ts("Bookmark") %></li>
<% end %>
- <% if @subscription && @subscription.new_record? %>
+ <% if current_user && @subscription %>
<li>
- <%= form_for [current_user, @subscription] do |f| %>
- <%= f.hidden_field :subscribable_id, :value => @user.id %>
- <%= f.hidden_field :subscribable_type, :value => @user.class.to_s %>
- <%= f.submit ts("Subscribe") %>
- <% end %>
+ <%= render :partial => 'subscriptions/form', :locals => { :subscription => @subscription } %>
</li>
- <% elsif @subscription %>
- <%= form_for [current_user, @subscription], :html => {:method => :delete} do |f| %>
- <li><%= f.submit ts("Unsubscribe") %></li>
- <% end %>
<% end %>
<% if @user == current_user %>
<li><%= span_if_current ts("Invitations"), user_invitations_path(@user) %></li>
@@ -91,19 +91,11 @@
</div>
</li>
- <li class="subscribe">
- <% if @subscription && @subscription.new_record? %>
- <%= form_for [current_user, @subscription] do |f| %>
- <%= f.hidden_field :subscribable_id, :value => @work.id %>
- <%= f.hidden_field :subscribable_type, :value => @work.class.to_s %>
- <%= f.submit "Subscribe" %>
- <% end %>
- <% elsif @subscription %>
- <%= form_for [current_user, @subscription], :html => {:method => :delete} do |f| %>
- <li><%= f.submit ts("Unsubscribe") %></li>
- <% end %>
- <% end %>
- </li>
+ <% if current_user && @subscription %>
+ <li class="subscribe">
+ <%= render :partial => 'subscriptions/form', :locals => { :subscription => @subscription } %>
+ </li>
+ <% end %>
<li class="download" aria-haspopup="true">
<a title="Download" class="downloads_open open"><%= ts("Download") %> &#8595;</a>

0 comments on commit 5aaa66f

Please sign in to comment.