core: add user.group_attributes
This commit is contained in:
parent
d696d854ff
commit
52c4fb431f
|
@ -1,6 +1,6 @@
|
||||||
"""passbook core models"""
|
"""passbook core models"""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import Any, Optional, Type
|
from typing import Any, Dict, Optional, Type
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from django.contrib.auth.models import AbstractUser
|
from django.contrib.auth.models import AbstractUser
|
||||||
|
@ -80,6 +80,13 @@ class User(GuardianUserMixin, AbstractUser):
|
||||||
|
|
||||||
objects = UserManager()
|
objects = UserManager()
|
||||||
|
|
||||||
|
def group_attributes(self) -> Dict[str, Any]:
|
||||||
|
"""Get a dictionary containing the attributes from all groups the user belongs to"""
|
||||||
|
final_attributes = {}
|
||||||
|
for group in self.pb_groups.all().order_by("name"):
|
||||||
|
final_attributes.update(group.attributes)
|
||||||
|
return final_attributes
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_superuser(self) -> bool:
|
def is_superuser(self) -> bool:
|
||||||
"""Get supseruser status based on membership in a group with superuser status"""
|
"""Get supseruser status based on membership in a group with superuser status"""
|
||||||
|
|
Reference in New Issue