class AuthConfigSchema(BaseSchema): host = fields.String(validate=Length(min=1, max=1024), missing='localhost') port = fields.Integer(validate=Range(min=1, max=65535), missing=9497) key_file = fields.String(validate=Length(min=1, max=1024), allow_none=True) username = fields.String(validate=Length(min=1, max=512), allow_none=True) password = fields.String(validate=Length(min=1, max=512), allow_none=True) verify_certificate = VerifyCertificateField(missing=True) timeout = fields.Float(validate=Range(min=0, max=3660)) version = fields.String(validate=Length(min=1, max=16), missing='0.1') @validates_schema def validate_auth_info(self, data): key_file = data.get('key_file') username = data.get('username') if key_file and username: raise exceptions.ValidationError( 'a "key_file" or a "username" and "password" must be specified', ) if key_file or username: return raise exceptions.ValidationError( 'a "key_file" or a "username" and "password" must be specified', )
class RefreshTokenSchema(BaseSchema): client_id = xfields.String(min=1, max=1024) created_at = xfields.DateTime() mobile = xfields.Boolean() user_uuid = xfields.String() tenant_uuid = xfields.String()
class ExportSchema(Schema): uuid = fields.UUID() tenant_uuid = fields.UUID() user_uuid = fields.UUID() requested_at = fields.DateTime() filename = fields.String() status = fields.String()
class ConfdConfigSchema(BaseSchema): host = fields.String(validate=Length(min=1, max=1024), missing='localhost') port = fields.Integer(validate=Range(min=1, max=65535), missing=9486) verify_certificate = VerifyCertificateField(missing=True) timeout = fields.Float(validate=Range(min=0, max=3660)) https = fields.Boolean(missing=True) version = fields.String(validate=Length(min=1, max=16), missing='1.1')
class SourceSchema(BaseSourceSchema): lookup_url = fields.URL(required=True) list_url = fields.URL(allownone=True, missing=None) verify_certificate = VerifyCertificateField(missing=True) delimiter = fields.String(Length(min=1, max=1), missing=',') timeout = fields.Float(Range(min=0), missing=10.0) unique_column = fields.String(Length(min=1, max=128), allownone=True, missing=None)
class MarketListRequestSchema(Schema): direction = fields.String(validate=OneOf(['asc', 'desc']), missing='asc') order = fields.String(validate=Length(min=1), missing='name') limit = fields.Integer(validate=Range(min=0), missing=None) offset = fields.Integer(validate=Range(min=0), missing=0) search = fields.String(missing=None) installed = fields.Boolean()
class MobileSchema(schemas.BaseSchema): token = fields.String(min=1, max=512, missing=None) apns_token = fields.String(allow_none=True, max=512, missing=None) # deprecated apns_voip_token = fields.String(allow_none=True, max=512, missing=None) apns_notification_token = fields.String(allow_none=True, max=512, missing=None)
class BaseAuthConfigSchema(BaseSchema): host = fields.String(validate=Length(min=1, max=1024), missing='localhost') port = fields.Integer(validate=Range(min=1, max=65535), missing=443) https = fields.Boolean(missing=True) verify_certificate = VerifyCertificateField(missing=True) prefix = fields.String(allow_none=True, missing='/api/auth') version = fields.String(validate=Length(min=1, max=16), missing='0.1') timeout = fields.Float(validate=Range(min=0, max=3660))
class SourceSchema(BaseSourceSchema): auth = fields.Dict(keys=fields.String(validate=Length(min=1, max=64)), values=fields.String(validate=Length(min=1, max=64))) endpoint = fields.String( missing='https://graph.microsoft.com/v1.0/me/contacts', validate=Length(min=1, max=255), )
class SourceSchema(BaseSourceSchema): unique_column = fields.String( validate=Length(min=1, max=128), allow_none=True, missing=None, ) file = fields.String(validate=Length(min=1), required=True) separator = fields.String(validate=Length(min=1, max=1), missing=',')
class UserRegisterPostSchema(BaseSchema): username = fields.String(validate=validate.Length(min=1, max=256)) password = fields.String(validate=validate.Length(min=1), required=True) firstname = fields.String(missing=None) lastname = fields.String(missing=None) email_address = fields.Email(required=True) purpose = fields.Constant('user')
class BaseSourceSchema(BaseSchema): uuid = fields.UUID(dump_only=True) tenant_uuid = fields.UUID(dump_only=True) name = fields.String(validate=Length(min=1, max=512), required=True) first_matched_columns = fields.List( fields.String(validate=Length(min=1, max=128)), missing=[]) searched_columns = fields.List( fields.String(validate=Length(min=1, max=128)), missing=[]) format_columns = fields.Dict(validate=validate_string_dict, missing={})
class InitPostSchema(BaseSchema): username = fields.String(validate=validate.Length(min=1, max=256), required=True) password = fields.String(validate=validate.Length(min=1), required=True) key = fields.String(validate=validate.Length(equal=20), required=True) purpose = fields.String( missing='internal', validate=validate.OneOf(['user', 'internal', 'external_api']) )
class _BaseUserSchema(BaseSchema): username = fields.String(validate=validate.Length(min=1, max=256), required=True) firstname = fields.String(missing=None, allow_none=True) lastname = fields.String(missing=None, allow_none=True) purpose = fields.String(missing='user', validate=validate.OneOf( ['user', 'internal', 'external_api'])) enabled = fields.Boolean(missing=True)
class MessageSchema(Schema): uuid = fields.UUID(dump_only=True) content = fields.String(required=True) alias = fields.String(validate=validate.Length(max=256), allow_none=True) user_uuid = fields.UUID(dump_only=True) tenant_uuid = fields.UUID(dump_only=True) wazo_uuid = fields.UUID(dump_only=True) created_at = fields.DateTime(dump_only=True) room = fields.Nested('RoomSchema', dump_only=True, only=['uuid'])
class ParticipantSchema(Schema): class Meta: ordered = True unknown = EXCLUDE id = fields.String() caller_id_name = fields.String() caller_id_number = fields.String() call_id = fields.String() user_uuid = fields.String(allow_none=True)
class UserPresenceSchema(Schema): uuid = fields.UUID(dump_only=True) tenant_uuid = fields.UUID(dump_only=True) state = fields.String( required=True, validate=OneOf(['available', 'unavailable', 'invisible', 'away'])) status = fields.String(allow_none=True) last_activity = fields.DateTime(dump_only=True) line_state = fields.String(dump_only=True) mobile = fields.Boolean(dump_only=True) do_not_disturb = fields.Boolean(dump_only=True) connected = fields.Boolean(dump_only=True) lines = fields.Nested('LinePresenceSchema', many=True, dump_only=True) @post_dump def _set_line_state(self, user, **kwargs): line_states = [line['state'] for line in user['lines']] if 'ringing' in line_states: merged_state = 'ringing' elif 'progressing' in line_states: merged_state = 'progressing' elif 'holding' in line_states: merged_state = 'holding' elif 'talking' in line_states: merged_state = 'talking' elif 'available' in line_states: merged_state = 'available' else: merged_state = 'unavailable' user['line_state'] = merged_state return user @post_dump(pass_original=True) def _set_mobile(self, user, raw_user, **kwargs): for token in raw_user.refresh_tokens: if token.mobile is True: user['mobile'] = True return user for session in raw_user.sessions: if session.mobile is True: user['mobile'] = True return user user['mobile'] = False return user @post_dump(pass_original=True) def _set_connected(self, user, raw_user, **kwargs): user['connected'] = True if raw_user.sessions else False return user
class DisplayColumnSchema(BaseSchema): field = fields.String(allow_none=True) title = fields.String(allow_none=True) type = fields.String(allow_none=True) default = fields.String(allow_none=True) number_display = fields.String(allow_none=True) @marshmallow.validates_schema def check_not_empty(self, data, **kwargs): if not data: raise marshmallow.ValidationError('Empty columns are now allowed')
class _StatisticsPeriodSchema(Schema): from_ = fields.String(attribute='from', data_key='from') until = fields.String() tenant_uuid = fields.UUID(default=None) @pre_dump def convert_from_and_until_to_isoformat(self, data, **kwargs): if data.get('from'): data['from'] = data['from'].isoformat() if data.get('until'): data['until'] = data['until'].isoformat() return data
class UserSubscriptionSchema(Schema): uuid = fields.UUID(dump_only=True) name = fields.String(validate=Length(max=128), required=True) service = fields.String(validate=Length(max=128), allow_none=False, required=True) events = fields.List(fields.String(validate=Length(max=128), allow_none=False), allow_none=False, required=True) config = ConfigField(allow_none=False, required=True) metadata_ = fields.Dict(load_from='metadata')
class ParticipantSchema(Schema): class Meta: strict = True ordered = True id = fields.String() caller_id_name = fields.String() caller_id_number = fields.String() muted = fields.Boolean() join_time = fields.Integer() admin = fields.Boolean() language = fields.String() call_id = fields.String()
class MessageListRequestSchema(_ListSchema): default_sort_column = 'created_at' sort_columns = ['created_at'] searchable_columns = [] default_direction = 'desc' search = fields.String() distinct = fields.String(validate=validate.OneOf(['room_uuid'])) @validates_schema def search_or_distinct(self, data, **kwargs): if not data.get('search') and not data.get('distinct'): raise ValidationError('Missing search or distinct')
class LDAPConfig(BaseSchema): tenant_uuid = fields.String(dump_only=True, default=None) host = fields.String(validate=Length(max=512), required=True, default=None) port = fields.Integer(required=True, default=None) protocol_version = fields.Integer(validate=Range(min=2, max=3), missing=3, default=None) protocol_security = fields.String( validate=OneOf(['ldaps', 'tls']), allow_none=True, default=None, ) bind_dn = fields.String(validate=Length(max=256), allow_none=True, default=None) user_base_dn = fields.String(validate=Length(max=256), required=True, default=None) user_login_attribute = fields.String(validate=Length(max=64), required=True, default=None) user_email_attribute = fields.String(validate=Length(max=64), required=True, default=None) search_filters = fields.String(allow_none=True, default=None)
class RoomSchema(Schema): uuid = fields.UUID(dump_only=True) tenant_uuid = fields.UUID(dump_only=True) name = fields.String(allow_none=True) users = fields.Nested('RoomUserSchema', many=True, missing=[])
class ProfileSchema(BaseSchema): uuid = fields.UUID(dump_only=True) tenant_uuid = fields.UUID(dump_only=True) name = fields.String(validate=Length(min=1, max=512), required=True) display = fields.Nested(ResourceSchema) services = ServiceDictSchema(BaseSchema, required=True)
class UserSubscriptionSchema(Schema): class Meta: unknown = EXCLUDE uuid = fields.UUID(dump_only=True) name = fields.String(validate=Length(max=128), required=True) service = fields.String(validate=Length(max=128), allow_none=False, required=True) events = fields.List( fields.String(validate=Length(max=128), allow_none=False), allow_none=False, required=True, ) config = ConfigField(allow_none=False, required=True) metadata_ = fields.Dict(data_key='metadata')
class ListSchema(BaseSchema): limit = fields.Integer(validate=validate.Range(min=0)) offset = fields.Integer(validate=validate.Range(min=0)) search = fields.String() recurse = fields.Boolean() class Meta: unknown = marshmallow.INCLUDE
class AgentStatisticsSchema(_StatisticsPeriodSchema): agent_id = fields.Integer(default=None) agent_number = fields.String(default=None) answered = fields.Integer(default=0) conversation_time = fields.Integer(default=0) login_time = fields.Integer(default=0) pause_time = fields.Integer(default=0) wrapup_time = fields.Integer(default=0)
class ContactListSchema(_ListSchema): searchable_columns = ['uuid', 'firstname', 'lastname'] sort_columns = ['firstname', 'lastname'] default_sort_column = 'firstname' recurse = fields.Boolean(missing=False) uuid = fields.String()
class CDRListRequestSchema(CDRListingBase): direction = fields.String(validate=OneOf(['asc', 'desc']), missing='desc') order = fields.String( validate=OneOf(set(CDRSchema().fields) - {'end', 'tags', 'recordings'}), missing='start', ) limit = fields.Integer(validate=Range(min=0), missing=1000) offset = fields.Integer(validate=Range(min=0), missing=None) distinct = fields.String(validate=OneOf(['peer_exten']), missing=None) recorded = fields.Boolean(missing=None) format = fields.String(validate=OneOf(['csv', 'json']), missing=None) @post_load def map_order_field(self, in_data, **kwargs): mapped_order = CDRSchema().fields[in_data['order']].attribute if mapped_order: in_data['order'] = mapped_order return in_data