mirror of
https://github.com/plausible/analytics.git
synced 2024-12-23 01:22:15 +03:00
Enable teams sync (#4726)
This commit is contained in:
parent
0f93328b6f
commit
1234cbf2c1
@ -4,7 +4,6 @@ defmodule Plausible do
|
||||
"""
|
||||
|
||||
@ce_builds [:ce, :ce_test, :ce_dev]
|
||||
@public_builds [:ce, :prod]
|
||||
|
||||
defmacro __using__(_) do
|
||||
quote do
|
||||
@ -59,12 +58,4 @@ defmodule Plausible do
|
||||
"Plausible Analytics"
|
||||
end
|
||||
end
|
||||
|
||||
defmacro with_teams(do: do_block) do
|
||||
if Mix.env() not in @public_builds do
|
||||
quote do
|
||||
unquote(do_block)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -62,12 +62,10 @@ defmodule Plausible.Auth.UserAdmin do
|
||||
]
|
||||
end
|
||||
|
||||
with_teams do
|
||||
def after_update(_conn, user) do
|
||||
Plausible.Teams.sync_team(user)
|
||||
def after_update(_conn, user) do
|
||||
Plausible.Teams.sync_team(user)
|
||||
|
||||
{:ok, user}
|
||||
end
|
||||
{:ok, user}
|
||||
end
|
||||
|
||||
defp lock(user) do
|
||||
|
@ -41,9 +41,7 @@ defmodule Plausible.Site.Memberships.AcceptInvitation do
|
||||
|
||||
case Repo.transaction(multi) do
|
||||
{:ok, changes} ->
|
||||
with_teams do
|
||||
Plausible.Teams.Invitations.transfer_site_sync(site, user)
|
||||
end
|
||||
Plausible.Teams.Invitations.transfer_site_sync(site, user)
|
||||
|
||||
membership = Repo.preload(changes.membership, [:site, :user])
|
||||
|
||||
@ -77,9 +75,7 @@ defmodule Plausible.Site.Memberships.AcceptInvitation do
|
||||
site = Repo.preload(invitation.site, :owner)
|
||||
|
||||
with :ok <- Invitations.ensure_can_take_ownership(site, user) do
|
||||
with_teams do
|
||||
Plausible.Teams.Invitations.accept_transfer_sync(invitation, user)
|
||||
end
|
||||
Plausible.Teams.Invitations.accept_transfer_sync(invitation, user)
|
||||
|
||||
site
|
||||
|> add_and_transfer_ownership(membership, user)
|
||||
@ -89,9 +85,7 @@ defmodule Plausible.Site.Memberships.AcceptInvitation do
|
||||
end
|
||||
|
||||
defp do_accept_invitation(invitation, user) do
|
||||
with_teams do
|
||||
Plausible.Teams.Invitations.accept_invitation_sync(invitation, user)
|
||||
end
|
||||
Plausible.Teams.Invitations.accept_invitation_sync(invitation, user)
|
||||
|
||||
membership = get_or_create_membership(invitation, user)
|
||||
|
||||
|
@ -82,9 +82,7 @@ defmodule Plausible.Site.Memberships.CreateInvitation do
|
||||
{:ok, invitation} <- Plausible.Repo.insert(changeset) do
|
||||
send_invitation_email(invitation, invitee)
|
||||
|
||||
with_teams do
|
||||
Plausible.Teams.Invitations.invite_sync(site, invitation)
|
||||
end
|
||||
Plausible.Teams.Invitations.invite_sync(site, invitation)
|
||||
|
||||
invitation
|
||||
else
|
||||
|
@ -36,9 +36,7 @@ defmodule Plausible.Users do
|
||||
|> Auth.User.changeset(%{accept_traffic_until: accept_traffic_until(user)})
|
||||
|> Repo.update!()
|
||||
|
||||
with_teams do
|
||||
Plausible.Teams.sync_team(user)
|
||||
end
|
||||
Plausible.Teams.sync_team(user)
|
||||
|
||||
user
|
||||
end
|
||||
@ -112,9 +110,7 @@ defmodule Plausible.Users do
|
||||
|> Auth.User.start_trial()
|
||||
|> Repo.update!()
|
||||
|
||||
with_teams do
|
||||
Plausible.Teams.sync_team(user)
|
||||
end
|
||||
Plausible.Teams.sync_team(user)
|
||||
|
||||
user
|
||||
end
|
||||
@ -125,9 +121,7 @@ defmodule Plausible.Users do
|
||||
|> Auth.User.changeset(%{allow_next_upgrade_override: true})
|
||||
|> Repo.update!()
|
||||
|
||||
with_teams do
|
||||
Plausible.Teams.sync_team(user)
|
||||
end
|
||||
Plausible.Teams.sync_team(user)
|
||||
|
||||
user
|
||||
end
|
||||
@ -139,9 +133,7 @@ defmodule Plausible.Users do
|
||||
|> Auth.User.changeset(%{allow_next_upgrade_override: false})
|
||||
|> Repo.update!()
|
||||
|
||||
with_teams do
|
||||
Plausible.Teams.sync_team(user)
|
||||
end
|
||||
Plausible.Teams.sync_team(user)
|
||||
|
||||
user
|
||||
else
|
||||
@ -161,9 +153,7 @@ defmodule Plausible.Users do
|
||||
|> GracePeriod.start_changeset()
|
||||
|> Repo.update!()
|
||||
|
||||
with_teams do
|
||||
Plausible.Teams.sync_team(user)
|
||||
end
|
||||
Plausible.Teams.sync_team(user)
|
||||
|
||||
user
|
||||
end
|
||||
@ -174,9 +164,7 @@ defmodule Plausible.Users do
|
||||
|> GracePeriod.start_manual_lock_changeset()
|
||||
|> Repo.update!()
|
||||
|
||||
with_teams do
|
||||
Plausible.Teams.sync_team(user)
|
||||
end
|
||||
Plausible.Teams.sync_team(user)
|
||||
|
||||
user
|
||||
end
|
||||
@ -187,9 +175,7 @@ defmodule Plausible.Users do
|
||||
|> GracePeriod.end_changeset()
|
||||
|> Repo.update!()
|
||||
|
||||
with_teams do
|
||||
Plausible.Teams.sync_team(user)
|
||||
end
|
||||
Plausible.Teams.sync_team(user)
|
||||
|
||||
user
|
||||
end
|
||||
@ -200,9 +186,7 @@ defmodule Plausible.Users do
|
||||
|> GracePeriod.remove_changeset()
|
||||
|> Repo.update!()
|
||||
|
||||
with_teams do
|
||||
Plausible.Teams.sync_team(user)
|
||||
end
|
||||
Plausible.Teams.sync_team(user)
|
||||
|
||||
user
|
||||
end
|
||||
|
@ -171,9 +171,7 @@ defmodule PlausibleWeb.Site.MembershipController do
|
||||
|> Membership.set_role(new_role)
|
||||
|> Repo.update!()
|
||||
|
||||
with_teams do
|
||||
Plausible.Teams.Memberships.update_role_sync(membership)
|
||||
end
|
||||
Plausible.Teams.Memberships.update_role_sync(membership)
|
||||
|
||||
redirect_target =
|
||||
if membership.user.id == current_user.id and new_role == :viewer do
|
||||
@ -221,9 +219,7 @@ defmodule PlausibleWeb.Site.MembershipController do
|
||||
if membership do
|
||||
Repo.delete!(membership)
|
||||
|
||||
with_teams do
|
||||
Plausible.Teams.Memberships.remove_sync(membership)
|
||||
end
|
||||
Plausible.Teams.Memberships.remove_sync(membership)
|
||||
|
||||
membership
|
||||
|> PlausibleWeb.Email.site_member_removed()
|
||||
|
Loading…
Reference in New Issue
Block a user