From e8b4d84eafbda80995a02a4b0e4f91c42215f0df Mon Sep 17 00:00:00 2001 From: Josue Kouka Date: Mon, 12 Mar 2018 16:41:01 +0100 Subject: [PATCH] add civil status connector interface (#16768) --- passerelle/civilstatus/__init__.py | 0 passerelle/civilstatus/mixin.py | 114 +++++++++++++++++++++ passerelle/civilstatus/readme.md | 198 +++++++++++++++++++++++++++++++++++++ 3 files changed, 312 insertions(+) create mode 100644 passerelle/civilstatus/__init__.py create mode 100644 passerelle/civilstatus/mixin.py create mode 100644 passerelle/civilstatus/readme.md diff --git a/passerelle/civilstatus/__init__.py b/passerelle/civilstatus/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/passerelle/civilstatus/mixin.py b/passerelle/civilstatus/mixin.py new file mode 100644 index 0000000..68db1f2 --- /dev/null +++ b/passerelle/civilstatus/mixin.py @@ -0,0 +1,114 @@ +# -*- coding: utf-8 -*- +# Passerelle - uniform access to data and services +# Copyright (C) 2018 Entr'ouvert +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +from __future__ import unicode_literals + +import json + +from django.utils.translation import ugettext_lazy as _ + +from passerelle.utils.api import endpoint +from passerelle.utils.jsonresponse import APIError + +MANDATORY_DATA = { + 'applicant_firstnames': None, + 'applicant_lastname': None, + 'application_id': None, + 'application_time': None, + 'certificate_type': ('birth', 'mariage', 'death', 'other'), + 'concerned_firstnames': None, + 'concerned_lastname': None, + 'document_type': ('full', 'multilingual', 'with-filiation', 'without-filiation'), +} + +DATASOURCES = { + 'application-reasons': [ + {'id': 'id-card', 'text': _('ID Card')}, # Carte nationale d'identité + {'id': 'passport', 'text': _('Passeport')}, + {'id': 'citizenship-certificate', 'text': _('Citizenship certtificate')}, # Certificat de nationalité française + {'id': 'mariage', 'text': 'Mariage'}, + {'id': 'pension', 'text': _('Pension')}, + {'id': 'judiciary', 'text': _('Legal process')}, # Procédure judiciaire + {'id': 'pacs', 'text': _('Civil solidairty pact')}, # Pacte civil de solidarité + {'id': 'notary-act', 'text': _('Notary act')}, # Acte notaire + {'id': 'other', 'text': _('Other')} + ], + 'applicant-status': [ + {'id': 'child', 'text': _('His/her child')}, # Son fils ou sa fille + {'id': 'concerned', 'text': _('The act holder')}, # La personne concernée par l'acte + {'id': 'grand-parent', 'text': _('His/her grand-parents')}, # Son grand-père ou sa grand-mère + {'id': 'heir', 'text': _('His/her heir')}, # Son héritier + {'id': 'parent', 'text': _('His/her parents')}, # Son père ou sa mère + {'id': 'partner', 'text': _('His/her partner')}, # Son conjoint ou sa conjointe + {'id': 'grand-child', 'text': _('His/her grand child')}, # Son petit-fils ou sa petite-fille + {'id': 'representative', 'text': _('His/her legal representative')}, # Son représentant légal + {'id': 'other', 'text': _('Other')} + ], + 'certificate-types': [ + {'id': 'birth', 'text': _('Birth')}, + {'id': 'mariage', 'text': _('Mariage')}, + {'id': 'death', 'text': _('Death')} + ], + 'document-types': [ + {'id': 'full', 'text': _('Full copy')}, # Copie intégrale + {'id': 'with-filiation', 'text': _('Excerpt with filiation')}, # Extrait avec filiation + {'id': 'without-filiation', 'text': _('Excerpt without filiation')}, # Extrait sans filiation + {'id': 'multilingual', 'text': _('Plurilingual excerpt')} # Extrait plurilingue + ], + 'titles': [ + {'id': 'mr', 'text': _('Sir')}, + {'id': 'ms', 'text': _('Mrs.')}, + {'id': 'mx', 'text': _('Other')}, + ] +} + + +class EndpointNotAvailable(APIError): + http_status = 400 + + +class CivilStatusMixin(object): + + category = _('Civil Status') + + def create_demand(self, formdata, *args, **kwargs): + raise EndpointNotAvailable(' endpoint is not available') + + def get_status(self, demand_id, **kwargs): + raise EndpointNotAvailable(' endpoint is not available') + + @endpoint(perm='can_access', methods=['post']) + def create(self, request, *args, **kwargs): + try: + payload = json.loads(request.body) + except (ValueError,) as exc: + raise APIError('Payload error: %s' % exc) + for key, values in MANDATORY_DATA.iteritems(): + if (key not in payload): + raise APIError('<%s> is required.' % key) + if values and payload[key] not in values: + raise APIError('<%s> value must be one of %s' % (key, values)) + return self.create_demand(request, payload, *args, **kwargs) + + @endpoint(perm='can_access', methods=['get'], pattern='(?P[\w-]+)/') + def status(self, request, demand_id, **kwargs): + return self.get_status(demand_id) + + @endpoint(methods=['get'], pattern='(?P[\w-]+)/') + def datasources(self, request, datasource, **kwargs): + if datasource not in DATASOURCES: + raise APIError('Invalid datasource name', http_status=404) + return DATASOURCES[datasource] diff --git a/passerelle/civilstatus/readme.md b/passerelle/civilstatus/readme.md new file mode 100644 index 0000000..b7335f5 --- /dev/null +++ b/passerelle/civilstatus/readme.md @@ -0,0 +1,198 @@ +[]() + +Connecteur État Civil[¶](#Connecteur-État-Civil){.wiki-anchor} +============================================================== + +- [Connecteur État Civil](#Connecteur-État-Civil) + - [Les variables](#Les-variables) + - - [Variables relatives au + demandeur](#Variables-relatives-au-demandeur) + - [Variables relatives à + l'intéressé](#Variables-relatives-à-lintéressé) + - [Variables relatives au partenaire de + l'intéréssé](#Variables-relatives-au-partenaire-de-lintéréssé) + - [Variables relatives aux parents de l'intéréssé ou de + son/sa + partenaire](#Variables-relatives-aux-parents-de-lintéréssé-ou-de-sonsa-partenaire) + + - [Les URL](#Les-URL) + - [Création d'une demande](#Création-dune-demande) + - [Récupération du statut d'une + demande](#Récupération-du-statut-dune-demande) + - [Sources de données](#Sources-de-données) + +Cette page décrit l'interface commune qui doit être utilisée par tous +les connecteurs type État Civil dans Passerelle. + +[]() + +Les variables[¶](#Les-variables){.wiki-anchor} +---------------------------------------------- + + Nom Type Obligatoire Valeurs possibles Commentaires + ------------------------------ --------- ------------- ------------------------------------------------------- ---------------------------------------------------------------------------------- + application\_id string **oui** (display\_id) + application\_time string **oui** (receipt\_time) + certificate\_type string **oui** birth, marriage, death, other + certificate\_type\_label string non e.g Acte de Naissance + document\_type string **oui** full, multilingual, with-filiation, without-filiation + document\_type\_label string non e.g Copie intégrale, plurilingue, extrait avec filiation, extrait sans filiation + document\_copies integer non + event\_city string non + event\_date\_start date non format ISO + event\_date\_end date non format ISO + application\_reason string non motif de la demande + application\_comment string non commentaire sur la demande + application\_city string non nom de la ville à qui la demande est adressée + application\_city\_inseecode string non code INSEE de la ville à qui la demande est adressée + application\_city\_zipcode string non code postal de la ville à qui la demande est adressée + applicant\_is\_concerned boolean non true,false définit si le demandeur est aussi le titulaire de l'acte + application\_priority string non définit la priorité de la demande + +[]() + +#### Variables relatives au demandeur[¶](#Variables-relatives-au-demandeur){.wiki-anchor} + + Nom Type Obligatoire Valeurs possibles Commentaires + ------------------------------------ -------- ------------- ---------------------------------------------------------- --------------------------------------------------------------------- + applicant\_title string non mr, ms, mx + applicant\_title\_label string non e.g monsieur, madame, neutre + applicant\_lastname string **oui** + applicant\_firstnames string **oui** + applicant\_usual\_name string non + applicant\_email string non + applicant\_phone string non + applicant\_status string **oui** concerned, partner, parent, child, representative, other personne concernée, conjoint(e), parent, enfant, représentant légal + applicant\_status\_label string non + applicant\_address\_street\_number string non numéro de la voie + applicant\_address\_street\_type string non type de la voie + applicant\_address\_street string non + applicant\_address\_complement string non + applicant\_address\_city string non + applicant\_address\_zipcode string non + applicant\_address\_country string non `Code ISO` ou `nom du pays` en fonction du connecteur + +[]() + +#### Variables relatives à l'intéressé[¶](#Variables-relatives-à-lintéressé){.wiki-anchor} + + Nom Type Obligatoire Valeurs possibles Commentaires + ------------------------- -------- ------------- ------------------- ------------------------------------------------------- + concerned\_title string non mr, ms, mx + concerned\_title\_label string non e.g monsieur, madame, neutre + concerned\_firstnames string **oui** + concerned\_lastname string **oui** + concerned\_usual\_name string non + concerned\_birthdate date non format ISO + concerned\_birthcountry string non `Code ISO` ou `nom du pays` en fonction du connecteur + concerned\_birthcity string non + concerned\_birthcounty string non Département + concerned\_sex string non m, f, o Homme, femme ou autre + concerned\_citizenship string non + +[]() + +#### Variables relatives au partenaire de l'intéréssé[¶](#Variables-relatives-au-partenaire-de-lintéréssé){.wiki-anchor} + + Nom Type Obligatoire Valeurs possibles Commentaires + ----------------------- -------- ------------- ------------------- ------------------------------ + partner\_title string non mr, ms, mx + partner\_title\_label string non e.g monsieur, madame, neutre + partner\_firstnames string non + partner\_lastname string non + partner\_usual\_name string non + partner\_birthdate date non format ISO + partner\_birthcountry string non + partner\_birthcity string non + partner\_birthcounty string non Département + partner\_sex string non m, f, o Homme, femme ou autre + partner\_citizenship string non + +[]() + +#### Variables relatives aux parents de l'intéréssé ou de son/sa partenaire[¶](#Variables-relatives-aux-parents-de-lintéréssé-ou-de-sonsa-partenaire){.wiki-anchor} + + Nom Type Obligatoire Valeurs possibles Commentaires + ---------------------------------------------------- -------- ------------- ------------------- -------------------------- + {concerned,partner}\_{parent1,parent2}\_title string non mr, ms, mx monsieur, madame, neutre + {concerned,partner}\_{parent1,parent2}\_firstnames string non + {concerned,partner}\_{parent1,parent2}\_lastname string non + {concerned,partner}\_{parent1,parent2}\_sex string non m, f, o Homme, femme ou autre + +[]() + +Les URL[¶](#Les-URL){.wiki-anchor} +---------------------------------- + +[]() + +### Création d'une demande[¶](#Création-dune-demande){.wiki-anchor} + +- `///create/` + +Avec le payload json:\ + + { + "display_id": 123, + "receipt_time": "2017-07-01T00:00:00", + "certificate_type": "Acte de Mariage", + "certificate_type_raw": "MAR", + "document_type": "Extrait avec filiation", + "document_type_raw": "EF", + "document_copies": 3, + "concerned_firstnames": "Johnny Jumper", + "concerned_lastname": "Doe", + "concerned_birthdate": "1980-07-07", + "concerned_birthcity": "Nantes", + "concerned_birthcountry": "France", + "applicant_firstnames": "Kevin", + "applicant_lastname": "Troll", + "applicant_address_street": "27 Blvd Henry Orion", + "applicant_address_city": "Nantes", + "applicant_address_zipcode": 44000, + "concerned_parent2_firstnames": "Kim", + "concerned_parent2_lastname": "Sung-Ho", + "partner_firstnames": "Chelsea Ruth", + "partner_lastname": "Whatever", + "event_date": "2014-05-07" + } + +

+Le retour attendu est un json contenant la clé `demand_id` i.e. :\ + + { + "err": 0, + "data": { + "demand_id": "123-MAR-0" + } + } + +

+[]() + +### Récupération du statut d'une demande[¶](#Récupération-du-statut-dune-demande){.wiki-anchor} + +Dans le cas où le connecteur peut le permettre, l'URL de récupération du +statut d'une demande sera comme suit : + +- `///status//` + +La réponse renvoyée doit au minimum avoir les clés `status` et `closed` +(Boolean). + + { + "err": 0, + "data":{ + "status": "rejected", + "closed": true, + "comment": "Invalid demand" + } + } + +[]() + +### Sources de données[¶](#Sources-de-données){.wiki-anchor} + +- `///datasources//` e.g + `/mdel/test/datasources/applicant-status/` + -- 2.11.0