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 @@ def binary_id(%User{} = user), do: binary_id(user.id)
def account_status(%User{deactivated: true}), do: :deactivated def account_status(%User{deactivated: true}), do: :deactivated
def account_status(%User{password_reset_pending: true}), do: :password_reset_pending 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_approved: false}), do: :approval_pending
def account_status(%User{local: true, is_confirmed: false}), do: :confirmation_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{}), do: :active def account_status(%User{}), do: :active
@spec visible_for(User.t(), User.t() | nil) :: @spec visible_for(User.t(), User.t() | nil) ::

View File

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

View File

@ -1563,14 +1563,9 @@ test "it deactivates a user, all follow relationships and all activities", %{use
end end
end end
describe "delete/1 when confirmation is pending" do test "delete/1 when confirmation is pending deletes the user" do
setup do
user = insert(:user, is_confirmed: false)
{:ok, user: user}
end
test "deletes user from database when activation required", %{user: user} do
clear_config([:instance, :account_activation_required], true) clear_config([:instance, :account_activation_required], true)
user = insert(:user, is_confirmed: false)
{:ok, job} = User.delete(user) {:ok, job} = User.delete(user)
{:ok, _} = ObanHelpers.perform(job) {:ok, _} = ObanHelpers.perform(job)
@ -1579,17 +1574,6 @@ test "deletes user from database when activation required", %{user: user} do
refute User.get_by_id(user.id) refute User.get_by_id(user.id)
end 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 test "delete/1 when approval is pending deletes the user" do
user = insert(:user, is_approved: false) user = insert(:user, is_approved: false)
@ -1830,13 +1814,6 @@ test "returns true when the account is unconfirmed and confirmation is required
assert User.visible_for(user, other_user) == :visible assert User.visible_for(user, other_user) == :visible
end 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 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) Pleroma.Config.put([:instance, :account_activation_required], true)

View File

@ -165,14 +165,6 @@ test "creates a notification", %{emoji_react: emoji_react, poster: poster} do
{:ok, delete: delete_user, user: user} {:ok, delete: delete_user, user: user}
end 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 test "when activation is required", %{delete: delete, user: user} do
clear_config([:instance, :account_activation_required], true) clear_config([:instance, :account_activation_required], true)
{:ok, _, _} = SideEffects.handle(delete) {:ok, _, _} = SideEffects.handle(delete)