AO3-5556 Don't change collections on preview - Follow up PR#5820
AO3-5556 Don't change collections on preview - Follow up PR#5820pmonfort wants to merge 9 commits into
Conversation
I think it's pre-existing, but it's vaguely related, so I might as well fix it.
0e88cf1 to
809c2e6
Compare
- Extract AssociationAssignment into its own concern - Restore update_bookmarker_collections_index in Bookmarkable - Fix set_anon_unrevealed for new records in Collectible - Reorder CollectionItem callbacks per rubocop-rails 2.12.4 - Normalize locale files and add missing i18n keys
- Update specs to use item: instead of work: for CollectionItem - Fix stale tags cache in rake spec with collection.reload - Update bookmark controller spec for simplified flash message - Fix cucumber scenario: remove non-existent flash assertion
809c2e6 to
4ef0c3f
Compare
| return if collections_data.blank? | ||
|
|
||
| content_tag(:dt, t("works_helper.collections_meta_tag.collections"), class: "collections") + | ||
| "\n".html_safe + |
There was a problem hiding this comment.
Is there a way to join these with a newline that doesn't need html_safe? (Not super blocking if there isn't a nice way, but since we're in the neighbourhood...) Maybe content_tag(:br)?
| distinct.joins(:approved_collection_items).merge(collection.all_items) | ||
| } | ||
|
|
||
| after_validation :set_anon_unrevealed, if: -> { collection_items.loaded? } |
There was a problem hiding this comment.
To make sure I understand the flow here, why do we need the if condition?
|
|
||
| # approve with the current user, who is the person who has just | ||
| # added this item -- might be either moderator or owner | ||
| approve(User.current_user) |
There was a problem hiding this comment.
Do we still need to check if this is :false? iirc there's some legacy code that sets it to that 🥲
| FactoryBot.create(:work, collection_names: @owner.name) | ||
| @owner.collection_items.each {|ci| ci.approve(nil); ci.save} | ||
| @child.collection_items.each {|ci| ci.approve(nil); ci.save} if @child | ||
| expect(@original_cache_key).not_to eq(@owner.works_index_cache_key) |
There was a problem hiding this comment.
Are these deletions because the approval is automatic now? Or some other reason?
| "Added to collection(s): #{collection.title}. " \ | ||
| "Please note: private bookmarks are not listed in collections." | ||
| it_redirects_to_with_notice(bookmark_path(bookmark), success_msg) | ||
| it_redirects_to_with_notice(bookmark_path(bookmark), "Bookmark was successfully updated.") |
There was a problem hiding this comment.
This doesn't seem to match the description of the test -- is the test useful anymore?
| success: Bookmark was successfully created. It should appear in bookmark listings within the next few minutes. | ||
| warnings: | ||
| private_bookmark_added_to_collection: " Please note: private bookmarks are not listed in collections." | ||
| new_moderated_collections_message_html: |
There was a problem hiding this comment.
Why does this (and the other key) need _html? I don't see any HTML getting injected 🤔
|
|
||
| message = t("bookmarks.new_moderated_collections_message_html", | ||
| count: new_moderated_collections.length, | ||
| collections: view_context.safe_join(links, ", ")) |
There was a problem hiding this comment.
Does this need to be collections_html? (Related to my question about the parent key name)
| if moderated_collections.present? | ||
| flash[:notice] ||= '' | ||
| flash[:notice] += ts(" You have submitted your work to #{moderated_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: moderated_collections.map(&:title).join(', ')) | ||
| def in_moderated_collection(flash = self.flash) |
There was a problem hiding this comment.
in_moderated_collection sounds like it would return a boolean to me; maybe show_moderated_collection_warning would be more accurate?
Pull Request Checklist
AO3-1234 Fix thing)Issue
https://otwarchive.atlassian.net/browse/AO3-5556
Purpose
Follow-up to #4501 by @tickinginstant, adopting and completing the work from that PR.
Original PR (#4501)
collections_to_addandcollections_to_remove.This PR
CollectionItemto follow Rails convention (before_validation→before_save→after_save→after_create_commit→after_destroy→after_commit)Collectible(# Note:→# NOTE:) per Hound/Rubocop conventionassign_through_associationfromApplicationRecordinto anAssociationAssignmentconcern, included only inCollectibleandTaggablecollections_meta_taghelper inWorksHelperto replace variable assignment inworks/_meta.html.erbI follow), not a button (I press)Testing Instructions
Steps to reproduce the bug
indication on the preview page if the collection is unrevealed)
Automated tests
bundle exec rspec spec/models/collection_item_spec.rb spec/models/concerns/collectible_spec.rb spec/lib/works_owner_spec.rb— 65 examples, 0 failuresbundle exec cucumber features/collections/work_preview_collections.feature— 6 scenarios, 6 passedReferences
Follow-up to #4501
Credit
Pablo Monfort (he/him))