A collaborative tool to monitor and improve food product data on Open Food Facts.
NutriPatrol is a web-based application designed to help the Open Food Facts community ensure the quality and accuracy of the data in the world's largest open database of food products. It allows users to easily patrol recent changes, spot inaccuracies, and contribute to making the food supply chain more transparent.
Production: https://nutripatrol.openfoodfacts.org Pre-production: https://nutripatrol.openfoodfacts.net
- The frontend is located at https://github.com/openfoodfacts/nutripatrol-frontend
https://nutripatrol.openfoodfacts.org/api/docs
- Available in the JS SDK, the Dart SDK: https://github.com/openfoodfacts/openfoodfacts-js, https://github.com/openfoodfacts/openfoodfacts-dart
- Available as a webcomponent: https://openfoodfacts.github.io/openfoodfacts-webcomponents/?path=/story/components-nutri-patrol--flag-product
The goal of NutriPatrol is to gamify the process of data verification for Open Food Facts. Moderators can quickly swipe through recent reports, to act on true issues and mark them as fixed, or flag incorrect ones as not a problem. This helps maintain the integrity of the data that powers countless apps and research projects related to food, nutrition, and health.
- π΅οΈββοΈ Patrol Recent Reports: Quickly review and verify edits made to products.
- β Approve or Flag from many places: Basic integration is available in the website (openfoodfacts-server), being added to openfoodfacts-explorer and the mobile app (smooth-app)
- π± Mobile-Friendly: A responsive design that works on any device.
To get a local copy up and running, follow these simple steps.
- Clone this repository :
git clone https://github.com/openfoodfacts/nutripatrol.gitcd nutripatrol- create your local env
Copy .env.example to create your .env file
Make docker containers
make upYour local instance of NutriPatrol should now be running at http://localhost:3000.
The Open Food Facts session cookie is set on an openfoodfacts host, so a
front end served from localhost never gets one - which leaves every local
request anonymous, and the parts of the API that tell users apart impossible
to exercise: a moderator lists every ticket and flag, anyone else only the
flags they raised and the tickets those are attached to.
Set AUTH_DEV_USERS=1 in .env and a request can name the user it acts as
instead:
| Header | Meaning |
|---|---|
X-Dev-User-Id: <user id> |
Act as that Open Food Facts user id |
X-Dev-Moderator: 1 |
...and as a moderator |
Sending neither header leaves the request anonymous, as before - which is how
a logged-out visitor is tested. The headers are still subject to the usual
permission checks: without X-Dev-Moderator, the moderator-only endpoints
answer 403, exactly as they would for a real account.
curl -H "X-Dev-User-Id: alice" http://localhost:8000/api/v1/tickets # alice's own tickets
curl -H "X-Dev-User-Id: bob" -H "X-Dev-Moderator: 1" \
http://localhost:8000/api/v1/tickets # every ticketThe NutriPatrol front end sends these for you: its login page, in dev mode,
offers the same three choices (see nutripatrol-frontend).
The one thing this cannot fake is /products/{barcode}/..., which edits Open
Food Facts on the moderator's behalf and forwards their real session cookie -
those endpoints answer 401 without one, and need the setup below.
AUTH_DEV_USERS is impersonation by header: any caller can claim any user
id, and moderator rights with it. It must stay unset outside a developer's own
machine.
In .env file uncomment the AUTH_SERVER_STATIC variable.
If you want to use a local Product Opener Instance, use http://world.openfoodfacts.localhost
Then connect to your Open Food Facts profile, copy the session cookie (use developper toolbar, and find a cookie named session for openfoodfacts.org domain, copy its value) and paste it in the body at this endpoint /api/set_session_cookie (you have a form at the /api/docs URI).
Once the application is running, you can log in with your Open Food Facts account. The main screen will present you with cards showing recent reports. You might need to be a moderator to be able to use it.
The test suite lives in tests/unit and is made of pure unit tests: calls to
Open Food Facts are stubbed and the endpoints run against a throwaway SQLite
file. It needs neither a running stack nor network access, so there is no need
for make up or a Postgres database.
The tests are not part of the Docker image, which only carries what the API needs to run. Install them in a local virtualenv:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt -r requirements-dev.txtThen run the whole suite from the repository root:
pytestA single file, or a single test:
pytest tests/unit/test_flag_creation.py
pytest tests/unit/test_flag_creation.py::test_the_product_revision_is_capturedThis repo uses pre-commit to enforce code styling, etc. To use it:
pre-commit runContributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this project better, please fork the repo and create a pull request. You can also simply open an issue with the type "enhancement".
Mockups & Benchmarks
- Are you a designer ? Join the design team
- Image reporting
- List of tickets (can be images, productsβ¦)
- List of reported images (both by humans and Robotoff, our AI)
- Support frontend features (filters, displaying the reporter, displaying the uploaderβ¦)
- More filters to focus on the most important issues first
- Quick and easy actions to fix the errors
We currently have no maintener for this tool. Please ping us here or on Slack if you'd like to contribute. We have more general quality meetings every month.
- The meeting will handle Agenda items first, and if time permits, collaborative bug triage.
- We strive to timebox the core of the meeting (decision making) to 30 minutes, with an optional free discussion/live debugging afterwards.
- We take comprehensive notes in the Weekly Agenda of agenda item discussions and of decisions taken. Please read our Contributing Guidelines for more details on our code of conduct and the process for submitting pull requests.
Distributed under the AGPL. See LICENSE for more information.
Open Food Facts - tech@openfoodfacts.org
Project Link: https://github.com/openfoodfacts/nutripatrol
This README is a starting point. Feel free to suggest improvements!