diff --git a/cgi/product_multilingual.pl b/cgi/product_multilingual.pl index 4649788a5aede..b44c201fee545 100755 --- a/cgi/product_multilingual.pl +++ b/cgi/product_multilingual.pl @@ -721,6 +721,8 @@ ($product_ref, $field, $language) $template_data_ref_field->{display_lc} = $display_lc; $template_data_ref_field->{autocomplete} = $autocomplete; $template_data_ref_field->{fieldtype} = $Lang{$fieldtype}{$lc}; + $template_data_ref_field->{owner_field} = is_owner_field($product_ref, $field); + $template_data_ref_field->{protected_field} = skip_protected_field($product_ref, $field, $User{moderator}); my $html_field = ''; @@ -1311,6 +1313,12 @@ ($product_ref, $field, $language) } + # Determine which field has a value from the manufacturer and if it is protected + $nutriment_ref->{owner_field} = is_owner_field($product_ref, $nid); + $nutriment_ref->{protected_field} = skip_protected_field($product_ref, $nid, $User{moderator}); + $nutriment_ref->{protected_field_prepared} + = skip_protected_field($product_ref, $nid . "_prepared", $User{moderator}); + $nutriment_ref->{shown} = $shown; $nutriment_ref->{enid} = $enid; $nutriment_ref->{enidp} = $enidp; diff --git a/lib/ProductOpener/APIProductWrite.pm b/lib/ProductOpener/APIProductWrite.pm index f6159d9450996..cd0ebd337b921 100644 --- a/lib/ProductOpener/APIProductWrite.pm +++ b/lib/ProductOpener/APIProductWrite.pm @@ -68,9 +68,8 @@ sub skip_protected_field ($product_ref, $field, $moderator = 0) { # If we are on the public platform, and the field data has been imported from the producer platform # ignore the field changes for non tag fields, unless made by a moderator if ( (not $server_options{producers_platform}) - and (defined $product_ref->{owner_fields}) - and (defined $product_ref->{owner_fields}{$field}) - and (not $moderator)) + and (not $moderator) + and (is_owner_field($product_ref, $field))) { $log->debug( "skipping field with a value set by the owner", diff --git a/lib/ProductOpener/Food.pm b/lib/ProductOpener/Food.pm index ff8796a6cc9be..ea617dcca2665 100644 --- a/lib/ProductOpener/Food.pm +++ b/lib/ProductOpener/Food.pm @@ -3109,19 +3109,20 @@ sub assign_nutriments_values_from_request_parameters ($product_ref, $nutriment_t next if $nid =~ /^nutrition-score/; - # Only moderators can update values for fields sent by the producer - if (skip_protected_field($product_ref, $nid, $can_edit_owner_fields)) { - next; - } - # Unit and label are the same for as sold and prepared nutrition table my $enid = encodeURIComponent($nid); - my $unit = remove_tags_and_quote(decode utf8 => single_param("nutriment_${enid}_unit")); - my $label = remove_tags_and_quote(decode utf8 => single_param("nutriment_${enid}_label")); # We can have nutrient values for the product as sold, or prepared foreach my $product_type ("", "_prepared") { + # Only moderators can update values for fields sent by the producer + if (skip_protected_field($product_ref, $nid . $product_type, $can_edit_owner_fields)) { + next; + } + + my $unit = remove_tags_and_quote(decode utf8 => single_param("nutriment_${enid}_unit")); + my $label = remove_tags_and_quote(decode utf8 => single_param("nutriment_${enid}_label")); + # do not delete values if the nutriment is not provided next if (not defined single_param("nutriment_${enid}${product_type}")); diff --git a/lib/ProductOpener/Import.pm b/lib/ProductOpener/Import.pm index dd669d85036ee..94d9e2d06b299 100644 --- a/lib/ProductOpener/Import.pm +++ b/lib/ProductOpener/Import.pm @@ -963,7 +963,14 @@ sub import_nutrients ( and ($Owner_id !~ /^org-database-/) and ($Owner_id !~ /^org-label-/)) { - $product_ref->{owner_fields}{$nid} = $time; + $product_ref->{owner_fields}{$nid . $type} = $time; + # salt and sodium are linked + if ($nid eq "salt") { + $product_ref->{owner_fields}{"sodium" . $type} = $time; + } + elsif ($nid eq "sodium") { + $product_ref->{owner_fields}{"salt" . $type} = $time; + } } } } diff --git a/lib/ProductOpener/Products.pm b/lib/ProductOpener/Products.pm index 185065caec3ef..3286e59d32d20 100644 --- a/lib/ProductOpener/Products.pm +++ b/lib/ProductOpener/Products.pm @@ -116,6 +116,8 @@ BEGIN { &analyze_and_enrich_product_data + &is_owner_field + ); # symbols to export on request %EXPORT_TAGS = (all => [@EXPORT_OK]); } @@ -3721,3 +3723,30 @@ sub analyze_and_enrich_product_data ($product_ref, $response_ref) { return; } + +=head2 is_owner_field($product_ref, $field) + +Return 1 if the field value was provided by the owner (producer) and the field is not a tag field. + +=cut + +sub is_owner_field ($product_ref, $field) { + + if ( + (defined $product_ref->{owner_fields}) + and ( + (defined $product_ref->{owner_fields}{$field}) + # If the producer sent a field value for salt or sodium, the other value was automatically computed + or (($field =~ /^salt/) and (defined $product_ref->{owner_fields}{"sodium" . $'})) + or (($field =~ /^sodium/) and (defined $product_ref->{owner_fields}{"salt" . $'})) + ) + # Even if the producer sent a tag field value, it was merged with existing values, + # and may have been updated by a contributor (e.g. to add a more precise category) + # So we don't consider them to be owner fields + and (not defined $tags_fields{$field}) + ) + { + return 1; + } + return 0; +} diff --git a/po/common/common.pot b/po/common/common.pot index 0c600a9a09475..7356568356844 100644 --- a/po/common/common.pot +++ b/po/common/common.pot @@ -6932,6 +6932,14 @@ msgctxt "open_in_crm" msgid "Open in CRM" msgstr "Open in CRM" +msgctxt "information_provided_by_the_manufacturer" +msgid "Information provided by the manufacturer" +msgstr "Information provided by the manufacturer" + +msgctxt "information_provided_by_the_manufacturer_edit_form" +msgid "Information identified by a factory icon has been provided by the manufacturer. It can be changed only by the manufacturer and moderators. If it is out of date or incorrect, please let us know." +msgstr "Information identified by a factory icon has been provided by the manufacturer. It can be changed only by the manufacturer and moderators. If it is out of date or incorrect, please let us know." + msgctxt "knowledge_panels_did_you_know" msgid "Did you know?" msgstr "Did you know?" diff --git a/po/common/en.po b/po/common/en.po index 21757f7b27896..89e9aa18f6cab 100644 --- a/po/common/en.po +++ b/po/common/en.po @@ -6950,6 +6950,14 @@ msgctxt "open_in_crm" msgid "Open in CRM" msgstr "Open in CRM" +msgctxt "information_provided_by_the_manufacturer" +msgid "Information provided by the manufacturer" +msgstr "Information provided by the manufacturer" + +msgctxt "information_provided_by_the_manufacturer_edit_form" +msgid "Information identified by a factory icon has been provided by the manufacturer. It can be changed only by the manufacturer and moderators. If it is out of date or incorrect, please let us know." +msgstr "Information identified by a factory icon has been provided by the manufacturer. It can be changed only by the manufacturer and moderators. If it is out of date or incorrect, please let us know." + msgctxt "knowledge_panels_did_you_know" msgid "Did you know?" msgstr "Did you know?" diff --git a/templates/web/pages/product_edit/display_input_field.tt.html b/templates/web/pages/product_edit/display_input_field.tt.html index 5d45b48a18784..a5c6ab7ba7f11 100644 --- a/templates/web/pages/product_edit/display_input_field.tt.html +++ b/templates/web/pages/product_edit/display_input_field.tt.html @@ -4,12 +4,15 @@ [% IF language.defined %] ([% language %]) [% END %] + [% IF owner_field %] + + [% END %] [% IF field.match('infocard') || field.match('^packaging_text') || field.match('^ingredients_text') %] - + [% ELSE %] - + [% END %] diff --git a/templates/web/pages/product_edit/product_edit_form_display.tt.html b/templates/web/pages/product_edit/product_edit_form_display.tt.html index 0014a31901a7a..077516be3e12d 100644 --- a/templates/web/pages/product_edit/product_edit_form_display.tt.html +++ b/templates/web/pages/product_edit/product_edit_form_display.tt.html @@ -86,6 +86,17 @@
+ + [% lang("information_provided_by_the_manufacturer_edit_form") %] + + × +
+