Ejemplo n.º 1
0
    def validate(self, data: dict) -> Acknowledgment:
        """Validates the input data.

        :param dict data: Input data
        :returns: Acknowledgment with the status and possible error messages.
        :rtype: models.acknowledgment.Acknowledgment
        """
        ack = Acknowledgment()
        validate = Validate(ack)
        ssid = data.get('ssid')
        psk = data.get('psk')

        validate.string(ssid, label='SSID', min_value=1)

        if psk is not None:
            validate.string(psk, label='Password', min_value=8, max_value=63)

        return ack
Ejemplo n.º 2
0
    def validate(self, data: dict, create: bool) -> Acknowledgment:
        """Validates the input data.

        :param dict data: Input data
        :param bool create: If a new speaker will be created from this data or an existing updated.
        :returns: Acknowledgment with the status and possible error messages.
        :rtype: models.acknowledgment.Acknowledgment
        """
        ack = Acknowledgment()
        validate = Validate(ack)
        speaker_id = data.get('id')
        name = data.get('name')

        validate.string(name, label='Name', min_value=1, max_value=50)

        if self.config.balance:
            ack.add_error(
                'No configuration changes can be made when balancing is active'
            )

        if data.get('room') is None or isinstance(data.get('room'),
                                                  dict) is False:
            ack.add_error('Room id must not be empty')
        elif validate.integer(data.get('room').get('id'),
                              label='Room id',
                              min_value=1):
            if self.config.room_repository.get_room(
                    data.get('room').get('id')) is None:
                ack.add_error('A room with this id does not exist')

        if create:
            if self.config.speaker_repository.get_speaker(
                    speaker_id) is not None:
                ack.add_error('A speaker with this name already exists')
        elif validate.string(speaker_id, label='Speaker id'):
            existing = self.config.speaker_repository.get_speaker_by_name(name)

            if self.config.speaker_repository.get_speaker(speaker_id) is None:
                ack.add_error('A speaker with this id does not exist')
            elif existing and existing.speaker_id != speaker_id:
                ack.add_error('A speaker with this name already exists')

        return ack
Ejemplo n.º 3
0
    def validate(self, data: dict, create: bool) -> Acknowledgment:
        """Validates the input data.

        :param dict data: Input data
        :param bool create: If a new room will be created from this data or an existing updated.
        :returns: Acknowledgment with the status and possible error messages.
        :rtype: models.acknowledgment.Acknowledgment
        """
        ack = Acknowledgment()
        validate = Validate(ack)
        room_id = data.get('id')
        name = data.get('name')
        people_group = data.get('people_group')

        validate.string(name, label='Name', min_value=1, max_value=50)

        if self.config.balance:
            ack.add_error(
                'No configuration changes can be made when balancing is active'
            )

        if people_group is not None:
            validate.string(people_group,
                            label='Handle multiple people',
                            min_value=5,
                            max_value=10)

        if create:
            if self.config.room_repository.get_room_by_name(name) is not None:
                ack.add_error('A room with this name already exists')
        elif validate.integer(room_id, label='Room id', min_value=1):
            existing = self.config.room_repository.get_room_by_name(name)

            if self.config.room_repository.get_room(room_id) is None:
                ack.add_error('Room with this id does not exist')
            elif existing and existing.room_id != room_id:
                ack.add_error('A room with this name already exists')

        return ack