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: add /org/[orgid] facet in pro platform URL #10432

Merged
merged 26 commits into from
Jul 2, 2024

Conversation

4nt0ineB
Copy link
Collaborator

@4nt0ineB 4nt0ineB commented Jun 11, 2024

What

Add a visible facet of the current org in the URL for connected users on the pro platform.
Allows admins and pro moderators to easily access pages of multiple orgs and share user-friendly URLs:

  • /org/[orgid]/product/[productid]
  • /org/[orgid]/(nutrition-grades | nova-groups | .. )
  • /org/[orgid]/state/en:to-be-exported ...

Eventually, it might helps a new feature that will give producers access to several organizations (sub brands).

This feature is added on top of the existing routing and does not break old URLs.

  • Refactor of Routing.pm

Related issue(s) and discussion

@4nt0ineB 4nt0ineB requested a review from a team as a code owner June 11, 2024 17:32
@github-actions github-actions bot added Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. Display 👥 Users multilingual products Site layout labels Jun 11, 2024
@4nt0ineB 4nt0ineB added the 🏭 Producers Platform https://wiki.openfoodfacts.org/Platform_for_producers label Jun 11, 2024
@codecov-commenter
Copy link

codecov-commenter commented Jun 11, 2024

Codecov Report

Attention: Patch coverage is 42.18750% with 148 lines in your changes missing coverage. Please review.

Project coverage is 49.31%. Comparing base (dc04d18) to head (ccc6848).
Report is 456 commits behind head on main.

Files Patch % Lines
lib/ProductOpener/Routing.pm 42.97% 114 Missing and 24 partials ⚠️
lib/ProductOpener/Users.pm 0.00% 6 Missing ⚠️
lib/ProductOpener/Display.pm 33.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10432      +/-   ##
==========================================
- Coverage   49.54%   49.31%   -0.23%     
==========================================
  Files          67       76       +9     
  Lines       20650    21827    +1177     
  Branches     4980     5231     +251     
==========================================
+ Hits        10231    10764     +533     
- Misses       9131     9744     +613     
- Partials     1288     1319      +31     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

sonarcloud bot commented Jun 12, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@4nt0ineB 4nt0ineB added the ✨ Feature Features or enhancements to Open Food Facts server label Jun 12, 2024
# Compute HTML to display the small front image, currently embedded in the HTML of web queries
if (not $api) {
$product_ref->{image_front_small_html} = display_image_thumb($product_ref, 'front');

# For web queries with personal search, we can compute some generated fields we need
# For web queries with personal search, we can compute some generated fields we ne<ed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# For web queries with personal search, we can compute some generated fields we ne<ed
# For web queries with personal search, we can compute some generated fields we need

@stephanegigandet
Copy link
Contributor

Wow, that's a big refactor! It's a good idea to split in multiple functions.

# /search search endpoint, parameters will be parsed by CGI.pm param()
elsif ($components[0] eq "search") {
$request_ref->{search} = 1;
if (keys %routes == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably call load_routes() once in LoadData.pm module instead

@4nt0ineB
Copy link
Collaborator Author

4nt0ineB commented Jun 12, 2024

Wow, that's a big refactor! It's a good idea to split in multiple functions.

😅 yes. Basically, I needed to potentially have access to all other paths starting with /org/[orgid] while allowing the public platform to not have that prefix. So I had to brake the path, taking the part I needed (orgid) and with the remaining let the existing routing act normally.

@4nt0ineB 4nt0ineB marked this pull request as draft June 17, 2024 16:26
@4nt0ineB 4nt0ineB marked this pull request as ready for review June 19, 2024 10:25
@@ -180,9 +182,18 @@ use ProductOpener::Cache qw/$max_memcached_object_size $memd generate_cache_key/
use ProductOpener::Permissions qw/has_permission/;
use ProductOpener::ProductsFeatures qw(feature_enabled);

use ProductOpener::Index qw/:all/;
use ProductOpener::Display qw/:all/;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we need those lines? Especially Display as we are in Display.pm
a lot of those modules are already imported above

param("code", $components[3]);
$request_ref->{code} = $components[3];
}
elsif ($api_action eq "tag") { # api/v3/[tag]/[type]/[tagid]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
elsif ($api_action eq "tag") { # api/v3/[tag]/[type]/[tagid]
elsif ($api_action eq "tag") { # api/v3/tag/[type]/[tagid]

# Renamed text : en/nova-groups-for-food-processing -> nova, ...
my @redirect_text_route = ();
if (defined $options{redirect_texts}) {
# we use a custome regex to exactly match "en/nova-groups-for-food-processing"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# we use a custome regex to exactly match "en/nova-groups-for-food-processing"
# we use a custom regex to exactly match "en/nova-groups-for-food-processing"

return 1;
}

sub handle_other_tag_types_in_route($request_ref, @components) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this function could be renamed to facets_route()

@@ -110,6 +110,8 @@ sub load_routes() {
['', \&index_route],
['^(?<page>\d+)$', \&index_route, {regex => 1}],
['org/[orgid]/', \&org_route],
# Known tag type? Catch all if no route matched
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great

Copy link
Contributor

@stephanegigandet stephanegigandet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you for all the refactor work!

@4nt0ineB 4nt0ineB merged commit 55820d0 into openfoodfacts:main Jul 2, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Display ✨ Feature Features or enhancements to Open Food Facts server multilingual products 🏭 Producers Platform https://wiki.openfoodfacts.org/Platform_for_producers Site layout Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. 🧪 tests 👥 Users
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add /org/[organisation name] facet directly in URL on the producers platform
3 participants