From c269e348731c8023a82b89cf336c5d66aadc645c Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Wed, 1 Feb 2023 19:52:43 -0600 Subject: [PATCH] Fix bug that superuser can't leave group --- judge/views/organization.py | 8 ++++++++ templates/organization/org-right-sidebar.html | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/judge/views/organization.py b/judge/views/organization.py index d36e7ab..411074d 100644 --- a/judge/views/organization.py +++ b/judge/views/organization.py @@ -109,6 +109,13 @@ class OrganizationBase(object): self.request.profile in org if self.request.user.is_authenticated else False ) + def is_admin(self, org=None): + if org is None: + org = self.object + if self.request.profile: + return org.admins.filter(id=self.request.profile.id).exists() + return False + def can_access(self, org): if self.request.user.is_superuser: return True @@ -121,6 +128,7 @@ class OrganizationMixin(OrganizationBase): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["is_member"] = self.is_member(self.organization) + context["is_admin"] = self.is_admin(self.organization) context["can_edit"] = self.can_edit_organization(self.organization) context["organization"] = self.organization context["logo_override_image"] = self.organization.logo_override_image diff --git a/templates/organization/org-right-sidebar.html b/templates/organization/org-right-sidebar.html index 0a60aca..b1f5920 100644 --- a/templates/organization/org-right-sidebar.html +++ b/templates/organization/org-right-sidebar.html @@ -56,7 +56,7 @@ {% endif %} - {% if is_member and not can_edit %} + {% if is_member and not is_admin %}
  • {% csrf_token %}