Skip to content

Commit

Permalink
Merge branch 'openfoodfacts:main' into Naruyoko-ja-fix-space
Browse files Browse the repository at this point in the history
  • Loading branch information
Naruyoko authored Sep 30, 2023
2 parents 85b5b49 + 028c35d commit ae3c1c3
Show file tree
Hide file tree
Showing 13 changed files with 1,400 additions and 1,665 deletions.
4 changes: 3 additions & 1 deletion .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"stylelint-config-recommended-scss"
],
"rules": {
"no-descending-specificity": null
"no-descending-specificity": null,
"scss/at-extend-no-missing-placeholder": null,
"no-invalid-position-at-import-rule": null
}
}
6 changes: 5 additions & 1 deletion cgi/user.pl
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,11 @@

$template_data_ref->{accepted_organization} = $user_ref->{org};
}
elsif ((defined $options{product_type}) and ($options{product_type} eq "food")) {
elsif ( (defined $options{product_type})
and ($options{product_type} eq "food")
and (defined $user_ref->{requested_org})
and ($user_ref->{requested_org} ne ""))
{
my $requested_org_ref = retrieve_org($user_ref->{requested_org});
$template_data_ref->{requested_org_ref} = $requested_org_ref;
$template_data_ref->{org_name} = sprintf(lang("add_user_existing_org"), org_name($requested_org_ref));
Expand Down
68 changes: 68 additions & 0 deletions lib/ProductOpener/DataQualityFood.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,73 @@ sub check_categories ($product_ref) {
return;
}

=head2 check_labels( PRODUCT_REF )
Checks related to specific product labels.
Vegan label: check that there is no non-vegan ingredient.
Vegetarian label: check that there is no non-vegetarian ingredient.
=cut

sub check_labels ($product_ref) {
# this also include en:vegan that is a child of en:vegetarian
if (defined $product_ref->{labels_tags} && has_tag($product_ref, "labels", "en:vegetarian")) {
if (defined $product_ref->{ingredients}) {
my @ingredients = @{$product_ref->{ingredients}};

while (@ingredients) {

# Remove and process the first ingredient
my $ingredient_ref = shift @ingredients;
my $ingredientid = $ingredient_ref->{id};

# Add sub-ingredients at the beginning of the ingredients array
if (defined $ingredient_ref->{ingredients}) {

unshift @ingredients, @{$ingredient_ref->{ingredients}};
}

# some additives_classes (like thickener, for example) do not have the key-value vegan and vegetarian
# it can be additives_classes that contain only vegan/vegetarian additives.
# to avoid false-positive - instead of raising a warning (else below) we ignore additives_classes
if (!exists_taxonomy_tag("additives_classes", $ingredientid)) {
if (has_tag($product_ref, "labels", "en:vegan")) {
# vegan
if (defined $ingredient_ref->{"vegan"}) {
if ($ingredient_ref->{"vegan"} eq 'no') {
push @{$product_ref->{data_quality_errors_tags}},
"en:vegan-label-but-non-vegan-ingredient";
}
# else 'yes', 'maybe'
}
else {
push @{$product_ref->{data_quality_warnings_tags}},
"en:vegan-label-but-could-not-confirm-for-all-ingredients";
}
}

# vegetarian
if (defined $ingredient_ref->{"vegetarian"}) {
if ($ingredient_ref->{"vegetarian"} eq 'no') {
push @{$product_ref->{data_quality_errors_tags}},
"en:vegetarian-label-but-non-vegetarian-ingredient";
}
# else 'yes', 'maybe'
}
else {
push @{$product_ref->{data_quality_warnings_tags}},
"en:vegetarian-label-but-could-not-confirm-for-all-ingredients";
}
}
}
}
}

return;
}

sub compare_nutriscore_with_value_from_producer ($product_ref) {

if (
Expand Down Expand Up @@ -1572,6 +1639,7 @@ sub check_quality_food ($product_ref) {
check_quantity($product_ref);
detect_categories($product_ref);
check_categories($product_ref);
check_labels($product_ref);
compare_nutriscore_with_value_from_producer($product_ref);
check_ecoscore_data($product_ref);
check_food_groups($product_ref);
Expand Down
8 changes: 6 additions & 2 deletions lib/ProductOpener/Orgs.pm
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@ sub retrieve_org ($org_id_or_name) {

$log->debug("retrieve_org", {org_id_or_name => $org_id_or_name, org_id => $org_id}) if $log->is_debug();

my $org_ref = retrieve("$data_root/orgs/$org_id.sto");
if (defined $org_id and $org_id ne "") {

return $org_ref;
my $org_ref = retrieve("$data_root/orgs/$org_id.sto");
return $org_ref;
}

return;
}

=head1 FUNCTIONS
Expand Down
Loading

0 comments on commit ae3c1c3

Please sign in to comment.