In this episode, we walk through how to implement the ability to revoke (cancel) team invitations in our application.
We start by adjusting permissions, making sure only users with the right authorization can revoke invites. We show how you can add a more granular permission specifically for revoking invites, separate from the broader "invite to team" permission, if you want more fine-grained control.
Then, we set up the policy logic so that the UI only displays the revoke option if you actually have permission. We use a canAny
helper to hide the entire actions dropdown if there are no actions you can take—cleaning up the UI.
Next, we build the actual backend route and controller logic: when a user clicks to revoke an invite, it sends a delete request to the server, which simply deletes the invite record from the database and returns you to the team edit page.
After that, we add tests to check both that authorized users can successfully revoke invites, and that users without permission can't. We handle some edge cases, like trying to revoke invites from other teams.
Finally, we do a little bit of manual UI testing just to double-check the logic is sound. By the end of the episode, you’ll be able to confidently invite people to your team, and revoke those invites if necessary, with all the correct permission checks in place!