Esempio n. 1
0
 def validate_source(self, attrs, source):
     user = self.context.get('request').user
     source_ip = attrs.get('source')
     res = clean_source(user, source_ip)
     if res != source_ip:
         raise serializers.ValidationError(res)
     return attrs
Esempio n. 2
0
 def validate_source(self, attrs, source):
     user = self.context.get('request').user
     source_ip = attrs.get('source')
     res = clean_source(user, source_ip)
     if res != source_ip:
         raise serializers.ValidationError(res)
     return attrs
Esempio n. 3
0
    def validate(self, data):
        user = self.context.get('request').user
        # validate source
        source = data.get('source')
        res = clean_source(user, source)
        if res != source:
            raise serializers.ValidationError(res)

        # validate destination
        destination = data.get('destination')
        res = clean_destination(user, destination)
        if res != destination:
            raise serializers.ValidationError(res)

        # validate expires
        expires = data.get('expires')
        res = clean_expires(expires)
        if res != expires:
            raise serializers.ValidationError(res)

        # check if rule already exists with different name
        fields = {
            'source': data.get('source'),
            'destination': data.get('destination'),
        }
        exists = check_if_rule_exists(fields)
        if exists:
            raise serializers.ValidationError(exists)
        return data
Esempio n. 4
0
 def clean_source(self):
     # run validator which is used by rest framework too
     source = self.cleaned_data["source"]
     res = clean_source(User.objects.get(pk=self.data["applier"]), source)
     if res != source:
         raise forms.ValidationError(res)
     else:
         return res
Esempio n. 5
0
 def clean_source(self):
     # run validator which is used by rest framework too
     source = self.cleaned_data['source']
     res = clean_source(User.objects.get(pk=self.data['applier']), source)
     if res != source:
         raise forms.ValidationError(res)
     else:
         return res
Esempio n. 6
0
    def validate(self, data):
        user = self.context.get('request').user
        # validate source
        source = data.get('source')
        res = clean_source(
            user,
            source
        )
        if res != source:
            raise serializers.ValidationError(res)

        # validate destination
        destination = data.get('destination')
        res = clean_destination(
            user,
            destination
        )
        if res != destination:
            raise serializers.ValidationError(res)

        # validate expires
        expires = data.get('expires')
        res = clean_expires(
            expires
        )
        if res != expires:
            raise serializers.ValidationError(res)

        # check if rule already exists with different name
        fields = {
            'source': data.get('source'),
            'destination': data.get('destination'),
        }
        exists = check_if_rule_exists(fields)
        if exists:
            raise serializers.ValidationError(exists)
        return data