aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api/models/bot
diff options
context:
space:
mode:
authorGravatar Sebastiaan Zeeff <[email protected]>2019-08-22 20:54:26 +0200
committerGravatar Sebastiaan Zeeff <[email protected]>2019-08-22 20:54:26 +0200
commit24bc7ced26a3d6aa8bd039f0b2cd95a6b5c85d5c (patch)
treeef117853f53cd376f37ca409732fa2b6793e7af7 /pydis_site/apps/api/models/bot
parentMaking User.top_role test only query once (diff)
Fixing top_role bug for users without roles & adding appropriate test
Diffstat (limited to 'pydis_site/apps/api/models/bot')
-rw-r--r--pydis_site/apps/api/models/bot/user.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/pydis_site/apps/api/models/bot/user.py b/pydis_site/apps/api/models/bot/user.py
index 8049d319..00c24d3d 100644
--- a/pydis_site/apps/api/models/bot/user.py
+++ b/pydis_site/apps/api/models/bot/user.py
@@ -54,5 +54,12 @@ class User(ModelReprMixin, models.Model):
@property
def top_role(self) -> Role:
- """Attribute that returns the user's top role."""
+ """
+ Attribute that returns the user's top role.
+
+ This will fall back to the Developers role if the user does not have any roles.
+ """
+ roles = self.roles.all()
+ if not roles:
+ return Role.objects.get(name="Developers")
return max(self.roles.all())