forked from AkkomaGang/akkoma
Add allow_following_move
setting to User
This commit is contained in:
parent
61fc739ab8
commit
e6d7e27bd6
10 changed files with 59 additions and 30 deletions
|
@ -57,6 +57,7 @@ Has these additional fields under the `pleroma` object:
|
|||
- `settings_store`: A generic map of settings for frontends. Opaque to the backend. Only returned in `verify_credentials` and `update_credentials`
|
||||
- `chat_token`: The token needed for Pleroma chat. Only returned in `verify_credentials`
|
||||
- `deactivated`: boolean, true when the user is deactivated
|
||||
- `allow_following_move`: boolean, true when the user allows automatically follow moved following accounts
|
||||
- `unread_conversation_count`: The count of unread conversations. Only returned to the account owner.
|
||||
|
||||
### Source
|
||||
|
@ -130,6 +131,7 @@ Additional parameters can be added to the JSON body/Form data:
|
|||
- `default_scope` - the scope returned under `privacy` key in Source subentity
|
||||
- `pleroma_settings_store` - Opaque user settings to be saved on the backend.
|
||||
- `skip_thread_containment` - if true, skip filtering out broken threads
|
||||
- `allow_following_move` - if true, allows automatically follow moved following accounts
|
||||
- `pleroma_background_image` - sets the background image of the user.
|
||||
|
||||
### Pleroma Settings Store
|
||||
|
|
|
@ -109,26 +109,20 @@ def following(%User{} = user) do
|
|||
end
|
||||
|
||||
def move_following(origin, target) do
|
||||
following_relationships =
|
||||
__MODULE__
|
||||
|> join(:inner, [r], f in assoc(r, :follower))
|
||||
|> where(following_id: ^origin.id)
|
||||
|> preload([:follower])
|
||||
|> where([r, f], f.allow_following_move == true)
|
||||
|> limit(50)
|
||||
|> preload([:follower])
|
||||
|> Repo.all()
|
||||
|
||||
case following_relationships do
|
||||
[] ->
|
||||
:ok
|
||||
|
||||
following_relationships ->
|
||||
Enum.each(following_relationships, fn following_relationship ->
|
||||
Repo.transaction(fn ->
|
||||
|> Enum.map(fn following_relationship ->
|
||||
Repo.delete(following_relationship)
|
||||
User.follow(following_relationship.follower, target)
|
||||
Pleroma.Web.CommonAPI.follow(following_relationship.follower, target)
|
||||
end)
|
||||
end)
|
||||
|
||||
move_following(origin, target)
|
||||
|> case do
|
||||
[] -> :ok
|
||||
_ -> move_following(origin, target)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -104,6 +104,7 @@ defmodule Pleroma.User do
|
|||
field(:raw_fields, {:array, :map}, default: [])
|
||||
field(:discoverable, :boolean, default: false)
|
||||
field(:invisible, :boolean, default: false)
|
||||
field(:allow_following_move, :boolean, default: true)
|
||||
field(:skip_thread_containment, :boolean, default: false)
|
||||
field(:also_known_as, {:array, :string}, default: [])
|
||||
|
||||
|
@ -314,6 +315,7 @@ def update_changeset(struct, params \\ %{}) do
|
|||
:hide_followers_count,
|
||||
:hide_follows_count,
|
||||
:hide_favorites,
|
||||
:allow_following_move,
|
||||
:background,
|
||||
:show_role,
|
||||
:skip_thread_containment,
|
||||
|
@ -359,6 +361,7 @@ def upgrade_changeset(struct, params \\ %{}, remote? \\ false) do
|
|||
:hide_follows,
|
||||
:fields,
|
||||
:hide_followers,
|
||||
:allow_following_move,
|
||||
:discoverable,
|
||||
:hide_followers_count,
|
||||
:hide_follows_count,
|
||||
|
|
|
@ -152,6 +152,7 @@ def update_credentials(%{assigns: %{user: original_user}} = conn, params) do
|
|||
:hide_favorites,
|
||||
:show_role,
|
||||
:skip_thread_containment,
|
||||
:allow_following_move,
|
||||
:discoverable
|
||||
]
|
||||
|> Enum.reduce(%{}, fn key, acc ->
|
||||
|
|
|
@ -163,6 +163,7 @@ defp do_render("show.json", %{user: user} = opts) do
|
|||
|> maybe_put_chat_token(user, opts[:for], opts)
|
||||
|> maybe_put_activation_status(user, opts[:for])
|
||||
|> maybe_put_follow_requests_count(user, opts[:for])
|
||||
|> maybe_put_allow_following_move(user, opts[:for])
|
||||
|> maybe_put_unread_conversation_count(user, opts[:for])
|
||||
end
|
||||
|
||||
|
@ -239,6 +240,12 @@ defp maybe_put_notification_settings(data, %User{id: user_id} = user, %User{id:
|
|||
|
||||
defp maybe_put_notification_settings(data, _, _), do: data
|
||||
|
||||
defp maybe_put_allow_following_move(data, %User{id: user_id} = user, %User{id: user_id}) do
|
||||
Kernel.put_in(data, [:pleroma, :allow_following_move], user.allow_following_move)
|
||||
end
|
||||
|
||||
defp maybe_put_allow_following_move(data, _, _), do: data
|
||||
|
||||
defp maybe_put_activation_status(data, user, %User{is_admin: true}) do
|
||||
Kernel.put_in(data, [:pleroma, :deactivated], user.deactivated)
|
||||
end
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
defmodule Pleroma.Repo.Migrations.AddAlsoKnownAsToUsers do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:users) do
|
||||
add(:also_known_as, {:array, :string}, default: [])
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
defmodule Pleroma.Repo.Migrations.AddMoveSupportToUsers do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:users) do
|
||||
add(:also_known_as, {:array, :string}, default: [], null: false)
|
||||
add(:allow_following_move, :boolean, default: true, null: false)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1428,10 +1428,13 @@ test "create" do
|
|||
%{ap_id: old_ap_id} = old_user = insert(:user)
|
||||
%{ap_id: new_ap_id} = new_user = insert(:user, also_known_as: [old_ap_id])
|
||||
follower = insert(:user)
|
||||
follower_move_opted_out = insert(:user, allow_following_move: false)
|
||||
|
||||
User.follow(follower, old_user)
|
||||
User.follow(follower_move_opted_out, old_user)
|
||||
|
||||
assert User.following?(follower, old_user)
|
||||
assert User.following?(follower_move_opted_out, old_user)
|
||||
|
||||
assert {:ok, activity} = ActivityPub.move(old_user, new_user)
|
||||
|
||||
|
@ -1458,6 +1461,9 @@ test "create" do
|
|||
|
||||
refute User.following?(follower, old_user)
|
||||
assert User.following?(follower, new_user)
|
||||
|
||||
assert User.following?(follower_move_opted_out, old_user)
|
||||
refute User.following?(follower_move_opted_out, new_user)
|
||||
end
|
||||
|
||||
test "old user must be in the new user's `also_known_as` list" do
|
||||
|
|
|
@ -103,6 +103,21 @@ test "updates the user's locking status", %{conn: conn} do
|
|||
assert user["locked"] == true
|
||||
end
|
||||
|
||||
test "updates the user's allow_following_move", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
assert user.allow_following_move == true
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{allow_following_move: "false"})
|
||||
|
||||
assert refresh_record(user).allow_following_move == false
|
||||
assert user = json_response(conn, 200)
|
||||
assert user["pleroma"]["allow_following_move"] == false
|
||||
end
|
||||
|
||||
test "updates the user's default scope", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ test "Represent the user account for the account owner" do
|
|||
privacy = user.default_scope
|
||||
|
||||
assert %{
|
||||
pleroma: %{notification_settings: ^notification_settings},
|
||||
pleroma: %{notification_settings: ^notification_settings, allow_following_move: true},
|
||||
source: %{privacy: ^privacy}
|
||||
} = AccountView.render("show.json", %{user: user, for: user})
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue