Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically unselect images when source image is deleted #9793

Closed
teolemon opened this issue Feb 13, 2024 · 6 comments · Fixed by #10692
Closed

Automatically unselect images when source image is deleted #9793

teolemon opened this issue Feb 13, 2024 · 6 comments · Fixed by #10692
Labels
good first issue Welcome to Open Food Facts. This issue should be approachable if you're new. Get in touch for help. 🖼️ Images 👮 Moderation

Comments

@teolemon
Copy link
Member

teolemon commented Feb 13, 2024

What

  • Automatically unselect images when source image is deleted

Why

  • This saves time for contributors on problematic images, and avoid forgetting to unselect it.

Code pointers

Notes to solve this:

  • Only admins can delete images, you need to edit lib/ProductOpener/Config_off.pm to add your userid to the list of admins, and then create this user on your local dev environment.
  • Related code is is in lib/ProductOpener/Images.pm
  • the function called when images are deleted is:
    sub process_image_move ($user_id, $code, $imgids, $move_to, $ownerid) {
  • Selected images are stored in $product_ref->{images} , once an image is deleted, you will need to check the images to see which ones have the "imgid" field equal to the id of the image deleted, and then call process_image_unselect.
  • e.g. https://world.openfoodfacts.org/api/v3/product/4056489637295/flammkuchen-vegetarisch-duc-de-coeur?fields=images

Steps to verify that the problem is solved

  • Create a user in your local product opener
  • Add your userid to %admins in Config_off.pm , and run "make restart" to restart the backend
  • Add or edit a product, upload an image, and crop it and select it in the ingredients section for instance
  • Save the product, and access the product page, you should see your cropped image in the ingredients section
  • Add .json?fields=images at the end of the product page: this will show you the structure of the "images" field. Use a browser extension to display JSON in a structured way. You should see an entry for the image you added (with a key that is a number), and an entry for the cropped / selected image (id starting with "ingredients_en")
  • Edit the product. As your are logged in as an admin, you can delete the source image (click on "Manage images" at the top of the product edit form)
  • Once the source image is deleted, reload the product page
  • You should not see the cropped ingredients image, as it should have been deselected

Part of

@stephanegigandet
Copy link
Contributor

stephanegigandet commented Mar 8, 2024

Notes to solve this:

Only admins can delete images, you need to edit lib/ProductOpener/Config_off.pm to add your userid to the list of admins, and then create this user on your local dev environment.

Related code is is in lib/ProductOpener/Images.pm

the function called when images are deleted is:
sub process_image_move ($user_id, $code, $imgids, $move_to, $ownerid) {

Selected images are stored in $product_ref->{images} , once an image is deleted, you will need to check the images to see which ones have the "imgid" field equal to the id of the image deleted, and then call process_image_unselect.

e.g. https://world.openfoodfacts.org/api/v3/product/4056489637295/flammkuchen-vegetarisch-duc-de-coeur?fields=images

@stephanegigandet stephanegigandet added the good first issue Welcome to Open Food Facts. This issue should be approachable if you're new. Get in touch for help. label Mar 8, 2024
@himanshi-154
Copy link

I would like to work on this issue!

himanshi-154 added a commit to himanshi-154/openfoodfacts-server that referenced this issue Mar 12, 2024
Added code to solve issue openfoodfacts#9793 to automatically unselect images when source image is deleted.
@stephanegigandet
Copy link
Contributor

stephanegigandet commented Mar 13, 2024

Steps to verify that the problem is solved:

  • Create a user in your local product opener
  • Add your userid to %admins in Config_off.pm , and run "make restart" to restart the backend
  • Add or edit a product, upload an image, and crop it and select it in the ingredients section for instance
  • Save the product, and access the product page, you should see your cropped image in the ingredients section
  • Add .json?fields=images at the end of the product page: this will show you the structure of the "images" field. Use a browser extension to display JSON in a structured way. You should see an entry for the image you added (with a key that is a number), and an entry for the cropped / selected image (id starting with "ingredients_en")
  • Edit the product. As your are logged in as an admin, you can delete the source image (click on "Manage images" at the top of the product edit form)
  • Once the source image is deleted, reload the product page
  • You should not see the cropped ingredients image, as it should have been deselected

@komalverma04
Copy link

@stephanegigandet can i work on this issue.

@himanshi-154
Copy link

@komalverma04 I have already done some work on this issue, please refer this PR and let me know if you find something that I need to improve in it!

@komalverma04
Copy link

@komalverma04 I have already done some work on this issue, please refer this PR and let me know if you find something that I need to improve in it!

Great!! For sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Welcome to Open Food Facts. This issue should be approachable if you're new. Get in touch for help. 🖼️ Images 👮 Moderation
4 participants