From bef0bf0d99a46980fb9138ebc6cabcd4cee0fe2a Mon Sep 17 00:00:00 2001 From: Adrian Gruntkowski Date: Thu, 19 Dec 2024 10:27:43 +0100 Subject: [PATCH] Show guest roles for other members in Site CRM --- lib/plausible/site/admin.ex | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/plausible/site/admin.ex b/lib/plausible/site/admin.ex index 684200e5a9719..01a741a12e3ec 100644 --- a/lib/plausible/site/admin.ex +++ b/lib/plausible/site/admin.ex @@ -34,7 +34,11 @@ defmodule Plausible.SiteAdmin do from(r in query, as: :site, inner_join: o in assoc(r, :owner), - preload: [owner: o, team: [team_memberships: :user]], + inner_join: t in assoc(r, :team), + left_join: gm in assoc(r, :guest_memberships), + left_join: tm in assoc(gm, :team_membership), + left_join: u in assoc(tm, :user), + preload: [owner: o, team: t, guest_memberships: {gm, team_membership: {tm, user: u}}], or_where: ilike(r.domain, ^search_term), or_where: ilike(o.email, ^search_term), or_where: ilike(o.name, ^search_term), @@ -193,8 +197,8 @@ defmodule Plausible.SiteAdmin do end defp get_other_members(site) do - site.team.team_memberships - |> Enum.map(fn m -> m.user.email <> "(#{to_string(m.role)})" end) + site.guest_memberships + |> Enum.map(fn m -> m.team_membership.user.email <> "(#{member_role(m.role)})" end) |> Enum.join(", ") end @@ -208,4 +212,7 @@ defmodule Plausible.SiteAdmin do def create_changeset(schema, attrs), do: Plausible.Site.crm_changeset(schema, attrs) def update_changeset(schema, attrs), do: Plausible.Site.crm_changeset(schema, attrs) + + defp member_role(:editor), do: :admin + defp member_role(other), do: other end