-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
outcalls: auto generate name to improve multi-tenancy #402
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
# Copyright 2016-2023 The Wazo Authors (see the AUTHORS file) | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from flask import url_for | ||
from flask import request, url_for | ||
from uuid import uuid4 | ||
|
||
from xivo_dao.alchemy.outcall import Outcall | ||
|
||
|
@@ -14,13 +15,30 @@ | |
class OutcallList(ListResource): | ||
model = Outcall | ||
schema = OutcallSchema | ||
outcall_name_fmt = 'outcall-{tenant_slug}-{outcall_uuid}' | ||
|
||
def __init__(self, tenant_dao, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self._tenant_dao = tenant_dao | ||
|
||
def build_headers(self, outcall): | ||
return {'Location': url_for('outcalls', id=outcall.id, _external=True)} | ||
|
||
@required_acl('confd.outcalls.create') | ||
def post(self): | ||
return super().post() | ||
form = self.schema().load(request.get_json()) | ||
form = self.add_tenant_to_form(form) | ||
|
||
tenant = self._tenant_dao.get(form['tenant_uuid']) | ||
# NOTE(afournier): we use a UUID as if it was the outcall UUID but it's not | ||
# Outcalls do not use UUIDs yet | ||
form['name'] = self.outcall_name_fmt.format( | ||
tenant_slug=tenant.slug, | ||
outcall_uuid=uuid4(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as: #401 (comment) |
||
) | ||
model = self.model(**form) | ||
model = self.service.create(model) | ||
return self.schema().dump(model), 201, self.build_headers(model) | ||
|
||
@required_acl('confd.outcalls.read') | ||
def get(self): | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,17 +1,21 @@ | ||||||
# Copyright 2016-2022 The Wazo Authors (see the AUTHORS file) | ||||||
# Copyright 2016-2023 The Wazo Authors (see the AUTHORS file) | ||||||
# SPDX-License-Identifier: GPL-3.0-or-later | ||||||
|
||||||
import logging | ||||||
|
||||||
from marshmallow import fields, post_dump | ||||||
from marshmallow import fields, post_dump, pre_load | ||||||
from marshmallow.validate import Length, Range | ||||||
|
||||||
from wazo_confd.helpers.mallow import BaseSchema, StrictBoolean, Link, ListLink, Nested | ||||||
|
||||||
logger = logging.getLogger(__name__) | ||||||
|
||||||
|
||||||
class OutcallSchema(BaseSchema): | ||||||
id = fields.Integer(dump_only=True) | ||||||
tenant_uuid = fields.String(dump_only=True) | ||||||
name = fields.String(validate=Length(max=128), required=True) | ||||||
name = fields.String(dump_only=True) | ||||||
label = fields.String(validate=Length(max=128), required=True) | ||||||
internal_caller_id = StrictBoolean() | ||||||
preprocess_subroutine = fields.String(validate=Length(max=39), allow_none=True) | ||||||
ring_time = fields.Integer(validate=Range(min=0), allow_none=True) | ||||||
|
@@ -40,6 +44,18 @@ class OutcallSchema(BaseSchema): | |||||
dump_only=True, | ||||||
) | ||||||
|
||||||
# DEPRECATED 23.10 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
@pre_load | ||||||
def copy_name_to_label(self, data, **kwargs): | ||||||
if 'label' in data: | ||||||
return data | ||||||
if 'name' in data: | ||||||
logger.warning( | ||||||
'The "name" field of outcall is deprecated. Use "label" instead' | ||||||
) | ||||||
data['label'] = data['name'] | ||||||
return data | ||||||
|
||||||
|
||||||
class DialPatternSchema(BaseSchema): | ||||||
external_prefix = fields.String() | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
# Copyright 2016-2020 The Wazo Authors (see the AUTHORS file) | ||
# Copyright 2016-2023 The Wazo Authors (see the AUTHORS file) | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from xivo_dao.resources.outcall import dao as outcall_dao | ||
|
||
from wazo_confd.helpers.validator import ( | ||
UniqueField, | ||
UniqueFieldChanged, | ||
ValidationGroup, | ||
) | ||
|
||
|
@@ -15,5 +14,4 @@ def build_validator(): | |
create=[ | ||
UniqueField('name', lambda name: outcall_dao.find_by(name=name), 'Outcall') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove this validator too, since the input does not come from the user anymore |
||
], | ||
edit=[UniqueFieldChanged('name', outcall_dao.find_by, 'Outcall')], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as #401 (comment)
about testing deprecated name