def add_or_replace_schedule(data):
    delete_schedules_with_name(data['name'])
    entity = entity_helper.get_entity_with_name(data['entity'])
    entity_id = entity['id'] if entity else entity_helper.default_entity_id()
    schedule = Schedule(
        entity_id=entity_id,
        name=data['name'],
        timezone=data.get('timezone', 'America/Montreal'),
    )
    world.ws.schedules.add(schedule)
Esempio n. 2
0
def add_or_replace_schedule(data):
    delete_schedules_with_name(data['name'])
    entity = entity_helper.get_entity_with_name(data['entity'])
    if entity:
        entity_id = entity.id
    else:
        entity_id = entity_helper.oldest_entity_id()
    schedule = Schedule(
        entity_id=entity_id,
        name=data['name'],
        timezone=data.get('timezone', 'America/Montreal'),
    )
    world.ws.schedules.add(schedule)
Esempio n. 3
0
def add_user(data_dict, step=None):
    user = User()

    if 'id' in data_dict:
        user.id = data_dict['id']

    user.firstname = data_dict['firstname']

    if 'lastname' in data_dict:
        user.lastname = data_dict['lastname']
    if 'agentid' in data_dict:
        user.agent_id = int(data_dict['agentid'])
    if 'language' in data_dict:
        user.language = data_dict['language']
    if 'enable_client' in data_dict:
        user.enable_client = bool(data_dict['enable_client'])
    if 'client_username' in data_dict:
        user.client_username = data_dict['client_username']
    if 'client_password' in data_dict:
        user.client_password = data_dict['client_password']
    if 'client_profile' in data_dict:
        user.client_profile = data_dict['client_profile']
    if 'bsfilter' in data_dict:
        user.bsfilter = data_dict['bsfilter']

    if 'entity_name' in data_dict:
        entity = entity_helper.get_entity_with_name(data_dict['entity_name'])
        if entity:
            user.entity_id = entity.id
    else:
        user.entity_id = entity_helper.oldest_entity_id()

    if 'line_number' in data_dict and 'line_context' in data_dict:
        user.line = UserLine()
        user.line.number = data_dict['line_number']
        user.line.context = data_dict['line_context']
        if 'protocol' in data_dict:
            user.line.protocol = data_dict['protocol']
        if 'device' in data_dict:
            device = provd_helper.find_by_mac(data_dict['device'])
            if device is not None:
                user.line.device_id = str(device['id'])

    if 'voicemail_name' in data_dict and 'voicemail_number' in data_dict:
        user.voicemail = UserVoicemail()
        user.voicemail.name = data_dict['voicemail_name']
        user.voicemail.number = data_dict['voicemail_number']

    if 'mobile_number' in data_dict:
        user.mobile_number = data_dict['mobile_number']

    try:
        ret = world.ws.users.add(user)
    except WebServiceRequestError as e:
        raise Exception('Could not add user %s %s: %s' % (user.firstname, user.lastname, e))
    if not ret:
        return False

    if step is not None:
        _register_and_track_phone(step.scenario, data_dict)

    return int(ret)
