Merge branch 'fix/active-user-query' into 'develop'

Active users must be confirmed, and other related fixes

See merge request pleroma/pleroma!3267
This commit is contained in:
Haelwenn 2021-01-20 20:07:30 +00:00
commit 91f74418b7
4 changed files with 9 additions and 47 deletions

View File

@ -289,15 +289,7 @@ defmodule Pleroma.User do
def account_status(%User{deactivated: true}), do: :deactivated
def account_status(%User{password_reset_pending: true}), do: :password_reset_pending
def account_status(%User{local: true, is_approved: false}), do: :approval_pending
def account_status(%User{local: true, is_confirmed: false}) do
if Config.get([:instance, :account_activation_required]) do
:confirmation_pending
else
:active
end
end
def account_status(%User{local: true, is_confirmed: false}), do: :confirmation_pending
def account_status(%User{}), do: :active
@spec visible_for(User.t(), User.t() | nil) ::

View File

@ -139,6 +139,7 @@ defmodule Pleroma.User.Query do
defp compose_query({:active, _}, query) do
User.restrict_deactivated(query)
|> where([u], u.is_approved == true)
|> where([u], u.is_confirmed == true)
end
defp compose_query({:legacy_active, _}, query) do

View File

@ -1563,14 +1563,9 @@ defmodule Pleroma.UserTest do
end
end
describe "delete/1 when confirmation is pending" do
setup do
user = insert(:user, is_confirmed: false)
{:ok, user: user}
end
test "deletes user from database when activation required", %{user: user} do
test "delete/1 when confirmation is pending deletes the user" do
clear_config([:instance, :account_activation_required], true)
user = insert(:user, is_confirmed: false)
{:ok, job} = User.delete(user)
{:ok, _} = ObanHelpers.perform(job)
@ -1579,17 +1574,6 @@ defmodule Pleroma.UserTest do
refute User.get_by_id(user.id)
end
test "deactivates user when activation is not required", %{user: user} do
clear_config([:instance, :account_activation_required], false)
{:ok, job} = User.delete(user)
{:ok, _} = ObanHelpers.perform(job)
assert %{deactivated: true} = User.get_cached_by_id(user.id)
assert %{deactivated: true} = User.get_by_id(user.id)
end
end
test "delete/1 when approval is pending deletes the user" do
user = insert(:user, is_approved: false)
@ -1830,13 +1814,6 @@ defmodule Pleroma.UserTest do
assert User.visible_for(user, other_user) == :visible
end
test "returns true when the account is unconfirmed and confirmation is not required" do
user = insert(:user, local: true, is_confirmed: false)
other_user = insert(:user, local: true)
assert User.visible_for(user, other_user) == :visible
end
test "returns true when the account is unconfirmed and being viewed by a privileged account (confirmation required)" do
Pleroma.Config.put([:instance, :account_activation_required], true)

View File

@ -165,14 +165,6 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
{:ok, delete: delete_user, user: user}
end
test "when activation is not required", %{delete: delete, user: user} do
clear_config([:instance, :account_activation_required], false)
{:ok, _, _} = SideEffects.handle(delete)
ObanHelpers.perform_all()
assert User.get_cached_by_id(user.id).deactivated
end
test "when activation is required", %{delete: delete, user: user} do
clear_config([:instance, :account_activation_required], true)
{:ok, _, _} = SideEffects.handle(delete)