Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85823656
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
6 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/changelog.d/user-query-is-active.fix b/changelog.d/user-query-is-active.fix
new file mode 100644
index 000000000..8f28d8a0e
--- /dev/null
+++ b/changelog.d/user-query-is-active.fix
@@ -0,0 +1 @@
+Fix deactivated users being counted in followers collections and getting admin emails, because User.Query ignored the is_active key
diff --git a/lib/mix/tasks/pleroma/email.ex b/lib/mix/tasks/pleroma/email.ex
index 37272c124..76725f65f 100644
--- a/lib/mix/tasks/pleroma/email.ex
+++ b/lib/mix/tasks/pleroma/email.ex
@@ -33,7 +33,7 @@ defmodule Mix.Tasks.Pleroma.Email do
Pleroma.User.Query.build(%{
local: true,
- is_active: true,
+ deactivated: false,
is_confirmed: false,
invisible: false
})
diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex
index 929fa1717..1035f2fce 100644
--- a/lib/mix/tasks/pleroma/user.ex
+++ b/lib/mix/tasks/pleroma/user.ex
@@ -362,7 +362,7 @@ defmodule Mix.Tasks.Pleroma.User do
Pleroma.User.Query.build(%{
local: true,
- is_active: true,
+ deactivated: false,
is_moderator: false,
is_admin: false,
invisible: false
@@ -380,7 +380,7 @@ defmodule Mix.Tasks.Pleroma.User do
Pleroma.User.Query.build(%{
local: true,
- is_active: true,
+ deactivated: false,
is_moderator: false,
is_admin: false,
invisible: false
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 3adc90c67..c0566c63d 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -969,7 +969,7 @@ defmodule Pleroma.User do
candidates = Config.get([:instance, :autofollowed_nicknames])
autofollowed_users =
- User.Query.build(%{nickname: candidates, local: true, is_active: true})
+ User.Query.build(%{nickname: candidates, local: true, deactivated: false})
|> Repo.all()
follow_all(user, autofollowed_users)
@@ -1401,7 +1401,7 @@ defmodule Pleroma.User do
@spec get_followers_query(User.t(), pos_integer() | nil) :: Ecto.Query.t()
def get_followers_query(%User{} = user, nil) do
- User.Query.build(%{followers: user, is_active: true})
+ User.Query.build(%{followers: user, deactivated: false})
end
def get_followers_query(%User{} = user, page) do
@@ -1476,7 +1476,7 @@ defmodule Pleroma.User do
|> where([u], not u.hide_follows)
|> select([u], u.id)
- User.Query.build(%{is_active: true})
+ User.Query.build(%{deactivated: false})
|> where([u], u.id not in ^[user.id, current_user.id])
|> join(:inner, [u], r in FollowingRelationship,
as: :followers_relationships,
@@ -1611,7 +1611,7 @@ defmodule Pleroma.User do
@spec get_users_from_set([String.t()], keyword()) :: [User.t()]
def get_users_from_set(ap_ids, opts \\ []) do
local_only = Keyword.get(opts, :local_only, true)
- criteria = %{ap_id: ap_ids, is_active: true}
+ criteria = %{ap_id: ap_ids, deactivated: false}
criteria = if local_only, do: Map.put(criteria, :local, true), else: criteria
User.Query.build(criteria)
@@ -1622,7 +1622,7 @@ defmodule Pleroma.User do
def get_recipients_from_activity(%Activity{recipients: to, actor: actor}) do
to = [actor | to]
- query = User.Query.build(%{recipients_from_activity: to, local: true, is_active: true})
+ query = User.Query.build(%{recipients_from_activity: to, local: true, deactivated: false})
query
|> Repo.all()
@@ -2473,7 +2473,7 @@ defmodule Pleroma.User do
@spec all_superusers() :: [User.t()]
def all_superusers do
- User.Query.build(%{super_users: true, local: true, is_active: true})
+ User.Query.build(%{super_users: true, local: true, deactivated: false})
|> Repo.all()
end
diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs
index ec5a2a12a..32d582b50 100644
--- a/test/pleroma/user_test.exs
+++ b/test/pleroma/user_test.exs
@@ -1197,11 +1197,32 @@ defmodule Pleroma.UserTest do
res = User.get_followers(user)
+ assert length(res) == 2
assert Enum.member?(res, follower_one)
assert Enum.member?(res, follower_two)
refute Enum.member?(res, not_follower)
end
+ test "does not return deactivated followers" do
+ user = insert(:user)
+ follower_one = insert(:user)
+ follower_two = insert(:user)
+ not_follower = insert(:user)
+
+ {:ok, follower_one, user} = User.follow(follower_one, user)
+ {:ok, follower_two, user} = User.follow(follower_two, user)
+
+ User.delete(follower_two)
+ follower_two = User.get_cached_by_id(follower_two.id)
+
+ res = User.get_followers(user)
+
+ assert length(res) == 1
+ assert Enum.member?(res, follower_one)
+ refute Enum.member?(res, follower_two)
+ refute Enum.member?(res, not_follower)
+ end
+
test "gets all friends (followed users) for a given user" do
user = insert(:user)
followed_one = insert(:user)
@@ -1215,10 +1236,34 @@ defmodule Pleroma.UserTest do
followed_one = User.get_cached_by_ap_id(followed_one.ap_id)
followed_two = User.get_cached_by_ap_id(followed_two.ap_id)
+
+ assert length(res) == 2
assert Enum.member?(res, followed_one)
assert Enum.member?(res, followed_two)
refute Enum.member?(res, not_followed)
end
+
+ test "does not return deactivated followed users (friends)" do
+ user = insert(:user)
+ followed_one = insert(:user)
+ followed_two = insert(:user)
+ not_followed = insert(:user)
+
+ {:ok, user, followed_one} = User.follow(user, followed_one)
+ {:ok, user, followed_two} = User.follow(user, followed_two)
+
+ User.delete(followed_two)
+
+ res = User.get_friends(user)
+
+ followed_one = User.get_cached_by_id(followed_one.id)
+ followed_two = User.get_cached_by_id(followed_two.id)
+
+ assert length(res) == 1
+ assert Enum.member?(res, followed_one)
+ refute Enum.member?(res, followed_two)
+ refute Enum.member?(res, not_followed)
+ end
end
describe "updating note and follower count" do
@@ -2964,6 +3009,18 @@ defmodule Pleroma.UserTest do
assert [%{id: ^id2}] = User.get_familiar_followers(user3, user1)
end
+
+ test "does not return deactivated users" do
+ user1 = insert(:user)
+ user2 = insert(:user)
+ user3 = insert(:user)
+
+ User.follow(user1, user2)
+ User.follow(user2, user3)
+ {:ok, _} = User.set_activation(user2, false)
+
+ assert [] = User.get_familiar_followers(user3, user1)
+ end
end
describe "account endorsements" do
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Oct 29, 7:59 AM (12 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1797750
Default Alt Text
(6 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline