core: add num_pk to group for applications that need a numerical group id

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>

#2497
This commit is contained in:
Jens Langhammer 2022-03-22 21:37:11 +01:00
parent 9ad4c736f1
commit 0c2b32da31
6 changed files with 1866 additions and 2287 deletions

View file

@ -4,7 +4,7 @@ from json import loads
from django.db.models.query import QuerySet from django.db.models.query import QuerySet
from django_filters.filters import CharFilter, ModelMultipleChoiceFilter from django_filters.filters import CharFilter, ModelMultipleChoiceFilter
from django_filters.filterset import FilterSet from django_filters.filterset import FilterSet
from rest_framework.fields import CharField, JSONField from rest_framework.fields import CharField, IntegerField, JSONField
from rest_framework.serializers import ListSerializer, ModelSerializer, ValidationError from rest_framework.serializers import ListSerializer, ModelSerializer, ValidationError
from rest_framework.viewsets import ModelViewSet from rest_framework.viewsets import ModelViewSet
from rest_framework_guardian.filters import ObjectPermissionsFilter from rest_framework_guardian.filters import ObjectPermissionsFilter
@ -46,11 +46,14 @@ class GroupSerializer(ModelSerializer):
) )
parent_name = CharField(source="parent.name", read_only=True) parent_name = CharField(source="parent.name", read_only=True)
num_pk = IntegerField(read_only=True)
class Meta: class Meta:
model = Group model = Group
fields = [ fields = [
"pk", "pk",
"num_pk",
"name", "name",
"is_superuser", "is_superuser",
"parent", "parent",

View file

@ -81,6 +81,13 @@ class Group(models.Model):
) )
attributes = models.JSONField(default=dict, blank=True) attributes = models.JSONField(default=dict, blank=True)
@property
def num_pk(self) -> int:
"""Get a numerical, int32 ID for the group"""
# int max is 2147483647 (10 digits) so 9 is the max usable
# in the LDAP Outpost we use the last 5 chars so match here
return int(str(self.pk.int)[:5])
def is_member(self, user: "User") -> bool: def is_member(self, user: "User") -> bool:
"""Recursively check if `user` is member of us, or any parent.""" """Recursively check if `user` is member of us, or any parent."""
query = """ query = """

View file

@ -21673,6 +21673,9 @@ components:
format: uuid format: uuid
readOnly: true readOnly: true
title: Group uuid title: Group uuid
num_pk:
type: integer
readOnly: true
name: name:
type: string type: string
maxLength: 80 maxLength: 80
@ -21700,6 +21703,7 @@ components:
readOnly: true readOnly: true
required: required:
- name - name
- num_pk
- parent - parent
- parent_name - parent_name
- pk - pk

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff