mirror of
https://github.com/plausible/analytics.git
synced 2024-12-28 12:01:39 +03:00
44d71c8c0e
* Avoid redirect in site settings * Fix unicode in SiteController existing tests * Fix various tests * Add CHANGELOG * Make sure test site is example.com * Use Route helpers in site_controller * Fix UTF redirect in change domain submit action * Fix UTF site domain in reset stats action
55 lines
2.0 KiB
Elixir
55 lines
2.0 KiB
Elixir
defmodule PlausibleWeb.InvitationController do
|
|
use PlausibleWeb, :controller
|
|
|
|
plug PlausibleWeb.RequireAccountPlug
|
|
|
|
plug PlausibleWeb.AuthorizeSiteAccess, [:owner, :admin] when action in [:remove_invitation]
|
|
|
|
def accept_invitation(conn, %{"invitation_id" => invitation_id}) do
|
|
case Plausible.Site.Memberships.accept_invitation(invitation_id, conn.assigns.current_user) do
|
|
{:ok, membership} ->
|
|
conn
|
|
|> put_flash(:success, "You now have access to #{membership.site.domain}")
|
|
|> redirect(external: "/#{URI.encode_www_form(membership.site.domain)}")
|
|
|
|
{:error, :invitation_not_found} ->
|
|
conn
|
|
|> put_flash(:error, "Invitation missing or already accepted")
|
|
|> redirect(to: "/sites")
|
|
|
|
{:error, _} ->
|
|
conn
|
|
|> put_flash(:error, "Something went wrong, please try again")
|
|
|> redirect(to: "/sites")
|
|
end
|
|
end
|
|
|
|
def reject_invitation(conn, %{"invitation_id" => invitation_id}) do
|
|
case Plausible.Site.Memberships.reject_invitation(invitation_id, conn.assigns.current_user) do
|
|
{:ok, invitation} ->
|
|
conn
|
|
|> put_flash(:success, "You have rejected the invitation to #{invitation.site.domain}")
|
|
|> redirect(to: "/sites")
|
|
|
|
{:error, :invitation_not_found} ->
|
|
conn
|
|
|> put_flash(:error, "Invitation missing or already accepted")
|
|
|> redirect(to: "/sites")
|
|
end
|
|
end
|
|
|
|
def remove_invitation(conn, %{"invitation_id" => invitation_id}) do
|
|
case Plausible.Site.Memberships.remove_invitation(invitation_id, conn.assigns.site) do
|
|
{:ok, invitation} ->
|
|
conn
|
|
|> put_flash(:success, "You have removed the invitation for #{invitation.email}")
|
|
|> redirect(external: Routes.site_path(conn, :settings_people, invitation.site.domain))
|
|
|
|
{:error, :invitation_not_found} ->
|
|
conn
|
|
|> put_flash(:error, "Invitation missing or already removed")
|
|
|> redirect(external: Routes.site_path(conn, :settings_people, conn.assigns.site.domain))
|
|
end
|
|
end
|
|
end
|