Change user.deactivated field to user.is_active

This commit is contained in:
Mark Felder 2020-10-12 17:42:27 -05:00 committed by Mark Felder
parent cf367fdbd5
commit 860b5c7804
40 changed files with 125 additions and 107 deletions

View File

@ -33,7 +33,7 @@ def run(["resend_confirmation_emails"]) do
Pleroma.User.Query.build(%{ Pleroma.User.Query.build(%{
local: true, local: true,
deactivated: false, is_active: true,
confirmation_pending: true, confirmation_pending: true,
invisible: false invisible: false
}) })

View File

@ -111,10 +111,10 @@ def run(["toggle_activated", nickname]) do
start_pleroma() start_pleroma()
with %User{} = user <- User.get_cached_by_nickname(nickname) do with %User{} = user <- User.get_cached_by_nickname(nickname) do
{:ok, user} = User.deactivate(user, !user.deactivated) {:ok, user} = User.deactivate(user, user.is_active)
shell_info( shell_info(
"Activation status of #{nickname}: #{if(user.deactivated, do: "de", else: "")}activated" "Activation status of #{nickname}: #{unless(user.is_active, do: "de", else: "")}activated"
) )
else else
_ -> _ ->
@ -365,7 +365,7 @@ def run(["confirm_all"]) do
Pleroma.User.Query.build(%{ Pleroma.User.Query.build(%{
local: true, local: true,
deactivated: false, is_active: true,
is_moderator: false, is_moderator: false,
is_admin: false, is_admin: false,
invisible: false invisible: false
@ -383,7 +383,7 @@ def run(["unconfirm_all"]) do
Pleroma.User.Query.build(%{ Pleroma.User.Query.build(%{
local: true, local: true,
deactivated: false, is_active: true,
is_moderator: false, is_moderator: false,
is_admin: false, is_admin: false,
invisible: false invisible: false
@ -420,7 +420,7 @@ def run(["list"]) do
shell_info( shell_info(
"#{user.nickname} moderator: #{user.is_moderator}, admin: #{user.is_admin}, locked: #{ "#{user.nickname} moderator: #{user.is_moderator}, admin: #{user.is_admin}, locked: #{
user.is_locked user.is_locked
}, deactivated: #{user.deactivated}" }, is_active: #{user.is_active}"
) )
end) end)
end) end)

View File

@ -152,7 +152,7 @@ def get_follow_requests(%User{id: id}) do
|> join(:inner, [r], f in assoc(r, :follower)) |> join(:inner, [r], f in assoc(r, :follower))
|> where([r], r.state == ^:follow_pending) |> where([r], r.state == ^:follow_pending)
|> where([r], r.following_id == ^id) |> where([r], r.following_id == ^id)
|> where([r, f], f.deactivated != true) |> where([r, f], f.is_active == true)
|> select([r, f], f) |> select([r, f], f)
|> Repo.all() |> Repo.all()
end end

View File

@ -115,7 +115,7 @@ def for_user_query(user, opts \\ %{}) do
|> where( |> where(
[n, a], [n, a],
fragment( fragment(
"? not in (SELECT ap_id FROM users WHERE deactivated = 'true')", "? not in (SELECT ap_id FROM users WHERE is_active = 'false')",
a.actor a.actor
) )
) )

View File

@ -75,7 +75,7 @@ def calculate_stat_data do
users_query = users_query =
from(u in User, from(u in User,
where: u.deactivated != true, where: u.is_active == true,
where: u.local == true, where: u.local == true,
where: not is_nil(u.nickname), where: not is_nil(u.nickname),
where: not u.invisible where: not u.invisible

View File

@ -117,7 +117,7 @@ defmodule Pleroma.User do
field(:confirmation_token, :string, default: nil) field(:confirmation_token, :string, default: nil)
field(:default_scope, :string, default: "public") field(:default_scope, :string, default: "public")
field(:domain_blocks, {:array, :string}, default: []) field(:domain_blocks, {:array, :string}, default: [])
field(:deactivated, :boolean, default: false) field(:is_active, :boolean, default: true)
field(:no_rich_text, :boolean, default: false) field(:no_rich_text, :boolean, default: false)
field(:ap_enabled, :boolean, default: false) field(:ap_enabled, :boolean, default: false)
field(:is_moderator, :boolean, default: false) field(:is_moderator, :boolean, default: false)
@ -286,7 +286,7 @@ def binary_id(%User{} = user), do: binary_id(user.id)
@doc "Returns status account" @doc "Returns status account"
@spec account_status(User.t()) :: account_status() @spec account_status(User.t()) :: account_status()
def account_status(%User{deactivated: true}), do: :deactivated def account_status(%User{is_active: false}), 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, approval_pending: true}), do: :approval_pending def account_status(%User{local: true, approval_pending: true}), do: :approval_pending
@ -388,7 +388,7 @@ def ap_following(%User{} = user), do: "#{ap_id(user)}/following"
@spec restrict_deactivated(Ecto.Query.t()) :: Ecto.Query.t() @spec restrict_deactivated(Ecto.Query.t()) :: Ecto.Query.t()
def restrict_deactivated(query) do def restrict_deactivated(query) do
from(u in query, where: u.deactivated != ^true) from(u in query, where: u.is_active == ^true)
end end
defp truncate_fields_param(params) do defp truncate_fields_param(params) do
@ -785,7 +785,7 @@ defp autofollow_users(user) do
candidates = Config.get([:instance, :autofollowed_nicknames]) candidates = Config.get([:instance, :autofollowed_nicknames])
autofollowed_users = autofollowed_users =
User.Query.build(%{nickname: candidates, local: true, deactivated: false}) User.Query.build(%{nickname: candidates, local: true, is_active: true})
|> Repo.all() |> Repo.all()
follow_all(user, autofollowed_users) follow_all(user, autofollowed_users)
@ -946,7 +946,7 @@ def follow(%User{} = follower, %User{} = followed, state \\ :follow_accept) do
deny_follow_blocked = Config.get([:user, :deny_follow_blocked]) deny_follow_blocked = Config.get([:user, :deny_follow_blocked])
cond do cond do
followed.deactivated -> followed.is_active == false ->
{:error, "Could not follow user: #{followed.nickname} is deactivated."} {:error, "Could not follow user: #{followed.nickname} is deactivated."}
deny_follow_blocked and blocks?(followed, follower) -> deny_follow_blocked and blocks?(followed, follower) ->
@ -1181,7 +1181,7 @@ def get_or_fetch_by_nickname(nickname) do
@spec get_followers_query(User.t(), pos_integer() | nil) :: Ecto.Query.t() @spec get_followers_query(User.t(), pos_integer() | nil) :: Ecto.Query.t()
def get_followers_query(%User{} = user, nil) do def get_followers_query(%User{} = user, nil) do
User.Query.build(%{followers: user, deactivated: false}) User.Query.build(%{followers: user, is_active: true})
end end
def get_followers_query(%User{} = user, page) do def get_followers_query(%User{} = user, page) do
@ -1357,7 +1357,7 @@ def update_following_count(%User{local: true} = user) do
@spec get_users_from_set([String.t()], keyword()) :: [User.t()] @spec get_users_from_set([String.t()], keyword()) :: [User.t()]
def get_users_from_set(ap_ids, opts \\ []) do def get_users_from_set(ap_ids, opts \\ []) do
local_only = Keyword.get(opts, :local_only, true) local_only = Keyword.get(opts, :local_only, true)
criteria = %{ap_id: ap_ids, deactivated: false} criteria = %{ap_id: ap_ids, is_active: true}
criteria = if local_only, do: Map.put(criteria, :local, true), else: criteria criteria = if local_only, do: Map.put(criteria, :local, true), else: criteria
User.Query.build(criteria) User.Query.build(criteria)
@ -1368,7 +1368,7 @@ def get_users_from_set(ap_ids, opts \\ []) do
def get_recipients_from_activity(%Activity{recipients: to, actor: actor}) do def get_recipients_from_activity(%Activity{recipients: to, actor: actor}) do
to = [actor | to] to = [actor | to]
query = User.Query.build(%{recipients_from_activity: to, local: true, deactivated: false}) query = User.Query.build(%{recipients_from_activity: to, local: true, is_active: true})
query query
|> Repo.all() |> Repo.all()
@ -1600,7 +1600,7 @@ def deactivate(users, status) when is_list(users) do
end end
def deactivate(%User{} = user, status) do def deactivate(%User{} = user, status) do
with {:ok, user} <- set_activation_status(user, status) do with {:ok, user} <- set_activation_status(user, !status) do
user user
|> get_followers() |> get_followers()
|> Enum.filter(& &1.local) |> Enum.filter(& &1.local)
@ -1688,7 +1688,7 @@ def purge_user_changeset(user) do
registration_reason: nil, registration_reason: nil,
confirmation_token: nil, confirmation_token: nil,
domain_blocks: [], domain_blocks: [],
deactivated: true, is_active: false,
ap_enabled: false, ap_enabled: false,
is_moderator: false, is_moderator: false,
is_admin: false, is_admin: false,
@ -2056,7 +2056,7 @@ def error_user(ap_id) do
@spec all_superusers() :: [User.t()] @spec all_superusers() :: [User.t()]
def all_superusers do def all_superusers do
User.Query.build(%{super_users: true, local: true, deactivated: false}) User.Query.build(%{super_users: true, local: true, is_active: true})
|> Repo.all() |> Repo.all()
end end
@ -2097,7 +2097,7 @@ def list_inactive_users_query(inactivity_threshold \\ 7) do
left_join: a in Pleroma.Activity, left_join: a in Pleroma.Activity,
on: u.ap_id == a.actor, on: u.ap_id == a.actor,
where: not is_nil(u.nickname), where: not is_nil(u.nickname),
where: u.deactivated != ^true, where: u.is_active == ^true,
where: u.id not in ^has_read_notifications, where: u.id not in ^has_read_notifications,
group_by: u.id, group_by: u.id,
having: having:
@ -2218,9 +2218,9 @@ def change_email(user, email) do
end end
# Internal function; public one is `deactivate/2` # Internal function; public one is `deactivate/2`
defp set_activation_status(user, deactivated) do defp set_activation_status(user, status) do
user user
|> cast(%{deactivated: deactivated}, [:deactivated]) |> cast(%{is_active: status}, [:is_active])
|> update_and_set_cache() |> update_and_set_cache()
end end

View File

@ -151,7 +151,7 @@ defp compose_query({:deactivated, false}, query) do
end end
defp compose_query({:deactivated, true}, query) do defp compose_query({:deactivated, true}, query) do
where(query, [u], u.deactivated == ^true) where(query, [u], u.is_active == false)
end end
defp compose_query({:confirmation_pending, bool}, query) do defp compose_query({:confirmation_pending, bool}, query) do

View File

@ -56,7 +56,7 @@ defp check_actor_is_active(nil), do: true
defp check_actor_is_active(actor) when is_binary(actor) do defp check_actor_is_active(actor) when is_binary(actor) do
case User.get_cached_by_ap_id(actor) do case User.get_cached_by_ap_id(actor) do
%User{deactivated: deactivated} -> not deactivated %User{is_active: true} -> true
_ -> false _ -> false
end end
end end

View File

@ -35,7 +35,7 @@ def validate_actor_presence(cng, options \\ []) do
cng cng
|> validate_change(field_name, fn field_name, actor -> |> validate_change(field_name, fn field_name, actor ->
case User.get_cached_by_ap_id(actor) do case User.get_cached_by_ap_id(actor) do
%User{deactivated: true} -> %User{is_active: false} ->
[{field_name, "user is deactivated"}] [{field_name, "user is deactivated"}]
%User{} -> %User{} ->

View File

@ -172,9 +172,9 @@ def show(%{assigns: %{user: admin}} = conn, %{"nickname" => nickname}) do
def toggle_activation(%{assigns: %{user: admin}} = conn, %{"nickname" => nickname}) do def toggle_activation(%{assigns: %{user: admin}} = conn, %{"nickname" => nickname}) do
user = User.get_cached_by_nickname(nickname) user = User.get_cached_by_nickname(nickname)
{:ok, updated_user} = User.deactivate(user, !user.deactivated) {:ok, updated_user} = User.deactivate(user, !user.is_active)
action = if user.deactivated, do: "activate", else: "deactivate" action = if !user.is_active, do: "activate", else: "deactivate"
ModerationLog.insert_log(%{ ModerationLog.insert_log(%{
actor: admin, actor: admin,

View File

@ -73,7 +73,7 @@ def render("show.json", %{user: user}) do
"avatar" => avatar, "avatar" => avatar,
"nickname" => user.nickname, "nickname" => user.nickname,
"display_name" => display_name, "display_name" => display_name,
"deactivated" => user.deactivated, "is_active" => user.is_active,
"local" => user.local, "local" => user.local,
"roles" => User.roles(user), "roles" => User.roles(user),
"tags" => user.tags || [], "tags" => user.tags || [],

View File

@ -182,7 +182,7 @@ defp account_admin do
properties: properties:
Map.merge(Account.schema().properties, %{ Map.merge(Account.schema().properties, %{
nickname: %Schema{type: :string}, nickname: %Schema{type: :string},
deactivated: %Schema{type: :boolean}, is_active: %Schema{type: :boolean},
local: %Schema{type: :boolean}, local: %Schema{type: :boolean},
roles: %Schema{ roles: %Schema{
type: :object, type: :object,

View File

@ -132,7 +132,7 @@ def admin_account do
avatar: %Schema{type: :string}, avatar: %Schema{type: :string},
nickname: %Schema{type: :string}, nickname: %Schema{type: :string},
display_name: %Schema{type: :string}, display_name: %Schema{type: :string},
deactivated: %Schema{type: :boolean}, is_active: %Schema{type: :boolean},
local: %Schema{type: :boolean}, local: %Schema{type: :boolean},
roles: %Schema{ roles: %Schema{
type: :object, type: :object,

View File

@ -376,7 +376,7 @@ defp maybe_put_allow_following_move(data, %User{id: user_id} = user, %User{id: u
defp maybe_put_allow_following_move(data, _, _), do: data defp maybe_put_allow_following_move(data, _, _), do: data
defp maybe_put_activation_status(data, user, %User{is_admin: true}) do defp maybe_put_activation_status(data, user, %User{is_admin: true}) do
Kernel.put_in(data, [:pleroma, :deactivated], user.deactivated) Kernel.put_in(data, [:pleroma, :deactivated], !user.is_active)
end end
defp maybe_put_activation_status(data, _, _), do: data defp maybe_put_activation_status(data, _, _), do: data

View File

@ -14,7 +14,7 @@ defmodule Pleroma.Web.MongooseIM.MongooseIMController do
plug(RateLimiter, [name: :authentication, params: ["user"]] when action == :check_password) plug(RateLimiter, [name: :authentication, params: ["user"]] when action == :check_password)
def user_exists(conn, %{"user" => username}) do def user_exists(conn, %{"user" => username}) do
with %User{} <- Repo.get_by(User, nickname: username, local: true, deactivated: false) do with %User{} <- Repo.get_by(User, nickname: username, local: true, is_active: true) do
conn conn
|> json(true) |> json(true)
else else
@ -26,7 +26,7 @@ def user_exists(conn, %{"user" => username}) do
end end
def check_password(conn, %{"user" => username, "pass" => password}) do def check_password(conn, %{"user" => username, "pass" => password}) do
with %User{password_hash: password_hash, deactivated: false} <- with %User{password_hash: password_hash, is_active: true} <-
Repo.get_by(User, nickname: username, local: true), Repo.get_by(User, nickname: username, local: true),
true <- AuthenticationPlug.checkpw(password, password_hash) do true <- AuthenticationPlug.checkpw(password, password_hash) do
conn conn

View File

@ -26,7 +26,7 @@ defp fetch_users(user_ap_ids) do
user_ap_ids user_ap_ids
|> Enum.map(&Pleroma.User.get_cached_by_ap_id/1) |> Enum.map(&Pleroma.User.get_cached_by_ap_id/1)
|> Enum.filter(fn |> Enum.filter(fn
%{deactivated: false} -> true %{is_active: true} -> true
_ -> false _ -> false
end) end)
end end

View File

@ -59,7 +59,7 @@ defp create_user(params, opts) do
def password_reset(nickname_or_email) do def password_reset(nickname_or_email) do
with true <- is_binary(nickname_or_email), with true <- is_binary(nickname_or_email),
%User{local: true, email: email, deactivated: false} = user when is_binary(email) <- %User{local: true, email: email, is_active: true} = user when is_binary(email) <-
User.get_by_nickname_or_email(nickname_or_email), User.get_by_nickname_or_email(nickname_or_email),
{:ok, token_record} <- Pleroma.PasswordResetToken.create_token(user) do {:ok, token_record} <- Pleroma.PasswordResetToken.create_token(user) do
user user

View File

@ -0,0 +1,18 @@
defmodule Pleroma.Repo.Migrations.RefactorDeactivatedUserField do
use Ecto.Migration
def up do
# Flip the values before we change the meaning of the column
execute("UPDATE users SET deactivated = NOT deactivated;")
execute("ALTER TABLE users RENAME COLUMN deactivated TO is_active;")
execute("ALTER TABLE users ALTER COLUMN is_active SET DEFAULT true;")
execute("ALTER INDEX users_deactivated_index RENAME TO users_is_active_index;")
end
def down do
execute("UPDATE users SET is_active = NOT is_active;")
execute("ALTER TABLE users RENAME COLUMN is_active TO deactivated;")
execute("ALTER TABLE users ALTER COLUMN deactivated SET DEFAULT false;")
execute("ALTER INDEX users_is_active_index RENAME TO users_deactivated_index;")
end
end

View File

@ -63,7 +63,7 @@ test "Sends confirmation emails" do
insert(:user, %{ insert(:user, %{
confirmation_pending: true, confirmation_pending: true,
confirmation_token: "mytoken", confirmation_token: "mytoken",
deactivated: false, is_active: true,
email: "local1@pleroma.com", email: "local1@pleroma.com",
local: true local: true
}) })
@ -72,7 +72,7 @@ test "Sends confirmation emails" do
insert(:user, %{ insert(:user, %{
confirmation_pending: true, confirmation_pending: true,
confirmation_token: "mytoken", confirmation_token: "mytoken",
deactivated: false, is_active: true,
email: "local2@pleroma.com", email: "local2@pleroma.com",
local: true local: true
}) })
@ -90,28 +90,28 @@ test "Does not send confirmation email to inappropriate users" do
insert(:user, %{ insert(:user, %{
confirmation_pending: false, confirmation_pending: false,
confirmation_token: "mytoken", confirmation_token: "mytoken",
deactivated: false, is_active: true,
email: "confirmed@pleroma.com", email: "confirmed@pleroma.com",
local: true local: true
}) })
# remote user # remote user
insert(:user, %{ insert(:user, %{
deactivated: false, is_active: true,
email: "remote@not-pleroma.com", email: "remote@not-pleroma.com",
local: false local: false
}) })
# deactivated user = # deactivated user =
insert(:user, %{ insert(:user, %{
deactivated: true, is_active: false,
email: "deactivated@pleroma.com", email: "deactivated@pleroma.com",
local: false local: false
}) })
# invisible user # invisible user
insert(:user, %{ insert(:user, %{
deactivated: false, is_active: true,
email: "invisible@pleroma.com", email: "invisible@pleroma.com",
local: true, local: true,
invisible: true invisible: true

View File

@ -102,7 +102,7 @@ test "user is deleted" do
assert_received {:mix_shell, :info, [message]} assert_received {:mix_shell, :info, [message]}
assert message =~ " deleted" assert message =~ " deleted"
assert %{deactivated: true} = User.get_by_nickname(user.nickname) assert %{is_active: false} = User.get_by_nickname(user.nickname)
assert called(Pleroma.Web.Federator.publish(:_)) assert called(Pleroma.Web.Federator.publish(:_))
end end
@ -140,7 +140,7 @@ test "a remote user's create activity is deleted when the object has been pruned
assert_received {:mix_shell, :info, [message]} assert_received {:mix_shell, :info, [message]}
assert message =~ " deleted" assert message =~ " deleted"
assert %{deactivated: true} = User.get_by_nickname(user.nickname) assert %{is_active: false} = User.get_by_nickname(user.nickname)
assert called(Pleroma.Web.Federator.publish(:_)) assert called(Pleroma.Web.Federator.publish(:_))
refute Pleroma.Repo.get(Pleroma.Activity, like_activity.id) refute Pleroma.Repo.get(Pleroma.Activity, like_activity.id)
@ -167,11 +167,11 @@ test "user is deactivated" do
assert message =~ " deactivated" assert message =~ " deactivated"
user = User.get_cached_by_nickname(user.nickname) user = User.get_cached_by_nickname(user.nickname)
assert user.deactivated refute user.is_active
end end
test "user is activated" do test "user is activated" do
user = insert(:user, deactivated: true) user = insert(:user, is_active: false)
Mix.Tasks.Pleroma.User.run(["toggle_activated", user.nickname]) Mix.Tasks.Pleroma.User.run(["toggle_activated", user.nickname])
@ -179,7 +179,7 @@ test "user is activated" do
assert message =~ " activated" assert message =~ " activated"
user = User.get_cached_by_nickname(user.nickname) user = User.get_cached_by_nickname(user.nickname)
refute user.deactivated assert user.is_active
end end
test "no user to toggle" do test "no user to toggle" do
@ -210,7 +210,7 @@ test "user is unsubscribed" do
user = User.get_cached_by_nickname(user.nickname) user = User.get_cached_by_nickname(user.nickname)
assert Enum.empty?(Enum.filter(User.get_friends(user), & &1.local)) assert Enum.empty?(Enum.filter(User.get_friends(user), & &1.local))
assert user.deactivated refute user.is_active
end end
test "no user to deactivate" do test "no user to deactivate" do

View File

@ -202,11 +202,11 @@ test "doesn't return already accepted or duplicate follow requests" do
test "doesn't return follow requests for deactivated accounts" do test "doesn't return follow requests for deactivated accounts" do
locked = insert(:user, is_locked: true) locked = insert(:user, is_locked: true)
pending_follower = insert(:user, %{deactivated: true}) pending_follower = insert(:user, %{is_active: false})
CommonAPI.follow(pending_follower, locked) CommonAPI.follow(pending_follower, locked)
assert true == pending_follower.deactivated refute pending_follower.is_active
assert [] = User.get_follow_requests(locked) assert [] = User.get_follow_requests(locked)
end end
@ -275,7 +275,7 @@ test "follow takes a user and another user" do
test "can't follow a deactivated users" do test "can't follow a deactivated users" do
user = insert(:user) user = insert(:user)
followed = insert(:user, %{deactivated: true}) followed = insert(:user, %{is_active: false})
{:error, _} = User.follow(user, followed) {:error, _} = User.follow(user, followed)
end end
@ -1316,11 +1316,11 @@ test "has following" do
describe ".deactivate" do describe ".deactivate" do
test "can de-activate then re-activate a user" do test "can de-activate then re-activate a user" do
user = insert(:user) user = insert(:user)
assert false == user.deactivated assert user.is_active
{:ok, user} = User.deactivate(user) {:ok, user} = User.deactivate(user)
assert true == user.deactivated refute user.is_active
{:ok, user} = User.deactivate(user, false) {:ok, user} = User.deactivate(user, false)
assert false == user.deactivated assert user.is_active
end end
test "hide a user from followers" do test "hide a user from followers" do
@ -1544,7 +1544,7 @@ test "it deactivates a user, all follow relationships and all activities", %{use
follower = User.get_cached_by_id(follower.id) follower = User.get_cached_by_id(follower.id)
refute User.following?(follower, user) refute User.following?(follower, user)
assert %{deactivated: true} = User.get_by_id(user.id) assert %{is_active: false} = User.get_by_id(user.id)
assert [] == User.get_follow_requests(locked_user) assert [] == User.get_follow_requests(locked_user)
@ -1585,8 +1585,8 @@ test "deactivates user when activation is not required", %{user: user} do
{:ok, job} = User.delete(user) {:ok, job} = User.delete(user)
{:ok, _} = ObanHelpers.perform(job) {:ok, _} = ObanHelpers.perform(job)
assert %{deactivated: true} = User.get_cached_by_id(user.id) assert %{is_active: false} = User.get_cached_by_id(user.id)
assert %{deactivated: true} = User.get_by_id(user.id) assert %{is_active: false} = User.get_by_id(user.id)
end end
end end
@ -1622,7 +1622,7 @@ test "delete/1 purges a user when they wouldn't be fully deleted" do
registration_reason: "ahhhhh", registration_reason: "ahhhhh",
confirmation_token: "qqqq", confirmation_token: "qqqq",
domain_blocks: ["lain.com"], domain_blocks: ["lain.com"],
deactivated: true, is_active: false,
ap_enabled: true, ap_enabled: true,
is_moderator: true, is_moderator: true,
is_admin: true, is_admin: true,
@ -1664,7 +1664,7 @@ test "delete/1 purges a user when they wouldn't be fully deleted" do
registration_reason: nil, registration_reason: nil,
confirmation_token: nil, confirmation_token: nil,
domain_blocks: [], domain_blocks: [],
deactivated: true, is_active: false,
ap_enabled: false, ap_enabled: false,
is_moderator: false, is_moderator: false,
is_admin: false, is_admin: false,
@ -1750,7 +1750,7 @@ test "returns :password_reset_pending for user with reset password" do
end end
test "returns :deactivated for deactivated user" do test "returns :deactivated for deactivated user" do
user = insert(:user, local: true, confirmation_pending: false, deactivated: true) user = insert(:user, local: true, confirmation_pending: false, is_active: false)
assert User.account_status(user) == :deactivated assert User.account_status(user) == :deactivated
end end
@ -1908,7 +1908,7 @@ test "Users are inactive by default" do
users = users =
Enum.map(1..total, fn _ -> Enum.map(1..total, fn _ ->
insert(:user, last_digest_emailed_at: days_ago(20), deactivated: false) insert(:user, last_digest_emailed_at: days_ago(20), is_active: true)
end) end)
inactive_users_ids = inactive_users_ids =
@ -1926,7 +1926,7 @@ test "Only includes users who has no recent activity" do
users = users =
Enum.map(1..total, fn _ -> Enum.map(1..total, fn _ ->
insert(:user, last_digest_emailed_at: days_ago(20), deactivated: false) insert(:user, last_digest_emailed_at: days_ago(20), is_active: true)
end) end)
{inactive, active} = Enum.split(users, trunc(total / 2)) {inactive, active} = Enum.split(users, trunc(total / 2))
@ -1959,7 +1959,7 @@ test "Only includes users with no read notifications" do
users = users =
Enum.map(1..total, fn _ -> Enum.map(1..total, fn _ ->
insert(:user, last_digest_emailed_at: days_ago(20), deactivated: false) insert(:user, last_digest_emailed_at: days_ago(20), is_active: true)
end) end)
[sender | recipients] = users [sender | recipients] = users
@ -2029,7 +2029,7 @@ test "it returns a list of AP ids for a given set of nicknames" do
user1 = insert(:user, local: false, ap_id: "http://localhost:4001/users/masto_closed") user1 = insert(:user, local: false, ap_id: "http://localhost:4001/users/masto_closed")
user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2") user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2")
insert(:user, local: true) insert(:user, local: true)
insert(:user, local: false, deactivated: true) insert(:user, local: false, is_active: false)
{:ok, user1: user1, user2: user2} {:ok, user1: user1, user2: user2}
end end

View File

@ -39,7 +39,7 @@ test "it handles user deletions", %{delete_user: delete, user: user} do
{:ok, _delete, _} = SideEffects.handle(delete) {:ok, _delete, _} = SideEffects.handle(delete)
ObanHelpers.perform_all() ObanHelpers.perform_all()
assert User.get_cached_by_ap_id(user.ap_id).deactivated refute User.get_cached_by_ap_id(user.ap_id).is_active
end end
end end

View File

@ -170,7 +170,7 @@ test "when activation is not required", %{delete: delete, user: user} do
{:ok, _, _} = SideEffects.handle(delete) {:ok, _, _} = SideEffects.handle(delete)
ObanHelpers.perform_all() ObanHelpers.perform_all()
assert User.get_cached_by_id(user.id).deactivated refute User.get_cached_by_id(user.id).is_active
end end
test "when activation is required", %{delete: delete, user: user} do test "when activation is required", %{delete: delete, user: user} do

View File

@ -134,7 +134,7 @@ test "it doesn't work for deactivated users" do
ap_id: data["actor"], ap_id: data["actor"],
local: false, local: false,
last_refreshed_at: DateTime.utc_now(), last_refreshed_at: DateTime.utc_now(),
deactivated: true is_active: false
) )
_recipient = insert(:user, ap_id: List.first(data["to"]), local: true) _recipient = insert(:user, ap_id: List.first(data["to"]), local: true)

View File

@ -97,7 +97,7 @@ test "it works for incoming user deletes" do
{:ok, _} = Transmogrifier.handle_incoming(data) {:ok, _} = Transmogrifier.handle_incoming(data)
ObanHelpers.perform_all() ObanHelpers.perform_all()
assert User.get_cached_by_ap_id(ap_id).deactivated refute User.get_cached_by_ap_id(ap_id).is_active
end end
test "it fails for incoming user deletes with spoofed origin" do test "it fails for incoming user deletes with spoofed origin" do

View File

@ -154,7 +154,7 @@ test "it does not crash if the object in inReplyTo can't be fetched" do
test "it does not work for deactivated users" do test "it does not work for deactivated users" do
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Jason.decode!() data = File.read!("test/fixtures/mastodon-post-activity.json") |> Jason.decode!()
insert(:user, ap_id: data["actor"], deactivated: true) insert(:user, ap_id: data["actor"], is_active: false)
assert {:error, _} = Transmogrifier.handle_incoming(data) assert {:error, _} = Transmogrifier.handle_incoming(data)
end end

View File

@ -47,7 +47,7 @@ test "shows activity", %{conn: conn} do
assert account["id"] == actor.id assert account["id"] == actor.id
assert account["nickname"] == actor.nickname assert account["nickname"] == actor.nickname
assert account["deactivated"] == actor.deactivated assert account["is_active"] == actor.is_active
assert account["confirmation_pending"] == actor.confirmation_pending assert account["confirmation_pending"] == actor.confirmation_pending
end end
end end

View File

@ -169,7 +169,7 @@ test "single user", %{admin: admin, conn: conn} do
assert user.note_count == 1 assert user.note_count == 1
assert user.follower_count == 1 assert user.follower_count == 1
assert user.following_count == 1 assert user.following_count == 1
refute user.deactivated assert user.is_active
with_mock Pleroma.Web.Federator, with_mock Pleroma.Web.Federator,
publish: fn _ -> nil end, publish: fn _ -> nil end,
@ -181,7 +181,7 @@ test "single user", %{admin: admin, conn: conn} do
ObanHelpers.perform_all() ObanHelpers.perform_all()
assert User.get_by_nickname(user.nickname).deactivated refute User.get_by_nickname(user.nickname).is_active
log_entry = Repo.one(ModerationLog) log_entry = Repo.one(ModerationLog)
@ -191,7 +191,7 @@ test "single user", %{admin: admin, conn: conn} do
assert json_response(conn, 200) == [user.nickname] assert json_response(conn, 200) == [user.nickname]
user = Repo.get(User, user.id) user = Repo.get(User, user.id)
assert user.deactivated refute user.is_active
assert user.avatar == %{} assert user.avatar == %{}
assert user.banner == %{} assert user.banner == %{}
@ -621,7 +621,7 @@ test "only local users with no query", %{conn: conn, admin: old_admin} do
"roles" => %{"admin" => true, "moderator" => false} "roles" => %{"admin" => true, "moderator" => false}
}), }),
user_response(old_admin, %{ user_response(old_admin, %{
"deactivated" => false, "is_active" => true,
"roles" => %{"admin" => true, "moderator" => false} "roles" => %{"admin" => true, "moderator" => false}
}) })
] ]
@ -694,11 +694,11 @@ test "load only admins", %{conn: conn, admin: admin} do
users = users =
[ [
user_response(admin, %{ user_response(admin, %{
"deactivated" => false, "is_active" => true,
"roles" => %{"admin" => true, "moderator" => false} "roles" => %{"admin" => true, "moderator" => false}
}), }),
user_response(second_admin, %{ user_response(second_admin, %{
"deactivated" => false, "is_active" => true,
"roles" => %{"admin" => true, "moderator" => false} "roles" => %{"admin" => true, "moderator" => false}
}) })
] ]
@ -723,7 +723,7 @@ test "load only moderators", %{conn: conn} do
"page_size" => 50, "page_size" => 50,
"users" => [ "users" => [
user_response(moderator, %{ user_response(moderator, %{
"deactivated" => false, "is_active" => true,
"roles" => %{"admin" => false, "moderator" => true} "roles" => %{"admin" => false, "moderator" => true}
}) })
] ]
@ -839,10 +839,10 @@ test "`active` filters out users pending approval", %{token: token} do
test "it works with multiple filters" do test "it works with multiple filters" do
admin = insert(:user, nickname: "john", is_admin: true) admin = insert(:user, nickname: "john", is_admin: true)
token = insert(:oauth_admin_token, user: admin) token = insert(:oauth_admin_token, user: admin)
user = insert(:user, nickname: "bob", local: false, deactivated: true) user = insert(:user, nickname: "bob", local: false, is_active: false)
insert(:user, nickname: "ken", local: true, deactivated: true) insert(:user, nickname: "ken", local: true, is_active: false)
insert(:user, nickname: "bobb", local: false, deactivated: false) insert(:user, nickname: "bobb", local: false, is_active: true)
conn = conn =
build_conn() build_conn()
@ -873,8 +873,8 @@ test "it omits relay user", %{admin: admin, conn: conn} do
end end
test "PATCH /api/pleroma/admin/users/activate", %{admin: admin, conn: conn} do test "PATCH /api/pleroma/admin/users/activate", %{admin: admin, conn: conn} do
user_one = insert(:user, deactivated: true) user_one = insert(:user, is_active: false)
user_two = insert(:user, deactivated: true) user_two = insert(:user, is_active: false)
conn = conn =
patch( patch(
@ -884,7 +884,7 @@ test "PATCH /api/pleroma/admin/users/activate", %{admin: admin, conn: conn} do
) )
response = json_response(conn, 200) response = json_response(conn, 200)
assert Enum.map(response["users"], & &1["deactivated"]) == [false, false] assert Enum.map(response["users"], & &1["is_active"]) == [true, true]
log_entry = Repo.one(ModerationLog) log_entry = Repo.one(ModerationLog)
@ -893,8 +893,8 @@ test "PATCH /api/pleroma/admin/users/activate", %{admin: admin, conn: conn} do
end end
test "PATCH /api/pleroma/admin/users/deactivate", %{admin: admin, conn: conn} do test "PATCH /api/pleroma/admin/users/deactivate", %{admin: admin, conn: conn} do
user_one = insert(:user, deactivated: false) user_one = insert(:user, is_active: true)
user_two = insert(:user, deactivated: false) user_two = insert(:user, is_active: true)
conn = conn =
patch( patch(
@ -904,7 +904,7 @@ test "PATCH /api/pleroma/admin/users/deactivate", %{admin: admin, conn: conn} do
) )
response = json_response(conn, 200) response = json_response(conn, 200)
assert Enum.map(response["users"], & &1["deactivated"]) == [true, true] assert Enum.map(response["users"], & &1["is_active"]) == [false, false]
log_entry = Repo.one(ModerationLog) log_entry = Repo.one(ModerationLog)
@ -940,7 +940,7 @@ test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation", %{admin: admi
assert json_response(conn, 200) == assert json_response(conn, 200) ==
user_response( user_response(
user, user,
%{"deactivated" => !user.deactivated} %{"is_active" => user.is_active}
) )
log_entry = Repo.one(ModerationLog) log_entry = Repo.one(ModerationLog)
@ -951,7 +951,7 @@ test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation", %{admin: admi
defp user_response(user, attrs \\ %{}) do defp user_response(user, attrs \\ %{}) do
%{ %{
"deactivated" => user.deactivated, "is_active" => user.is_active,
"id" => user.id, "id" => user.id,
"email" => user.email, "email" => user.email,
"nickname" => user.nickname, "nickname" => user.nickname,

View File

@ -47,9 +47,9 @@ test "it returns local/external users" do
end end
test "it returns active/deactivated users" do test "it returns active/deactivated users" do
insert(:user, deactivated: true) insert(:user, is_active: false)
insert(:user, deactivated: true) insert(:user, is_active: false)
insert(:user, deactivated: false) insert(:user, is_active: true)
{:ok, _results, active_count} = {:ok, _results, active_count} =
Search.user(%{ Search.user(%{
@ -70,7 +70,7 @@ test "it returns active/deactivated users" do
test "it returns specific user" do test "it returns specific user" do
insert(:user) insert(:user)
insert(:user) insert(:user)
user = insert(:user, nickname: "bob", local: true, deactivated: false) user = insert(:user, nickname: "bob", local: true, is_active: true)
{:ok, _results, total_count} = Search.user(%{query: ""}) {:ok, _results, total_count} = Search.user(%{query: ""})

View File

@ -518,7 +518,7 @@ test "it adds an emoji on an external site" do
end end
test "deactivated users can't post" do test "deactivated users can't post" do
user = insert(:user, deactivated: true) user = insert(:user, is_active: false)
assert {:error, _} = CommonAPI.post(user, %{status: "ye"}) assert {:error, _} = CommonAPI.post(user, %{status: "ye"})
end end

View File

@ -126,7 +126,7 @@ test "returns 404 for internal.fetch actor", %{conn: conn} do
end end
test "returns 404 for deactivated user", %{conn: conn} do test "returns 404 for deactivated user", %{conn: conn} do
user = insert(:user, deactivated: true) user = insert(:user, is_active: false)
assert %{"error" => "Can't find user"} = assert %{"error" => "Can't find user"} =
conn conn
@ -256,7 +256,7 @@ test "works with announces that are just addressed to public", %{conn: conn} do
end end
test "deactivated user", %{conn: conn} do test "deactivated user", %{conn: conn} do
user = insert(:user, deactivated: true) user = insert(:user, is_active: false)
assert %{"error" => "Can't find user"} == assert %{"error" => "Can't find user"} ==
conn conn

View File

@ -136,7 +136,7 @@ test "it returns 204 when user is not local", %{conn: conn, user: user} do
end end
test "it returns 204 when user is deactivated", %{conn: conn, user: user} do test "it returns 204 when user is deactivated", %{conn: conn, user: user} do
{:ok, user} = Repo.update(Ecto.Changeset.change(user, deactivated: true, local: true)) {:ok, user} = Repo.update(Ecto.Changeset.change(user, is_active: false, local: true))
conn = post(conn, "/auth/password?email=#{user.email}") conn = post(conn, "/auth/password?email=#{user.email}")
assert empty_json_response(conn) assert empty_json_response(conn)

View File

@ -57,7 +57,7 @@ test "get instance stats", %{conn: conn} do
user = insert(:user, %{local: true}) user = insert(:user, %{local: true})
user2 = insert(:user, %{local: true}) user2 = insert(:user, %{local: true})
{:ok, _user2} = User.deactivate(user2, !user2.deactivated) {:ok, _user2} = User.deactivate(user2, user2.is_active)
insert(:user, %{local: false, nickname: "u@peer1.com"}) insert(:user, %{local: false, nickname: "u@peer1.com"})
insert(:user, %{local: false, nickname: "u@peer2.com"}) insert(:user, %{local: false, nickname: "u@peer2.com"})

View File

@ -16,7 +16,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
describe "follow/3" do describe "follow/3" do
test "returns error when followed user is deactivated" do test "returns error when followed user is deactivated" do
follower = insert(:user) follower = insert(:user)
user = insert(:user, local: true, deactivated: true) user = insert(:user, local: true, is_active: false)
assert {:error, _error} = MastodonAPI.follow(follower, user) assert {:error, _error} = MastodonAPI.follow(follower, user)
end end

View File

@ -211,7 +211,7 @@ test "Represent a Funkwhale channel" do
test "Represent a deactivated user for an admin" do test "Represent a deactivated user for an admin" do
admin = insert(:user, is_admin: true) admin = insert(:user, is_admin: true)
deactivated_user = insert(:user, deactivated: true) deactivated_user = insert(:user, is_active: false)
represented = AccountView.render("show.json", %{user: deactivated_user, for: admin}) represented = AccountView.render("show.json", %{user: deactivated_user, for: admin})
assert represented[:pleroma][:deactivated] == true assert represented[:pleroma][:deactivated] == true
end end

View File

@ -9,7 +9,7 @@ defmodule Pleroma.Web.MongooseIMControllerTest do
test "/user_exists", %{conn: conn} do test "/user_exists", %{conn: conn} do
_user = insert(:user, nickname: "lain") _user = insert(:user, nickname: "lain")
_remote_user = insert(:user, nickname: "alice", local: false) _remote_user = insert(:user, nickname: "alice", local: false)
_deactivated_user = insert(:user, nickname: "konata", deactivated: true) _deactivated_user = insert(:user, nickname: "konata", is_active: false)
res = res =
conn conn
@ -46,7 +46,7 @@ test "/check_password", %{conn: conn} do
_deactivated_user = _deactivated_user =
insert(:user, insert(:user,
nickname: "konata", nickname: "konata",
deactivated: true, is_active: false,
password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("cool") password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("cool")
) )

View File

@ -956,7 +956,7 @@ test "rejects token exchange for valid credentials belonging to deactivated user
user = user =
insert(:user, insert(:user,
password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password), password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password),
deactivated: true is_active: false
) )
app = insert(:oauth_app) app = insert(:oauth_app)

View File

@ -33,7 +33,7 @@ test "with a user that's not confirmed and a config requiring confirmation, it r
end end
test "with a user that is deactivated, it removes that user", %{conn: conn} do test "with a user that is deactivated, it removes that user", %{conn: conn} do
user = insert(:user, deactivated: true) user = insert(:user, is_active: false)
conn = conn =
conn conn

View File

@ -141,7 +141,7 @@ test "follows user", %{conn: conn} do
end end
test "returns error when user is deactivated", %{conn: conn} do test "returns error when user is deactivated", %{conn: conn} do
user = insert(:user, deactivated: true) user = insert(:user, is_active: false)
user2 = insert(:user) user2 = insert(:user)
response = response =

View File

@ -164,7 +164,7 @@ test "with valid permissions and password, it disables the account", %{conn: con
user = User.get_cached_by_id(user.id) user = User.get_cached_by_id(user.id)
assert user.deactivated == true refute user.is_active
end end
test "with valid permissions and invalid password, it returns an error", %{conn: conn} do test "with valid permissions and invalid password, it returns an error", %{conn: conn} do
@ -178,7 +178,7 @@ test "with valid permissions and invalid password, it returns an error", %{conn:
assert response == %{"error" => "Invalid password."} assert response == %{"error" => "Invalid password."}
user = User.get_cached_by_id(user.id) user = User.get_cached_by_id(user.id)
refute user.deactivated assert user.is_active
end end
end end
@ -428,7 +428,7 @@ test "with proper permissions and valid password", %{conn: conn, user: user} do
assert json_response(conn, 200) == %{"status" => "success"} assert json_response(conn, 200) == %{"status" => "success"}
user = User.get_by_id(user.id) user = User.get_by_id(user.id)
assert user.deactivated == true refute user.is_active
assert user.name == nil assert user.name == nil
assert user.bio == "" assert user.bio == ""
assert user.password_hash == nil assert user.password_hash == nil