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

feat: nutripatrol product report #10991

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion cgi/product_multilingual.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ ($product_ref, $field, $language, $request_ref)

$template_data_ref_process->{edited_product_url}
= $url_prefix . get_owner_pretty_path() . product_url($product_ref);
$template_data_ref_process->{edit_product_url} = $url_prefix . product_action_url($product_ref->{code}, "");
$template_data_ref_process->{edit_product_url} = $url_prefix . product_action_url($product_ref->{code});

if ($type ne 'delete') {
# adding contribution card
Expand Down
1 change: 1 addition & 0 deletions conf/apache-2.4/modperl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ PerlPassEnv POSTGRES_PASSWORD
PerlPassEnv LOG_LEVEL_ROOT
PerlPassEnv LOG_LEVEL_MONGODB
PerlPassEnv LOG_LEVEL_RATE_LIMITER
PerlPassEnv NUTRIPATROL_URL
PerlPassEnv OFF_LOG_EMAILS
PerlPassEnv BUILD_CACHE_REPO
PerlPassEnv RATE_LIMITER_BLOCKING_ENABLED
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ x-backend-conf: &backend-conf
- LOG_LEVEL_ROOT
- LOG_LEVEL_MONGODB
- LOG_LEVEL_RATE_LIMITER
- NUTRIPATROL_URL
- INFLUXDB_HOST
- BUILD_CACHE_REPO
- RATE_LIMITER_BLOCKING_ENABLED
Expand Down
3 changes: 2 additions & 1 deletion env/env.obf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ COMPOSE_PROJECT_NAME=po_obf

PRODUCT_OPENER_FLAVOR=openbeautyfacts
PRODUCT_OPENER_FLAVOR_SHORT=obf
ROBOTOFF_URL=https://robotoff.openfoodfacts.org
ROBOTOFF_URL=https://robotoff.openfoodfacts.org
NUTRIPATROL_URL=https://nutripatrol.openfoodfacts.org/
2 changes: 2 additions & 0 deletions env/env.off
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ COMPOSE_PROJECT_NAME=po_off

PRODUCT_OPENER_FLAVOR=openfoodfacts
PRODUCT_OPENER_FLAVOR_SHORT=off

NUTRIPATROL_URL=https://nutripatrol.openfoodfacts.org/
2 changes: 2 additions & 0 deletions env/env.opf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ COMPOSE_PROJECT_NAME=po_opf

PRODUCT_OPENER_FLAVOR=openproductfacts
PRODUCT_OPENER_FLAVOR_SHORT=opf

NUTRIPATROL_URL=https://nutripatrol.openfoodfacts.org/
2 changes: 2 additions & 0 deletions env/env.opff
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ COMPOSE_PROJECT_NAME=po_opff

PRODUCT_OPENER_FLAVOR=openpetfoodfacts
PRODUCT_OPENER_FLAVOR_SHORT=opff

NUTRIPATROL_URL=https://nutripatrol.openfoodfacts.org/
37 changes: 37 additions & 0 deletions lib/ProductOpener/ConfigEnv.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This file is part of Product Opener.
#
# Product Opener
# Copyright (C) 2011-2024 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/>.

package ProductOpener::ConfigEnv;

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

BEGIN {
use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS);
@EXPORT_OK = qw(
$nutripatrol_url
);
%EXPORT_TAGS = (all => [@EXPORT_OK]);
}
use vars @EXPORT_OK; # no 'my' keyword for these

$nutripatrol_url = $ENV{NUTRIPATROL_URL};

