mirror of
https://github.com/plausible/analytics.git
synced 2024-12-24 01:54:34 +03:00
Fixups sites (#3482)
* Revert "Fix sites query invitation left join lookup (#3480)" This reverts commit6e6508a359
. * Revert "Revert "Fix sites query invitation left join lookup (#3480)"" This reverts commitf5cc831d7a
. * Revert "Fix sites query invitation left join lookup (#3480)" This reverts commit6e6508a359
. * Fix sites listing
This commit is contained in:
parent
df44f549d8
commit
08bd10614f
@ -19,10 +19,10 @@ defmodule Plausible.Sites do
|
||||
base_query =
|
||||
from(s in Plausible.Site,
|
||||
left_join: sm in assoc(s, :memberships),
|
||||
on: sm.user_id == ^user.id,
|
||||
left_join: i in assoc(s, :invitations),
|
||||
where:
|
||||
(is_nil(i.id) and sm.user_id == ^user.id) or
|
||||
(not is_nil(i.id) and i.email == ^user.email),
|
||||
on: i.email == ^user.email,
|
||||
where: not is_nil(i.id) or not is_nil(sm.id),
|
||||
select: %{
|
||||
s
|
||||
| list_type:
|
||||
|
@ -98,24 +98,38 @@ defmodule Plausible.SitesTest do
|
||||
end
|
||||
|
||||
test "returns invitations and sites" do
|
||||
user = insert(:user)
|
||||
user = insert(:user, email: "hello@example.com")
|
||||
|
||||
%{id: site_id1} = insert(:site, members: [user])
|
||||
%{id: site_id2} = insert(:site, members: [user])
|
||||
_rogue_site = insert(:site)
|
||||
site1 = %{id: site_id1} = insert(:site, members: [user], domain: "one.example.com")
|
||||
%{id: site_id2} = insert(:site, members: [user], domain: "two.example.com")
|
||||
%{id: site_id4} = insert(:site, members: [user], domain: "four.example.com")
|
||||
|
||||
_rogue_site = insert(:site, domain: "rogue.example.com")
|
||||
|
||||
insert(:invitation, email: user.email, inviter: build(:user), role: :owner, site: site1)
|
||||
|
||||
%{id: site_id3} =
|
||||
insert(:site,
|
||||
domain: "three.example.com",
|
||||
invitations: [
|
||||
build(:invitation, email: user.email, inviter: build(:user), role: :viewer)
|
||||
]
|
||||
)
|
||||
|
||||
insert(:invitation, email: "friend@example.com", inviter: user, role: :viewer, site: site1)
|
||||
|
||||
insert(:invitation,
|
||||
site: site1,
|
||||
inviter: user,
|
||||
email: "another@example.com"
|
||||
)
|
||||
|
||||
assert %{
|
||||
entries: [
|
||||
%{id: ^site_id3},
|
||||
%{id: ^site_id1},
|
||||
%{id: ^site_id2}
|
||||
%{id: ^site_id1, list_type: "invitation"},
|
||||
%{id: ^site_id3, list_type: "invitation"},
|
||||
%{id: ^site_id4, list_type: "site"},
|
||||
%{id: ^site_id2, list_type: "site"}
|
||||
]
|
||||
} = Sites.list(user, %{})
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user