Esempio n. 4
0
def add_user(data_dict, step=None):
    user = User()

    if 'id' in data_dict:
        user.id = data_dict['id']

    user.firstname = data_dict['firstname']

    if 'lastname' in data_dict:
        user.lastname = data_dict['lastname']
    if 'agentid' in data_dict:
        user.agent_id = int(data_dict['agentid'])
    if 'language' in data_dict:
        user.language = data_dict['language']
    if 'enable_client' in data_dict:
        user.enable_client = bool(data_dict['enable_client'])
    if 'client_username' in data_dict:
        user.client_username = data_dict['client_username']
    if 'client_password' in data_dict:
        user.client_password = data_dict['client_password']
    if 'client_profile' in data_dict:
        user.client_profile = data_dict['client_profile']
    if 'bsfilter' in data_dict:
        user.bsfilter = data_dict['bsfilter']

    if 'entity_name' in data_dict:
        entity = entity_helper.get_entity_with_name(data_dict['entity_name'])
        if entity:
            user.entity_id = entity['id']
    else:
        user.entity_id = entity_helper.default_entity_id()

    if 'mobile_number' in data_dict:
        user.mobile_number = data_dict['mobile_number']

    try:
        user_id = world.ws.users.add(user)
    except WebServiceRequestError as e:
        raise Exception('Could not add user %s %s: %s' % (user.firstname, user.lastname, e))
    if not user_id:
        return False

    if 'line_number' in data_dict and 'line_context' in data_dict:
        extension = extension_action.create_extension({
            'context': data_dict['line_context'],
            'exten': data_dict['line_number'],
        }).resource()

        line_data = {
            'context': data_dict['line_context'],
        }
        if 'device_slot' in data_dict:
            line_data['device_slot'] = data_dict['device_slot']
        line = line_action.create(line_data).resource()

        protocol = data_dict.get('protocol', 'sip')
        if protocol == 'sip':
            endpoint = endpoint_action.create_sip().resource()
            line_endpoint_action.associate_sip(line['id'], endpoint['id'])
        elif protocol == 'sccp':
            endpoint = endpoint_action.create_sccp().resource()
            line_endpoint_action.associate_sccp(line['id'], endpoint['id'])
        elif protocol == 'custom':
            endpoint = endpoint_action.create_custom().resource()
            line_endpoint_action.associate_custom(line['id'], endpoint['id'])

        line_extension_action.associate(line['id'], extension['id'])
        user_line_action.create_user_line(user_id, {'line_id': line['id']})

        mac = data_dict.get('device')
        if mac:
            device = world.confd_client.devices.list(mac=mac)['items'][0]
            line_device_action.associate_device(line['id'], device['id'])

    if {'voicemail_name', 'voicemail_number', 'voicemail_context'}.issubset(data_dict):
        voicemail = voicemail_action.create_voicemail({
            'name': data_dict['voicemail_name'],
            'number': data_dict['voicemail_number'],
            'context': data_dict['voicemail_context'],
        }).resource()
        world.confd_client.users.relations(user_id).add_voicemail(voicemail)

    if step is not None:
        _register_and_track_phone(step.scenario, data_dict)

    return int(user_id)
Esempio n. 5
0
def add_user(data_dict, step=None):
    user = User()

    if 'id' in data_dict:
        user.id = data_dict['id']

    user.firstname = data_dict['firstname']

    if 'lastname' in data_dict:
        user.lastname = data_dict['lastname']
    if 'agentid' in data_dict:
        user.agent_id = int(data_dict['agentid'])
    if 'language' in data_dict:
        user.language = data_dict['language']
    if 'enable_client' in data_dict:
        user.enable_client = bool(data_dict['enable_client'])
    if 'client_username' in data_dict:
        user.client_username = data_dict['client_username']
    if 'client_password' in data_dict:
        user.client_password = data_dict['client_password']
    if 'client_profile' in data_dict:
        user.client_profile = data_dict['client_profile']
    if 'bsfilter' in data_dict:
        user.bsfilter = data_dict['bsfilter']

    if 'entity_name' in data_dict:
        entity = entity_helper.get_entity_with_name(data_dict['entity_name'])
        if entity:
            user.entity_id = entity.id
    else:
        user.entity_id = entity_helper.oldest_entity_id()

    if 'line_number' in data_dict and 'line_context' in data_dict:
        user.line = UserLine()
        user.line.number = data_dict['line_number']
        user.line.context = data_dict['line_context']
        if 'protocol' in data_dict:
            user.line.protocol = data_dict['protocol']
        if 'device' in data_dict:
            device = provd_helper.find_by_mac(data_dict['device'])
            if device is not None:
                user.line.device_id = str(device['id'])

    if 'voicemail_name' in data_dict and 'voicemail_number' in data_dict:
        user.voicemail = UserVoicemail()
        user.voicemail.name = data_dict['voicemail_name']
        user.voicemail.number = data_dict['voicemail_number']

    if 'mobile_number' in data_dict:
        user.mobile_number = data_dict['mobile_number']

    try:
        ret = world.ws.users.add(user)
    except WebServiceRequestError as e:
        raise Exception('Could not add user %s %s: %s' %
                        (user.firstname, user.lastname, e))
    if not ret:
        return False

    if step is not None:
        _register_and_track_phone(step.scenario, data_dict)

    return int(ret)