summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfeld <feld@feld.me>2020-10-27 22:55:31 +0000
committerfeld <feld@feld.me>2020-10-27 22:55:31 +0000
commit1204aaa2e35983f7361d61ee7906ccf3d09d84e4 (patch)
treeb7ece4fbca3ec8f309a3c58cf27087a20546b31c
parentd8d4bd15d064e44d9900b91696a1ca2c373fcfc8 (diff)
parent03a318af9ac1cc86e1201d6f55babd06c0b5ecd9 (diff)
Merge branch 'feature/autofollowing' into 'develop'
autofollowing_nicknames See merge request pleroma/pleroma!3087
-rw-r--r--CHANGELOG.md1
-rw-r--r--config/config.exs1
-rw-r--r--config/description.exs6
-rw-r--r--docs/configuration/cheatsheet.md1
-rw-r--r--lib/pleroma/user.ex11
-rw-r--r--test/pleroma/user_test.exs18
6 files changed, 38 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6ca56a90d..9af4a15cc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Pleroma API: Importing the mutes users from CSV files.
- Experimental websocket-based federation between Pleroma instances.
- App metrics: ability to restrict access to specified IP whitelist.
+- Configuration: Add `:instance, autofollowing_nicknames` setting to provide a way to make accounts automatically follow new users that register on the local Pleroma instance.
### Changed
diff --git a/config/config.exs b/config/config.exs
index bd611fd42..c52ee8f82 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -234,6 +234,7 @@ config :pleroma, :instance,
"text/bbcode"
],
autofollowed_nicknames: [],
+ autofollowing_nicknames: [],
max_pinned_statuses: 1,
attachment_links: false,
max_report_comment_size: 1000,
diff --git a/config/description.exs b/config/description.exs
index 55363c45a..0bfa9979f 100644
--- a/config/description.exs
+++ b/config/description.exs
@@ -832,6 +832,12 @@ config :pleroma, :config_description, [
"Set to nicknames of (local) users that every new user should automatically follow"
},
%{
+ key: :autofollowing_nicknames,
+ type: {:list, :string},
+ description:
+ "Set to nicknames of (local) users that automatically follows every newly registered user"
+ },
+ %{
key: :attachment_links,
type: :boolean,
description: "Enable to automatically add attachment link text to statuses"
diff --git a/docs/configuration/cheatsheet.md b/docs/configuration/cheatsheet.md
index 0b13d7e88..f4b4b6c3c 100644
--- a/docs/configuration/cheatsheet.md
+++ b/docs/configuration/cheatsheet.md
@@ -45,6 +45,7 @@ To add configuration to your config file, you can copy it from the base config.
older software for theses nicknames.
* `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.
+* `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.
* `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`.
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 72f507f1e..a1e546b2d 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -766,6 +766,16 @@ defmodule Pleroma.User do
follow_all(user, autofollowed_users)
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.)"
def register(%Ecto.Changeset{} = changeset) do
with {:ok, user} <- Repo.insert(changeset) do
@@ -775,6 +785,7 @@ defmodule Pleroma.User do
def post_register_action(%User{} = user) do
with {:ok, user} <- autofollow_users(user),
+ {:ok, _} <- autofollowing_users(user),
{:ok, user} <- set_cache(user),
{:ok, _} <- send_welcome_email(user),
{:ok, _} <- send_welcome_message(user),
diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs
index 7220ce846..9ae52d594 100644
--- a/test/pleroma/user_test.exs
+++ b/test/pleroma/user_test.exs
@@ -388,6 +388,7 @@ defmodule Pleroma.UserTest do
}
setup do: clear_config([:instance, :autofollowed_nicknames])
+ setup do: clear_config([:instance, :autofollowing_nicknames])
setup do: clear_config([:welcome])
setup do: clear_config([:instance, :account_activation_required])
@@ -408,6 +409,23 @@ defmodule Pleroma.UserTest do
refute User.following?(registered_user, remote_user)
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
welcome_user = insert(:user)
Pleroma.Config.put([:welcome, :direct_message, :enabled], true)