Fix bug that superuser can't leave group

This commit is contained in:
cuom1999 2023-02-01 19:52:43 -06:00
parent a03624b73e
commit c269e34873
2 changed files with 9 additions and 1 deletions

View file

@ -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

View file

@ -56,7 +56,7 @@
</div>
</li>
{% endif %}
{% if is_member and not can_edit %}
{% if is_member and not is_admin %}
<li>
<form method="post" action="{{ url('leave_organization', organization.id, organization.slug) }}">
{% csrf_token %}