Skip to content

AO3-2665 Allow collection owners/mods to add/invite works to their collections #2458

Merged
merged 1 commit into from May 15, 2016

2 participants

@zz9pzza zz9pzza Revert "Revert "AO3-2665 Allow collection owners/mods to add/invite w…
…orks to their collections""
77f06fd
@houndci-bot houndci-bot commented on the diff 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]
@houndci-bot
houndci-bot added a note May 14, 2016

Use the new Ruby 1.9 hash syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@houndci-bot houndci-bot commented on the diff 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,
@houndci-bot
houndci-bot added a note May 14, 2016

Use the new Ruby 1.9 hash syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@houndci-bot houndci-bot commented on the diff 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,
@houndci-bot
houndci-bot added a note May 14, 2016

Align the parameters of a method call if they span more than one line.
Use the new Ruby 1.9 hash syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@houndci-bot houndci-bot commented on the diff May 14, 2016
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?
@houndci-bot
houndci-bot added a note May 14, 2016

Redundant self detected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@houndci-bot houndci-bot commented on the diff May 14, 2016
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)
@houndci-bot
houndci-bot added a note May 14, 2016

Favor unless over if for negative conditions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@houndci-bot houndci-bot commented on the diff May 14, 2016
app/models/collection_item.rb
approve_by_user
+ users.each do |email_user|
+ unless email_user.preference.collection_emails_off
@houndci-bot
houndci-bot added a note May 14, 2016

Avoid more than 3 levels of block nesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@houndci-bot houndci-bot commented on the diff May 14, 2016
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,
@houndci-bot
houndci-bot added a note May 14, 2016

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
@houndci-bot houndci-bot commented on the diff May 14, 2016
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,
@houndci-bot
houndci-bot added a note May 14, 2016

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
@houndci-bot houndci-bot commented on the diff May 14, 2016
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?
@houndci-bot
houndci-bot added a note May 14, 2016

Rename is_maintainer? to maintainer?.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@houndci-bot houndci-bot commented on the diff May 14, 2016
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(', '))
@houndci-bot
houndci-bot added a note May 14, 2016

Prefer single-quoted strings inside interpolations.
Pass &:title as an argument to map instead of a block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@houndci-bot houndci-bot commented on the diff May 14, 2016
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)
@houndci-bot
houndci-bot added a note May 14, 2016

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
@zz9pzza zz9pzza merged commit 53978da into master May 15, 2016

2 of 4 checks passed

Details continuous-integration/travis-ci/push The Travis CI build could not complete due to an error
Details continuous-integration/codeship Build in progress
Details continuous-integration/travis-ci/pr The Travis CI build passed
hound 13 violations found.
@zz9pzza zz9pzza deleted the revert-2455-revert-1162-issue_2668 branch May 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.