AO3-2665 Allow collection owners/mods to add/invite works to their collections #2458
+278
−83
zz9pzza
commented
May 14, 2016
•
lib/collectible.rb
| @@ -16,6 +16,10 @@ def self.included(collectible) | ||
| :through => :collection_items, | ||
| :source => :collection, | ||
| :conditions => ['collection_items.user_approval_status = ? AND collection_items.collection_approval_status = ?', CollectionItem::APPROVED, CollectionItem::APPROVED] | ||
| + has_many :rejected_collections, | ||
| + :through => :collection_items, | ||
| + :source => :collection, | ||
| + :conditions => ['collection_items.user_approval_status = ? ', CollectionItem::REJECTED] |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
|
lib/collectible.rb
| @@ -16,6 +16,10 @@ def self.included(collectible) | ||
| :through => :collection_items, | ||
| :source => :collection, | ||
| :conditions => ['collection_items.user_approval_status = ? AND collection_items.collection_approval_status = ?', CollectionItem::APPROVED, CollectionItem::APPROVED] | ||
| + has_many :rejected_collections, | ||
| + :through => :collection_items, | ||
| + :source => :collection, |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
|
lib/collectible.rb
| @@ -16,6 +16,10 @@ def self.included(collectible) | ||
| :through => :collection_items, | ||
| :source => :collection, | ||
| :conditions => ['collection_items.user_approval_status = ? AND collection_items.collection_approval_status = ?', CollectionItem::APPROVED, CollectionItem::APPROVED] | ||
| + has_many :rejected_collections, | ||
| + :through => :collection_items, |
|
Align the parameters of a method call if they span more than one line.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
|
app/models/collection_item.rb
| break | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| - | ||
| + | ||
| + before_save :send_work_invitation | ||
| + def send_work_invitation | ||
| + if !approved_by_user? && approved_by_collection? && self.new_record? |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
|
app/models/collection_item.rb
| break | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| - | ||
| + | ||
| + before_save :send_work_invitation | ||
| + def send_work_invitation | ||
| + if !approved_by_user? && approved_by_collection? && self.new_record? | ||
| + if !User.current_user.is_author_of?(item) |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
|
app/models/collection_item.rb
| approve_by_user | ||
| + users.each do |email_user| | ||
| + unless email_user.preference.collection_emails_off |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
|
app/mailers/user_mailer.rb
| + @work = Work.find(work_id) | ||
| + @collection = Collection.find(collection_id) | ||
| + mail( | ||
| + to: @user.email, | ||
| + subject: "[#{ArchiveConfig.APP_SHORT_NAME}]#{'[' + @collection.title + ']'} Your work was added to a collection" | ||
| + ) | ||
| + end | ||
| + | ||
| + # Send a request to a work owner asking that they approve the inclusion | ||
| + # of their work in a collection | ||
| + def invited_to_collection_notification(user_id, work_id, collection_id) | ||
| + @user = User.find(user_id) | ||
| + @work = Work.find(work_id) | ||
| + @collection = Collection.find(collection_id) | ||
| + mail( | ||
| + to: @user.email, |
|
Indent the first parameter one step more than the start of the previous line.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
|
app/mailers/user_mailer.rb
| @@ -20,6 +20,29 @@ class UserMailer < BulletproofMailer::Base | ||
| default from: "Archive of Our Own " + "<#{ArchiveConfig.RETURN_ADDRESS}>" | ||
| + # Send an email letting authors know their work has been added to a collection | ||
| + def added_to_collection_notification(user_id, work_id, collection_id) | ||
| + @user = User.find(user_id) | ||
| + @work = Work.find(work_id) | ||
| + @collection = Collection.find(collection_id) | ||
| + mail( | ||
| + to: @user.email, |
|
Indent the first parameter one step more than the start of the previous line.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
|
app/helpers/users_helper.rb
| @@ -4,6 +4,11 @@ module UsersHelper | ||
| def is_author_of?(item) | ||
| current_user.is_a?(User) ? current_user.is_author_of?(item) : false | ||
| end | ||
| + | ||
| + # Can be used to check if user is maintainer of any collections | ||
| + def is_maintainer? |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
|
app/controllers/collection_items_controller.rb
| unless unapproved_collections.empty? | ||
| - flash[:notice] += "<br />" + ts("Your addition will have to be approved before it appears in %{moderated}.", | ||
| - :moderated => unapproved_collections.collect(&:title).join(", ")) | ||
| + flash[:notice] ||= "" | ||
| + flash[:notice] += ts(" You have submitted your work to #{unapproved_collections.size > 1 ? "moderated collections (%{all_collections}). It will not become a part of those collections" : "the moderated collection '%{all_collections}'. It will not become a part of the collection"} until it has been approved by a moderator.", all_collections: unapproved_collections.map { |f| f.title }.join(', ')) |
|
Prefer single-quoted strings inside interpolations.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
|
app/controllers/collection_items_controller.rb
| elsif @item.collections.include?(collection) | ||
| - errors << ts("This item has already been submitted to %{collection_title}.", :collection_title => collection.title) | ||
| + if @item.rejected_collections.include?(collection) |
|
Use the return of the conditional for variable assignment and comparison.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://otwarchive.atlassian.net/browse/AO3-2665
Reverts otwcode/otwarchive#2455