Exemplo n.º 1
0
 def validate_associate_to_register(self, trunk, endpoint):
     if self.endpoint == 'iax' and trunk.register_sip:
         raise errors.resource_associated(
             'Trunk',
             'SIPRegister',
             trunk_id=trunk.id,
             register_iax_id=trunk.register_sip.id,
         )
     if self.endpoint == 'sip' and trunk.register_iax:
         raise errors.resource_associated(
             'Trunk',
             'IAXRegister',
             trunk_id=trunk.id,
             register_sip_id=trunk.register_iax.id,
         )
     if self.endpoint == 'custom':
         if trunk.register_iax:
             raise errors.resource_associated(
                 'Trunk',
                 'IAXRegister',
                 trunk_id=trunk.id,
                 register_iax_id=trunk.register_iax.id,
             )
         if trunk.register_sip:
             raise errors.resource_associated(
                 'Trunk',
                 'SIPRegister',
                 trunk_id=trunk.id,
                 register_sip_id=trunk.register_sip.id,
             )
Exemplo n.º 2
0
def validate_extension_not_associated(extension_id):
    extension_type, typeval = extension_dao.get_type_typeval(extension_id)

    # extensions that are created or dissociated are set to these values by default
    if extension_type != 'user' and typeval != '0':
        raise errors.resource_associated('Extension', extension_type,
                                         extension_id=extension_id, associated_id=typeval)

    line_extension = line_extension_dao.find_by_extension_id(extension_id)
    if line_extension:
        raise errors.resource_associated('Extension', 'Line',
                                         extension_id=extension_id, line_id=line_extension.line_id)
Exemplo n.º 3
0
def _validate_user_not_associated_with_line(user_line):
    existing = user_line_dao.find_all_by_user_id(user_line.user_id)
    if len(existing) > 0:
        raise errors.resource_associated('User',
                                         'Line',
                                         user_id=user_line.user_id,
                                         line_id=user_line.line_id)
Exemplo n.º 4
0
 def validate_line_has_no_extension(self, line):
     extension_id = user_line_db.find_extension_id_for_line(line.id)
     if extension_id:
         raise errors.resource_associated('Line',
                                          'Extension',
                                          line_id=line.id,
                                          extension_id=extension_id)
Exemplo n.º 5
0
 def validate(self, device):
     lines = self.line_dao.find_all_by(device=device.id)
     if lines:
         ids = tuple(line.id for line in lines)
         raise errors.resource_associated(
             'Device', 'Line', device_id=device.id, line_ids=ids
         )
Exemplo n.º 6
0
def validate_line_not_associated_to_extension(line_extension):
    line_extension = line_extension_dao.find_by_line_id(line_extension.line_id)
    if line_extension:
        raise errors.resource_associated('Line',
                                         'Extension',
                                         line_id=line_extension.line_id,
                                         extension_id=line_extension.extension_id)
Exemplo n.º 7
0
 def validate_has_no_trunks(self, context):
     trunk = self.trunk_dao.find_by(context=context.name)
     if trunk:
         raise errors.resource_associated('Context',
                                          'Trunk',
                                          context_id=context.id,
                                          trunk_id=trunk.id)
Exemplo n.º 8
0
 def validate(self, line, endpoint):
     if line.is_associated():
         raise errors.resource_associated('Line',
                                          'Endpoint',
                                          line_id=line.id,
                                          endpoint=line.endpoint,
                                          endpoint_id=line.endpoint_id)
Exemplo n.º 9
0
 def validate_has_no_extensions(self, context):
     extension = self.extension_dao.find_by(context=context.name)
     if extension:
         raise errors.resource_associated('Context',
                                          'Extension',
                                          context_id=context.id,
                                          extension_id=extension.id)
Exemplo n.º 10
0
 def validate_has_no_voicemails(self, context):
     voicemail = self.voicemail_dao.find_by(context=context.name)
     if voicemail:
         raise errors.resource_associated('Context',
                                          'Voicemail',
                                          context_id=context.id,
                                          voicemail_id=voicemail.id)
Exemplo n.º 11
0
    def validate_we_are_not_creating_a_group_under_the_same_extension(
            self, user, line):
        main_line_extension = line_extension_dao.find_by_line_id(line.id)
        if not main_line_extension:
            return

        lines_reachable_from_extension = set(
            line_extension.line_id
            for line_extension in line_extension_dao.find_all_by(
                extension_id=main_line_extension.extension_id))

        users_reachable_from_extension = set(
            user_line.user_id for line_id in lines_reachable_from_extension
            for user_line in user_line_dao.find_all_by(line_id=line_id,
                                                       main_user=True))
        users_reachable_from_extension.add(user.id)

        if len(users_reachable_from_extension) == 1:
            return
        elif len(lines_reachable_from_extension) == 1:
            return
        else:
            lines_reachable_from_extension.remove(line.id)
            faulty_line_id = lines_reachable_from_extension.pop()
            raise errors.resource_associated(
                'Line',
                'Extension',
                line_id=faulty_line_id,
                extension_id=main_line_extension.extension_id,
            )
