From 51fcf7fa7ccb27c7441e0aaa7492b36ddc2b2461 Mon Sep 17 00:00:00 2001 From: Adrian Gruntkowski Date: Mon, 25 Nov 2024 15:50:41 +0100 Subject: [PATCH] Account for pending site transfers in Settings > People list --- lib/plausible/teams/adapter/read/sites.ex | 14 +++++++++++++- .../controllers/site_controller_test.exs | 13 +++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/plausible/teams/adapter/read/sites.ex b/lib/plausible/teams/adapter/read/sites.ex index 34a4e4df77de..0b7936ada7ed 100644 --- a/lib/plausible/teams/adapter/read/sites.ex +++ b/lib/plausible/teams/adapter/read/sites.ex @@ -176,7 +176,19 @@ defmodule Plausible.Teams.Adapter.Read.Sites do ) |> Repo.all() - %{memberships: memberships, invitations: invitations} + site_transfers = + from( + st in Teams.SiteTransfer, + where: st.site_id == ^site.id, + select: %Plausible.Auth.Invitation{ + invitation_id: st.transfer_id, + email: st.email, + role: :owner + } + ) + |> Repo.all() + + %{memberships: memberships, invitations: site_transfers ++ invitations} else site |> Repo.preload([:invitations, memberships: :user]) diff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exs index f8d9b857e610..52a5ca4e8fe3 100644 --- a/test/plausible_web/controllers/site_controller_test.exs +++ b/test/plausible_web/controllers/site_controller_test.exs @@ -552,6 +552,19 @@ defmodule PlausibleWeb.SiteControllerTest do assert text_of_element(resp, "#invitation-#{i2.invitation_id}") == "viewer@example.com Viewer" end + + test "lists pending site transfer", %{conn: conn, user: user} do + site = new_site(owner: user) + new_owner = new_user() + + st = invite_transfer(site, new_owner, inviter: user) + + conn = get(conn, "/#{site.domain}/settings/people") + resp = html_response(conn, 200) + + assert text_of_element(resp, "#invitation-#{st.invitation_id}") == + "#{new_owner.email} Owner" + end end describe "GET /:domain/settings/goals" do