diff --git a/README.md b/README.md index fcf296c01..b9449ad86 100644 --- a/README.md +++ b/README.md @@ -59,3 +59,15 @@ Add the following to your `dev.secret.exs` or `prod.secret.exs` if you want to p proxy_url: "127.0.0.1:8123" This is useful for running pleroma inside Tor or i2p. + +## Admin Tasks + +### Password reset + +Run `mix generate_password_reset username` to generate a password reset link that you can then send to the user. + +### Moderators + +You can make users moderators. They will then be able to delete any post. + +Run `mix set_moderator username [true|false]` to make user a moderator or not. diff --git a/lib/mix/tasks/generate_password_reset.ex b/lib/mix/tasks/generate_password_reset.ex new file mode 100644 index 000000000..b968b1f98 --- /dev/null +++ b/lib/mix/tasks/generate_password_reset.ex @@ -0,0 +1,19 @@ +defmodule Mix.Tasks.GeneratePasswordReset do + use Mix.Task + import Mix.Ecto + alias Pleroma.{Repo, User} + + @shortdoc "Generate password reset link for user" + def run([nickname]) do + Mix.Task.run("app.start") + + with %User{local: true} = user <- User.get_by_nickname(nickname), + {:ok, token} <- Pleroma.PasswordResetToken.create_token(user) do + IO.puts "Generated password reset token for #{user.nickname}" + IO.puts "Url: #{Pleroma.Web.Router.Helpers.util_url(Pleroma.Web.Endpoint, :show_password_reset, token.token)}" + else + _ -> + IO.puts "No local user #{nickname}" + end + end +end diff --git a/lib/mix/tasks/make_moderator.ex b/lib/mix/tasks/make_moderator.ex new file mode 100644 index 000000000..a76b54f40 --- /dev/null +++ b/lib/mix/tasks/make_moderator.ex @@ -0,0 +1,27 @@ +defmodule Mix.Tasks.SetModerator do + use Mix.Task + import Mix.Ecto + alias Pleroma.{Repo, User} + + @shortdoc "Set moderator status" + def run([nickname | rest]) do + ensure_started(Repo, []) + + moderator = case rest do + [moderator] -> moderator == "true" + _ -> true + end + + with %User{local: true} = user <- User.get_by_nickname(nickname) do + info = user.info + |> Map.put("is_moderator", !!moderator) + cng = User.info_changeset(user, %{info: info}) + user = Repo.update!(cng) + + IO.puts "Moderator status of #{nickname}: #{user.info["is_moderator"]}" + else + _ -> + IO.puts "No local user #{nickname}" + end + end +end diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index c6657b8e8..5bd6e136f 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -8,7 +8,7 @@ defmodule Pleroma.Web.CommonAPI do def delete(activity_id, user) do with %Activity{data: %{"object" => %{"id" => object_id}}} <- Repo.get(Activity, activity_id), %Object{} = object <- Object.get_by_ap_id(object_id), - true <- user.ap_id == object.data["actor"], + true <- user.info["is_moderator"] || (user.ap_id == object.data["actor"]), {:ok, delete} <- ActivityPub.delete(object) do {:ok, delete} end diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index f49bcc0fb..6fb07f052 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -41,7 +41,9 @@ def render("user.json", %{user: user = %User{}} = assigns) do "profile_image_url_https" => image, "profile_image_url_profile_size" => image, "profile_image_url_original" => image, - "rights" => %{}, + "rights" => %{ + "delete_others_notice" => !!user.info["is_moderator"] + }, "screen_name" => user.nickname, "statuses_count" => user_info[:note_count], "statusnet_profile_url" => user.ap_id, diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index a687020f0..9e0a8a532 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -53,7 +53,9 @@ test "A user" do "following" => false, "follows_you" => false, "statusnet_blocking" => false, - "rights" => %{}, + "rights" => %{ + "delete_others_notice" => false + }, "statusnet_profile_url" => user.ap_id, "cover_photo" => banner, "background_image" => nil, @@ -86,7 +88,9 @@ test "A user for a given other follower", %{user: user} do "following" => true, "follows_you" => false, "statusnet_blocking" => false, - "rights" => %{}, + "rights" => %{ + "delete_others_notice" => false + }, "statusnet_profile_url" => user.ap_id, "cover_photo" => banner, "background_image" => nil, @@ -120,7 +124,9 @@ test "A user that follows you", %{user: user} do "following" => false, "follows_you" => true, "statusnet_blocking" => false, - "rights" => %{}, + "rights" => %{ + "delete_others_notice" => false + }, "statusnet_profile_url" => follower.ap_id, "cover_photo" => banner, "background_image" => nil, @@ -130,6 +136,13 @@ test "A user that follows you", %{user: user} do assert represented == UserView.render("show.json", %{user: follower, for: user}) end + test "a user that is a moderator" do + user = insert(:user, %{info: %{"is_moderator" => true}}) + represented = UserView.render("show.json", %{user: user, for: user}) + + assert represented["rights"]["delete_others_notice"] + end + test "A blocked user for the blocker" do user = insert(:user) blocker = insert(:user) @@ -154,7 +167,9 @@ test "A blocked user for the blocker" do "following" => false, "follows_you" => false, "statusnet_blocking" => true, - "rights" => %{}, + "rights" => %{ + "delete_others_notice" => false + }, "statusnet_profile_url" => user.ap_id, "cover_photo" => banner, "background_image" => nil,