Exemplo n.º 12
0
def validate_not_associated_to_voicemail(user):
    user_voicemail = user_voicemail_dao.find_by_user_id(user.id)
    if user_voicemail:
        raise errors.resource_associated('User',
                                         'Voicemail',
                                         user_id=user_voicemail.user_id,
                                         voicemail_id=user_voicemail.voicemail_id)
Exemplo n.º 13
0
 def validate(self, model):
     associations = self.dao.find_all_by_voicemail_id(model.id)
     if len(associations) > 0:
         user_ids = ", ".join(str(uv.user_id) for uv in associations)
         raise errors.resource_associated('Voicemail', 'User',
                                          voicemail_id=model.id,
                                          user_ids=user_ids)
Exemplo n.º 14
0
 def validate(self, voicemail):
     if voicemail.users:
         user_ids = ", ".join(str(user.id) for user in voicemail.users)
         raise errors.resource_associated('Voicemail',
                                          'User',
                                          voicemail_id=voicemail.id,
                                          user_ids=user_ids)
Exemplo n.º 15
0
 def validate_trunk_not_already_associated(self, trunk, register):
     if trunk.register_sip:
         raise errors.resource_associated(
             'Trunk',
             'SIPRegister',
             trunk_id=trunk.id,
             register_sip_id=trunk.register_sip.id,
         )
Exemplo n.º 16
0
 def validate_incall_not_already_associated(self, incall):
     if incall.schedules:
         raise errors.resource_associated(
             'Incall',
             'Schedule',
             incall_id=incall.id,
             schedule_id=incall.schedules[0].id,
         )
Exemplo n.º 17
0
 def validate(self, user):
     user_voicemail = self.dao.find_by_user_id(user.id)
     if user_voicemail:
         raise errors.resource_associated(
             'User',
             'Voicemail',
             user_id=user_voicemail.user_id,
             voicemail_id=user_voicemail.voicemail_id)
Exemplo n.º 18
0
 def validate_associate_to_register(self, trunk, endpoint):
     if trunk.register_iax:
         raise errors.resource_associated(
             'Trunk',
             'IAXRegister',
             trunk_id=trunk.id,
             register_sip_id=trunk.register_iax.id,
         )
Exemplo n.º 19
0
 def validate_not_already_associated(self, line, application):
     if line.application_uuid is not None:
         raise errors.resource_associated(
             'Line',
             'Application',
             line_id=line.id,
             application_uuid=line.application_uuid,
         )
Exemplo n.º 20
0
 def validate_extension_not_already_associated(self, extension):
     if extension.parking_lot:
         raise errors.resource_associated(
             'ParkingLot',
             'Extension',
             parking_lot_id=extension.parking_lot.id,
             extension_id=extension.id,
         )
Exemplo n.º 21
0
 def validate_parking_lot_not_already_associated(self, parking_lot):
     if parking_lot.extensions:
         raise errors.resource_associated(
             'ParkingLot',
             'Extension',
             parking_lot_id=parking_lot.id,
             extension_id=parking_lot.extensions[0].id,
         )
Exemplo n.º 22
0
 def validate_no_surrogate_user(self, call_filter, users):
     for surrogate in call_filter.surrogates:
         if surrogate.user in users:
             raise errors.resource_associated(
                 'CallFilter',
                 call_filter.id,
                 surrogate_user_uuid=surrogate.user.uuid,
             )
Exemplo n.º 23
0
 def validate_no_recipient_user(self, call_filter, users):
     for recipient in call_filter.recipients:
         if recipient.user in users:
             raise errors.resource_associated(
                 'CallFilter',
                 call_filter.id,
                 recipient_user_uuid=recipient.user.uuid,
             )
Exemplo n.º 24
0
 def validate_outcall_not_already_associated(self, outcall):
     if outcall.schedules:
         raise errors.resource_associated(
             'Outcall',
             'Schedule',
             outcall_id=outcall.id,
             schedule_id=outcall.schedules[0].id,
         )
