Skip to content

Commit

Permalink
fix join workspace login redirect
Browse files Browse the repository at this point in the history
allow case mismatch for invite emails
  • Loading branch information
devxpy committed Dec 17, 2024
1 parent 432c62d commit 99b5548
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion workspaces/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ def accept(
"""
Raises: ValidationError
"""
assert invitee.email == self.email, "Email mismatch"
assert invitee.email.lower() == self.email.lower(), "Email mismatch"

membership, created = WorkspaceMembership.objects.get_or_create(
workspace=self.workspace,
Expand Down
21 changes: 15 additions & 6 deletions workspaces/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
def invitation_page(
current_user: AppUser | None, session: dict, invite: WorkspaceInvite
):
from routers.root import login

with (
gui.div(
className="position-absolute top-0 start-0 bottom-0 bg-black min-vw-100 min-vh-100",
Expand Down Expand Up @@ -82,6 +84,18 @@ def invitation_page(
members_text = ngettext("member", "members", members_count)
gui.caption(f"{members_count} {members_text}")

if not current_user or current_user.is_anonymous:
login_url = get_app_route_url(
login, query_params={"next": invite.get_invite_url()}
)
with gui.tag(
"a",
className="my-2 w-100 btn btn-theme btn-primary",
href=login_url,
):
gui.html("Join Workspace")
return

if gui.button(
"Join Workspace",
className="my-2 w-100",
Expand All @@ -102,13 +116,8 @@ def _handle_invite_accepted(
from routers.root import login, logout

workspace_redirect_url = get_route_path(account_route)
if not current_user or current_user.is_anonymous:
login_url = get_app_route_url(
login, query_params={"next": invite.get_invite_url()}
)
raise gui.RedirectException(login_url)

if invite.email != current_user.email:
if invite.email.lower() != current_user.email.lower():
# logout current user, and redirect to login
login_url = get_app_route_url(
login, query_params={"next": invite.get_invite_url()}
Expand Down

0 comments on commit 99b5548

Please sign in to comment.