Prevent admins to be able to view carousel in shops#14364
Conversation
73a5fe9 to
17d5bcb
Compare
rioug
left a comment
There was a problem hiding this comment.
It looks good, I just have some reservation around the migration testing.
| let(:product) { create(:product) } | ||
|
|
||
| it 'keeps the first image and removes additional images for a product' do | ||
| first_image = described_class::SpreeImage.create!( |
There was a problem hiding this comment.
Shouldn't we be using the actual app model instead of the one defined in the migration ? I think technically it should not make a difference but I feel like we are not testing a real production scenario where database entries would be created by a different model. Thought ?
There was a problem hiding this comment.
Good point, @rioug. I considered using the application Spree::Image model initially as well, but I ended up avoiding it because migrations should ideally be tested independently of the application code.
But your point is valid as well. That way, we may not be testing the actual production scenario. I've addressed it here: b7f8de2
rioug
left a comment
There was a problem hiding this comment.
Nice ! thanks for updating the migration spec 👍
mkllnk
left a comment
There was a problem hiding this comment.
Nice. Ideally we would modify the UX first and then delete old data in a separate pull request to avoid uploads during deploy. But it's very unlikely. So this is okay.
I have one suggestion below but you can also just leave it as is. Not important.
|
|
||
| RSpec.describe EnsureSingleProductImage, type: :migration do | ||
| let(:migration) { described_class.new } | ||
| let(:attachment) { Rack::Test::UploadedFile.new(Rails.root.join('app/webpacker/images/logo-white.png'), "image/png") } |
There was a problem hiding this comment.
We have a helper for this:
| let(:attachment) { Rack::Test::UploadedFile.new(Rails.root.join('app/webpacker/images/logo-white.png'), "image/png") } | |
| include FileHelper | |
| let(:attachment) { white_logo_file } |
|
@chahmedejaz Also, just wondering: are you planning to directly delete the images or they're still going to be retained for a while in case for very unlikely reasons some revert is needed? Thank you! |
|
Hey @mariocarabotta - you're right, but that's the behavior when uploading an image from the Products listing page, where the upload updates the earliest image record. By "Verify that only the earliest product image is retained", I was referring to the multiple images created when using the New Image button on the Images page. In that scenario, only the first image is actually displayed. Sorry for the confusion - I just realized the wording is misleading. I'll update the testing instructions. Thanks for pointing it out!
Hmm... that's a good callout. My initial thought was to remove the image records that aren't actually being displayed by the application. Before doing that, though, we could take a database backup so we have an easy rollback path if we need to restore anything later. Edit: |
|
thanks @chahmedejaz for clarifying, that was actually my mistake, and your approach is correct. Add first image to product
Add new image from settings
Replace image
I would still suggest to do a snapshot of the database for backup. Since this is a bug and I am not entirely sure what the software was doing in the past (and why those leftovers are still there :D ), it feels a bit safer to keep the data for a while. Thank you again! |
|
Thanks @mariocarabotta for the detailed testing. And sure we will make sure to keep the snapshot of the database just in case. |
|
Tested successfully scenario 1 & 2... |
|
Thanks @AMEA-LYON - For the migration scenario, we just need to make sure that before and after the PR the visible images on the products should remain intact. For example we added multiple images on a product. And only the first one is visible on the page. After the migration, the first image should still be visible. Deletion of images can only be verified when its dependent PR is merged. So, I think we can verify this scenario in the release testing. |
|
Thanks for the explanations @chahmedejaz , so I deployed 5.5.0, and added 2 images on a product, |
fd32335 to
b12596d
Compare
…ity and consistency
This commit needs to be reverted once we are good with the migration.
b12596d to
af31d7a
Compare
|
Hi @rioug - the conflict has been resolved. |
…first by ID - Use SpreeProduct model with `has_one :image` to preserve the product's associated image. Since the association has no default order, the first image by ID may differ from the associated image at runtime - Batch process products in slices of 1000 to reduce memory usage. - Update spec to rely on the product-image association instead of creation-order assumptions
|
I tested this on staging and found an issue with the migration. The migration was keeping the first image because that's the behavior I observed locally and with newly created products on staging. However, after testing older products, I found that this assumption isn't always correct. The reason is that the product currently displays its image through a I've updated the migration to preserve the image that's currently associated with the product (i.e. Here's the commit for the above change: 33b723c |
| images.where.not(id: image_to_keep.id).update_all(deleted_at: Time.current) | ||
| viewable_id: product.id | ||
| ).where.not(id: image_to_keep.id) | ||
| .update_all(deleted_at: Time.current) |
There was a problem hiding this comment.
Given that update_all bypasses usual ActiveRecord callback, does the associated physical image gets deleted ?
There was a problem hiding this comment.
Nope @rioug - The associated physical image doesn't get deleted in this case. It's preserved for us to restore if required.
There was a problem hiding this comment.
Thanks for clarifying, I had forgotten we wanted to keep the image for potential restore.
|
Tested the 3 scenario successfully ! Congratulations !! 🎉 🎉 🎉 |
|
@chahmedejaz there's a conflict |
|
Thanks @sigmundpetersen - It's resolved! |
|
Hi @rioug - Sorry but this is not meant to be deployed to production yet. It needs to go with its dependent PR mentioned in the description, that's still up. Let me revert this and redraft the release. Sorry for the inconvenience. 😞 |
|
I've redrafted the release including this PR's revert. |
What? Why?
As part of the multiple product images roadmap, the carousel functionality is being developed before backoffice support for managing multiple images is available.
Currently, it is possible for products to have multiple images associated with them through the image settings page, even though this functionality is not intended to be available to users yet. To keep production data aligned with the current user experience, this PR:
Users can still replace an existing product image through the product list and image settings page, so there is no change to the intended image management workflow. A new image can only be added through the product list page.
What should we test?
Scenario 1 - Existing product image management
Scenario 2 - Product without an image
Scenario 3 - Migration
Release notes
Changelog Category (reviewers may add a label for the release notes):
Dependencies
Need the following PR to be merged along with this one: