Projet

Général

Profil

0001-add-civil-status-connector-interface-16768.patch

Josué Kouka, 28 mars 2018 11:41

Télécharger (16,4 ko)

Voir les différences:

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
passerelle/civilstatus/mixin.py
1
# -*- coding: utf-8 -*-
2
# Passerelle - uniform access to data and services
3
# Copyright (C) 2018  Entr'ouvert
4
#
5
# This program is free software: you can redistribute it and/or modify it
6
# under the terms of the GNU Affero General Public License as published
7
# by the Free Software Foundation, either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU Affero General Public License for more details.
14
#
15
# You should have received a copy of the GNU Affero General Public License
16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
from __future__ import unicode_literals
18

  
19
import json
20

  
21
from django.utils.translation import ugettext_lazy as _
22

  
23
from passerelle.utils.api import endpoint
24
from passerelle.utils.jsonresponse import APIError
25

  
26
MANDATORY_DATA = {
27
    'applicant_firstnames': None,
28
    'applicant_lastname': None,
29
    'application_id': None,
30
    'application_time': None,
31
    'certificate_type': ('birth', 'mariage', 'death', 'other'),
32
    'concerned_firstnames': None,
33
    'concerned_lastname': None,
34
    'document_type': ('full', 'multilingual', 'with-filiation', 'without-filiation'),
35
}
36

  
37
DATASOURCES = {
38
    'application-reasons': [
39
        {'id': 'id-card', 'text': _('ID Card')},  # Carte nationale d'identité
40
        {'id': 'passport', 'text': _('Passeport')},
41
        {'id': 'citizenship-certificate', 'text': _('Citizenship certtificate')},  # Certificat de nationalité française
42
        {'id': 'mariage', 'text': 'Mariage'},
43
        {'id': 'pension', 'text': _('Pension')},
44
        {'id': 'judiciary', 'text': _('Legal process')},  # Procédure judiciaire
45
        {'id': 'pacs', 'text': _('Civil solidairty pact')},  # Pacte civil de solidarité
46
        {'id': 'notary-act', 'text': _('Notary act')},  # Acte notaire
47
        {'id': 'other', 'text': _('Other')}
48
    ],
49
    'applicant-status': [
50
        {'id': 'child', 'text': _('His/her child')},  # Son fils ou sa fille
51
        {'id': 'concerned', 'text': _('The act holder')},  # La personne concernée par l'acte
52
        {'id': 'grand-parent', 'text': _('His/her grand-parents')},  # Son grand-père ou sa grand-mère
53
        {'id': 'heir', 'text': _('His/her heir')},  # Son héritier
54
        {'id': 'parent', 'text': _('His/her parents')},  # Son père ou sa mère
55
        {'id': 'partner', 'text': _('His/her partner')},  # Son conjoint ou sa conjointe
56
        {'id': 'grand-child', 'text': _('His/her grand child')},  # Son petit-fils ou sa petite-fille
57
        {'id': 'representative', 'text': _('His/her legal representative')},  # Son représentant légal
58
        {'id': 'other', 'text': _('Other')}
59
    ],
60
    'certificate-types': [
61
        {'id': 'birth', 'text': _('Birth')},
62
        {'id': 'mariage', 'text': _('Mariage')},
63
        {'id': 'death', 'text': _('Death')}
64
    ],
65
    'document-types': [
66
        {'id': 'full', 'text': _('Full copy')},  # Copie intégrale
67
        {'id': 'with-filiation', 'text': _('Excerpt with filiation')},  # Extrait avec filiation
68
        {'id': 'without-filiation', 'text': _('Excerpt without filiation')},  # Extrait sans filiation
69
        {'id': 'multilingual', 'text': _('Plurilingual excerpt')}  # Extrait plurilingue
70
    ],
71
    'titles': [
72
        {'id': 'mr', 'text': _('Sir')},
73
        {'id': 'ms', 'text': _('Mrs.')},
74
        {'id': 'mx', 'text': _('Other')},
75
    ]
76
}
77

  
78

  
79
class EndpointNotAvailable(APIError):
80
    http_status = 400
81

  
82

  
83
class CivilStatusMixin(object):
84

  
85
    category = _('Civil Status')
86

  
87
    def create_demand(self, formdata, *args, **kwargs):
88
        raise EndpointNotAvailable('<create> endpoint is not available')
89

  
90
    def get_status(self, demand_id, **kwargs):
91
        raise EndpointNotAvailable('<status> endpoint is not available')
92

  
93
    @endpoint(perm='can_access', methods=['post'])
94
    def create(self, request, *args, **kwargs):
95
        try:
96
            payload = json.loads(request.body)
97
        except (ValueError,) as exc:
98
            raise APIError('Payload error: %s' % exc)
99
        for key, values in MANDATORY_DATA.iteritems():
100
            if (key not in payload):
101
                raise APIError('<%s> is required.' % key)
102
            if values and payload[key] not in values:
103
                raise APIError('<%s> value must be one of %s' % (key, values))
104
        return self.create_demand(request, payload, *args, **kwargs)
