Skip to content

Commit

Permalink
fix ownership transfer when is_selfhost=true (#2455)
Browse files Browse the repository at this point in the history
* fix ownership transfer when is_selfhost=true

* add changelog entry
  • Loading branch information
ruslandoga authored Nov 24, 2022
1 parent 994e7d0 commit 77cca04
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ All notable changes to this project will be documented in this file.
- ARM64 support for docker images plausible/analytics#2103
- Add support for international domain names (IDNs) plausible/analytics#2034
- Allow self-hosters to register an account on first launch
- Fix ownership transfer invitation link in self-hosted deployments

### Fixed
- Plausible script does not prevent default if it's been prevented by an external script [plausible/analytics#1941](https://github.com/plausible/analytics/issues/1941)
Expand Down
4 changes: 3 additions & 1 deletion lib/plausible_web/controllers/invitation_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ defmodule PlausibleWeb.InvitationController do
end

defp maybe_end_trial_of_new_owner(multi, new_owner) do
if !Application.get_env(:plausible, :is_selfhost) do
if Application.get_env(:plausible, :is_selfhost) do
multi
else
end_trial_of_new_owner(multi, new_owner)
end
end
Expand Down
27 changes: 27 additions & 0 deletions test/plausible_web/controllers/invitation_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,33 @@ defmodule PlausibleWeb.Site.InvitationControllerTest do

assert new_owner_membership.role == :owner
end

test "works in self-hosted", %{conn: conn, user: user} do
patch_env(:is_selfhost, true)

old_owner = insert(:user)
site = insert(:site, members: [old_owner])

invitation =
insert(:invitation,
site_id: site.id,
inviter: old_owner,
email: user.email,
role: :owner
)

post(conn, "/sites/invitations/#{invitation.invitation_id}/accept")

old_owner_membership =
Repo.get_by(Plausible.Site.Membership, user_id: old_owner.id, site_id: site.id)

assert old_owner_membership.role == :admin

new_owner_membership =
Repo.get_by(Plausible.Site.Membership, user_id: user.id, site_id: site.id)

assert new_owner_membership.role == :owner
end
end

describe "POST /sites/invitations/:invitation_id/reject" do
Expand Down

0 comments on commit 77cca04

Please sign in to comment.