From 5bc810c452cab97443aed76c16d7f2db5303666b Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 20 Feb 2018 18:44:50 +0100 Subject: [PATCH 1/5] Add moderator function. --- .../web/twitter_api/views/user_view.ex | 4 +++- test/web/twitter_api/views/user_view_test.exs | 23 +++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) 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, From eec6a87dbb1186349c766c88829ad121588bb43b Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 20 Feb 2018 18:54:13 +0100 Subject: [PATCH 2/5] Allow moderators to delete posts. --- lib/pleroma/web/common_api/common_api.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index d3a9f7b85..849360a16 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 From 765671a5b0eea5f906f333f39f03289a59506bb6 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 21 Feb 2018 18:24:17 +0100 Subject: [PATCH 3/5] Add password reset task. --- README.md | 6 ++++++ lib/mix/tasks/generate_password_reset.ex | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 lib/mix/tasks/generate_password_reset.ex diff --git a/README.md b/README.md index fcf296c01..5c6753b0a 100644 --- a/README.md +++ b/README.md @@ -59,3 +59,9 @@ 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. 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 From 56cfe7185852320b740392e0f58ce096b6cbecb6 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 21 Feb 2018 18:33:36 +0100 Subject: [PATCH 4/5] Add moderator task. --- lib/mix/tasks/make_moderator.ex | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 lib/mix/tasks/make_moderator.ex 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 From e98aeabbdebee8f6c9a10d0c9e3f48c1031172cb Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 21 Feb 2018 18:33:59 +0100 Subject: [PATCH 5/5] Moderator README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 5c6753b0a..b9449ad86 100644 --- a/README.md +++ b/README.md @@ -65,3 +65,9 @@ This is useful for running pleroma inside Tor or i2p. ### 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.