105

  
106
    @endpoint(perm='can_access', methods=['get'], pattern='(?P<demand_id>[\w-]+)/')
107
    def status(self, request, demand_id, **kwargs):
108
        return self.get_status(demand_id)
109

  
110
    @endpoint(methods=['get'], pattern='(?P<datasource>[\w-]+)/')
111
    def datasources(self, request, datasource, **kwargs):
112
        if datasource not in DATASOURCES:
113
            raise APIError('Invalid datasource name', http_status=404)
114
        return DATASOURCES[datasource]
passerelle/civilstatus/readme.md
1
[]()
2

  
3
Connecteur État Civil[¶](#Connecteur-État-Civil){.wiki-anchor}
4
==============================================================
5

  
6
-   [Connecteur État Civil](#Connecteur-État-Civil)
7
    -   [Les variables](#Les-variables)
8
        -   -   [Variables relatives au
9
                demandeur](#Variables-relatives-au-demandeur)
10
            -   [Variables relatives à
11
                l'intéressé](#Variables-relatives-à-lintéressé)
12
            -   [Variables relatives au partenaire de
13
                l'intéréssé](#Variables-relatives-au-partenaire-de-lintéréssé)
14
            -   [Variables relatives aux parents de l'intéréssé ou de
15
                son/sa
16
                partenaire](#Variables-relatives-aux-parents-de-lintéréssé-ou-de-sonsa-partenaire)
17

  
18
    -   [Les URL](#Les-URL)
19
        -   [Création d'une demande](#Création-dune-demande)
20
        -   [Récupération du statut d'une
21
            demande](#Récupération-du-statut-dune-demande)
22
        -   [Sources de données](#Sources-de-données)
23

  
24
Cette page décrit l'interface commune qui doit être utilisée par tous
25
les connecteurs type État Civil dans Passerelle.
26

  
27
[]()
28

  
29
Les variables[¶](#Les-variables){.wiki-anchor}
30
----------------------------------------------
31

  
32
  Nom                            Type      Obligatoire   Valeurs possibles                                       Commentaires
33
  ------------------------------ --------- ------------- ------------------------------------------------------- ----------------------------------------------------------------------------------
34
  application\_id                string    **oui**                                                               (display\_id)
35
  application\_time              string    **oui**                                                               (receipt\_time)
36
  certificate\_type              string    **oui**       birth, marriage, death, other
37
  certificate\_type\_label       string    non                                                                   e.g Acte de Naissance
38
  document\_type                 string    **oui**       full, multilingual, with-filiation, without-filiation
39
  document\_type\_label          string    non                                                                   e.g Copie intégrale, plurilingue, extrait avec filiation, extrait sans filiation
40
  document\_copies               integer   non
41
  event\_city                    string    non
42
  event\_date\_start             date      non                                                                   format ISO
43
  event\_date\_end               date      non                                                                   format ISO
44
  application\_reason            string    non                                                                   motif de la demande
45
  application\_comment           string    non                                                                   commentaire sur la demande
46
  application\_city              string    non                                                                   nom de la ville à qui la demande est adressée
47
  application\_city\_inseecode   string    non                                                                   code INSEE de la ville à qui la demande est adressée
48
  application\_city\_zipcode     string    non                                                                   code postal de la ville à qui la demande est adressée
49
  applicant\_is\_concerned       boolean   non           true,false                                              définit si le demandeur est aussi le titulaire de l'acte
50
  application\_priority          string    non                                                                   définit la priorité de la demande
51

  
52
[]()
53

  
54
#### Variables relatives au demandeur[¶](#Variables-relatives-au-demandeur){.wiki-anchor}
55

  
56
  Nom                                  Type     Obligatoire   Valeurs possibles                                          Commentaires
57
  ------------------------------------ -------- ------------- ---------------------------------------------------------- ---------------------------------------------------------------------
58
  applicant\_title                     string   non           mr, ms, mx
59
  applicant\_title\_label              string   non                               e.g monsieur, madame, neutre
60
  applicant\_lastname                  string   **oui**
61
  applicant\_firstnames                string   **oui**
62
  applicant\_usual\_name               string   non
63
  applicant\_email                     string   non
64
  applicant\_phone                     string   non
65
  applicant\_status                    string   **oui**       concerned, partner, parent, child, representative, other   personne concernée, conjoint(e), parent, enfant, représentant légal
66
  applicant\_status\_label             string   non
67
  applicant\_address\_street\_number   string   non                                                                      numéro de la voie
68
  applicant\_address\_street\_type     string   non                                                                      type de la voie
69
  applicant\_address\_street           string   non
70
  applicant\_address\_complement       string   non
71
  applicant\_address\_city             string   non
72
  applicant\_address\_zipcode          string   non
73
  applicant\_address\_country          string   non                                                                      `Code ISO` ou `nom du pays` en fonction du connecteur
74

  
75
[]()
76

  
77
#### Variables relatives à l'intéressé[¶](#Variables-relatives-à-lintéressé){.wiki-anchor}
78

  
79
  Nom                       Type     Obligatoire   Valeurs possibles   Commentaires
80
  ------------------------- -------- ------------- ------------------- -------------------------------------------------------
81
  concerned\_title          string   non           mr, ms, mx
82
  concerned\_title\_label   string   non                               e.g monsieur, madame, neutre
83
  concerned\_firstnames     string   **oui**
84
  concerned\_lastname       string   **oui**
85
  concerned\_usual\_name    string   non
86
  concerned\_birthdate      date     non                               format ISO
87
  concerned\_birthcountry   string   non                               `Code ISO` ou `nom du pays` en fonction du connecteur
88
  concerned\_birthcity      string   non
89
  concerned\_birthcounty    string   non                               Département
90
  concerned\_sex            string   non           m, f, o             Homme, femme ou autre
91
  concerned\_citizenship    string   non
92

  
93
[]()
94

  
95
#### Variables relatives au partenaire de l'intéréssé[¶](#Variables-relatives-au-partenaire-de-lintéréssé){.wiki-anchor}
96

  
97
  Nom                     Type     Obligatoire   Valeurs possibles   Commentaires
98
  ----------------------- -------- ------------- ------------------- ------------------------------
99
  partner\_title          string   non           mr, ms, mx
100
  partner\_title\_label   string   non                               e.g monsieur, madame, neutre
101
  partner\_firstnames     string   non
102
  partner\_lastname       string   non
103
  partner\_usual\_name    string   non
104
  partner\_birthdate      date     non                               format ISO
105
  partner\_birthcountry   string   non
106
  partner\_birthcity      string   non
107
  partner\_birthcounty    string   non                               Département
108
  partner\_sex            string   non           m, f, o             Homme, femme ou autre
109
  partner\_citizenship    string   non
110

  
111
[]()
112

  
113
#### 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}
114

  
115
  Nom                                                  Type     Obligatoire   Valeurs possibles   Commentaires
116
  ---------------------------------------------------- -------- ------------- ------------------- --------------------------
117
  {concerned,partner}\_{parent1,parent2}\_title        string   non           mr, ms, mx          monsieur, madame, neutre
118
  {concerned,partner}\_{parent1,parent2}\_firstnames   string   non
119
  {concerned,partner}\_{parent1,parent2}\_lastname     string   non
120
  {concerned,partner}\_{parent1,parent2}\_sex          string   non           m, f, o             Homme, femme ou autre
121

  
122
[]()
123

  
124
Les URL[¶](#Les-URL){.wiki-anchor}
125
----------------------------------
126

  
127
[]()
128

  
129
### Création d'une demande[¶](#Création-dune-demande){.wiki-anchor}
130

  
131
-   `/<connector>/<slug>/create/`
132

  
133
Avec le payload json:\
134

  
135
    {
136
      "display_id": 123,
137
      "receipt_time": "2017-07-01T00:00:00",
138
      "certificate_type": "Acte de Mariage",
139
      "certificate_type_raw": "MAR",
140
      "document_type": "Extrait avec filiation",
141
      "document_type_raw": "EF",
142
      "document_copies": 3,
143
      "concerned_firstnames": "Johnny Jumper",
144
      "concerned_lastname": "Doe",
145
      "concerned_birthdate": "1980-07-07",
146
      "concerned_birthcity": "Nantes",
147
      "concerned_birthcountry": "France",
148
      "applicant_firstnames": "Kevin",
149
      "applicant_lastname": "Troll",
150
      "applicant_address_street": "27 Blvd Henry Orion",
151
      "applicant_address_city": "Nantes",
152
      "applicant_address_zipcode": 44000,
153
      "concerned_parent2_firstnames": "Kim",
154
      "concerned_parent2_lastname": "Sung-Ho",
155
      "partner_firstnames": "Chelsea Ruth",
156
      "partner_lastname": "Whatever",
157
      "event_date": "2014-05-07"
158
    }
159

  
160
</p>
161
Le retour attendu est un json contenant la clé `demand_id` i.e. :\
162

  
163
    {
164
     "err": 0,
165
     "data": {
166
         "demand_id": "123-MAR-0"
167
     }
168
    }
169

  
170
</p>
171
[]()
172

  
173
### Récupération du statut d'une demande[¶](#Récupération-du-statut-dune-demande){.wiki-anchor}
174

  
175
Dans le cas où le connecteur peut le permettre, l'URL de récupération du
176
statut d'une demande sera comme suit :
177

  
178
-   `/<connector>/<slug>/status/<demand_id>/`
179

  
180
La réponse renvoyée doit au minimum avoir les clés `status` et `closed`
181
(Boolean).
182

  
183
    {
184
      "err": 0,
185
      "data":{
186
       "status": "rejected",
187
       "closed": true,
188
       "comment": "Invalid demand"
189
      }
190
    }
191

  
192
[]()
193

  
194
### Sources de données[¶](#Sources-de-données){.wiki-anchor}
195

  
196
-   `/<connector>/<slug>/datasources/<data_source_name>/` e.g
197
    `/mdel/test/datasources/applicant-status/`
198

  
0
-