From 4849a8912506377b2c36125ba3d43abeb865d17b Mon Sep 17 00:00:00 2001 From: dandds Date: Wed, 7 Nov 2018 08:59:04 -0500 Subject: [PATCH] working implementation of revoke invitation --- atst/models/workspace_role.py | 4 +++- atst/routes/workspaces.py | 6 ++---- templates/components/confirmation_button.html | 5 +++-- templates/workspaces/members/edit.html | 8 ++++++++ tests/routes/test_workspaces.py | 8 +++++++- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/atst/models/workspace_role.py b/atst/models/workspace_role.py index bdb8dc18..93a4a85b 100644 --- a/atst/models/workspace_role.py +++ b/atst/models/workspace_role.py @@ -51,7 +51,9 @@ class WorkspaceRole(Base, mixins.TimestampsMixin, mixins.AuditableMixin): if self.status == Status.ACTIVE: return "Active" elif self.latest_invitation: - if self.latest_invitation.is_rejected_expired: + if self.latest_invitation.is_revoked: + return "Revoked" + elif self.latest_invitation.is_rejected_expired: return "Invite expired" elif self.latest_invitation.is_rejected_wrong_user: return "Error on invite" diff --git a/atst/routes/workspaces.py b/atst/routes/workspaces.py index 0a6c0beb..c259410f 100644 --- a/atst/routes/workspaces.py +++ b/atst/routes/workspaces.py @@ -375,8 +375,6 @@ def revoke_invitation(workspace_id, token): Permissions.ASSIGN_AND_UNASSIGN_ATAT_ROLE, "revoke member invitation", ) - invite = Invitations.revoke(token) + Invitations.revoke(token) - return redirect( - url_for("workspaces.show_workspace", workspace_id=workspace.id) - ) + return redirect(url_for("workspaces.workspace_members", workspace_id=workspace.id)) diff --git a/templates/components/confirmation_button.html b/templates/components/confirmation_button.html index 5802052a..71b15a3b 100644 --- a/templates/components/confirmation_button.html +++ b/templates/components/confirmation_button.html @@ -1,9 +1,10 @@ -{% macro ConfirmationButton(btn_text, action, confirm_msg="Are you sure?", confirm_btn="Confirm", cancel_btn="Cancel") -%} +{% macro ConfirmationButton(btn_text, action, csrf_token, confirm_msg="Are you sure?", confirm_btn="Confirm", cancel_btn="Cancel") -%} - + {%- endmacro %} diff --git a/templates/workspaces/members/edit.html b/templates/workspaces/members/edit.html index 2dc8dcf2..e840ffef 100644 --- a/templates/workspaces/members/edit.html +++ b/templates/workspaces/members/edit.html @@ -5,6 +5,7 @@ {% from "components/selector.html" import Selector %} {% from "components/options_input.html" import OptionsInput %} {% from "components/alert.html" import Alert %} +{% from "components/confirmation_button.html" import ConfirmationButton %} {% block content %} @@ -38,6 +39,13 @@ {% if editable %} edit account details {% endif %} + {% if member.latest_invitation.is_pending %} + {{ ConfirmationButton( + "Revoke Invitation", + url_for("workspaces.revoke_invitation", workspace_id=workspace.id, token=member.latest_invitation.token), + form.csrf_token + ) }} + {% endif %} diff --git a/tests/routes/test_workspaces.py b/tests/routes/test_workspaces.py index b3b3dd22..7f3e0ad3 100644 --- a/tests/routes/test_workspaces.py +++ b/tests/routes/test_workspaces.py @@ -435,7 +435,13 @@ def test_revoke_invitation(client, user_session): expiration_time=datetime.datetime.now() - datetime.timedelta(seconds=1), ) user_session(workspace.owner) - response = client.post(url_for("workspaces.revoke_invitation", workspace_id=workspace.id, token=invite.token)) + response = client.post( + url_for( + "workspaces.revoke_invitation", + workspace_id=workspace.id, + token=invite.token, + ) + ) assert response.status_code == 302 assert invite.is_revoked