Adds feature to permit e.g., local admins and community moderators to automatically follow all newly registered accounts
This commit is contained in:
parent
023f726d7f
commit
1b8fd7e65a
@ -235,6 +235,7 @@ config :pleroma, :instance,
|
|||||||
"text/bbcode"
|
"text/bbcode"
|
||||||
],
|
],
|
||||||
autofollowed_nicknames: [],
|
autofollowed_nicknames: [],
|
||||||
|
autofollowing_nicknames: [],
|
||||||
max_pinned_statuses: 1,
|
max_pinned_statuses: 1,
|
||||||
attachment_links: false,
|
attachment_links: false,
|
||||||
max_report_comment_size: 1000,
|
max_report_comment_size: 1000,
|
||||||
|
@ -837,6 +837,17 @@ config :pleroma, :config_description, [
|
|||||||
"rinpatch"
|
"rinpatch"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
%{
|
||||||
|
key: :autofollowing_nicknames,
|
||||||
|
type: {:list, :string},
|
||||||
|
description:
|
||||||
|
"Set to nicknames of (local) users that automatically follows every newly registered user",
|
||||||
|
suggestions: [
|
||||||
|
"admin",
|
||||||
|
"info",
|
||||||
|
"moderator",
|
||||||
|
]
|
||||||
|
},
|
||||||
%{
|
%{
|
||||||
key: :attachment_links,
|
key: :attachment_links,
|
||||||
type: :boolean,
|
type: :boolean,
|
||||||
|
@ -45,6 +45,7 @@ To add configuration to your config file, you can copy it from the base config.
|
|||||||
older software for theses nicknames.
|
older software for theses nicknames.
|
||||||
* `max_pinned_statuses`: The maximum number of pinned statuses. `0` will disable the feature.
|
* `max_pinned_statuses`: The maximum number of pinned statuses. `0` will disable the feature.
|
||||||
* `autofollowed_nicknames`: Set to nicknames of (local) users that every new user should automatically follow.
|
* `autofollowed_nicknames`: Set to nicknames of (local) users that every new user should automatically follow.
|
||||||
|
* `autofollowing_nicknames`: Set to nicknames of (local) users that automatically follows every newly registered user.
|
||||||
* `attachment_links`: Set to true to enable automatically adding attachment link text to statuses.
|
* `attachment_links`: Set to true to enable automatically adding attachment link text to statuses.
|
||||||
* `max_report_comment_size`: The maximum size of the report comment (Default: `1000`).
|
* `max_report_comment_size`: The maximum size of the report comment (Default: `1000`).
|
||||||
* `safe_dm_mentions`: If set to true, only mentions at the beginning of a post will be used to address people in direct messages. This is to prevent accidental mentioning of people when talking about them (e.g. "@friend hey i really don't like @enemy"). Default: `false`.
|
* `safe_dm_mentions`: If set to true, only mentions at the beginning of a post will be used to address people in direct messages. This is to prevent accidental mentioning of people when talking about them (e.g. "@friend hey i really don't like @enemy"). Default: `false`.
|
||||||
|
@ -765,6 +765,16 @@ defmodule Pleroma.User do
|
|||||||
follow_all(user, autofollowed_users)
|
follow_all(user, autofollowed_users)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp autofollowing_users(user) do
|
||||||
|
candidates = Config.get([:instance, :autofollowing_nicknames])
|
||||||
|
|
||||||
|
User.Query.build(%{nickname: candidates, local: true, deactivated: false})
|
||||||
|
|> Repo.all()
|
||||||
|
|> Enum.each(&follow(&1, user, :follow_accept))
|
||||||
|
|
||||||
|
{:ok, :success}
|
||||||
|
end
|
||||||
|
|
||||||
@doc "Inserts provided changeset, performs post-registration actions (confirmation email sending etc.)"
|
@doc "Inserts provided changeset, performs post-registration actions (confirmation email sending etc.)"
|
||||||
def register(%Ecto.Changeset{} = changeset) do
|
def register(%Ecto.Changeset{} = changeset) do
|
||||||
with {:ok, user} <- Repo.insert(changeset) do
|
with {:ok, user} <- Repo.insert(changeset) do
|
||||||
@ -774,6 +784,7 @@ defmodule Pleroma.User do
|
|||||||
|
|
||||||
def post_register_action(%User{} = user) do
|
def post_register_action(%User{} = user) do
|
||||||
with {:ok, user} <- autofollow_users(user),
|
with {:ok, user} <- autofollow_users(user),
|
||||||
|
{:ok, _} <- autofollowing_users(user),
|
||||||
{:ok, user} <- set_cache(user),
|
{:ok, user} <- set_cache(user),
|
||||||
{:ok, _} <- send_welcome_email(user),
|
{:ok, _} <- send_welcome_email(user),
|
||||||
{:ok, _} <- send_welcome_message(user),
|
{:ok, _} <- send_welcome_message(user),
|
||||||
|
@ -388,6 +388,7 @@ defmodule Pleroma.UserTest do
|
|||||||
}
|
}
|
||||||
|
|
||||||
setup do: clear_config([:instance, :autofollowed_nicknames])
|
setup do: clear_config([:instance, :autofollowed_nicknames])
|
||||||
|
setup do: clear_config([:instance, :autofollowing_nicknames])
|
||||||
setup do: clear_config([:welcome])
|
setup do: clear_config([:welcome])
|
||||||
setup do: clear_config([:instance, :account_activation_required])
|
setup do: clear_config([:instance, :account_activation_required])
|
||||||
|
|
||||||
@ -408,6 +409,23 @@ defmodule Pleroma.UserTest do
|
|||||||
refute User.following?(registered_user, remote_user)
|
refute User.following?(registered_user, remote_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it adds automatic followers for new registered accounts" do
|
||||||
|
user1 = insert(:user)
|
||||||
|
user2 = insert(:user)
|
||||||
|
|
||||||
|
Pleroma.Config.put([:instance, :autofollowing_nicknames], [
|
||||||
|
user1.nickname,
|
||||||
|
user2.nickname
|
||||||
|
])
|
||||||
|
|
||||||
|
cng = User.register_changeset(%User{}, @full_user_data)
|
||||||
|
|
||||||
|
{:ok, registered_user} = User.register(cng)
|
||||||
|
|
||||||
|
assert User.following?(user1, registered_user)
|
||||||
|
assert User.following?(user2, registered_user)
|
||||||
|
end
|
||||||
|
|
||||||
test "it sends a welcome message if it is set" do
|
test "it sends a welcome message if it is set" do
|
||||||
welcome_user = insert(:user)
|
welcome_user = insert(:user)
|
||||||
Pleroma.Config.put([:welcome, :direct_message, :enabled], true)
|
Pleroma.Config.put([:welcome, :direct_message, :enabled], true)
|
||||||
|
Loading…
Reference in New Issue
Block a user