Skip to content

Commit

Permalink
handle admin restriction in the parent method itself
Browse files Browse the repository at this point in the history
  • Loading branch information
mkangia committed Dec 17, 2018
1 parent 7f356ff commit 0fb9573
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions corehq/apps/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,16 +618,15 @@ def transfer_domain_membership(self, domain, to_user, create_record=False, is_ad
self.delete_domain_membership(domain, create_record=create_record)

@memoized
def is_domain_admin(self, domain=None, restrict_global_admin=False):
def is_domain_admin(self, domain=None):
if not domain:
# hack for template
if hasattr(self, 'current_domain'):
# this is a hack needed because we can't pass parameters from views
domain = self.current_domain
else:
return False # no domain, no admin
if (not restrict_global_admin and self.is_global_admin() and
(domain is None or not domain_restricts_superusers(domain))):
if self.is_global_admin() and (domain is None or not domain_restricts_superusers(domain)):
return True
dm = self.get_domain_membership(domain)
if dm:
Expand All @@ -644,12 +643,12 @@ def get_domains(self):

@memoized
def has_permission(self, domain, permission, data=None, restrict_global_admin=False):
# is_admin is the same as having all the permissions set
if (not restrict_global_admin and self.is_global_admin() and
(domain is None or not domain_restricts_superusers(domain))):
return True
elif self.is_domain_admin(domain, restrict_global_admin):
return True
if not restrict_global_admin:
# is_admin is the same as having all the permissions set
if self.is_global_admin() and (domain is None or not domain_restricts_superusers(domain)):
return True
elif self.is_domain_admin(domain):
return True

dm = self.get_domain_membership(domain)
if dm:
Expand Down Expand Up @@ -1668,7 +1667,7 @@ def delete(self):
def project(self):
return Domain.get_by_name(self.domain)

def is_domain_admin(self, domain=None, restrict_global_admin=False):
def is_domain_admin(self, domain=None):
# cloudcare workaround
return False

Expand Down

0 comments on commit 0fb9573

Please sign in to comment.