Skip to content

About

The backend part of our moderation tool for Open Food Facts

Topics

Resources

Security policy

Stars

5 stars

Watchers

2 watching

Forks

Repository files navigation

NutriPatrol πŸ›‘οΈ

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

This is the backend

API documentation

https://nutripatrol.openfoodfacts.org/api/docs

SDKs

Webcomponent

Understanding Open Food Facts' data quality infrastructure

🌟 About the Project

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.

Key Features:

  • πŸ•΅οΈβ€β™€οΈ 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.

πŸš€ Getting Started

To get a local copy up and running, follow these simple steps.

Prerequisites

Installation

  1. Clone this repository :
git clone https://github.com/openfoodfacts/nutripatrol.git
cd nutripatrol
  1. create your local env

Copy .env.example to create your .env file

Run with docker containers

Make docker containers

make up

Your local instance of NutriPatrol should now be running at http://localhost:3000.

Authentication for local dev

Switching between users in local dev

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 ticket

The 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.

To test with a global instance of Product Opener

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).

πŸ“– Usage

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.

How to Contribute

Tests

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.txt

Then run the whole suite from the repository root:

pytest

A 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_captured

Pre-Commit

This repo uses pre-commit to enforce code styling, etc. To use it:

pre-commit run

🀝 Contributing

Contributions 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".

Wikipage

🎨 Design

Features

  • Image reporting
  • List of tickets (can be images, products…)
  • List of reported images (both by humans and Robotoff, our AI)

Roadmap

Backend

  • Support frontend features (filters, displaying the reporter, displaying the uploader…)

Frontend

  • More filters to focus on the most important issues first
  • Quick and easy actions to fix the errors

Weekly meetings

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.

πŸ“œ License

Distributed under the AGPL. See LICENSE for more information.

πŸ“¬ Contact

Open Food Facts - tech@openfoodfacts.org

Project Link: https://github.com/openfoodfacts/nutripatrol

This README is a starting point. Feel free to suggest improvements!

Contributors

List of contributors to this repository

About

The backend part of our moderation tool for Open Food Facts

Topics

Resources

Security policy

Stars

5 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages