From 24bc7ced26a3d6aa8bd039f0b2cd95a6b5c85d5c Mon Sep 17 00:00:00 2001 From: Sebastiaan Zeeff <33516116+SebastiaanZ@users.noreply.github.com> Date: Thu, 22 Aug 2019 20:54:26 +0200 Subject: Fixing top_role bug for users without roles & adding appropriate test --- pydis_site/apps/api/models/bot/user.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'pydis_site/apps/api/models/bot') 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()) -- cgit v1.2.3