Improve member adding and excluding flow
Allow to exclude a member Send emails to the member when it's excluded Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
19
lib/web/cache/activity_pub.ex
vendored
19
lib/web/cache/activity_pub.ex
vendored
@@ -16,13 +16,30 @@ defmodule Mobilizon.Web.Cache.ActivityPub do
|
||||
|
||||
@cache :activity_pub
|
||||
|
||||
@doc """
|
||||
Gets a actor by username and eventually domain.
|
||||
"""
|
||||
@spec get_actor_by_name(String.t()) ::
|
||||
{:commit, Actor.t()} | {:ignore, nil}
|
||||
def get_actor_by_name(name) do
|
||||
Cachex.fetch(@cache, "actor_" <> name, fn "actor_" <> name ->
|
||||
case Actors.get_actor_by_name(name) do
|
||||
%Actor{} = actor ->
|
||||
{:commit, actor}
|
||||
|
||||
nil ->
|
||||
{:ignore, nil}
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a local actor by username.
|
||||
"""
|
||||
@spec get_local_actor_by_name(String.t()) ::
|
||||
{:commit, Actor.t()} | {:ignore, nil}
|
||||
def get_local_actor_by_name(name) do
|
||||
Cachex.fetch(@cache, "actor_" <> name, fn "actor_" <> name ->
|
||||
Cachex.fetch(@cache, "local_actor_" <> name, fn "local_actor_" <> name ->
|
||||
case Actors.get_local_actor_by_name(name) do
|
||||
%Actor{} = actor ->
|
||||
{:commit, actor}
|
||||
|
||||
1
lib/web/cache/cache.ex
vendored
1
lib/web/cache/cache.ex
vendored
@@ -17,6 +17,7 @@ defmodule Mobilizon.Web.Cache do
|
||||
Enum.each(@caches, &Cachex.del(&1, "actor_" <> preferred_username))
|
||||
end
|
||||
|
||||
defdelegate get_actor_by_name(name), to: ActivityPub
|
||||
defdelegate get_local_actor_by_name(name), to: ActivityPub
|
||||
defdelegate get_public_event_by_uuid_with_preload(uuid), to: ActivityPub
|
||||
defdelegate get_comment_by_uuid_with_preload(uuid), to: ActivityPub
|
||||
|
||||
@@ -27,7 +27,7 @@ defmodule Mobilizon.Web.PageController do
|
||||
|
||||
@spec actor(Plug.Conn.t(), map) :: {:error, :not_found} | Plug.Conn.t()
|
||||
def actor(conn, %{"name" => name}) do
|
||||
{status, actor} = Cache.get_local_actor_by_name(name)
|
||||
{status, actor} = Cache.get_actor_by_name(name)
|
||||
render_or_error(conn, &ok_status?/3, status, :actor, actor)
|
||||
end
|
||||
|
||||
|
||||
@@ -15,10 +15,14 @@ defmodule Mobilizon.Web.Email.Group do
|
||||
@doc """
|
||||
Send emails to local user
|
||||
"""
|
||||
@spec send_invite_to_user(Member.t(), String.t()) :: :ok
|
||||
def send_invite_to_user(member, locale \\ "en")
|
||||
def send_invite_to_user(%Member{actor: %Actor{user_id: nil}}, _locale), do: :ok
|
||||
|
||||
def send_invite_to_user(
|
||||
%Member{actor: %Actor{user_id: user_id}, parent: %Actor{} = group, role: :invited} =
|
||||
member,
|
||||
locale \\ "en"
|
||||
locale
|
||||
) do
|
||||
with %User{email: email} <- Users.get_user!(user_id) do
|
||||
Gettext.put_locale(locale)
|
||||
@@ -43,5 +47,33 @@ defmodule Mobilizon.Web.Email.Group do
|
||||
end
|
||||
end
|
||||
|
||||
# Only send notification to local members
|
||||
def send_notification_to_removed_member(%Member{actor: %Actor{user_id: nil}}), do: :ok
|
||||
|
||||
def send_notification_to_removed_member(%Member{
|
||||
actor: %Actor{user_id: user_id},
|
||||
parent: %Actor{} = group,
|
||||
role: :rejected
|
||||
}) do
|
||||
with %User{email: email, locale: locale} <- Users.get_user!(user_id) do
|
||||
Gettext.put_locale(locale)
|
||||
|
||||
subject =
|
||||
gettext(
|
||||
"You have been removed from group %{group}",
|
||||
group: group.name
|
||||
)
|
||||
|
||||
Email.base_email(to: email, subject: subject)
|
||||
|> assign(:locale, locale)
|
||||
|> assign(:group, group)
|
||||
|> assign(:subject, subject)
|
||||
|> render(:group_removal)
|
||||
|> Email.Mailer.deliver_later()
|
||||
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
||||
# TODO : def send_confirmation_to_inviter()
|
||||
end
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="left" style="padding: 20px 30px 0px 30px; color: #474467; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;" >
|
||||
<p style="margin: 0;">
|
||||
<%= gettext "%{inviter} just invited you to join their group %{group}", group: @group.name, inviter: @inviter.name %>
|
||||
<%= gettext("<b>%{inviter}</b> just invited you to join their group %{link_start}<b>%{group}</b>%{link_end}", group: @group.name, inviter: @inviter.name, link_start: "<a href=\"#{@group.url}\">", link_end: "</a>") |> raw %>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<%= gettext "Come along!" %>
|
||||
==
|
||||
<%= gettext "%{inviter} just invited you to join their group %{group}", group: @group.name, inviter: @inviter.name %>
|
||||
<%= @group.url %>
|
||||
<%= gettext "To accept this invitation, head over to your groups." %>
|
||||
<%= page_url(Mobilizon.Web.Endpoint, :my_groups) %>
|
||||
|
||||
56
lib/web/templates/email/group_removal.html.eex
Normal file
56
lib/web/templates/email/group_removal.html.eex
Normal file
@@ -0,0 +1,56 @@
|
||||
<!-- HERO -->
|
||||
<tr>
|
||||
<td bgcolor="#474467" align="center" style="padding: 0px 10px 0px 10px;">
|
||||
<!--[if (gte mso 9)|(IE)]>
|
||||
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600">
|
||||
<tr>
|
||||
<td align="center" valign="top" width="600">
|
||||
<![endif]-->
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;" >
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="center" valign="top" style="padding: 40px 20px 20px 20px; border-radius: 4px 4px 0px 0px; color: #3A384C; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 48px; font-weight: 400; line-height: 48px;">
|
||||
<h1 style="font-size: 48px; font-weight: 400; margin: 0;">
|
||||
<%= gettext "So long, and thanks for the fish!" %>
|
||||
</h1>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!--[if (gte mso 9)|(IE)]>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<![endif]-->
|
||||
</td>
|
||||
</tr>
|
||||
<!-- COPY BLOCK -->
|
||||
<tr>
|
||||
<td bgcolor="#E6E4F4" align="center" style="padding: 0px 10px 0px 10px;">
|
||||
<!--[if (gte mso 9)|(IE)]>
|
||||
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600">
|
||||
<tr>
|
||||
<td align="center" valign="top" width="600">
|
||||
<![endif]-->
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;" >
|
||||
<!-- COPY -->
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="left" style="padding: 20px 30px 0px 30px; color: #474467; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;" >
|
||||
<p style="margin: 0;">
|
||||
<%= gettext("You have been removed from group %{link_start}<b>%{group}</b>%{link_end}. You will not be able to access this group's private content anymore.", group: @group.name, link_start: "<a href=\"#{@group.url}\">", link_end: "</a>") |> raw %>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="left" style="padding: 20px 30px 40px 30px; color: #474467; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;" >
|
||||
<p style="margin: 0">
|
||||
<%= gettext "If you feel this is an error, you may contact the group's administrators so that they can add you back." %>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!--[if (gte mso 9)|(IE)]>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<![endif]-->
|
||||
</td>
|
||||
</tr>
|
||||
5
lib/web/templates/email/group_removal.text.eex
Normal file
5
lib/web/templates/email/group_removal.text.eex
Normal file
@@ -0,0 +1,5 @@
|
||||
<%= gettext "So long, and thanks for the fish!" %>
|
||||
==
|
||||
<%= gettext "You have been removed from group %{group}. You will not be able to access this group's private content anymore.", group: @group.name %>
|
||||
<%= @group.url %>
|
||||
<%= gettext "If you feel this is an error, you may contact the group's administrators so that they can add you back." %>
|
||||
@@ -14,7 +14,7 @@ defmodule Mobilizon.Web.ActivityPub.ObjectView do
|
||||
end,
|
||||
"actor" => activity.actor,
|
||||
# Not sure if needed since this is used into outbox
|
||||
"published" => Timex.now(),
|
||||
"published" => DateTime.utc_now() |> DateTime.to_iso8601(),
|
||||
"to" => activity.recipients,
|
||||
"object" =>
|
||||
case data["type"] do
|
||||
|
||||
Reference in New Issue
Block a user