Metadata-Version: 2.2
Name: ckanext-fair3r
Version: 3.1.83
Summary: A ckan extension meant to customize fair3r.fr theme and add special views
Home-page: https://github.com/Phen-ICS/ckanext-fair3r
Author: Nathanaël Debanne
Author-email: debannen@igbmc.fr
License: AGPL-3.0-or-later
Keywords: CKAN
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Description-Content-Type: text/markdown
License-File: LICENSE

<table>
<tr>
<td width="150">
  <img alt="Fair3R logo" src="https://fair3r.fr/base/images/fair3r_logo.png" width="150">
</td>
<td>

# ckanext-fair3r

![CKAN](https://img.shields.io/badge/CKAN-2.12.1-orange)
![License](https://img.shields.io/badge/license-AGPL--3.0-blue)
[![PyPI](https://img.shields.io/pypi/v/ckanext-fair3r)](https://pypi.org/project/ckanext-fair3r/)

</td>
</tr>
</table>

The CKAN plugin behind [fair3r.fr](https://fair3r.fr), a catalogue of
research datasets (animal models, phenotyping). It adds the **FDF**
(FAIR3R Dataset Form): a dynamic, ontology-driven metadata form built from
a JSON schema. It turns those metadata into DataCite, DCAT-AP, Croissant
and schema.org, and gives the site its theme and a few features around
datasets.

For a ready-to-run FAIR3R stack with this plugin already wired up, see
[fair3r-docker-alt](https://github.com/Phen-ICS/fair3r-docker-alt). The
rest of this page is for adding the plugin to your own CKAN 2.12.

## Features

- **FDF form**: dataset creation and editing with a form generated from
  [fdf_schema.json](https://github.com/Phen-ICS/fair3r-fdf-schema), which
  looks terms up in external databases (ORCID, ROR, ontologies, genes,
  alleles, strains) and is checked again on the server. The answers are
  stored on the dataset (`fdf_output_json`) with DataCite-shaped
  `datacite.*` extras derived from them. The API checks an
  `fdf_output_json` the same way, with errors giving the exact place and
  reason ([details](https://github.com/Phen-ICS/ckanext-fair3r/blob/main/docs/workflows.md#through-the-api)).
- **Completeness score** on the dataset page and live in the form.
- **Metadata for other systems**: DataCite DOI metadata through
  ckanext-doi, DCAT-AP, Croissant and schema.org through ckanext-dcat, a
  sitemap.
- **Publishing and downloading**: a "Publish" button (private -> public,
  one way), "Download all" as one ZIP, a fix for a CKAN/xloader race that
  can turn a just-published dataset back to draft.
- **Resource form**: several files at once with progress, duplicate-name
  warning, routing of large files to Zenodo with
  [ckanext-zenodo](https://github.com/Phen-ICS/ckanext-zenodo).
- **Accounts and access**: account sign-up (e-mail confirmation, then an
  administrator activates or rejects it at `/ckan-admin/accounts`;
  optional ORCID proof, which a user can also link or unlink from their profile; a request cannot log in, reset its password, or be seen in
  user lists and profiles until an administrator activates it; a sysadmin can softly delete an
  active account, export what is held about it as JSON, or erase its personal data (GDPR) at
  `/ckan-admin/accounts`; `ckan fair3r purge-requests` deletes the requests left unconfirmed;
  sysadmin accounts can be limited to given networks), members-only
  organization/group activity streams, HTML emails.
- **Legal pages**: `/legal-notice` and `/privacy` (French and English, linked in the footer and
  from the account request and contact forms). The CNRS is named as data controller: the texts
  must be validated by its data protection officer.
- **Authors from your ORCID profile**: a user who linked an ORCID iD gets a button at the top of an empty
  creator or contributor of the dataset form, which fills in the name type, the given and family name, the
  ORCID iD and the affiliation (the employer's ROR when ORCID has it, else its name in the ROR search) in one click (once per section: the button goes when the person is in it). The name is
  read once from the public ORCID record and kept with the link. Which fields it fills is declared by
  `prefill_from_user` in the FDF schema (3.1.8).
- **Theme** of fair3r.fr, French translations.

The full specification is in [docs/](https://github.com/Phen-ICS/ckanext-fair3r/blob/main/docs/README.md): architecture, the
FDF schema, every workflow step by step, metadata mapping, security,
configuration and operations.

## Requirements

- CKAN 2.12, with Redis and the background worker (`ckan jobs worker`)
  running: they're used to fix the draft race and to limit account
  requests.
- **[ckanext-doi](https://github.com/Phen-ICS/ckanext-doi)**, FAIR3R's
  fork, published on PyPI as `ckanext-fair3r-doi` (the `ckanext-doi`
  package on PyPI is a different one, the original). It must be
  **installed**, since this plugin uses its interface. Enabling it (and
  having a DataCite account) is only needed to mint DOIs.
- Optional, each one adds something when enabled:

  | Plugin | Adds |
  |---|---|
  | `dcat`, `structured_data`, `croissant` ([ckanext-dcat](https://github.com/ckan/ckanext-dcat)) | The FAIR3R RDF profiles |
  | `activity` (CKAN core) | Members-only activity streams |
  | `pages` ([ckanext-pages](https://github.com/Phen-ICS/ckanext-pages), PyPI: `ckanext-fair3r-pages`) | Pages and Blog links in this plugin's header |
  | `citations` ([ckanext-citations](https://github.com/Phen-ICS/ckanext-citations)) | The "FAIR & Impact" panel, with the completeness score |
  | `zenodo` ([ckanext-zenodo](https://github.com/Phen-ICS/ckanext-zenodo)) | Large files on Zenodo, with a DOI |
  | `contact` ([ckanext-contact](https://github.com/NaturalHistoryMuseum/ckanext-contact)) | The contact page; its `ckanext.contact.mail_to` is where account requests go |

## Installation

1. In CKAN's virtualenv:

   ```shell
   pip install ckanext-fair3r ckanext-fair3r-doi
   ```

2. Enable the plugin in `ckan.ini`. The first-listed plugin's templates
   win, and this plugin's header replaces CKAN's: keep `pages` before
   `fair3r`, or the Pages and Blog links disappear.

   ```ini
   ckan.plugins = ... dcat structured_data croissant pages fair3r doi citations ...
   ```

3. Optional, for the FAIR3R RDF output (with ckanext-dcat):

   ```ini
   ckanext.dcat.rdf.profiles = fair3r_dcat_ap
   ckanext.dcat.croissant.profiles = fair3r_croissant
   ckanext.dcat.structured_data.profiles = fair3r_schemaorg
   ```

4. Fetch the FDF schema, then keep it up to date daily, as the CKAN user
   (cron). The package doesn't include it: until the first
   `update-schema`, the FDF form is empty.

   ```shell
   ckan -c /path/to/ckan.ini fair3r update-schema
   ```

   ```cron
   0 0 * * * /path/to/venv/bin/ckan -c /path/to/ckan.ini fair3r update-schema
   ```

   The CKAN user needs write access to the package's
   `ckanext/fair3r/schema/` directory.

5. Restart CKAN and its worker.

## Configuration

| Setting | Default | Meaning |
|---|---|---|
| `ckanext.fair3r.context` | `DEV` | `DEV`, `INTEGRATION`, `VALIDATION` or `PRODUCTION`. Shown as a badge in the header (except in production). `PRODUCTION`: `/dataset/new` opens the FDF form directly, without the choice page. |
| `ckanext.fair3r.enable_fdf_integration` | `true` | `false`: `/dataset/new` opens CKAN's standard form. |
| `ckanext.fair3r.fdf_schema_dir` | (the package's `schema/` directory) | A directory with `fdf_schema.json` and `i18n/*.json`, used instead of the one `update-schema` downloads (for working on the schema locally); also read from `CKANEXT_FAIR3R_FDF_SCHEMA_DIR`. |
| `ckanext.contact.mail_to` | `smtp.mail_from` | Who is told that an account request waits for a decision. |
| `ckanext.fair3r.docs_url` | `https://phen-ics.github.io/fair3r-fdf-schema/` | Address of the documentation, linked from the About page and the footer. Empty or not a web address: the default. |
| `ckanext.fair3r.admin_networks` | empty | Comma-separated networks (CIDR, e.g. `10.0.0.0/8, 192.168.0.0/16`) the sysadmin accounts can be used from. A sysadmin session or API token from elsewhere gets a 403; regular users, anonymous visitors and the `ckan` command line are not affected, loopback is always allowed. Empty: no restriction. Needs `ckanext.fair3r.proxies` to be right. |
| `ckanext.fair3r.proxies` | `0` | How many reverse proxies add their address to `X-Forwarded-For` in front of CKAN (a load balancer and nginx: `2`; nginx alone: `1`). The limit on account requests is per visitor, and the visitor is that many entries from the right of the header. A wrong value makes every visitor look like a proxy (the load balancer, say): the per-visitor limits (account requests, contact form) are then shared by everybody, and `ckanext.fair3r.admin_networks` cannot tell who is who. |
| `ckanext.fair3r.contact_antispam` | `true` | Anti-spam in front of the contact form: a trap field, a minimum time between opening and sending the form, 5 messages per hour and per visitor, and an [ALTCHA](https://altcha.org) proof of work (self-hosted widget, no outside service). `false` switches it off. |
| `ckanext.fair3r.require_institutional_email` | `true` | Refuse personal addresses (Gmail, Yahoo, disposable...) in account requests. |
| `ckanext.fair3r.orcid_client_id`, `ckanext.fair3r.orcid_client_secret` | (unset) | An ORCID public API client (redirect URI `<site>/account/orcid/callback`). Set both to offer "Sign in with ORCID" on the account request form: it proves the ORCID iD and fills in name, public e-mail and affiliation. |
| `ckanext.fair3r.orcid_domain` | `orcid.org` | `sandbox.orcid.org` with a sandbox ORCID client. |

More in [docs/operations.md](https://github.com/Phen-ICS/ckanext-fair3r/blob/main/docs/operations.md), with troubleshooting.

## Commands

| Command | Use |
|---|---|
| `ckan fair3r update-schema` | Download the latest `fdf_schema.json` and its French translations from GitHub into the package (daily cron). Does nothing when `fdf_schema_dir` points to a local clone. |

## Development

```shell
git clone https://github.com/Phen-ICS/ckanext-fair3r.git
cd ckanext-fair3r
pip install -e .
pip install -r dev-requirements.txt
```

Code style, checked in CI (ruff 0.16.0):

```shell
ruff format ckanext
ruff check ckanext --fix
```

### Tests

```shell
docker exec -u ckan -it ckan-app pytest --ckan-ini=/plugins/ckanext-fair3r/test.ini /plugins/ckanext-fair3r/ckanext/fair3r/tests
```

Always pass `--ckan-ini`: the test fixtures empty the database they run
against, and refuse to run unless its name contains `test`. The
`test.ini` at the repository root is for the DEV container;
`ckanext/fair3r/tests/test.ini`, shipped in the package, is the one the
integration server uses - keep their plugin lists in sync.

### Translations

English source strings, French catalogue in `ckanext/fair3r/i18n/fr/`:
see [docs/operations.md](https://github.com/Phen-ICS/ckanext-fair3r/blob/main/docs/operations.md#translations) for the
extract / update / compile steps.

## License

Released under the GNU Affero General Public License (AGPL) v3.0. See the
file `LICENSE` for details.
