allow users to disable their own account
This commit is contained in:
parent
dd5865535e
commit
eb84de0143
16 changed files with 167 additions and 51 deletions
|
|
@ -311,6 +311,17 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
|
|||
end
|
||||
end
|
||||
|
||||
def disable_account(%{assigns: %{user: user}} = conn, params) do
|
||||
case CommonAPI.Utils.confirm_current_password(user, params["password"]) do
|
||||
{:ok, user} ->
|
||||
User.disable_async(user)
|
||||
json(conn, %{status: "success"})
|
||||
|
||||
{:error, msg} ->
|
||||
json(conn, %{error: msg})
|
||||
end
|
||||
end
|
||||
|
||||
def captcha(conn, _params) do
|
||||
json(conn, Pleroma.Captcha.new())
|
||||
end
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
|||
end
|
||||
|
||||
def delete(%User{} = user, id) do
|
||||
with %Activity{data: %{"type" => _type}} <- Repo.get(Activity, id),
|
||||
with %Activity{data: %{"type" => _type}} <- Activity.get_by_id(id),
|
||||
{:ok, activity} <- CommonAPI.delete(id, user) do
|
||||
{:ok, activity}
|
||||
end
|
||||
|
|
@ -232,21 +232,27 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
|||
def get_user(user \\ nil, params) do
|
||||
case params do
|
||||
%{"user_id" => user_id} ->
|
||||
case target = User.get_cached_by_nickname_or_id(user_id) do
|
||||
case User.get_cached_by_nickname_or_id(user_id) do
|
||||
nil ->
|
||||
{:error, "No user with such user_id"}
|
||||
|
||||
_ ->
|
||||
{:ok, target}
|
||||
%User{info: %{disabled: true}} ->
|
||||
{:error, "User has been disabled"}
|
||||
|
||||
user ->
|
||||
{:ok, user}
|
||||
end
|
||||
|
||||
%{"screen_name" => nickname} ->
|
||||
case target = Repo.get_by(User, nickname: nickname) do
|
||||
case User.get_by_nickname(nickname) do
|
||||
nil ->
|
||||
{:error, "No user with such screen_name"}
|
||||
|
||||
_ ->
|
||||
{:ok, target}
|
||||
%User{info: %{disabled: true}} ->
|
||||
{:error, "User has been disabled"}
|
||||
|
||||
user ->
|
||||
{:ok, user}
|
||||
end
|
||||
|
||||
_ ->
|
||||
|
|
|
|||
|
|
@ -269,7 +269,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
|||
end
|
||||
|
||||
def fetch_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||
with %Activity{} = activity <- Repo.get(Activity, id),
|
||||
with %Activity{} = activity <- Activity.get_by_id(id),
|
||||
true <- Visibility.visible_for_user?(activity, user) do
|
||||
conn
|
||||
|> put_view(ActivityView)
|
||||
|
|
@ -341,7 +341,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
|||
end
|
||||
|
||||
def get_by_id_or_ap_id(id) do
|
||||
activity = Repo.get(Activity, id) || Activity.get_create_by_object_ap_id(id)
|
||||
activity = Activity.get_by_id(id) || Activity.get_create_by_object_ap_id(id)
|
||||
|
||||
if activity.data["type"] == "Create" do
|
||||
activity
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue