From 04e06f0ea4e89e658366579b0d7d641d0171a41e Mon Sep 17 00:00:00 2001 From: Charles Langlois Date: Mon, 11 Dec 2023 17:04:30 -0500 Subject: [PATCH 1/4] Updated phonebook_backend api.yml why: corrections and intended change --- wazo_dird/plugins/phonebook_backend/api.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wazo_dird/plugins/phonebook_backend/api.yml b/wazo_dird/plugins/phonebook_backend/api.yml index d5cea2df..be290c73 100644 --- a/wazo_dird/plugins/phonebook_backend/api.yml +++ b/wazo_dird/plugins/phonebook_backend/api.yml @@ -65,7 +65,7 @@ paths: - $ref: '#/parameters/tenantuuid' - name: body in: body - description: The display configuration body + description: The phonebook source configuration body required: true schema: $ref: '#/definitions/PhonebookSource' @@ -152,6 +152,8 @@ definitions: allOf: - $ref: '#/definitions/Source' - properties: + name: + readOnly: true phonebook_uuid: type: string phonebook_name: @@ -159,7 +161,6 @@ definitions: phonebook_description: type: string - required: - - name - phonebook_uuid PhonebookSourceItems: title: PhonebookSourceItems From 155bcf3ef09d9dee55a44db2eb05478984809833 Mon Sep 17 00:00:00 2001 From: Charles Langlois Date: Thu, 21 Mar 2024 16:53:26 -0400 Subject: [PATCH 2/4] plugins.phonebook_backend: updated api.yml to specify readOnly attributes --- wazo_dird/plugins/phonebook_backend/api.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wazo_dird/plugins/phonebook_backend/api.yml b/wazo_dird/plugins/phonebook_backend/api.yml index be290c73..26e03437 100644 --- a/wazo_dird/plugins/phonebook_backend/api.yml +++ b/wazo_dird/plugins/phonebook_backend/api.yml @@ -156,10 +156,13 @@ definitions: readOnly: true phonebook_uuid: type: string + readOnly: true phonebook_name: type: string + readOnly: true phonebook_description: type: string + readOnly: true - required: - phonebook_uuid PhonebookSourceItems: From 472a3477e520116482d81304885319428fd05367 Mon Sep 17 00:00:00 2001 From: Charles Langlois Date: Thu, 21 Mar 2024 16:54:04 -0400 Subject: [PATCH 3/4] plugins.phonebook_backend: updated SourceSchema to specify name as dump_only(not writable) --- wazo_dird/plugins/phonebook_backend/schemas.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wazo_dird/plugins/phonebook_backend/schemas.py b/wazo_dird/plugins/phonebook_backend/schemas.py index 16382e40..0d0d3890 100644 --- a/wazo_dird/plugins/phonebook_backend/schemas.py +++ b/wazo_dird/plugins/phonebook_backend/schemas.py @@ -6,7 +6,7 @@ from typing import TypedDict from marshmallow import post_load -from xivo.mallow import fields +from xivo.mallow import fields, validate from xivo.mallow_helpers import ListSchema as _ListSchema from wazo_dird.schemas import BaseSourceSchema @@ -16,6 +16,7 @@ class SourceSchema(BaseSourceSchema): phonebook_uuid = fields.UUID(required=True) phonebook_name = fields.String(dump_only=True) phonebook_description = fields.String(dump_only=True) + name = fields.String(validate=validate.Length(min=1, max=512), dump_only=True) @post_load def stringify_uuid(self, data, **kwargs): From 559d699701f55d9658ab2db2678ce315e7b398fd Mon Sep 17 00:00:00 2001 From: Charles Langlois Date: Thu, 21 Mar 2024 16:54:39 -0400 Subject: [PATCH 4/4] database.models: updated Source model to validate name and phonebook name consistency for phonebook source type --- wazo_dird/database/models.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/wazo_dird/database/models.py b/wazo_dird/database/models.py index c2ed7ecb..9a451b69 100644 --- a/wazo_dird/database/models.py +++ b/wazo_dird/database/models.py @@ -1,11 +1,11 @@ -# Copyright 2016-2023 The Wazo Authors (see the AUTHORS file) +# Copyright 2016-2024 The Wazo Authors (see the AUTHORS file) # SPDX-License-Identifier: GPL-3.0-or-later from sqlalchemy import Column, ForeignKey, Integer, Sequence, String, Text, schema, text from sqlalchemy.dialects.postgresql import ARRAY, HSTORE, JSON, UUID from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.orm import relationship +from sqlalchemy.orm import relationship, validates Base = declarative_base() @@ -263,6 +263,21 @@ class Source(Base): lambda: Phonebook, foreign_keys=[phonebook_uuid], lazy='joined' ) + @validates('name') + def ensure_phonebook_name(self, key, value): + assert key == 'name' + if not self.backend == 'phonebook': + return value + else: + assert self.phonebook_uuid and self.phonebook + if self.phonebook.name == value: + return value + else: + raise ValueError( + f'Source name {value} does not correspond to underlying ' + f'phonebook name {self.phonebook.name}' + ) + class Tenant(Base): __tablename__ = 'dird_tenant'