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, |
|
Sure @AMEA-LYON - I'll check this scenario and get back to you. Thanks! |
|
@openfoodfoundation/reviewers I just thought of something:
|
|
I would assume the underlying Image in S3 would be deleted, you should be able to check that in staging.
There is something in place to allow you to backup the database before releasing a PR on staging, which you can then load back on staging. But I can't remember how it works, maybe @mkllnk or @RachL would know more. |
|
i never used it, but Filipe has documented some steps here, maybe it helps: https://ofn-user-guide.gitbook.io/ofn-testing-handbook/testers-toolkit/reverting-database-changes |
|
Thanks both, it really helps alot! |
edecf47 to
3b5622d
Compare
3b5622d to
1c3ad26
Compare
This commit needs to be reverted once we are good with the migration.
1c3ad26 to
fba566f
Compare
|
@rioug - I've added the soft delete functionality in this commit. To be honest, I don't particularly like this workaround, but after investigating ActiveStorage's behavior, this seemed to be the cleanest and safest approach. The issue is that even though This is intended to be a temporary solution, and we should be able to revert this specific commit once we get confirmation from instance managers that all existing images are intact and no further recovery actions are required. |
rioug
left a comment
There was a problem hiding this comment.
Thanks @chahmedejaz, I think we need to fix the migration order, but we should be good afterwards.
| image_to_keep = images.first | ||
|
|
||
| images.where.not(id: image_to_keep.id).delete_all | ||
| images.where.not(id: image_to_keep.id).update_all(deleted_at: Time.current) |
There was a problem hiding this comment.
This needs to run after the other migration, and I am pretty sure currently it's the other way around, based on the migration's timestamp in the name. Could you fix the migration to make sure they run in the correct order ?
|
|
||
| attachment_reflection = _reflections["attachment_attachment"] | ||
| attachment_reflection.options[:dependent] = nil | ||
|
|
There was a problem hiding this comment.
I am assuming this refers to :
The attachment association's dependent behavior has also been overridden to prevent automatic file cleanup.
Could you add a comment to explain what it does and why it's needed ?
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: