Skip to content
Open
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
119 changes: 0 additions & 119 deletions lib/plausible_web/controllers/site/membership_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -93,125 +93,6 @@ defmodule PlausibleWeb.Site.MembershipController do
end
end

def transfer_ownership_form(conn, _params) do
site_domain = conn.assigns.site.domain

site =
Plausible.Sites.get_for_user!(conn.assigns.current_user, site_domain)

render(
conn,
"transfer_ownership_form.html",
site: site,
skip_plausible_tracking: true
)
end

def transfer_ownership(conn, %{"email" => email}) do
site_domain = conn.assigns.site.domain

site =
Plausible.Sites.get_for_user!(conn.assigns.current_user, site_domain)

case Teams.Invitations.InviteToSite.invite(
site,
conn.assigns.current_user,
email,
:owner
) do
{:ok, _invitation} ->
conn
|> put_flash(:success, "Site transfer request has been sent to #{email}")
|> redirect(to: Routes.site_path(conn, :settings_people, site.domain))

{:error, changeset} ->
errors = Plausible.ChangesetHelpers.traverse_errors(changeset)

message =
case errors do
%{invitation: ["already sent" | _]} -> "Invitation has already been sent"
_other -> "Site transfer request to #{email} has failed"
end

conn
|> put_flash(:ttl, :timer.seconds(5))
|> put_flash(:error_title, "Transfer error")
|> put_flash(:error, message)
|> redirect(to: Routes.site_path(conn, :settings_people, site.domain))
end
end

def change_team_form(conn, _params) do
site_domain = conn.assigns.site.domain
user = conn.assigns.current_user

site =
Plausible.Sites.get_for_user!(user, site_domain)

render_change_team_form(conn, user, site)
end

defp render_change_team_form(conn, user, site, opts \\ []) do
transferable_teams =
user
|> Plausible.Teams.Users.teams(roles: [:owner, :admin])
|> Enum.reject(&(&1.id == site.team_id))
|> Enum.map(&{&1.name, &1.identifier})

render(
conn,
"change_team_form.html",
site: site,
skip_plausible_tracking: true,
transferable_teams: transferable_teams,
error: opts[:error]
)
end

def change_team(conn, %{"team_identifier" => identifier}) do
site_domain = conn.assigns.site.domain
user = conn.assigns.current_user

site =
Plausible.Sites.get_for_user!(user, site_domain)

destination_team =
Repo.one!(Teams.Users.teams_query(user, roles: [:admin, :owner], identifier: identifier))

case Teams.Sites.Transfer.change_team(
site,
conn.assigns.current_user,
destination_team
) do
:ok ->
conn
|> put_flash(:success, "Site team was changed")
|> redirect(to: Routes.site_path(conn, :index, __team: identifier))

{:error, :no_plan} ->
conn
|> render_change_team_form(conn.assigns.current_user, site,
error:
"This team doesn't have a subscription. Please start a subscription for " <>
"the team first and then try moving the site again"
)

{:error, {:over_plan_limits, _}} ->
conn
|> render_change_team_form(conn.assigns.current_user, site,
error:
"This site's usage is over the limits of the team's subscription. " <>
"Please upgrade the team to an appropriate subscription and then try moving the site again"
)

{:error, _} ->
conn
|> render_change_team_form(conn.assigns.current_user, site,
error: "Sorry, this team cannot be used"
)
end
end

@doc """
Updates the role of a user. The user being updated could be the same or different from the user taking
the action. When updating the role, it's important to enforce permissions:
Expand Down
1 change: 1 addition & 0 deletions lib/plausible_web/controllers/site_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ defmodule PlausibleWeb.SiteController do
conn
|> render("settings_danger_zone.html",
site: site,
connect_live_socket: true,
dogfood_page_path: "/:dashboard/settings/danger-zone",
layout: {PlausibleWeb.LayoutView, "site_settings.html"}
)
Expand Down
4 changes: 2 additions & 2 deletions lib/plausible_web/live/components/form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ defmodule PlausibleWeb.Live.Components.Form do
id={@id}
name={@name}
checked={assigns[:checked]}
class="block dark:bg-gray-900 size-4.5 mt-px cursor-pointer text-indigo-600 border-gray-400 dark:border-gray-600 checked:border-indigo-600 dark:checked:border-white"
class="block dark:bg-gray-900 size-4.5 mt-px cursor-pointer text-indigo-600 border-gray-400 dark:border-gray-600 checked:border-indigo-600 dark:checked:border-white disabled:cursor-not-allowed"
{@rest}
/>
<.label :if={@label} class="flex flex-col flex-inline" for={@id}>
Expand Down Expand Up @@ -416,7 +416,7 @@ defmodule PlausibleWeb.Live.Components.Form do

def error(assigns) do
~H"""
<p class="flex gap-3 text-sm leading-6 text-red-500">
<p class="mt-1 flex gap-3 text-sm text-red-500 leading-4.5 text-pretty">
{render_slot(@inner_block)}
</p>
"""
Expand Down
Loading
Loading