def user_match(self, userid, tomatch): domatch = False user = self.xod_config['users'].keeplist.get(userid) if not user: return False # does the user fullfil the destination criteria ? if 'desttype' in tomatch and 'destid' in tomatch: dest_type, dest_id = tomatch['desttype'], tomatch['destid'] if dest_type == 'user' and userid == str(dest_id): domatch = True elif dest_type == 'agent': domatch = user['agentid'] == int(dest_id) elif dest_type == 'queue' and dest_id: with session_scope(): domatch = queue_dao.is_user_member_of_queue( userid, dest_id) elif dest_type == 'group' and dest_id: with session_scope(): domatch = group_dao.is_user_member_of_group( userid, dest_id) else: # 'all' case domatch = True if domatch and 'profileids' in tomatch: if user['cti_profile_id'] not in tomatch['profileids']: domatch = False if domatch and 'contexts' in tomatch: domatch = False if user['context'] in tomatch['contexts']: domatch = True return domatch
def main(): cli_args = parse_cli_args() config = load_config() xivo_logging.setup_logging('/dev/null', log_level=cli_args['log_level']) xivo_logging.silence_loggers(['stevedore.extension'], logging.WARNING) token = AuthClient(**config['auth']).token.new(expiration=300)['token'] del config['auth']['username'] del config['auth']['password'] tenants = AuthClient(token=token, **config['auth']).tenants.list()['items'] auth_tenants = set(tenant['uuid'] for tenant in tenants) auth_tenant_slugs = {tenant['uuid']: tenant['slug'] for tenant in tenants} logger.debug('wazo-auth tenants: %s', auth_tenants) init_db_from_config(config) default_sip_template_service = DefaultSIPTemplateService( sip_dao, transport_dao, ) with session_scope() as session: confd_tenants = set() confd_tenant_without_slugs = set() for tenant in session.query(Tenant).all(): confd_tenants.add(tenant.uuid) if not tenant.slug: confd_tenant_without_slugs.add(tenant.uuid) logger.debug('wazo-confd tenants: %s', confd_tenants) removed_tenants = confd_tenants - auth_tenants for tenant_uuid in removed_tenants: logger.info('Removing tenant: %s... (SKIP)', tenant_uuid) remove_tenant(tenant_uuid) with session_scope() as session: for tenant_uuid in auth_tenants: tenant = tenant_dao.find_or_create_tenant(tenant_uuid) default_sip_template_service.generate_sip_templates(tenant) for tenant_uuid in confd_tenant_without_slugs: slug = auth_tenant_slugs.get(tenant_uuid) if not slug: continue tenant = tenant_dao.find_or_create_tenant(tenant_uuid) tenant.slug = slug session.flush()
def clean_db(): with session_scope() as dao_sess: stat_call_on_queue_dao.clean_table(dao_sess) stat_agent_periodic_dao.clean_table(dao_sess) stat_queue_periodic_dao.clean_table(dao_sess) stat_agent_dao.clean_table(dao_sess) stat_queue_dao.clean_table(dao_sess)
def find_agent_exten(self, agent_id): with session_scope(): line_ids = [] users = user_dao.find_all_by(agentid=agent_id) for user in users: line_ids.extend(user_line_dao.find_line_id_by_user_id(user.id)) return [user_line_dao.get_main_exten_by_line_id(line_id) for line_id in line_ids]
def unpause_agent_on_queue(self, agent_id, queue_id): logger.info('Unpausing agent %r on queue %r', agent_id, queue_id) agent_interface = self._get_agent_interface(agent_id) if agent_interface: with session_scope(): queue_name = queue_dao.queue_name(queue_id) self.agent_executor.unpause_on_queue(agent_interface, queue_name)
def handle(self, agi, cursor, args): self.lock.acquire_read() try: with session_scope(): self.handle_fn(agi, cursor, args) finally: self.lock.release()
def _get_voicemails(self): with session_scope(): res = {} voicemails = voicemail_dao.all() for voicemail in voicemails: res.update(self._format_voicemail_data(voicemail)) return res
def get_user_config(user_id): with session_scope() as session: query = _config_query(session).filter(User.id == user_id) row = query.first() if not row: raise LookupError('No user with ID {}'.format(user_id)) return {str(row.id): _format_row(row)}
def handle_login_user_agent(self, user_uuid, line_id, tenant_uuids=None): logger.info('Executing login command (agent of user %s) on line %d', user_uuid, line_id) with db_utils.session_scope(): agent = self._agent_dao.get_agent_by_user_uuid( user_uuid, tenant_uuids=tenant_uuids) self._login_manager.login_user_agent(agent, user_uuid, line_id)
def _get_meetmes(self): with session_scope(): res = {} meetmes = meetme_dao.all() for meetme in meetmes: res.update(self._format_meetme_data(meetme)) return res
def _get_pause_info(self, msg): _, agent_number = msg['MemberName'].split('/', 1) reason = msg['PausedReason'] queue = msg['Queue'] with db_utils.session_scope(): agent = self._agent_dao.agent_with_number(agent_number) return agent.id, agent_number, reason, queue
def _get_queues(self): with session_scope(): res = {} queues = queue_dao.all_queues() for queue in queues: res.update(self._format_queue_data(queue)) return res
def _handle_status(self, agent): with db_utils.session_scope(): agent_status = self._agent_status_dao.get_status(agent.id) if agent_status is None: logged = False paused = False paused_reason = None extension = None context = None state_interface = None else: logged = True paused = agent_status.paused paused_reason = agent_status.paused_reason extension = agent_status.extension context = agent_status.context state_interface = agent_status.state_interface return { 'id': agent.id, 'tenant_uuid': agent.tenant_uuid, 'origin_uuid': self._uuid, 'number': agent.number, 'logged': logged, 'paused': paused, 'paused_reason': paused_reason, 'extension': extension, 'context': context, 'state_interface': state_interface, }
def disable_service(user_id, enable_name, dest_name=None, dest_value=None): data = {enable_name: 0} if dest_name and dest_value: data[dest_name] = dest_value with session_scope() as session: session.query(User).filter_by(id=user_id).update(data)
def get_last_callid(event, agent_number): with session_scope(): callid = queue_log_dao.get_last_callid_with_event_for_agent( event, _build_agent_db_tag_from_number(agent_number) ) return callid
def _get_agents(self): with session_scope(): res = {} agents = agent_dao.all() for agent in agents: res.update(self._format_agent_data(agent)) return res
def _check_user_has_agent(self, user_uuid, tenant_uuids=None): try: with db_utils.session_scope(): self._agent_dao.agent_with_user_uuid(user_uuid, tenant_uuids=tenant_uuids) except LookupError: raise NoSuchAgentError()
def _add_dao_queue_members_on_update(self): old_queue_member_ids = set( self._queue_member_manager.get_queue_members_id()) new_queue_member_ids = set() add_queue_members = [] with session_scope(): for dao_queue_member in queue_member_dao.get_queue_members_for_queues( ): queue_name = dao_queue_member.queue_name member_name = dao_queue_member.member_name queue_member_id = format_queue_member_id( queue_name, member_name) new_queue_member_ids.add(queue_member_id) if queue_member_id not in old_queue_member_ids: queue_member = QueueMember.from_dao_queue_member( dao_queue_member) add_queue_members.append(queue_member) for queue_member in add_queue_members: self._queue_member_manager._add_queue_member(queue_member) self._ask_member_queue_status(queue_member) obsolete_queue_member_ids = old_queue_member_ids - new_queue_member_ids return obsolete_queue_member_ids
def generate_from_count(self, cel_count): with session_scope(): cels = self.cel_fetcher.fetch_last_unprocessed(cel_count) logger.debug( 'Generating call logs from the last %s CEL (found %s)', cel_count, len(cels)) self._generate_from_cels(cels)
def _auth_tenant_added(self, event): tenant_uuid = event['uuid'] slug = event['slug'] with session_scope(): tenant = self.tenant_dao.find_or_create_tenant(tenant_uuid) self.service.generate_sip_templates(tenant) self.service.copy_slug(tenant, slug)
def on_agent_deleted(self, agent_id): with db_utils.session_scope(): agent_status = self._agent_status_dao.get_status(agent_id) if agent_status is None: return self._logoff_action.logoff_agent(agent_status)
def userevent_did(self, chanprops, event): uniqueid = event['Uniqueid'] _set = self._get_set_fn(uniqueid) calleridnum = event.get('XIVO_SRCNUM') calleridname = event.get('XIVO_SRCNAME') calleridton = event.get('XIVO_SRCTON') calleridrdnis = event.get('XIVO_SRCRDNIS') didnumber = event.get('XIVO_EXTENPATTERN') _set('origin', 'did') _set('direction', 'incoming') _set('did', didnumber) _set('calleridnum', calleridnum) _set('calleridname', calleridname) _set('calleridrdnis', calleridrdnis) _set('calleridton', calleridton) _set('channel', chanprops.channel) with session_scope(): incall = incall_dao.get_by_exten(didnumber) if incall: _set('desttype', incall.action) _set('destid', incall.actionarg1) self._call_form_dispatch_filter.handle_did(uniqueid, chanprops.channel)
def _get_xivo_user_uuid_by_ldap_attribute(self, user_email): with session_scope(): xivo_user = find_by(email=user_email) if not xivo_user: logger.warning('%s does not have an email associated with a XiVO user', user_email) return xivo_user return xivo_user.uuid
def get_transfer_dial_timeout(): with session_scope() as session: query = session.query(Features.var_val).filter( and_(Features.category == 'general', Features.var_name == 'atxfernoanswertimeout')) timeout_str = query.scalar() return int(timeout_str)
def get_reachable_contexts(user_id): with session_scope() as session: query = (session.query(Extension.context).join( LineExtension.main_extension_rel).join( UserLine.main_user_rel).filter(UserLine.user_id == user_id)) contexts = [row.context for row in query] return _get_nested_contexts(session, contexts)
def _check_context_is_in_same_tenant(self, agent, context): with db_utils.session_scope(): retrieved_context = self._context_dao.get(context) if retrieved_context: context_tenant_uuid = retrieved_context.tenant_uuid if agent.tenant_uuid != context_tenant_uuid: raise ContextDifferentTenantError()
def post(self, id): with session_scope(): meetme = meetme_dao.get(id) form = MeetmeForm(obj=meetme) if form.validate_on_submit(): form.populate_obj(meetme) meetme_dao.edit(meetme) return redirect(url_for('meetme.Meetme:index'))
def _update_agent_status( self, agent, extension, context, interface, state_interface ): with db_utils.session_scope(): self._agent_status_dao.log_in_agent( agent.id, agent.number, extension, context, interface, state_interface ) self._agent_status_dao.add_agent_to_queues(agent.id, agent.queues)
def _get_state_interface(self, extension, context): try: with db_utils.session_scope(): return self._line_dao.get_interface_from_exten_and_context( extension, context ) except LookupError: raise NoSuchExtensionError(extension, context)
def post(self): with session_scope(): sip = generalsip_dao.list() form = FormGeneralSIP(obj=sip) if form.validate_on_submit(): form.populate_obj(sip) generalsip_dao.edit(sip) return redirect(url_for("q_generalsip.GeneralSIP:get"))
def _get_agent_statuses(self, tenant_uuids=None): with db_utils.session_scope(): agent_ids = self._agent_status_dao.get_logged_agent_ids( tenant_uuids=tenant_uuids) return [ self._agent_status_dao.get_status(agent_id) for agent_id in agent_ids ]
def handle_unpause_user_agent(self, user_uuid, tenant_uuids=None): logger.info('Executing unpause command (agent of user %s)', user_uuid) with db_utils.session_scope(): agent_status = self._agent_status_dao.get_status_by_user( user_uuid, tenant_uuids=tenant_uuids) self._pause_manager.unpause_user_agent(user_uuid, agent_status, tenant_uuids=tenant_uuids)
def _update_cti_config(): if _rw_lock.acquire_write(): try: with session_scope(): contexts = cti_context_dao.get_config() directories = cti_directories_dao.get_config() _directories_mgr.update(directories) _contexts_mgr.update(_directories_mgr.directories, contexts) finally: _rw_lock.release() else: logger.error('could not update callerid_forphones config: lock acquisition failed')
def exec_count_request(table, **cond_dict): pg_command = 'SELECT COUNT(*) FROM "%s"' % table if len(cond_dict) > 0: pg_command += " WHERE " cond = [] for key, value in cond_dict.iteritems(): cond.append('%s = %s' % (key, value)) pg_command = '%s%s' % (pg_command, ' AND '.join(cond)) with session_scope() as session: result = session.execute(pg_command) row = result.fetchone() return int(row[0])
def insert_entries(entries): with session_scope(): for entry in entries: queue_log_dao.insert_entry( entry['time'], entry['callid'], entry['queuename'], entry['agent'], entry['event'], entry['data1'], entry['data2'], entry['data3'], entry['data4'], entry['data5'] )
def delete_event_between(start, end): with session_scope(): queue_log_dao.delete_event_between(start, end)
def index(self): with session_scope(): meetme = meetme_dao.list() return render_template('meetme.html', meetme=meetme)
def get(self): with session_scope(): sip = convertToSIPToDict(generalsip_dao.list()) form = FormGeneralSIP(obj=sip) return render_template('generalsip.html', form=form)
def get(self, id): with session_scope(): meetme = meetme_dao.get(id) form = MeetmeForm(obj=meetme) return render_template('meetme_form.html', form=form)
def post(self): form = MeetmeForm() if form.validate_on_submit(): with session_scope(): meetme_dao.add(form) return redirect(url_for('meetme.Meetme:index'))
def get(self, id): with session_scope(): meetme_dao.delete(id) return redirect(url_for('meetme.Meetme:index'))
def exec_sql_request(query, **args): with session_scope() as session: return session.execute(text(query), args)
def get_uuid(): with session_scope(): return dao.get().uuid
def delete_event_by_queue_between(event, queuename, start, end): with session_scope(): queue_log_dao.delete_event_by_queue_between(event, queuename, start, end)
def exec_sql(qry, data={}): with session_scope() as session: session.execute(qry, data)
def _allow_provd_listen_on_all_interfaces(): with session_scope() as session: query = 'UPDATE provisioning SET net4_ip_rest = \'0.0.0.0\'' session.execute(query) common.open_url('commonconf')
def generate(self, output): with session_scope(): self._generate(output)