Projet

Général

Profil

0005-toulouse_maelis-relax-constaint-on-family-schema-673.patch

Nicolas Roche, 20 juillet 2022 18:42

Télécharger (4,87 ko)

Voir les différences:

Subject: [PATCH 5/5] toulouse_maelis: relax constaint on family schema
 (#67326)

 passerelle/contrib/toulouse_maelis/models.py  |  4 ++--
 passerelle/contrib/toulouse_maelis/schemas.py | 15 +++++++++------
 2 files changed, 11 insertions(+), 8 deletions(-)
passerelle/contrib/toulouse_maelis/models.py
297 297
        return {'data': response}
298 298

  
299 299
    @endpoint(
300 300
        display_category=_('Family'),
301 301
        description='Création de la famille',
302 302
        name='create-family',
303 303
        perm='can_access',
304 304
        parameters={'NameID': {'description': _('Publik ID')}},
305
        post={'request_body': {'schema': {'application/json': schemas.FAMILY_SCHEMA}}},
305
        post={'request_body': {'schema': {'application/json': schemas.CREATE_FAMILY_SCHEMA}}},
306 306
    )
307 307
    def create_family(self, request, NameID, post_data):
308 308
        if self.link_set.filter(name_id=NameID).exists():
309 309
            raise APIError('User already linked to family', err_code='already-linked')
310 310

  
311 311
        response = self.call('Family', 'createFamily', **post_data)
312 312
        data = serialize_object(response)
313 313
        family_id = data.get('number')
......
320 320
        return {'data': data}
321 321

  
322 322
    @endpoint(
323 323
        display_category=_('Family'),
324 324
        description='Modification de la famille',
325 325
        name='update-family',
326 326
        perm='can_access',
327 327
        parameters={'NameID': {'description': _('Publik ID')}},
328
        post={'request_body': {'schema': {'application/json': schemas.FAMILY_SCHEMA}}},
328
        post={'request_body': {'schema': {'application/json': schemas.UPDATE_FAMILY_SCHEMA}}},
329 329
    )
330 330
    def update_family(self, request, NameID, post_data):
331 331
        family_id = self.get_link(NameID).family_id
332 332
        self.replace_null_values(post_data)
333 333

  
334 334
        response = self.call('Family', 'updateFamily', dossierNumber=family_id, **post_data)
335 335
        data = serialize_object(response)
336 336
        family_id = data.get('number')
passerelle/contrib/toulouse_maelis/schemas.py
9 9
# This program is distributed in the hope that it will be useful,
10 10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 12
# GNU Affero General Public License for more details.
13 13
#
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import copy
18

  
17 19
BOOLEAN_TYPES = [
18 20
    {'type': 'boolean'},
19 21
    {
20 22
        'type': 'string',
21 23
        'pattern': '^([Oo][Uu][Ii]|[Nn][Oo][Nn]|[Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee]|1|0)$',
22 24
        'pattern_description': 'Les valeurs "0", "1", "true", "false", "oui" ou "non" sont autorisées (insensibles à la casse).',
23 25
    },
24 26
]
......
259 261
        'adresse': ADDRESS_SCHEMA,
260 262
        'contact': CONTACT_SCHEMA,
261 263
        'profession': PROFESSION_SCHEMA,
262 264
        'CAFInfo': CAFINFO_SCHEMA,
263 265
    },
264 266
}
265 267

  
266 268

  
267
FAMILY_SCHEMA = {
269
CREATE_FAMILY_SCHEMA = {
268 270
    '$schema': 'http://json-schema.org/draft-04/schema#',
269 271
    'title': 'Family',
270 272
    'description': 'Informations pour créer ou mettre à jour une famille',
271 273
    'type': 'object',
272
    'required': ['categorie', 'situation'],
273
    "oneOf": [
274
        {"required": ['rl1']},
275
        {"required": ['rl2']},
276
    ],
274
    'required': ['rl1', 'categorie', 'situation'],
277 275
    'properties': {
278 276
        'categorie': {
279 277
            'description': 'Categorie (depuis référenciel)',
280 278
            'type': 'string',
281 279
        },
282 280
        'situation': {
283 281
            'description': 'Situation familiale (depuis référenciel)',
284 282
            'type': 'string',
......
300 298
            'oneOf': [{'type': 'null'}, {'type': 'string'}],
301 299
        },
302 300
        'rl1': RLINFO_SCHEMA,
303 301
        'rl2': RLINFO_SCHEMA,
304 302
    },
305 303
    'unflatten': True,
306 304
}
307 305

  
306

  
307
UPDATE_FAMILY_SCHEMA = copy.deepcopy(CREATE_FAMILY_SCHEMA)
308
UPDATE_FAMILY_SCHEMA['required'] = ['categorie', 'situation']
309

  
310

  
308 311
# Schemas below describe parameters of Maelis wrapper around updateFamily endpoint
309 312

  
310 313
UPDATE_COORDINATE_SCHEMA = {
311 314
    '$schema': 'http://json-schema.org/draft-04/schema#',
312 315
    'title': 'Update coordinate',
313 316
    'description': "Mise à jour des coordonnées d'un responsable légal",
314 317
    'type': 'object',
315 318
    'properties': {
316
-