Exemplo n.º 25
0
 def validate_user_no_line_associated(self, user):
     user_lines = self.user_line_dao.find_all_by(user_id=user.id)
     if user_lines:
         line_ids = ','.join(str(ul.line_id) for ul in user_lines)
         raise errors.resource_associated('User',
                                          'Line',
                                          user_id=user.id,
                                          line_ids=line_ids)
Exemplo n.º 26
0
 def validate_extension_not_associated_to_other_resource(self, extension):
     if not (extension.type == 'user' and extension.typeval == '0'):
         raise errors.resource_associated(
             'Extension',
             extension.type,
             extension_id=extension.id,
             associated_id=extension.typeval,
         )
Exemplo n.º 27
0
 def validate_register_not_already_associated(self, trunk, register):
     if register.trunk:
         raise errors.resource_associated(
             'Trunk',
             'IAXRegister',
             trunk_id=register.trunk.id,
             register_iax_id=register.id,
         )
Exemplo n.º 28
0
 def validate_queue_not_already_associated(self, queue):
     if queue.extensions:
         raise errors.resource_associated(
             'Queue',
             'Extension',
             queue_id=queue.id,
             extension_id=queue.extensions[0].id,
         )
Exemplo n.º 29
0
 def validate_extension_not_already_associated(self, extension):
     if extension.queue:
         raise errors.resource_associated(
             'Queue',
             'Extension',
             queue_id=extension.queue.id,
             extension_id=extension.id,
         )
Exemplo n.º 30
0
 def validate(self, model):
     associations = self.dao.find_all_by_voicemail_id(model.id)
     if len(associations) > 0:
         user_ids = ", ".join(str(uv.user_id) for uv in associations)
         raise errors.resource_associated('Voicemail',
                                          'User',
                                          voicemail_id=model.id,
                                          user_ids=user_ids)
Exemplo n.º 31
0
 def validate_extension_not_already_associated(self, extension):
     if extension.type == 'incall':
         raise errors.resource_associated(
             'Incall',
             'Extension',
             incall_id=extension.typeval,
             extension_id=extension.id,
         )
Exemplo n.º 32
0
 def validate_users(self, line):
     user_lines = self.user_line_dao.find_all_by_line_id(line.id)
     if user_lines:
         user_ids = ','.join(str(ul.user_id) for ul in user_lines)
         raise errors.resource_associated('Line',
                                          'User',
                                          line_id=line.id,
                                          user_ids=user_ids)
Exemplo n.º 33
0
 def validate_extension_not_already_associated(self, extension):
     if extension.group:
         raise errors.resource_associated(
             'Group',
             'Extension',
             group_id=extension.group.id,
             extension_id=extension.id,
         )
Exemplo n.º 34
0
 def validate_group_not_already_associated(self, group):
     if group.extensions:
         raise errors.resource_associated(
             'Group',
             'Extension',
             group_id=group.id,
             extension_id=group.extensions[0].id,
         )
Exemplo n.º 35
0
    def validate(self, extension):
        extension_type, typeval = extension.type, extension.typeval

        # extensions that are created or dissociated are set to these values by default
        if extension_type != 'user' and typeval != '0':
            raise errors.resource_associated('Extension',
                                             extension_type,
                                             extension_id=extension.id,
                                             associated_id=typeval)

        line_extension = self.line_extension_dao.find_by_extension_id(
            extension.id)
        if line_extension:
            raise errors.resource_associated('Extension',
                                             'Line',
                                             extension_id=extension.id,
                                             line_id=line_extension.line_id)
Exemplo n.º 36
0
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
Exemplo n.º 37
0
def validate_no_device(line_id):
    line = line_dao.get(line_id)
    if line.device_id:
        raise errors.resource_associated('Line', 'Device',
                                         line_id=line_id, device_id=line.device_id)
Exemplo n.º 38
0
 def validate(self, association):
     existing = self.dao.find_by_user_id(association.user_id)
     if existing:
         raise errors.resource_associated('User', 'Voicemail',
                                          user_id=association.user_id,
                                          voicemail_id=association.voicemail_id)
Exemplo n.º 39
0
def validate_not_associated_to_line(user):
    user_lines = user_line_dao.find_all_by_user_id(user.id)
    if user_lines:
        ids = tuple(ul.line_id for ul in user_lines)
        raise errors.resource_associated('User', 'Line', line_ids=ids)
Exemplo n.º 40
0
 def _check_device_is_not_linked_to_line(self, device):
     linked_lines = self.line_dao.find_all_by_device_id(device.id)
     if linked_lines:
         ids = tuple(l.id for l in linked_lines)
         raise errors.resource_associated('Device', 'Line',
                                          device_id=device.id, line_ids=ids)