Merge pull request 'User: stop passing the ignored is_active key to User.Query' (#8025) from lambadalambda/pleroma:fix/user-query-is-active into develop
Reviewed-on: https://git.pleroma.social/pleroma/pleroma/pulls/8025
This commit is contained in:
commit
7ccdd47134
5 changed files with 67 additions and 9 deletions
1
changelog.d/user-query-is-active.fix
Normal file
1
changelog.d/user-query-is-active.fix
Normal file
|
|
@ -0,0 +1 @@
|
|||
Fix deactivated users being counted in followers collections and getting admin emails, because User.Query ignored the is_active key
|
||||
|
|
@ -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
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue