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:
parent
9ad4c736f1
commit
0c2b32da31
|
@ -4,7 +4,7 @@ from json import loads
|
|||
from django.db.models.query import QuerySet
|
||||
from django_filters.filters import CharFilter, ModelMultipleChoiceFilter
|
||||
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.viewsets import ModelViewSet
|
||||
from rest_framework_guardian.filters import ObjectPermissionsFilter
|
||||
|
@ -46,11 +46,14 @@ class GroupSerializer(ModelSerializer):
|
|||
)
|
||||
parent_name = CharField(source="parent.name", read_only=True)
|
||||
|
||||
num_pk = IntegerField(read_only=True)
|
||||
|
||||
class Meta:
|
||||
|
||||
model = Group
|
||||
fields = [
|
||||
"pk",
|
||||
"num_pk",
|
||||
"name",
|
||||
"is_superuser",
|
||||
"parent",
|
||||
|
|
|
@ -81,6 +81,13 @@ class Group(models.Model):
|
|||
)
|
||||
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:
|
||||
"""Recursively check if `user` is member of us, or any parent."""
|
||||
query = """
|
||||
|
|
|
@ -21673,6 +21673,9 @@ components:
|
|||
format: uuid
|
||||
readOnly: true
|
||||
title: Group uuid
|
||||
num_pk:
|
||||
type: integer
|
||||
readOnly: true
|
||||
name:
|
||||
type: string
|
||||
maxLength: 80
|
||||
|
@ -21700,6 +21703,7 @@ components:
|
|||
readOnly: true
|
||||
required:
|
||||
- name
|
||||
- num_pk
|
||||
- parent
|
||||
- parent_name
|
||||
- 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
Reference in a new issue