From d013b58e84f2c8213a5d26b1c3daf36e2f4807e5 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 12 Mar 2019 22:04:08 +0700 Subject: add `mix pleroma.user delete_activities NICKNAME` task --- lib/mix/tasks/pleroma/user.ex | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 037e44716..e232df14f 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -304,6 +304,18 @@ defmodule Mix.Tasks.Pleroma.User do end end + def run(["delete_activities", nickname]) do + Common.start_pleroma() + + with %User{local: true} = user <- User.get_by_nickname(nickname) do + User.delete_user_activities(user) + Mix.shell().info("User #{nickname} deleted.") + else + _ -> + Mix.shell().error("No local user #{nickname}") + end + end + defp set_moderator(user, value) do info_cng = User.Info.admin_api_update(user.info, %{is_moderator: value}) -- cgit v1.2.3 From 16e598ec11cb9178b9fc53a1ec4b649d97c5f3b8 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 12 Mar 2019 22:12:05 +0700 Subject: fix wording --- lib/mix/tasks/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index e232df14f..ec06d908a 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -309,7 +309,7 @@ defmodule Mix.Tasks.Pleroma.User do with %User{local: true} = user <- User.get_by_nickname(nickname) do User.delete_user_activities(user) - Mix.shell().info("User #{nickname} deleted.") + Mix.shell().info("User #{nickname} statuses deleted..") else _ -> Mix.shell().error("No local user #{nickname}") -- cgit v1.2.3 From a14742f495fac78f4dfd7ab02f4c3ae5c7c37c3b Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 2 Apr 2019 16:30:11 +0700 Subject: add `user delete_activities` mix task --- lib/mix/tasks/pleroma/user.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 680422c19..62c9fceda 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -23,7 +23,7 @@ defmodule Mix.Tasks.Pleroma.User do - `--password PASSWORD` - the user's password - `--moderator`/`--no-moderator` - whether the user is a moderator - `--admin`/`--no-admin` - whether the user is an admin - - `-y`, `--assume-yes`/`--no-assume-yes` - whether to assume yes to all questions + - `-y`, `--assume-yes`/`--no-assume-yes` - whether to assume yes to all questions ## Generate an invite link. @@ -33,6 +33,10 @@ defmodule Mix.Tasks.Pleroma.User do mix pleroma.user rm NICKNAME + ## Delete the user's activities. + + mix pleroma.user delete_activities NICKNAME + ## Deactivate or activate the user's account. mix pleroma.user toggle_activated NICKNAME @@ -309,7 +313,7 @@ defmodule Mix.Tasks.Pleroma.User do with %User{local: true} = user <- User.get_by_nickname(nickname) do User.delete_user_activities(user) - Mix.shell().info("User #{nickname} statuses deleted..") + Mix.shell().info("User #{nickname} statuses deleted.") else _ -> Mix.shell().error("No local user #{nickname}") -- cgit v1.2.3 From 1b3d92192194baf6b431cd9f0ce58062d1b703d5 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 2 Apr 2019 17:01:26 +0700 Subject: change `Repo.get(User, id)` => `User.get_by_id(id)` --- lib/mix/tasks/pleroma/user.ex | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index f6cca0d06..2487b4ab5 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -6,7 +6,6 @@ defmodule Mix.Tasks.Pleroma.User do use Mix.Task import Ecto.Changeset alias Mix.Tasks.Pleroma.Common - alias Pleroma.Repo alias Pleroma.User @shortdoc "Manages Pleroma users" @@ -23,7 +22,7 @@ defmodule Mix.Tasks.Pleroma.User do - `--password PASSWORD` - the user's password - `--moderator`/`--no-moderator` - whether the user is a moderator - `--admin`/`--no-admin` - whether the user is an admin - - `-y`, `--assume-yes`/`--no-assume-yes` - whether to assume yes to all questions + - `-y`, `--assume-yes`/`--no-assume-yes` - whether to assume yes to all questions ## Generate an invite link. @@ -202,7 +201,7 @@ defmodule Mix.Tasks.Pleroma.User do {:ok, friends} = User.get_friends(user) Enum.each(friends, fn friend -> - user = Repo.get(User, user.id) + user = User.get_by_id(user.id) Mix.shell().info("Unsubscribing #{friend.nickname} from #{user.nickname}") User.unfollow(user, friend) @@ -210,7 +209,7 @@ defmodule Mix.Tasks.Pleroma.User do :timer.sleep(500) - user = Repo.get(User, user.id) + user = User.get_by_id(user.id) if Enum.empty?(user.following) do Mix.shell().info("Successfully unsubscribed all followers from #{user.nickname}") -- cgit v1.2.3 From cd41584ac4a90a666f33786d967d37a619c67762 Mon Sep 17 00:00:00 2001 From: Sachin Joshi Date: Wed, 3 Apr 2019 00:54:16 +0545 Subject: Generate permissive or restrictive robots.txt in the config generator --- lib/mix/tasks/pleroma/instance.ex | 34 ++++++++++++++++++++++++++++++++++ lib/mix/tasks/pleroma/robots_txt.eex | 2 ++ 2 files changed, 36 insertions(+) create mode 100644 lib/mix/tasks/pleroma/robots_txt.eex (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 1ba452275..8f8d86a11 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -81,6 +81,14 @@ defmodule Mix.Tasks.Pleroma.Instance do email = Common.get_option(options, :admin_email, "What is your admin email address?") + indexable = + Common.get_option( + options, + :indexable, + "Do you want search engines to index your site? (y/n)", + "y" + ) === "y" + dbhost = Common.get_option(options, :dbhost, "What is the hostname of your database?", "localhost") @@ -142,6 +150,8 @@ defmodule Mix.Tasks.Pleroma.Instance do Mix.shell().info("Writing #{psql_path}.") File.write(psql_path, result_psql) + write_robots_txt(indexable) + Mix.shell().info( "\n" <> """ @@ -163,4 +173,28 @@ defmodule Mix.Tasks.Pleroma.Instance do ) end end + + defp write_robots_txt(indexable) do + robots_txt = + EEx.eval_file( + Path.expand("robots_txt.eex", __DIR__), + indexable: indexable + ) + + static_dir = Pleroma.Config.get([:instance, :static_dir], "instance/static/") + + unless File.exists?(static_dir) do + File.mkdir_p!(static_dir) + end + + robots_txt_path = Path.join(static_dir, "robots.txt") + + if File.exists?(robots_txt_path) do + File.cp!(robots_txt_path, "#{robots_txt_path}.bak") + Mix.shell().info("Backing up existing robots.txt to #{robots_txt_path}.bak") + end + + File.write(robots_txt_path, robots_txt) + Mix.shell().info("Writing #{robots_txt_path}.") + end end diff --git a/lib/mix/tasks/pleroma/robots_txt.eex b/lib/mix/tasks/pleroma/robots_txt.eex new file mode 100644 index 000000000..1af3c47ee --- /dev/null +++ b/lib/mix/tasks/pleroma/robots_txt.eex @@ -0,0 +1,2 @@ +User-Agent: * +Disallow: <%= if indexable, do: "", else: "/" %> -- cgit v1.2.3