From 52c4fb431f755f0c07509b0e25638dc4a4153f66 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 24 Sep 2020 15:45:58 +0200 Subject: [PATCH] core: add user.group_attributes --- passbook/core/models.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/passbook/core/models.py b/passbook/core/models.py index 545d05825..19d31b026 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -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"""