Esempio n. 1
0
    def validate_groups(self, attrs, source):
        try:
            value = attrs[source]
        except KeyError:
            pass
        else:
            groups = []

            for grp in value:
                try:
                    group = Role.objects.get(name=grp)
                except Role.DoesNotExist:
                    raise s.ObjectDoesNotExist(grp)
                else:
                    if self.request.user.is_staff:
                        groups.append(group)
                    else:
                        if group.dc_bound and self._dc_bound and group.dc_bound == self._dc_bound:
                            groups.append(group)
                        else:
                            raise s.ValidationError(
                                _('You don\'t have permission to use DC-unbound groups.'
                                  ))

            attrs[source] = groups

        return attrs
Esempio n. 2
0
    def validate_ptr_domain(self, attrs, source):
        try:
            value = attrs[source]
        except KeyError:
            pass
        else:
            if value:
                if not value.endswith('in-addr.arpa'):
                    raise s.ValidationError(_('Invalid PTR domain name.'))
                if settings.DNS_ENABLED:
                    if not Domain.objects.filter(name=value).exists():
                        raise s.ObjectDoesNotExist(value)

        return attrs
Esempio n. 3
0
    def validate_permissions(self, attrs, source):
        try:
            value = attrs[source]
        except KeyError:
            pass
        else:
            permissions = []

            for perm in value:
                try:
                    permission = Permission.objects.get(name=perm)
                except Permission.DoesNotExist:
                    raise s.ObjectDoesNotExist(perm)
                else:
                    permissions.append(permission)

            attrs[source] = permissions
        return attrs
Esempio n. 4
0
    def validate_users(self, attrs, source):
        try:
            value = attrs[source]
        except KeyError:
            pass
        else:
            users = []

            for user in value:
                try:
                    usr = User.objects.filter(
                        ExcludeInternalUsers).select_related('dc_bound').get(
                            username=user)
                except User.DoesNotExist:
                    raise s.ObjectDoesNotExist(user, field_name=_('username'))
                else:
                    users.append(usr)

            attrs[source] = users
        return attrs