Commit db4badc6 authored by minibikini's avatar minibikini
Browse files

move user disable into deactivation

parent 0f2f7d2c
...@@ -53,10 +53,6 @@ defmodule Mix.Tasks.Pleroma.User do ...@@ -53,10 +53,6 @@ defmodule Mix.Tasks.Pleroma.User do
mix pleroma.user toggle_activated NICKNAME mix pleroma.user toggle_activated NICKNAME
## Disable or enable the user's account.
mix pleroma.user toggle_disabled NICKNAME
## Unsubscribe local users from user's account and deactivate it ## Unsubscribe local users from user's account and deactivate it
mix pleroma.user unsubscribe NICKNAME mix pleroma.user unsubscribe NICKNAME
...@@ -190,20 +186,6 @@ def run(["toggle_activated", nickname]) do ...@@ -190,20 +186,6 @@ def run(["toggle_activated", nickname]) do
end end
end end
def run(["toggle_disabled", nickname]) do
Common.start_pleroma()
case User.get_by_nickname(nickname) do
%User{} = user ->
{:ok, user} = User.disable(user, !user.info.disabled)
status = if(user.info.disabled, do: "ON", else: "OFF")
Mix.shell().info("Disabled status of #{nickname}: #{status}")
_ ->
Mix.shell().error("No user #{nickname}")
end
end
def run(["reset_password", nickname]) do def run(["reset_password", nickname]) do
Common.start_pleroma() Common.start_pleroma()
......
...@@ -100,7 +100,7 @@ def get_by_ap_id_with_object(ap_id) do ...@@ -100,7 +100,7 @@ def get_by_ap_id_with_object(ap_id) do
def get_by_id(id) do def get_by_id(id) do
Activity Activity
|> where([a], a.id == ^id) |> where([a], a.id == ^id)
|> restrict_disabled_users() |> restrict_deactivated_users()
|> Repo.one() |> Repo.one()
end end
...@@ -169,7 +169,7 @@ def get_all_create_by_object_ap_id(ap_id) do ...@@ -169,7 +169,7 @@ def get_all_create_by_object_ap_id(ap_id) do
def get_create_by_object_ap_id(ap_id) when is_binary(ap_id) do def get_create_by_object_ap_id(ap_id) when is_binary(ap_id) do
create_by_object_ap_id(ap_id) create_by_object_ap_id(ap_id)
|> restrict_disabled_users() |> restrict_deactivated_users()
|> Repo.one() |> Repo.one()
end end
...@@ -296,11 +296,11 @@ def decrease_replies_count(id) do ...@@ -296,11 +296,11 @@ def decrease_replies_count(id) do
end end
end end
def restrict_disabled_users(query) do def restrict_deactivated_users(query) do
from(activity in query, from(activity in query,
where: where:
fragment( fragment(
"? not in (SELECT ap_id FROM users WHERE info->'disabled' @> 'true')", "? not in (SELECT ap_id FROM users WHERE info->'deactivated' @> 'true')",
activity.actor activity.actor
) )
) )
......
...@@ -36,7 +36,7 @@ def for_user_query(user) do ...@@ -36,7 +36,7 @@ def for_user_query(user) do
|> where( |> where(
[n, a], [n, a],
fragment( fragment(
"? not in (SELECT ap_id FROM users WHERE info->'disabled' @> 'true')", "? not in (SELECT ap_id FROM users WHERE info->'deactivated' @> 'true')",
a.actor a.actor
) )
) )
......
...@@ -117,9 +117,9 @@ def user_info(%User{} = user) do ...@@ -117,9 +117,9 @@ def user_info(%User{} = user) do
} }
end end
defp restrict_disabled(query) do defp restrict_deactivated(query) do
from(u in query, from(u in query,
where: not fragment("? \\? 'disabled' AND ?->'disabled' @> 'true'", u.info, u.info) where: not fragment("? \\? 'deactivated' AND ?->'deactivated' @> 'true'", u.info, u.info)
) )
end end
...@@ -130,7 +130,7 @@ def following_count(%User{following: following, id: id}) do ...@@ -130,7 +130,7 @@ def following_count(%User{following: following, id: id}) do
where: u.follower_address in ^following, where: u.follower_address in ^following,
where: u.id != ^id where: u.id != ^id
) )
|> restrict_disabled() |> restrict_deactivated()
|> Repo.aggregate(:count, :id) |> Repo.aggregate(:count, :id)
end end
...@@ -584,7 +584,7 @@ def get_followers_query(%User{id: id, follower_address: follower_address}, nil) ...@@ -584,7 +584,7 @@ def get_followers_query(%User{id: id, follower_address: follower_address}, nil)
where: fragment("? <@ ?", ^[follower_address], u.following), where: fragment("? <@ ?", ^[follower_address], u.following),
where: u.id != ^id where: u.id != ^id
) )
|> restrict_disabled() |> restrict_deactivated()
end end
def get_followers_query(user, page) do def get_followers_query(user, page) do
...@@ -612,7 +612,7 @@ def get_friends_query(%User{id: id, following: following}, nil) do ...@@ -612,7 +612,7 @@ def get_friends_query(%User{id: id, following: following}, nil) do
where: u.follower_address in ^following, where: u.follower_address in ^following,
where: u.id != ^id where: u.id != ^id
) )
|> restrict_disabled() |> restrict_deactivated()
end end
def get_friends_query(user, page) do def get_friends_query(user, page) do
...@@ -736,7 +736,7 @@ def update_follower_count(%User{} = user) do ...@@ -736,7 +736,7 @@ def update_follower_count(%User{} = user) do
|> where([u], ^user.follower_address in u.following) |> where([u], ^user.follower_address in u.following)
|> where([u], u.id != ^user.id) |> where([u], u.id != ^user.id)
|> select([u], %{count: count(u.id)}) |> select([u], %{count: count(u.id)})
|> restrict_disabled() |> restrict_deactivated()
User User
|> where(id: ^user.id) |> where(id: ^user.id)
...@@ -887,7 +887,7 @@ defp fts_search_subquery(term, query \\ User) do ...@@ -887,7 +887,7 @@ defp fts_search_subquery(term, query \\ User) do
^processed_query ^processed_query
) )
) )
|> restrict_disabled() |> restrict_deactivated()
end end
defp trigram_search_subquery(term) do defp trigram_search_subquery(term) do
...@@ -906,7 +906,7 @@ defp trigram_search_subquery(term) do ...@@ -906,7 +906,7 @@ defp trigram_search_subquery(term) do
}, },
where: fragment("trim(? || ' ' || coalesce(?, '')) % ?", u.nickname, u.name, ^term) where: fragment("trim(? || ' ' || coalesce(?, '')) % ?", u.nickname, u.name, ^term)
) )
|> restrict_disabled() |> restrict_deactivated()
end end
def blocks_import(%User{} = blocker, blocked_identifiers) when is_list(blocked_identifiers) do def blocks_import(%User{} = blocker, blocked_identifiers) when is_list(blocked_identifiers) do
...@@ -1150,13 +1150,24 @@ def moderator_user_query do ...@@ -1150,13 +1150,24 @@ def moderator_user_query do
) )
end end
def deactivate_async(user, status \\ true) do
PleromaJobQueue.enqueue(:user, __MODULE__, [:deactivate_async, user, status])
end
def perform(:deactivate_async, user, status), do: deactivate(user, status)
def deactivate(%User{} = user, status \\ true) do def deactivate(%User{} = user, status \\ true) do
info_cng = User.Info.set_activation_status(user.info, status) info_cng = User.Info.set_activation_status(user.info, status)
user with {:ok, user} <- user
|> change() |> change()
|> put_embed(:info, info_cng) |> put_embed(:info, info_cng)
|> update_and_set_cache() |> update_and_set_cache(),
{:ok, friends} <- User.get_friends(user) do
Enum.each(friends, &update_follower_count(&1))
{:ok, user}
end
end end
def update_notification_settings(%User{} = user, settings \\ %{}) do def update_notification_settings(%User{} = user, settings \\ %{}) do
...@@ -1199,26 +1210,6 @@ def delete_user_activities(%User{ap_id: ap_id} = user) do ...@@ -1199,26 +1210,6 @@ def delete_user_activities(%User{ap_id: ap_id} = user) do
{:ok, user} {:ok, user}
end end
def disable_async(user, status \\ true) do
PleromaJobQueue.enqueue(:user, __MODULE__, [:disable_async, user, status])
end
def disable(%User{} = user, status \\ true) do
with {:ok, user} <- User.deactivate(user, status),
info_cng <- User.Info.set_disabled_status(user.info, status),
{:ok, user} <-
user
|> change()
|> put_embed(:info, info_cng)
|> update_and_set_cache(),
{:ok, friends} <- User.get_friends(user) do
Enum.each(friends, &update_follower_count(&1))
{:ok, user}
end
end
def perform(:disable_async, user, status), do: disable(user, status)
def html_filter_policy(%User{info: %{no_rich_text: true}}) do def html_filter_policy(%User{info: %{no_rich_text: true}}) do
Pleroma.HTML.Scrubber.TwitterText Pleroma.HTML.Scrubber.TwitterText
end end
......
...@@ -40,7 +40,6 @@ defmodule Pleroma.User.Info do ...@@ -40,7 +40,6 @@ defmodule Pleroma.User.Info do
field(:hide_follows, :boolean, default: false) field(:hide_follows, :boolean, default: false)
field(:pinned_activities, {:array, :string}, default: []) field(:pinned_activities, {:array, :string}, default: [])
field(:flavour, :string, default: nil) field(:flavour, :string, default: nil)
field(:disabled, :boolean, default: false)
field(:notification_settings, :map, field(:notification_settings, :map,
default: %{"remote" => true, "local" => true, "followers" => true, "follows" => true} default: %{"remote" => true, "local" => true, "followers" => true, "follows" => true}
...@@ -76,14 +75,6 @@ def update_notification_settings(info, settings) do ...@@ -76,14 +75,6 @@ def update_notification_settings(info, settings) do
|> validate_required([:notification_settings]) |> validate_required([:notification_settings])
end end
def set_disabled_status(info, disabled) do
params = %{disabled: disabled}
info
|> cast(params, [:disabled])
|> validate_required([:disabled])
end
def add_to_note_count(info, number) do def add_to_note_count(info, number) do
set_note_count(info, info.note_count + number) set_note_count(info, info.note_count + number)
end end
......
...@@ -804,7 +804,7 @@ def fetch_activities_query(recipients, opts \\ %{}) do ...@@ -804,7 +804,7 @@ def fetch_activities_query(recipients, opts \\ %{}) do
|> restrict_reblogs(opts) |> restrict_reblogs(opts)
|> restrict_pinned(opts) |> restrict_pinned(opts)
|> restrict_muted_reblogs(opts) |> restrict_muted_reblogs(opts)
|> Activity.restrict_disabled_users() |> Activity.restrict_deactivated_users()
end end
def fetch_activities(recipients, opts \\ %{}) do def fetch_activities(recipients, opts \\ %{}) do
......
...@@ -75,16 +75,6 @@ def user_show(conn, %{"nickname" => nickname}) do ...@@ -75,16 +75,6 @@ def user_show(conn, %{"nickname" => nickname}) do
end end
end end
def user_toggle_disabled(conn, %{"nickname" => nickname}) do
user = User.get_by_nickname(nickname)
{:ok, updated_user} = User.disable(user, !user.info.disabled)
conn
|> put_view(AccountView)
|> render("show.json", %{user: updated_user})
end
def user_toggle_activation(conn, %{"nickname" => nickname}) do def user_toggle_activation(conn, %{"nickname" => nickname}) do
user = User.get_by_nickname(nickname) user = User.get_by_nickname(nickname)
......
...@@ -153,7 +153,6 @@ defmodule Pleroma.Web.Router do ...@@ -153,7 +153,6 @@ defmodule Pleroma.Web.Router do
delete("/user", AdminAPIController, :user_delete) delete("/user", AdminAPIController, :user_delete)
patch("/users/:nickname/toggle_activation", AdminAPIController, :user_toggle_activation) patch("/users/:nickname/toggle_activation", AdminAPIController, :user_toggle_activation)
patch("/users/:nickname/toggle_disabled", AdminAPIController, :user_toggle_disabled)
post("/user", AdminAPIController, :user_create) post("/user", AdminAPIController, :user_create)
put("/users/tag", AdminAPIController, :tag_users) put("/users/tag", AdminAPIController, :tag_users)
delete("/users/tag", AdminAPIController, :untag_users) delete("/users/tag", AdminAPIController, :untag_users)
......
...@@ -358,7 +358,7 @@ def delete_account(%{assigns: %{user: user}} = conn, params) do ...@@ -358,7 +358,7 @@ def delete_account(%{assigns: %{user: user}} = conn, params) do
def disable_account(%{assigns: %{user: user}} = conn, params) do def disable_account(%{assigns: %{user: user}} = conn, params) do
case CommonAPI.Utils.confirm_current_password(user, params["password"]) do case CommonAPI.Utils.confirm_current_password(user, params["password"]) do
{:ok, user} -> {:ok, user} ->
User.disable_async(user) User.deactivate_async(user)
json(conn, %{status: "success"}) json(conn, %{status: "success"})
{:error, msg} -> {:error, msg} ->
......
...@@ -235,7 +235,7 @@ def get_user(user \\ nil, params) do ...@@ -235,7 +235,7 @@ def get_user(user \\ nil, params) do
nil -> nil ->
{:error, "No user with such user_id"} {:error, "No user with such user_id"}
%User{info: %{disabled: true}} -> %User{info: %{deactivated: true}} ->
{:error, "User has been disabled"} {:error, "User has been disabled"}
user -> user ->
......
defmodule Pleroma.Repo.Migrations.UsersAddDisabledIndex do
use Ecto.Migration
def change do
create(index(:users, ["(info->'disabled')"], name: :users_disabled_index, using: :gin))
end
end
defmodule Pleroma.Repo.Migrations.AddIndexOnUserInfoDeactivated do
use Ecto.Migration
def change do
create(index(:users, ["(info->'deactivated')"], name: :users_deactivated_index, using: :gin))
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment