Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file.
### Fixed

- To make internal stats API requests for password-protected shared links, shared link auth cookie must be set in the requests
- Fix issue with site guests in Editor role and team members in Editor role not being able to change the domain of site

## v3.1.0 - 2025-11-13

Expand Down
1 change: 1 addition & 0 deletions lib/plausible_web/live/change_domain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ defmodule PlausibleWeb.Live.ChangeDomain do
site =
Plausible.Sites.get_for_user!(socket.assigns.current_user, domain,
roles: [
:editor,
:owner,
:admin,
:super_admin
Expand Down
42 changes: 29 additions & 13 deletions test/plausible_web/live/change_domain_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,38 @@ defmodule PlausibleWeb.Live.ChangeDomainTest do
assert is_nil(site.domain_changed_from)
end

test "successful form submission updates database", %{conn: conn, site: site} do
original_domain = site.domain
new_domain = "new.#{site.domain}"
{:ok, lv, _html} = live(conn, "/#{site.domain}/change-domain")
for {role, membership_type} <- [
{:editor, :site_guest},
{:editor, :team_member},
{:admin, :team_member},
{:owner, :team_member}
] do
test "#{Phoenix.Naming.humanize(membership_type)} with role #{role} can submit the form and it changes the record in the database",
%{conn: conn, user: user} do
site = new_site()

add_site_guest_or_team_member(site,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or you can use apply/3

user: user,
role: unquote(role),
membership_type: unquote(membership_type)
)

original_domain = site.domain
new_domain = "new.#{site.domain}"
{:ok, lv, _html} = live(conn, "/#{site.domain}/change-domain")

lv
|> element("form")
|> render_submit(%{site: %{domain: new_domain}})
lv
|> element("form")
|> render_submit(%{site: %{domain: new_domain}})

on_ee do
render_async(lv, 500)
end
on_ee do
render_async(lv, 500)
end

site = Repo.reload!(site)
assert site.domain == new_domain
assert site.domain_changed_from == original_domain
site = Repo.reload!(site)
assert site.domain == new_domain
assert site.domain_changed_from == original_domain
end
end

test "successful form submission navigates to success page", %{conn: conn, site: site} do
Expand Down
7 changes: 7 additions & 0 deletions test/support/teams/test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ defmodule Plausible.Teams.Test do
end
end

def add_site_guest_or_team_member(site, args \\ []) do
case Keyword.pop!(args, :membership_type) do
{:site_guest, args} -> add_guest(site, args)
{:team_member, args} -> add_member(site.team, args)
end
end

def add_guest(site, args \\ []) do
user = Keyword.get(args, :user, new_user())
role = Keyword.fetch!(args, :role)
Expand Down
Loading