Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Fix sites query invitation left join lookup (#3480)

hq16e6508a3595c
diff --git a/lib/plausible/sites.ex b/lib/plausible/sites.ex
index 6b34c721d0..6a2b783d74 100644
--- a/lib/plausible/sites.ex
+++ b/lib/plausible/sites.ex
@@ -20,7 +20,9 @@ defmodule Plausible.Sites do
from(s in Plausible.Site,
left_join: sm in assoc(s, :memberships),
left_join: i in assoc(s, :invitations),
- where: sm.user_id == ^user.id or i.email == ^user.email,
+ where:
+ (is_nil(i.id) and sm.user_id == ^user.id) or
+ (not is_nil(i.id) and i.email == ^user.email),
select: %{
s
| list_type: