Пример #1
0
    def validate_raw(self, attrs, source):
        if not attrs[source].strip():
            return attrs
        try:
            rules = parse_rules(attrs[source])
        except ParseError as e:
            raise serializers.ValidationError(
                u'Parse error: %r (line %d, column %d)' % (
                    e.expr.name, e.line(), e.column()
                ))

        schema = dump_schema(rules)

        owners = {o for rule in rules for o in rule.owners}
        actors = resolve_actors(owners, self.context['ownership'].project_id)

        bad_actors = []
        for owner, actor in six.iteritems(actors):
            if actor is None:
                if owner.type == 'user':
                    bad_actors.append(owner.identifier)
                elif owner.type == 'team':
                    bad_actors.append(u'#{}'.format(owner.identifier))

        if bad_actors:
            raise serializers.ValidationError(
                u'Invalid rule owners: {}'.format(", ".join(bad_actors))
            )

        attrs['schema'] = schema
        return attrs
Пример #2
0
    def validate(self, attrs):
        if not attrs.get("raw", "").strip():
            return attrs
        try:
            rules = parse_rules(attrs["raw"])
        except ParseError as e:
            raise serializers.ValidationError({
                "raw":
                "Parse error: %r (line %d, column %d)" %
                (e.expr.name, e.line(), e.column())
            })

        schema = dump_schema(rules)

        owners = {o for rule in rules for o in rule.owners}
        actors = resolve_actors(owners, self.context["ownership"].project_id)

        bad_actors = []
        for owner, actor in actors.items():
            if actor is None:
                if owner.type == "user":
                    bad_actors.append(owner.identifier)
                elif owner.type == "team":
                    bad_actors.append(f"#{owner.identifier}")

        if bad_actors:
            bad_actors.sort()
            raise serializers.ValidationError({
                "raw":
                "Invalid rule owners: {}".format(", ".join(bad_actors))
            })

        attrs["schema"] = schema
        return attrs
Пример #3
0
    def validate(self, attrs):
        if not attrs.get('raw', '').strip():
            return attrs
        try:
            rules = parse_rules(attrs['raw'])
        except ParseError as e:
            raise serializers.ValidationError({
                'raw':
                u'Parse error: %r (line %d, column %d)' %
                (e.expr.name, e.line(), e.column())
            })

        schema = dump_schema(rules)

        owners = {o for rule in rules for o in rule.owners}
        actors = resolve_actors(owners, self.context['ownership'].project_id)

        bad_actors = []
        for owner, actor in six.iteritems(actors):
            if actor is None:
                if owner.type == 'user':
                    bad_actors.append(owner.identifier)
                elif owner.type == 'team':
                    bad_actors.append(u'#{}'.format(owner.identifier))

        if bad_actors:
            raise serializers.ValidationError({
                'raw':
                u'Invalid rule owners: {}'.format(", ".join(bad_actors))
            })

        attrs['schema'] = schema
        return attrs