From 5ac6efc5809bc7517d8d7b0e609e81b9ca4ce718 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 4 May 2022 16:40:29 +0100 Subject: [PATCH] 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. --- app/models/user.py | 10 ++++++++++ app/templates/views/manage-users.html | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/user.py b/app/models/user.py index ce7e41842..74745f3c8 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -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): diff --git a/app/templates/views/manage-users.html b/app/templates/views/manage-users.html index b17469d1c..a8d3daac7 100644 --- a/app/templates/views/manage-users.html +++ b/app/templates/views/manage-users.html @@ -73,7 +73,7 @@ {% if current_user.has_permissions('manage_service') %} {% if user.status == 'pending' %} Cancel invitation for {{ user.email_address }} - {% elif user.state == 'active' and current_user.id != user.id %} + {% elif user.is_editable_by(current_user) %} Change details for {{ user.name }} {{ user.email_address }} {% endif %} {% endif %}