def get_by_extension_id(extension_id): context = context_dao.find_by_extension_id(extension_id) if not context: raise errors.not_found('Extension', id=extension_id) line_extension = _find_line_extension_by_type(context, extension_id) if not line_extension: raise errors.not_found('LineExtension', extension_id=extension_id) return line_extension
def get_member_agent(self, queue, agent): member = self.find_member_agent(queue, agent) if not member: raise errors.not_found('QueueMember', agent_id=agent.id, queue_id=queue.id) return member
def load_first_file(self, sound): path = self._get_first_file_path(sound) if not os.path.isfile(path): raise errors.not_found('Sound file', name=sound.name, path=path) return send_file(path, mimetype='application/octet-stream', as_attachment=True)
def get(context_name): context = find(context_name) if not context: raise errors.not_found('Context', name=context_name) return context
def get_by_extension_id(extension_id): context = find_by_extension_id(extension_id) if not context: raise errors.not_found('Context', extension_id=extension_id) return context
def get_directory(self, tenant_uuid, directory, parameters, with_files=True): if directory in RESERVED_DIRECTORIES: raise errors.not_found('Sound', name=directory) if not os.path.exists( self._build_path('tenants', tenant_uuid, directory)): raise errors.not_found('Sound', name=directory, **parameters) sound = SoundCategory(name=directory, tenant_uuid=tenant_uuid) if with_files: sound = self._populate_files(sound, parameters) return sound
def get(self, registrar_id, tenant_uuids=None): parameters = {'X_type': 'registrar', 'id': registrar_id} resources = self.client.configs.list(parameters)['configs'] if not resources: raise errors.not_found('Registrar', id=registrar_id) return Registrar(resources[0])
def get(self, id, tenant_uuid=None): try: provd_device = self.devices.get(id, tenant_uuid=tenant_uuid) except ProvdError as e: if e.status_code == 404: raise errors.not_found('Device', id=id) raise return self.build_device(provd_device)
def get_template_row(self, template_id): query = self.session.query(FuncKeyTemplate) query = query.filter(FuncKeyTemplate.id == template_id) query = self._filter_tenant_uuid(query) template = query.first() if not template: raise errors.not_found('FuncKeyTemplate', id=template_id) return template
def get_registrar(self, registrar_id): registrars = self.configs.find({ 'X_type': 'registrar', 'id': registrar_id }) if not registrars: raise errors.not_found('Registrar', id=registrar_id) return registrars[0]
def find_profile_by_userid(session, userid): user = session.query(UserSchema).filter(UserSchema.id == userid).first() if user is None: raise errors.not_found('User', id=userid) if user.cti_profile_id is None: return None row = session.query(CtiProfileSchema).filter(CtiProfileSchema.id == user.cti_profile_id).first() return cti_profile_db_converter.to_model(row)
def get_value(session, feature_id): value = (session.query(Features.var_val) .filter(Features.id == feature_id) .scalar()) if not value: raise errors.not_found('Features', id=feature_id) return value
def put(self, id): device = self.service.get(id) if not device.is_new: raise errors.not_found('Device', id=id) kwargs = self._add_tenant_uuid() self.service.assign_tenant(device, **kwargs) return ('', 204)
def get_type_typeval(session, extension_id): row = (session.query(ExtensionSchema.type, ExtensionSchema.typeval) .filter(ExtensionSchema.id == extension_id) .first()) if not row: raise errors.not_found('Extension', id=extension_id) return (row.type, row.typeval)
def get_association_from_trunk(self, trunk_id): trunk = self.trunk_dao.get(trunk_id) if not trunk.is_associated(self.endpoint): raise errors.not_found('TrunkEndpoint', trunk_id=trunk_id) return { 'trunk_id': trunk.id, 'endpoint': trunk.endpoint, 'endpoint_id': trunk.endpoint_id, }
def get_association_from_line(self, line_id): line = self.line_service.get(line_id) if not line.is_associated(self.endpoint): raise errors.not_found('LineEndpoint', line_id=line_id) return { 'line_id': line.id, 'endpoint': self.endpoint, 'endpoint_id': line.endpoint_id, }
def get_number(session, paging_id): number = (session.query(Paging.number) .filter(Paging.id == paging_id) .scalar() ) if not number: raise errors.not_found('Paging', id=paging_id) return number
def get_value(session, feature_id): value = (session.query( Features.var_val).filter(Features.id == feature_id).scalar()) if not value: raise errors.not_found('Features', id=feature_id) value = _extract_applicationmap_dtmf(value) return value
def validate_associate_agent_queue(queue_id, agent_id): if not _queue_exists(queue_id): raise errors.not_found('Queue', queue_id=queue_id) if not _agent_exists(agent_id): raise errors.param_not_found('agent_id', 'Agent') try: queue_members_dao.get_by_queue_id_and_agent_id(queue_id, agent_id) raise errors.resource_associated('Agent', 'Queue', agent_id, queue_id) except NotFoundError: pass
def get(self, user_uuid, tenant_uuid, name, view=None): result = self.dao.find(user_uuid, name) if result: return result if view == 'fallback': result = self.external_app_dao.find(name, tenant_uuids=[tenant_uuid]) if result: return result raise errors.not_found('UserExternalApp', name=name)
def get_by_queue_id_and_agent_id(session, queue_id, agent_id): row = (session.query(QueueMemberSchema) .filter(QueueFeaturesSchema.name == QueueMemberSchema.queue_name) .filter(QueueMemberSchema.usertype == 'agent') .filter(QueueMemberSchema.userid == agent_id) .filter(QueueFeaturesSchema.id == queue_id)).first() if not row: raise errors.not_found('QueueMember', agent_id=agent_id, queue_id=queue_id) result = db_converter.to_model(row) result.queue_id = queue_id return result
def get_association_from_endpoint(self, endpoint_id): endpoint = self.endpoint_dao.get(endpoint_id) trunk = self.trunk_dao.find_by(protocol=self.endpoint, endpoint_id=endpoint.id) if not trunk: raise errors.not_found('TrunkEndpoint', endpoint_id=endpoint_id) return { 'trunk_id': trunk.id, 'endpoint': trunk.endpoint, 'endpoint_id': trunk.endpoint_id, }
def get_association_from_endpoint(self, endpoint_id): endpoint = self.endpoint_service.get(endpoint_id) line = self.line_service.find_by(protocol=self.endpoint, protocolid=endpoint.id) if not line: raise errors.not_found('LineEndpoint', endpoint_id=endpoint_id) return { 'line_id': line.id, 'endpoint': self.endpoint, 'endpoint_id': line.endpoint_id, }
def get(self, guest_uuid, meeting_uuid, authorization_uuid): ids = { 'guest_uuid': guest_uuid, 'meeting_uuid': meeting_uuid, 'authorization_uuid': authorization_uuid, } ids = MeetingAuthorizationIDSchema().load(ids) try: self._meeting_dao.get(ids['meeting_uuid']) except NotFoundError as e: raise errors.not_found('meetings', 'Meeting', **e.metadata) try: model = self._service.get( ids['meeting_uuid'], ids['authorization_uuid'], guest_uuid=ids['guest_uuid'], ) except NotFoundError as e: raise errors.not_found('meeting_authorizations', 'MeetingAuthorization', **e.metadata) return self.schema().dump(model)
def _extract_form(self, fields, tenant): if not fields.get('username'): fields['username'] = self._random_string(8) if not fields.get('password'): fields['password'] = self._random_string(8) form = { 'name': fields['username'], 'auth_section_options': [[key, value] for key, value in fields.items()], } if not tenant.global_sip_template: raise errors.not_found('global_sip_template') return self.schema(handle_error=False).load(form)
def get(self, meeting_uuid): ids = { 'meeting_uuid': meeting_uuid, } ids = MeetingAuthorizationIDSchema().load(ids) user_uuid = self._find_user_uuid() try: self.meeting_dao.get_by(uuid=ids['meeting_uuid'], owner=user_uuid) except NotFoundError as e: raise errors.not_found('meetings', 'Meeting', **e.metadata) params = self.search_params() total, items = self.service.search(params, ids['meeting_uuid']) return {'total': total, 'items': self.schema().dump(items, many=True)}
def remove_files(self, sound): paths = self._get_file_paths(sound) remove_errors = [] for path in paths: try: os.remove(path) except OSError as e: if e.errno == errno.ENOENT: remove_errors.append( errors.not_found('Sound file', name=sound.name, path=path)) else: remove_errors.append(e) if len(remove_errors) == len(paths): for error in remove_errors: raise error
def get(self, meeting_uuid, authorization_uuid): ids = { 'meeting_uuid': meeting_uuid, 'authorization_uuid': authorization_uuid, } ids = MeetingAuthorizationIDSchema().load(ids) user_uuid = self._find_user_uuid() try: model = self.meeting_authorization_dao.get( ids['meeting_uuid'], ids['authorization_uuid'], owner=user_uuid, ) except NotFoundError as e: raise errors.not_found('meeting_authorization', 'MeetingAuthorization', **e.metadata) return self.schema().dump(model)
def _get_asterisk_sound(self, parameters, with_files=True): sound = SoundCategory(name='system') if with_files: if 'file_name' in parameters: try: ari_sounds = [ self._ari_client.get_sound(parameters['file_name'], parameters) ] except HTTPError as e: if e.response.status_code == 404: raise errors.not_found( 'Sound', name='system', file_name=parameters['file_name']) raise else: ari_sounds = self._ari_client.get_sounds() sound.files = convert_ari_sounds_to_model(ari_sounds) return sound
def get(self, position): if position not in self.keys: raise errors.not_found('FuncKey', template_id=self.id, position=position) return self.keys[position]
def validate_get_agent_queue_association(queue_id, agent_id): if not _queue_exists(queue_id): raise errors.not_found('Queue', queue_id=queue_id) if not _agent_exists(agent_id): raise errors.not_found('Agent', agent_id=agent_id)
def validate_remove_agent_from_queue(agent_id, queue_id): if not _queue_exists(queue_id): raise errors.not_found('Queue', queue_id=queue_id) if not _agent_exists(agent_id): raise errors.not_found('Agent', agent_id=agent_id) queue_members_dao.get_by_queue_id_and_agent_id(queue_id, agent_id)
def get(self, iax_id): iax = self.find_by({'id': iax_id}) if not iax: raise errors.not_found('IAXEndpoint', id=iax_id) return iax
def get_by(self, criteria): user = self.find_by(criteria) if not user: raise errors.not_found('User', **criteria) return user
def get_by(self, **criteria): user_line = self.find_by(**criteria) if not user_line: raise errors.not_found(self.resource, **criteria) return user_line
def get_id_by_name(session, cti_profile_name): row = session.query(CtiProfile).filter(CtiProfile.name == cti_profile_name).first() if row is None: raise errors.not_found('CtiProfile', name=cti_profile_name) return row.id
def get(self, id): row = self.session.query(SIP).filter(SIP.id == id).first() if not row: raise errors.not_found('SIPEndpoint', id=id) return row
def validate_edit_agent_queue_association(queue_member): if not _queue_exists(queue_member.queue_id): raise errors.not_found('Queue', queue_id=queue_member.queue_id) if not _agent_exists(queue_member.agent_id): raise errors.not_found('Agent', agent_id=queue_member.agent_id) queue_members_dao.get_by_queue_id_and_agent_id(queue_member.queue_id, queue_member.agent_id)
def get(self, id): line = self.line_service.get(id) if line.sip_endpoint is None: raise errors.not_found('LineSIP', id=id) return LineSip.from_line_and_sip(line, line.sip_endpoint)
def _moh_file_not_found(path, moh, filename): logger.info('MOH file %s not found', path) raise errors.not_found('MOH file', uuid=moh.uuid, filename=filename)
def get_by(**criteria): extension = find_by(**criteria) if not extension: raise errors.not_found('UserVoicemail', **criteria) return extension
def get_by(**criteria): user_voicemail = find_by(**criteria) if not user_voicemail: raise errors.not_found('UserVoicemail', **criteria) return user_voicemail
def get(self, id): custom = self.session.query(Custom).filter_by(id=id).first() if not custom: raise errors.not_found('CustomEndpoint', id=id) return custom
def get_by(self, criteria): model = self.find_by(criteria) if not model: raise errors.not_found('Transport', **criteria) return model
def get(self, line_id): line = self.find(line_id) if not line: raise errors.not_found('Line', id=line_id) return line
def get(self, custom_id): custom = self._find_query({'id': custom_id}).first() if not custom: raise errors.not_found('CustomEndpoint', id=id) return custom
def get_by(**criteria): extension = find_by(**criteria) if not extension: raise errors.not_found('Extension', **criteria) return extension
def get_by(self, criteria): model = self.find_by(criteria) if not model: resource_name = self._search_table.__mapper__.class_.__name__ raise errors.not_found(resource_name, **criteria) return model
def get(self, id): sccp = self.find(id) if not sccp: raise errors.not_found('SCCPEndpoint', id=id) return sccp
def get_association_from_line(self, line): if not line.device_id: raise errors.not_found('LineDevice', line_id=line.id) return LineDevice.from_line(line)
def get_template_row(self, template_id): template_row = self.session.query(FuncKeyTemplate).get(template_id) if not template_row: raise errors.not_found('FuncKeyTemplate', id=template_id) return template_row
def get(session, profile_id): row = session.query(CtiProfile).filter(CtiProfile.id == profile_id).first() if row is None: raise errors.not_found('CtiProfile', id=profile_id) return db_converter.to_model(row)
def get(session): row = (session.query(InfosSchema).first()) if not row: raise errors.not_found('Infos') return db_converter.to_model(row)