mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-27 04:58:42 +02:00
cleaning up domainpermission
This commit is contained in:
parent
3f2ceb81e8
commit
bd071a0fb3
2 changed files with 4 additions and 24 deletions
|
@ -71,6 +71,10 @@ def _user_has_permission(user, request, rules, **kwargs):
|
||||||
if not user.is_authenticated:
|
if not user.is_authenticated:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# Ensure user is not restricted
|
||||||
|
if user.is_restricted():
|
||||||
|
return False
|
||||||
|
|
||||||
conditions_met = []
|
conditions_met = []
|
||||||
|
|
||||||
if IS_STAFF in rules:
|
if IS_STAFF in rules:
|
||||||
|
|
|
@ -205,39 +205,15 @@ class DomainPermission(PermissionsLoginMixin):
|
||||||
The user is in self.request.user and the domain needs to be looked
|
The user is in self.request.user and the domain needs to be looked
|
||||||
up from the domain's primary key in self.kwargs["domain_pk"]
|
up from the domain's primary key in self.kwargs["domain_pk"]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not self.request.user.is_authenticated:
|
|
||||||
return False
|
|
||||||
|
|
||||||
if self.request.user.is_restricted():
|
|
||||||
return False
|
|
||||||
|
|
||||||
pk = self.kwargs["domain_pk"]
|
pk = self.kwargs["domain_pk"]
|
||||||
# If pk is none then something went very wrong...
|
|
||||||
if pk is None:
|
|
||||||
raise ValueError("Primary key is None")
|
|
||||||
|
|
||||||
# test if domain in editable state
|
# test if domain in editable state
|
||||||
if not self.in_editable_state(pk):
|
if not self.in_editable_state(pk):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.can_access_other_user_domains(pk):
|
|
||||||
return True
|
|
||||||
|
|
||||||
# user needs to have a role on the domain
|
|
||||||
if not UserDomainRole.objects.filter(user=self.request.user, domain__id=pk).exists():
|
|
||||||
return self.can_access_domain_via_portfolio(pk)
|
|
||||||
|
|
||||||
# if we need to check more about the nature of role, do it here.
|
# if we need to check more about the nature of role, do it here.
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def can_access_domain_via_portfolio(self, pk):
|
|
||||||
"""Most views should not allow permission to portfolio users.
|
|
||||||
If particular views allow access to the domain pages, they will need to override
|
|
||||||
this function.
|
|
||||||
"""
|
|
||||||
return False
|
|
||||||
|
|
||||||
def in_editable_state(self, pk):
|
def in_editable_state(self, pk):
|
||||||
"""Is the domain in an editable state"""
|
"""Is the domain in an editable state"""
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue