Skip to content

Commit

Permalink
feat: report a problem panels (OFF data + French SignalConso) (#10106)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanegigandet authored Apr 8, 2024
1 parent bdc0168 commit 4d19492
Show file tree
Hide file tree
Showing 33 changed files with 1,775 additions and 54 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added html/images/panels/report_problem/signalconso.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7655,6 +7655,8 @@ JS
= display_knowledge_panel($product_ref, $product_ref->{"knowledge_panels_" . $lc}, "environment_card");
$template_data_ref->{health_card_panel}
= display_knowledge_panel($product_ref, $product_ref->{"knowledge_panels_" . $lc}, "health_card");
$template_data_ref->{report_problem_card_panel}
= display_knowledge_panel($product_ref, $product_ref->{"knowledge_panels_" . $lc}, "report_problem_card");
if ($product_ref->{"knowledge_panels_" . $lc}{"contribution_card"}) {
$template_data_ref->{contribution_card_panel}
= display_knowledge_panel($product_ref, $product_ref->{"knowledge_panels_" . $lc}, "contribution_card");
Expand Down
2 changes: 2 additions & 0 deletions lib/ProductOpener/KnowledgePanels.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ use ProductOpener::Display qw/:all/;
use ProductOpener::Ecoscore qw/is_ecoscore_extended_data_more_precise_than_agribalyse/;
use ProductOpener::PackagerCodes qw/%packager_codes/;
use ProductOpener::KnowledgePanelsContribution qw/create_contribution_card_panel/;
use ProductOpener::KnowledgePanelsReportProblem qw/create_report_problem_card_panel/;

use JSON::PP;
use Encode;
Expand Down Expand Up @@ -196,6 +197,7 @@ sub create_knowledge_panels ($product_ref, $target_lc, $target_cc, $options_ref)

create_health_card_panel($product_ref, $target_lc, $target_cc, $options_ref);
create_environment_card_panel($product_ref, $target_lc, $target_cc, $options_ref);
create_report_problem_card_panel($product_ref, $target_lc, $target_cc, $options_ref);
my $has_contribution_card = create_contribution_card_panel($product_ref, $target_lc, $target_cc, $options_ref);

# Create the root panel that contains the panels we want to show directly on the product page
Expand Down
123 changes: 123 additions & 0 deletions lib/ProductOpener/KnowledgePanelsReportProblem.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# This file is part of Product Opener.
#
# Product Opener
# Copyright (C) 2011-2023 Association Open Food Facts
# Contact: [email protected]
# Address: 21 rue des Iles, 94100 Saint-Maur des Fossés, France
#
# Product Opener is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

=head1 NAME
ProductOpener::KnowledgePanelsReportProblem - Generate knowledge panels to report a problem with the data or the product
=head1 SYNOPSIS
Knowledge panels to indicate how to report a problem with the product data,
or with the product (e.g. link to report to authorities like SignalConso in France)
=cut

package ProductOpener::KnowledgePanelsReportProblem;

use ProductOpener::PerlStandards;
use Exporter qw< import >;

use Log::Any qw($log);

BEGIN {
use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS);
@EXPORT_OK = qw(
&create_report_problem_card_panel
&create_data_quality_panel
); # symbols to export on request
%EXPORT_TAGS = (all => [@EXPORT_OK]);
}

use vars @EXPORT_OK;

use ProductOpener::KnowledgePanels qw(create_panel_from_json_template);
use ProductOpener::Tags qw(:all);

use Encode;
use Data::DeepAccess qw(deep_get);

=head2 create_report_problem_card_panel ( $product_ref, $target_lc, $target_cc, $options_ref )
Creates a knowledge panel card that contains all knowledge panels related to reporting problems.
=head3 Arguments
=head4 product reference $product_ref
Loaded from the MongoDB database, Storable files, or the OFF API.
=head4 language code $target_lc
Returned attributes contain both data and strings intended to be displayed to users.
This parameter sets the desired language for the user facing strings.
=head4 country code $target_cc
We may display country specific recommendations from health authorities, or country specific scores.
=head4 options reference $options_ref
=cut

sub create_report_problem_card_panel ($product_ref, $target_lc, $target_cc, $options_ref) {

$log->debug("create contribution card panel", {code => $product_ref->{code}}) if $log->is_debug();

my @panels = ();
my $panel_data_ref = {};

# TODO: add a panel to display the consumer service contact information if we have it
# for the owner of the product. Otherwise, warn that we don't make or sell the product
# + add promo message for the pro platform ("Are you the owner? Add your contact information")

# Panel to tell users that they can fix the data themselves

create_panel_from_json_template(
"incomplete_or_incorrect_data",
"api/knowledge-panels/report_problem/incomplete_or_incorrect_data.tt.json",
$panel_data_ref, $product_ref, $target_lc, $target_cc, $options_ref
);
push(@panels, "incomplete_or_incorrect_data");

# TODO: add a panel for Nutri-Patrol once it is ready

# Panels to report product issues to local authorities

# France - SignalConso

if (($target_cc eq "fr") and ($target_lc eq "fr")) {

create_panel_from_json_template(
"fr_report_product_signalconso",
"api/knowledge-panels/report_problem/fr_report_product_signalconso.tt.json",
$panel_data_ref, $product_ref, $target_lc, $target_cc, $options_ref
);
push(@panels, "fr_report_product_signalconso");
}

my $panel_data_ref = {report_problem_panels => \@panels,};
create_panel_from_json_template("report_problem_card",
"api/knowledge-panels/report_problem/report_problem_card.tt.json",
$panel_data_ref, $product_ref, $target_lc, $target_cc, $options_ref);

return;
}

1;
63 changes: 20 additions & 43 deletions lib/ProductOpener/Products.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2798,54 +2798,31 @@ This function is called by the web/panels/panel.tt.html template for knowledge p
=cut

my %actions_urls = (
edit_product => "",
add_categories => "#categories",
add_ingredients_image => "#ingredients",
add_ingredients_text => "#ingredients",
add_nutrition_facts_image => "#nutrition",
add_nutrition_facts => "#nutrition",
add_packaging_image => "#packaging",
add_packaging_text => "#packaging",
add_packaging_components => "#packaging",
add_origins => "#origins",
add_quantity => "#product_characteristics",
add_stores => "#stores",
add_packager_codes_image => "#packager_codes",
add_labels => "#labels",
add_countries => "#countries",
);

sub product_action_url ($code, $action) {

my $url = "/cgi/product.pl?type=edit&code=" . $code;

if ($action eq "add_categories") {
$url .= "#categories";
}
elsif ($action eq "add_ingredients_image") {
$url .= "#ingredients";
}
elsif ($action eq "add_ingredients_text") {
$url .= "#ingredients";
}
elsif ($action eq "add_nutrition_facts_image") {
$url .= "#nutrition";
}
elsif ($action eq "add_nutrition_facts") {
$url .= "#nutrition";
}
elsif ($action eq "add_packaging_image") {
$url .= "#packaging";
}
elsif ($action eq "add_packaging_text") {
$url .= "#packaging";
}
elsif ($action eq "add_packaging_components") {
$url .= "#packaging";
}
# Note: 27/11/2022 - Pierre - The following HTML anchors links will do nothing unless a matching custom HTML anchor is added in the future to the product edition template
elsif ($action eq "add_origins") {
$url .= "#origins";
}
elsif ($action eq "add_quantity") {
$url .= "#product_characteristics";
}
elsif ($action eq "add_stores") {
$url .= "#stores";
}
elsif ($action eq "add_packager_codes_image") {
$url .= "#packager_codes";
}
elsif ($action eq "add_labels") {
$url .= "#labels";
}
elsif ($action eq "add_countries") {
$url .= "#countries";
if (defined $actions_urls{$action}) {
$url .= $actions_urls{$action};
}
# END will do nothing unless a custom section is added
else {
$log->error("unknown product action", {code => $code, action => $action});
}
Expand Down
1 change: 1 addition & 0 deletions lib/ProductOpener/Store.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use ProductOpener::Config qw/:all/;
use ProductOpener::Paths qw/:all/;

use Storable qw(lock_store lock_nstore lock_retrieve);

use URI::Escape::XS;
use Unicode::Normalize;
use Log::Any qw($log);
Expand Down
28 changes: 28 additions & 0 deletions po/common/common.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6842,6 +6842,34 @@ msgctxt "sweetener"
msgid "sweetener"
msgstr ""

msgctxt "action_edit_product"
msgid "Complete or correct product information"
msgstr "Complete or correct product information"

msgctxt "report_problem_panel_title"
msgid "Report a problem"
msgstr "Report a problem"

msgctxt "incomplete_or_incorrect_data_title"
msgid "Incomplete or incorrect information?"
msgstr "Incomplete or incorrect information?"

msgctxt "incomplete_or_incorrect_data_subtitle_off"
msgid "Category, labels, ingredients, allergens, nutritional information, photos etc."
msgstr "Category, labels, ingredients, allergens, nutritional information, photos etc."

msgctxt "incomplete_or_incorrect_data_content_correct"
msgid "If the information does not match the information on the packaging, you can complete or correct it. Thank you!"
msgstr "If the information does not match the information on the packaging, you can complete or correct it. Thank you!"

msgctxt "incomplete_or_incorrect_data_content_correct_off"
msgid "Open Food Facts is a collaborative database, and every contribution is useful for all."
msgstr "Open Food Facts is a collaborative database, and every contribution is useful for all."

msgctxt "description"
msgid "Description"
msgstr "Description"

msgctxt "report_problem_navigation"
msgid "Report a problem"
msgstr "Report a problem"
32 changes: 31 additions & 1 deletion po/common/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -6861,6 +6861,36 @@ msgctxt "sweetener"
msgid "sweetener"
msgstr "sweetener"

msgctxt "action_edit_product"
msgid "Complete or correct product information"
msgstr "Complete or correct product information"

msgctxt "report_problem_panel_title"
msgid "Report a problem"
msgstr "Report a problem"

msgctxt "incomplete_or_incorrect_data_title"
msgid "Incomplete or incorrect information?"
msgstr "Incomplete or incorrect information?"

msgctxt "incomplete_or_incorrect_data_subtitle_off"
msgid "Category, labels, ingredients, allergens, nutritional information, photos etc."
msgstr "Category, labels, ingredients, allergens, nutritional information, photos etc."

msgctxt "incomplete_or_incorrect_data_content_correct"
msgid "If the information does not match the information on the packaging, please complete or correct it."
msgstr "If the information does not match the information on the packaging, please complete or correct it."

msgctxt "incomplete_or_incorrect_data_content_correct_off"
msgid "Open Food Facts is a collaborative database, and every contribution is useful for all."
msgstr "Open Food Facts is a collaborative database, and every contribution is useful for all."

msgctxt "description"
msgid "Description"
msgstr "Description"
msgstr "Description"

msgctxt "report_problem_navigation"
msgid "Report a problem"
msgstr "Report a problem"


26 changes: 26 additions & 0 deletions po/common/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -6829,4 +6829,30 @@ msgctxt "api_result_product_reverted"
msgid "Product reverted to the specified revision"
msgstr "Produit rétabli à la version spécifiée"

msgctxt "action_edit_product"
msgid "Complete or correct product information"
msgstr "Compléter ou corriger les informations du produit"

msgctxt "report_problem_panel_title"
msgid "Report a problem"
msgstr "Signaler un problème"

msgctxt "incomplete_or_incorrect_data_title"
msgid "Incomplete or incorrect information?"
msgstr "Informations incomplètes ou incorrectes ?"

msgctxt "incomplete_or_incorrect_data_subtitle_off"
msgid "Category, labels, ingredients, allergens, nutritional information, photos etc."
msgstr "Catégorie, labels, ingrédients, allergènes, informations nutritionnelles, photos etc."

msgctxt "incomplete_or_incorrect_data_content_correct"
msgid "If the information does not match the information on the packaging, you can complete or correct it. Thank you!"
msgstr "Si les informations ne correspondent pas aux informations présentes sur l'emballage, vous pouvez les compléter ou de les corriger. Merci !"

msgctxt "incomplete_or_incorrect_data_content_correct_off"
msgid "Open Food Facts is a collaborative database, and every contribution is useful for all."
msgstr "Open Food Facts est une base de données collaborative, et chaque contribution est utile à tous."

msgctxt "report_problem_navigation"
msgid "Signaler un problème"
msgstr "Signaler un problème"
1 change: 1 addition & 0 deletions stop_words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ scrypt
Scrypt
serverTimePretty
sftp
SignalConso
sirop
slad
Sonnenblumen
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"level": "info",
"topics": [
"problem"
],
"expand_for": "large",
"evaluation": "neutral",
"title_element": {
"title": "Faire un signalement sur SignalConso",
"subtitle": "Etiquetage non conforme, vente d'un produit périmé, présence d'un corps étranger, etc.",
"icon_url": "[% static_subdomain %]/images/panels/report_problem/signalconso.png",
},
"elements": [
{
"element_type": "text",
"text_element": {
"html": `
Vous avez rencontré un problème avec ce produit : <b>étiquetage non conforme, produit périmé encore en vente,
présence d'un corps étranger, etc.</b> ?<br>
Faites un signalement à l'entreprise et à la répression des fraudes sur SignalConso, un outil de la
Direction générale de la concurrence, de la consommation et de la répression des fraudes (DGCCRF).
`
},
},
{
"element_type": "image",
"image_element": {
"url": "[% static_subdomain %]/images/panels/report_problem/signalconso-button.png",
"alt": "Je fais un signalement sur SignalConso",
"link_url": "https://signal.conso.gouv.fr/fr/alimentaire-codebarres/faire-un-signalement?gtin=[% product.code %]&utm_source=openfoodfacts&utm_campaign=product_page_panel"
}

}
]
}
Loading

0 comments on commit 4d19492

Please sign in to comment.