core: add user.group_attributes

This commit is contained in:
Jens Langhammer 2020-09-24 15:45:58 +02:00
parent d696d854ff
commit 52c4fb431f
1 changed files with 8 additions and 1 deletions

View File

@ -1,6 +1,6 @@
"""passbook core models"""
from datetime import timedelta
from typing import Any, Optional, Type
from typing import Any, Dict, Optional, Type
from uuid import uuid4
from django.contrib.auth.models import AbstractUser
@ -80,6 +80,13 @@ class User(GuardianUserMixin, AbstractUser):
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
def is_superuser(self) -> bool:
"""Get supseruser status based on membership in a group with superuser status"""