1;
10 changes: 5 additions & 5 deletions lib/ProductOpener/KnowledgePanelsReportProblem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ BEGIN {
use vars @EXPORT_OK;

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

use Encode;
use Data::DeepAccess qw(deep_get);
Expand Down Expand Up @@ -87,16 +88,15 @@ sub create_report_problem_card_panel ($product_ref, $target_lc, $target_cc, $opt
# + 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

# or report to nutripatrol
create_panel_from_json_template(
"incomplete_or_incorrect_data",
"api/knowledge-panels/report_problem/incomplete_or_incorrect_data.tt.json",
{}, $product_ref, $target_lc, $target_cc, $options_ref
{nutripatrol_enabled => !!$nutripatrol_url},
$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
Expand Down
22 changes: 17 additions & 5 deletions lib/ProductOpener/Products.pm
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ use vars @EXPORT_OK;

use ProductOpener::Store qw/get_string_id_for_lang get_url_id_for_lang retrieve store/;
use ProductOpener::Config qw/:all/;
use ProductOpener::ConfigEnv qw/:all/;
use ProductOpener::Paths qw/%BASE_DIRS ensure_dir_created_or_die/;
use ProductOpener::Users qw/$Org_id $Owner_id $User_id %User init_user/;
use ProductOpener::Orgs qw/retrieve_org/;
Expand Down Expand Up @@ -2828,20 +2829,31 @@ my %actions_urls = (
add_packager_codes_image => "#packager_codes",
add_labels => "#labels",
add_countries => "#countries",
# this is for web rendering so source is web
report_product_to_nutripatrol => "$nutripatrol_url/flag/product/?barcode=PRODUCT_CODE&source=web&flavor=$flavor"
);

sub product_action_url ($code, $action) {

my $url = "/cgi/product.pl?type=edit&code=" . $code;
sub product_action_url ($code, $action = "edit_product") {

my $url;
if (defined $actions_urls{$action}) {
$url .= $actions_urls{$action};
my $action_url = $actions_urls{$action};
if (($action_url eq '') || ($action_url =~ /^#/)) {
# link to the edit form
$url = "/cgi/product.pl?type=edit&code=" . $code;
$url .= $action_url;
}
else {
# full url
$url = $action_url;
$url =~ s/PRODUCT_CODE/$code/;
}
}
else {
$log->error("unknown product action", {code => $code, action => $action});
}

return $url;
return $url // "";
}

sub compute_keywords ($product_ref) {
Expand Down
8 changes: 8 additions & 0 deletions po/common/common.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6359,6 +6359,10 @@ msgctxt "action_packager_codes_image"
msgid "Take a photo of traceability codes"
msgstr "Take a photo of traceability codes"

msgctxt "action_report_product_to_nutripatrol"
msgid "Report this product to our moderators"
msgstr "Report this product to our moderators"

# Used as a header for key facts
msgctxt "knowledge_panels_facts"
msgid "What you need to know"
Expand Down Expand Up @@ -6961,6 +6965,10 @@ 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 "report_to_nutripatrol_explain"
msgid "If you want to report vandalism, inappropriate content or erroneous data you can't fix yourself, report it to our moderators team."
msgstr "If you want to report vandalism, inappropriate content or erroneous data you can't fix yourself, report it to our moderators team."

msgctxt "description"
msgid "Description"
msgstr "Description"
Expand Down
8 changes: 8 additions & 0 deletions po/common/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -6378,6 +6378,10 @@ msgctxt "action_packager_codes_image"
msgid "Take a photo of traceability codes"
msgstr "Take a photo of traceability codes"

msgctxt "action_report_product_to_nutripatrol"
msgid "Report this product to our moderators"
msgstr "Report this product to our moderators"

# Used as a header for key facts
msgctxt "knowledge_panels_facts"
msgid "What you need to know"
Expand Down Expand Up @@ -6974,6 +6978,10 @@ 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 "report_to_nutripatrol_explain"
msgid "If you want to report vandalism, inappropriate content or erroneous data you can't fix yourself, report it to our moderators team."
msgstr "If you want to report vandalism, inappropriate content or erroneous data you can't fix yourself, report it to our moderators team."

msgctxt "description"
msgid "Description"
msgstr "Description"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"html": `
[% lang('incomplete_or_incorrect_data_content_correct') %]
[% lang('incomplete_or_incorrect_data_content_correct_off') %]
`
`
},
},
{
Expand All @@ -26,6 +26,23 @@
"html": "",
"actions": ["edit_product"]
}
}
},
[% IF panel.nutripatrol_enabled %]
{
"element_type": "text",
"text_element": {
"html": `
[% lang('report_to_nutripatrol_explain') %]
`
},
},
{
"element_type": "action",
"action_element": {
"html": "",
"actions": ["report_product_to_nutripatrol"]
}
},
[% END %]
]
}
}
Loading