Pleroma.User.Query.build(%{
local: true,
- deactivated: false,
+ is_active: true,
confirmation_pending: true,
invisible: false
})
start_pleroma()
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(
- "Activation status of #{nickname}: #{if(user.deactivated, do: "de", else: "")}activated"
+ "Activation status of #{nickname}: #{unless(user.is_active, do: "de", else: "")}activated"
)
else
_ ->
Pleroma.User.Query.build(%{
local: true,
- deactivated: false,
+ is_active: true,
is_moderator: false,
is_admin: false,
invisible: false
Pleroma.User.Query.build(%{
local: true,
- deactivated: false,
+ is_active: true,
is_moderator: false,
is_admin: false,
invisible: false
shell_info(
"#{user.nickname} moderator: #{user.is_moderator}, admin: #{user.is_admin}, locked: #{
user.is_locked
- }, deactivated: #{user.deactivated}"
+ }, is_active: #{user.is_active}"
)
end)
end)
|> join(:inner, [r], f in assoc(r, :follower))
|> where([r], r.state == ^:follow_pending)
|> where([r], r.following_id == ^id)
- |> where([r, f], f.deactivated != true)
+ |> where([r, f], f.is_active == true)
|> select([r, f], f)
|> Repo.all()
end
|> where(
[n, a],
fragment(
- "? not in (SELECT ap_id FROM users WHERE deactivated = 'true')",
+ "? not in (SELECT ap_id FROM users WHERE is_active = 'false')",
a.actor
)
)
users_query =
from(u in User,
- where: u.deactivated != true,
+ where: u.is_active == true,
where: u.local == true,
where: not is_nil(u.nickname),
where: not u.invisible
field(:confirmation_token, :string, default: nil)
field(:default_scope, :string, default: "public")
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(:ap_enabled, :boolean, default: false)
field(:is_moderator, :boolean, default: false)
@doc "Returns status account"
@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{local: true, approval_pending: true}), do: :approval_pending
@spec restrict_deactivated(Ecto.Query.t()) :: Ecto.Query.t()
def restrict_deactivated(query) do
- from(u in query, where: u.deactivated != ^true)
+ from(u in query, where: u.is_active == ^true)
end
defp truncate_fields_param(params) do
candidates = Config.get([:instance, :autofollowed_nicknames])
autofollowed_users =
- User.Query.build(%{nickname: candidates, local: true, deactivated: false})
+ User.Query.build(%{nickname: candidates, local: true, is_active: true})
|> Repo.all()
follow_all(user, autofollowed_users)
deny_follow_blocked = Config.get([:user, :deny_follow_blocked])
cond do
- followed.deactivated ->
+ followed.is_active == false ->
{:error, "Could not follow user: #{followed.nickname} is deactivated."}
deny_follow_blocked and blocks?(followed, follower) ->
@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, deactivated: false})
+ User.Query.build(%{followers: user, is_active: true})
end
def get_followers_query(%User{} = user, page) 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, deactivated: false}
+ criteria = %{ap_id: ap_ids, is_active: true}
criteria = if local_only, do: Map.put(criteria, :local, true), else: criteria
User.Query.build(criteria)
def get_recipients_from_activity(%Activity{recipients: to, actor: actor}) do
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
|> Repo.all()
end
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
|> get_followers()
|> Enum.filter(& &1.local)
registration_reason: nil,
confirmation_token: nil,
domain_blocks: [],
- deactivated: true,
+ is_active: false,
ap_enabled: false,
is_moderator: false,
is_admin: false,
@spec all_superusers() :: [User.t()]
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()
end
left_join: a in Pleroma.Activity,
on: u.ap_id == a.actor,
where: not is_nil(u.nickname),
- where: u.deactivated != ^true,
+ where: u.is_active == ^true,
where: u.id not in ^has_read_notifications,
group_by: u.id,
having:
end
# Internal function; public one is `deactivate/2`
- defp set_activation_status(user, deactivated) do
+ defp set_activation_status(user, status) do
user
- |> cast(%{deactivated: deactivated}, [:deactivated])
+ |> cast(%{is_active: status}, [:is_active])
|> update_and_set_cache()
end
end
defp compose_query({:deactivated, true}, query) do
- where(query, [u], u.deactivated == ^true)
+ where(query, [u], u.is_active == false)
end
defp compose_query({:confirmation_pending, bool}, query) do
defp check_actor_is_active(actor) when is_binary(actor) do
case User.get_cached_by_ap_id(actor) do
- %User{deactivated: deactivated} -> not deactivated
+ %User{is_active: true} -> true
_ -> false
end
end
cng
|> validate_change(field_name, fn field_name, actor ->
case User.get_cached_by_ap_id(actor) do
- %User{deactivated: true} ->
+ %User{is_active: false} ->
[{field_name, "user is deactivated"}]
%User{} ->
def toggle_activation(%{assigns: %{user: admin}} = conn, %{"nickname" => nickname}) do
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(%{
actor: admin,
"avatar" => avatar,
"nickname" => user.nickname,
"display_name" => display_name,
- "deactivated" => user.deactivated,
+ "is_active" => user.is_active,
"local" => user.local,
"roles" => User.roles(user),
"tags" => user.tags || [],
properties:
Map.merge(Account.schema().properties, %{
nickname: %Schema{type: :string},
- deactivated: %Schema{type: :boolean},
+ is_active: %Schema{type: :boolean},
local: %Schema{type: :boolean},
roles: %Schema{
type: :object,
avatar: %Schema{type: :string},
nickname: %Schema{type: :string},
display_name: %Schema{type: :string},
- deactivated: %Schema{type: :boolean},
+ is_active: %Schema{type: :boolean},
local: %Schema{type: :boolean},
roles: %Schema{
type: :object,
defp maybe_put_allow_following_move(data, _, _), do: data
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
defp maybe_put_activation_status(data, _, _), do: data
plug(RateLimiter, [name: :authentication, params: ["user"]] when action == :check_password)
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
|> json(true)
else
end
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),
true <- AuthenticationPlug.checkpw(password, password_hash) do
conn
user_ap_ids
|> Enum.map(&Pleroma.User.get_cached_by_ap_id/1)
|> Enum.filter(fn
- %{deactivated: false} -> true
+ %{is_active: true} -> true
_ -> false
end)
end
def password_reset(nickname_or_email) do
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),
{:ok, token_record} <- Pleroma.PasswordResetToken.create_token(user) do
user
--- /dev/null
+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
insert(:user, %{
confirmation_pending: true,
confirmation_token: "mytoken",
- deactivated: false,
+ is_active: true,
email: "local1@pleroma.com",
local: true
})
insert(:user, %{
confirmation_pending: true,
confirmation_token: "mytoken",
- deactivated: false,
+ is_active: true,
email: "local2@pleroma.com",
local: true
})
insert(:user, %{
confirmation_pending: false,
confirmation_token: "mytoken",
- deactivated: false,
+ is_active: true,
email: "confirmed@pleroma.com",
local: true
})
# remote user
insert(:user, %{
- deactivated: false,
+ is_active: true,
email: "remote@not-pleroma.com",
local: false
})
# deactivated user =
insert(:user, %{
- deactivated: true,
+ is_active: false,
email: "deactivated@pleroma.com",
local: false
})
# invisible user
insert(:user, %{
- deactivated: false,
+ is_active: true,
email: "invisible@pleroma.com",
local: true,
invisible: true
assert_received {:mix_shell, :info, [message]}
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(:_))
end
assert_received {:mix_shell, :info, [message]}
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(:_))
refute Pleroma.Repo.get(Pleroma.Activity, like_activity.id)
assert message =~ " deactivated"
user = User.get_cached_by_nickname(user.nickname)
- assert user.deactivated
+ refute user.is_active
end
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])
assert message =~ " activated"
user = User.get_cached_by_nickname(user.nickname)
- refute user.deactivated
+ assert user.is_active
end
test "no user to toggle" do
user = User.get_cached_by_nickname(user.nickname)
assert Enum.empty?(Enum.filter(User.get_friends(user), & &1.local))
- assert user.deactivated
+ refute user.is_active
end
test "no user to deactivate" do
test "doesn't return follow requests for deactivated accounts" do
locked = insert(:user, is_locked: true)
- pending_follower = insert(:user, %{deactivated: true})
+ pending_follower = insert(:user, %{is_active: false})
CommonAPI.follow(pending_follower, locked)
- assert true == pending_follower.deactivated
+ refute pending_follower.is_active
assert [] = User.get_follow_requests(locked)
end
test "can't follow a deactivated users" do
user = insert(:user)
- followed = insert(:user, %{deactivated: true})
+ followed = insert(:user, %{is_active: false})
{:error, _} = User.follow(user, followed)
end
describe ".deactivate" do
test "can de-activate then re-activate a user" do
user = insert(:user)
- assert false == user.deactivated
+ assert user.is_active
{:ok, user} = User.deactivate(user)
- assert true == user.deactivated
+ refute user.is_active
{:ok, user} = User.deactivate(user, false)
- assert false == user.deactivated
+ assert user.is_active
end
test "hide a user from followers" do
follower = User.get_cached_by_id(follower.id)
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)
{: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)
+ assert %{is_active: false} = User.get_cached_by_id(user.id)
+ assert %{is_active: false} = User.get_by_id(user.id)
end
end
registration_reason: "ahhhhh",
confirmation_token: "qqqq",
domain_blocks: ["lain.com"],
- deactivated: true,
+ is_active: false,
ap_enabled: true,
is_moderator: true,
is_admin: true,
registration_reason: nil,
confirmation_token: nil,
domain_blocks: [],
- deactivated: true,
+ is_active: false,
ap_enabled: false,
is_moderator: false,
is_admin: false,
end
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
end
users =
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)
inactive_users_ids =
users =
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)
{inactive, active} = Enum.split(users, trunc(total / 2))
users =
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)
[sender | recipients] = users
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")
insert(:user, local: true)
- insert(:user, local: false, deactivated: true)
+ insert(:user, local: false, is_active: false)
{:ok, user1: user1, user2: user2}
end
{:ok, _delete, _} = SideEffects.handle(delete)
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
{:ok, _, _} = SideEffects.handle(delete)
ObanHelpers.perform_all()
- assert User.get_cached_by_id(user.id).deactivated
+ refute User.get_cached_by_id(user.id).is_active
end
test "when activation is required", %{delete: delete, user: user} do
ap_id: data["actor"],
local: false,
last_refreshed_at: DateTime.utc_now(),
- deactivated: true
+ is_active: false
)
_recipient = insert(:user, ap_id: List.first(data["to"]), local: true)
{:ok, _} = Transmogrifier.handle_incoming(data)
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
test "it fails for incoming user deletes with spoofed origin" do
test "it does not work for deactivated users" do
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)
end
assert account["id"] == actor.id
assert account["nickname"] == actor.nickname
- assert account["deactivated"] == actor.deactivated
+ assert account["is_active"] == actor.is_active
assert account["confirmation_pending"] == actor.confirmation_pending
end
end
assert user.note_count == 1
assert user.follower_count == 1
assert user.following_count == 1
- refute user.deactivated
+ assert user.is_active
with_mock Pleroma.Web.Federator,
publish: fn _ -> nil end,
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)
assert json_response(conn, 200) == [user.nickname]
user = Repo.get(User, user.id)
- assert user.deactivated
+ refute user.is_active
assert user.avatar == %{}
assert user.banner == %{}
"roles" => %{"admin" => true, "moderator" => false}
}),
user_response(old_admin, %{
- "deactivated" => false,
+ "is_active" => true,
"roles" => %{"admin" => true, "moderator" => false}
})
]
users =
[
user_response(admin, %{
- "deactivated" => false,
+ "is_active" => true,
"roles" => %{"admin" => true, "moderator" => false}
}),
user_response(second_admin, %{
- "deactivated" => false,
+ "is_active" => true,
"roles" => %{"admin" => true, "moderator" => false}
})
]
"page_size" => 50,
"users" => [
user_response(moderator, %{
- "deactivated" => false,
+ "is_active" => true,
"roles" => %{"admin" => false, "moderator" => true}
})
]
test "it works with multiple filters" do
admin = insert(:user, nickname: "john", is_admin: true)
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: "bobb", local: false, deactivated: false)
+ insert(:user, nickname: "ken", local: true, is_active: false)
+ insert(:user, nickname: "bobb", local: false, is_active: true)
conn =
build_conn()
end
test "PATCH /api/pleroma/admin/users/activate", %{admin: admin, conn: conn} do
- user_one = insert(:user, deactivated: true)
- user_two = insert(:user, deactivated: true)
+ user_one = insert(:user, is_active: false)
+ user_two = insert(:user, is_active: false)
conn =
patch(
)
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)
end
test "PATCH /api/pleroma/admin/users/deactivate", %{admin: admin, conn: conn} do
- user_one = insert(:user, deactivated: false)
- user_two = insert(:user, deactivated: false)
+ user_one = insert(:user, is_active: true)
+ user_two = insert(:user, is_active: true)
conn =
patch(
)
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)
assert json_response(conn, 200) ==
user_response(
user,
- %{"deactivated" => !user.deactivated}
+ %{"is_active" => user.is_active}
)
log_entry = Repo.one(ModerationLog)
defp user_response(user, attrs \\ %{}) do
%{
- "deactivated" => user.deactivated,
+ "is_active" => user.is_active,
"id" => user.id,
"email" => user.email,
"nickname" => user.nickname,
end
test "it returns active/deactivated users" do
- insert(:user, deactivated: true)
- insert(:user, deactivated: true)
- insert(:user, deactivated: false)
+ insert(:user, is_active: false)
+ insert(:user, is_active: false)
+ insert(:user, is_active: true)
{:ok, _results, active_count} =
Search.user(%{
test "it returns specific user" do
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: ""})
end
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"})
end
end
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"} =
conn
end
test "deactivated user", %{conn: conn} do
- user = insert(:user, deactivated: true)
+ user = insert(:user, is_active: false)
assert %{"error" => "Can't find user"} ==
conn
end
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}")
assert empty_json_response(conn)
user = 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@peer2.com"})
describe "follow/3" do
test "returns error when followed user is deactivated" do
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)
end
test "Represent a deactivated user for an admin" do
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})
assert represented[:pleroma][:deactivated] == true
end
test "/user_exists", %{conn: conn} do
_user = insert(:user, nickname: "lain")
_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 =
conn
_deactivated_user =
insert(:user,
nickname: "konata",
- deactivated: true,
+ is_active: false,
password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("cool")
)
user =
insert(:user,
password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password),
- deactivated: true
+ is_active: false
)
app = insert(:oauth_app)
end
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
end
test "returns error when user is deactivated", %{conn: conn} do
- user = insert(:user, deactivated: true)
+ user = insert(:user, is_active: false)
user2 = insert(:user)
response =
user = User.get_cached_by_id(user.id)
- assert user.deactivated == true
+ refute user.is_active
end
test "with valid permissions and invalid password, it returns an error", %{conn: conn} do
assert response == %{"error" => "Invalid password."}
user = User.get_cached_by_id(user.id)
- refute user.deactivated
+ assert user.is_active
end
end
assert json_response(conn, 200) == %{"status" => "success"}
user = User.get_by_id(user.id)
- assert user.deactivated == true
+ refute user.is_active
assert user.name == nil
assert user.bio == ""
assert user.password_hash == nil