Refactor logic out of Jinja before making more complicated

To keep the conditionals in the Jinja template more readable, this
commit moves the logic into a method on the model, where it can
be split over multiple statements and lines.
This commit is contained in:
Chris Hill-Scott
2022-05-04 16:40:29 +01:00
parent b4b7ecb2aa
commit 5ac6efc580
2 changed files with 11 additions and 1 deletions

View File

@@ -440,6 +440,13 @@ class User(JSONModel, UserMixin):
def complete_webauthn_login_attempt(self, is_successful=True):
return user_api_client.complete_webauthn_login_attempt(self.id, is_successful)
def is_editable_by(self, other_user):
if other_user == self:
return False
if self.state == 'active':
return True
return False
class InvitedUser(JSONModel):
@@ -575,6 +582,9 @@ class InvitedUser(JSONModel):
# only used on the manage users page to display the count, so okay to not be fully fledged for now
return [{'id': x} for x in self.folder_permissions]
def is_editable_by(self, other):
return False
class InvitedOrgUser(JSONModel):

View File

@@ -73,7 +73,7 @@
{% if current_user.has_permissions('manage_service') %}
{% if user.status == 'pending' %}
<a class="user-list-edit-link govuk-link govuk-link--no-visited-state" href="{{ url_for('.cancel_invited_user', service_id=current_service.id, invited_user_id=user.id)}}">Cancel invitation<span class="govuk-visually-hidden"> for {{ user.email_address }}</span></a>
{% elif user.state == 'active' and current_user.id != user.id %}
{% elif user.is_editable_by(current_user) %}
<a class="user-list-edit-link govuk-link govuk-link--no-visited-state" href="{{ url_for('.edit_user_permissions', service_id=current_service.id, user_id=user.id)}}">Change details<span class="govuk-visually-hidden"> for {{ user.name }} {{ user.email_address }}</span></a>
{% endif %}
{% endif %}