From cef2e980b1f6b07c2bdb01030559aca83257bd7e Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Wed, 28 Aug 2019 21:32:44 +0300 Subject: division emoji.ex on loader.ex and emoji.ex --- lib/mix/tasks/pleroma/emoji.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index c2225af7d..dc5f7c193 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -235,7 +235,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do cwd: tmp_pack_dir ) - emoji_map = Pleroma.Emoji.make_shortcode_to_file_map(tmp_pack_dir, exts) + emoji_map = Pleroma.Emoji.Loader.make_shortcode_to_file_map(tmp_pack_dir, exts) File.write!(files_name, Jason.encode!(emoji_map, pretty: true)) -- cgit v1.2.3 From 447514dfa2759e3415399412e82bf772ff119e04 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 18 Sep 2019 23:20:54 +0200 Subject: Bump copyright years of files changed in 2019 Done via the following command: git diff 1e6c102bfcfe0e4835a48f2483f2376f9bf86a20 --stat --name-only | cat - | xargs sed -i 's/2017-2018 Pleroma Authors/2017-2019 Pleroma Authors/' --- lib/mix/pleroma.ex | 2 +- lib/mix/tasks/pleroma/database.ex | 2 +- lib/mix/tasks/pleroma/ecto/ecto.ex | 2 +- lib/mix/tasks/pleroma/ecto/migrate.ex | 2 +- lib/mix/tasks/pleroma/ecto/rollback.ex | 2 +- lib/mix/tasks/pleroma/emoji.ex | 2 +- lib/mix/tasks/pleroma/instance.ex | 2 +- lib/mix/tasks/pleroma/relay.ex | 2 +- lib/mix/tasks/pleroma/uploads.ex | 2 +- lib/mix/tasks/pleroma/user.ex | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex index 1b758ea33..faeb30e1d 100644 --- a/lib/mix/pleroma.ex +++ b/lib/mix/pleroma.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Pleroma do diff --git a/lib/mix/tasks/pleroma/database.ex b/lib/mix/tasks/pleroma/database.ex index bcc2052d6..890a383df 100644 --- a/lib/mix/tasks/pleroma/database.ex +++ b/lib/mix/tasks/pleroma/database.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.Database do diff --git a/lib/mix/tasks/pleroma/ecto/ecto.ex b/lib/mix/tasks/pleroma/ecto/ecto.ex index b66f63376..36808b93f 100644 --- a/lib/mix/tasks/pleroma/ecto/ecto.ex +++ b/lib/mix/tasks/pleroma/ecto/ecto.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-onl defmodule Mix.Tasks.Pleroma.Ecto do diff --git a/lib/mix/tasks/pleroma/ecto/migrate.ex b/lib/mix/tasks/pleroma/ecto/migrate.ex index 855c977f6..d87b6957d 100644 --- a/lib/mix/tasks/pleroma/ecto/migrate.ex +++ b/lib/mix/tasks/pleroma/ecto/migrate.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-onl defmodule Mix.Tasks.Pleroma.Ecto.Migrate do diff --git a/lib/mix/tasks/pleroma/ecto/rollback.ex b/lib/mix/tasks/pleroma/ecto/rollback.ex index 2ffb0901c..a1af73fa1 100644 --- a/lib/mix/tasks/pleroma/ecto/rollback.ex +++ b/lib/mix/tasks/pleroma/ecto/rollback.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-onl defmodule Mix.Tasks.Pleroma.Ecto.Rollback do diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index c2225af7d..238d8dcd9 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.Emoji do diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index b9b1991c2..1a1634fe9 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.Instance do diff --git a/lib/mix/tasks/pleroma/relay.ex b/lib/mix/tasks/pleroma/relay.ex index a738fae75..200721163 100644 --- a/lib/mix/tasks/pleroma/relay.ex +++ b/lib/mix/tasks/pleroma/relay.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.Relay do diff --git a/lib/mix/tasks/pleroma/uploads.ex b/lib/mix/tasks/pleroma/uploads.ex index be45383ee..95392d81b 100644 --- a/lib/mix/tasks/pleroma/uploads.ex +++ b/lib/mix/tasks/pleroma/uploads.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.Uploads do diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index a3f8bc945..eb0052144 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.User do -- cgit v1.2.3 From 79b25be4e1e9e97277a831c98ccea86a038914de Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 24 Sep 2019 14:16:52 +0700 Subject: Do not return tuple when unneeded --- lib/mix/tasks/pleroma/user.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index eb0052144..84c923901 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -228,9 +228,9 @@ defmodule Mix.Tasks.Pleroma.User do shell_info("Deactivating #{user.nickname}") User.deactivate(user) - {:ok, friends} = User.get_friends(user) - - Enum.each(friends, fn friend -> + user + |> User.get_friends() + |> Enum.each(fn friend -> user = User.get_cached_by_id(user.id) shell_info("Unsubscribing #{friend.nickname} from #{user.nickname}") @@ -405,7 +405,7 @@ defmodule Mix.Tasks.Pleroma.User do start_pleroma() with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do - {:ok, _} = User.delete_user_activities(user) + User.delete_user_activities(user) shell_info("User #{nickname} statuses deleted.") else _ -> -- cgit v1.2.3 From 209395c7e60afe7115f22afd6936d9c6bdd7bb72 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 24 Sep 2019 19:50:07 +0700 Subject: Add User.change_info/2 and User.update_info/2 --- lib/mix/tasks/pleroma/user.ex | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 84c923901..d93ba8dee 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -4,7 +4,6 @@ defmodule Mix.Tasks.Pleroma.User do use Mix.Task - import Ecto.Changeset import Mix.Pleroma alias Pleroma.User alias Pleroma.UserInviteToken @@ -443,39 +442,21 @@ defmodule Mix.Tasks.Pleroma.User do end defp set_moderator(user, value) do - info_cng = User.Info.admin_api_update(user.info, %{is_moderator: value}) - - user_cng = - Ecto.Changeset.change(user) - |> put_embed(:info, info_cng) - - {:ok, user} = User.update_and_set_cache(user_cng) + {:ok, user} = User.update_info(user, &User.Info.admin_api_update(&1, %{is_moderator: value})) shell_info("Moderator status of #{user.nickname}: #{user.info.is_moderator}") user end defp set_admin(user, value) do - info_cng = User.Info.admin_api_update(user.info, %{is_admin: value}) - - user_cng = - Ecto.Changeset.change(user) - |> put_embed(:info, info_cng) - - {:ok, user} = User.update_and_set_cache(user_cng) + {:ok, user} = User.update_info(user, &User.Info.admin_api_update(&1, %{is_admin: value})) shell_info("Admin status of #{user.nickname}: #{user.info.is_admin}") user end defp set_locked(user, value) do - info_cng = User.Info.user_upgrade(user.info, %{locked: value}) - - user_cng = - Ecto.Changeset.change(user) - |> put_embed(:info, info_cng) - - {:ok, user} = User.update_and_set_cache(user_cng) + {:ok, user} = User.update_info(user, &User.Info.user_upgrade(&1, %{locked: value})) shell_info("Locked status of #{user.nickname}: #{user.info.locked}") user -- cgit v1.2.3 From bd9c7807fbf21402cc0444c711c40677ca5de2a0 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 3 Oct 2019 01:03:47 +0300 Subject: Move emoji task docs to a separate file --- lib/mix/tasks/pleroma/emoji.ex | 48 ------------------------------------------ 1 file changed, 48 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index 881a6f725..32b92e6af 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -6,54 +6,6 @@ defmodule Mix.Tasks.Pleroma.Emoji do use Mix.Task @shortdoc "Manages emoji packs" - @moduledoc """ - Manages emoji packs - - ## ls-packs - - mix pleroma.emoji ls-packs [OPTION...] - - Lists the emoji packs and metadata specified in the manifest. - - ### Options - - - `-m, --manifest PATH/URL` - path to a custom manifest, it can - either be an URL starting with `http`, in that case the - manifest will be fetched from that address, or a local path - - ## get-packs - - mix pleroma.emoji get-packs [OPTION...] PACKS - - Fetches, verifies and installs the specified PACKS from the - manifest into the `STATIC-DIR/emoji/PACK-NAME` - - ### Options - - - `-m, --manifest PATH/URL` - same as ls-packs - - ## gen-pack - - mix pleroma.emoji gen-pack PACK-URL - - Creates a new manifest entry and a file list from the specified - remote pack file. Currently, only .zip archives are recognized - as remote pack files and packs are therefore assumed to be zip - archives. This command is intended to run interactively and will - first ask you some basic questions about the pack, then download - the remote file and generate an SHA256 checksum for it, then - generate an emoji file list for you. - - The manifest entry will either be written to a newly created - `index.json` file or appended to the existing one, *replacing* - the old pack with the same name if it was in the file previously. - - The file list will be written to the file specified previously, - *replacing* that file. You _should_ check that the file list doesn't - contain anything you don't need in the pack, that is, anything that is - not an emoji (the whole pack is downloaded, but only emoji files - are extracted). - """ def run(["ls-packs" | args]) do Application.ensure_all_started(:hackney) -- cgit v1.2.3 From 869ea2ab90bb461ad3dd06ac974f227da369fcf8 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 3 Oct 2019 01:09:51 +0300 Subject: Move digest email docs to a separate file and improve styling --- lib/mix/tasks/pleroma/digest.ex | 9 --------- 1 file changed, 9 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/digest.ex b/lib/mix/tasks/pleroma/digest.ex index 430116a50..100a81060 100644 --- a/lib/mix/tasks/pleroma/digest.ex +++ b/lib/mix/tasks/pleroma/digest.ex @@ -2,16 +2,7 @@ defmodule Mix.Tasks.Pleroma.Digest do use Mix.Task @shortdoc "Manages digest emails" - @moduledoc """ - Manages digest emails - ## Send digest email since given date (user registration date by default) - ignoring user activity status. - - ``mix pleroma.digest test `` - - Example: ``mix pleroma.digest test donaldtheduck 2019-05-20`` - """ def run(["test", nickname | opts]) do Mix.Pleroma.start_pleroma() -- cgit v1.2.3 From 6435ba83cd07162a9ad9a386253814e2f12d951d Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 3 Oct 2019 09:02:48 +0300 Subject: Move instance CLI task docs to a text file --- lib/mix/tasks/pleroma/instance.ex | 30 ------------------------------ 1 file changed, 30 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 1a1634fe9..25f94eceb 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -7,36 +7,6 @@ defmodule Mix.Tasks.Pleroma.Instance do import Mix.Pleroma @shortdoc "Manages Pleroma instance" - @moduledoc """ - Manages Pleroma instance. - - ## Generate a new instance config. - - mix pleroma.instance gen [OPTION...] - - If any options are left unspecified, you will be prompted interactively - - ## Options - - - `-f`, `--force` - overwrite any output files - - `-o PATH`, `--output PATH` - the output file for the generated configuration - - `--output-psql PATH` - the output file for the generated PostgreSQL setup - - `--domain DOMAIN` - the domain of your instance - - `--instance-name INSTANCE_NAME` - the name of your instance - - `--admin-email ADMIN_EMAIL` - the email address of the instance admin - - `--notify-email NOTIFY_EMAIL` - email address for notifications - - `--dbhost HOSTNAME` - the hostname of the PostgreSQL database to use - - `--dbname DBNAME` - the name of the database to use - - `--dbuser DBUSER` - the user (aka role) to use for the database connection - - `--dbpass DBPASS` - the password to use for the database connection - - `--rum Y/N` - Whether to enable RUM indexes - - `--indexable Y/N` - Allow/disallow indexing site by search engines - - `--db-configurable Y/N` - Allow/disallow configuring instance from admin part - - `--uploads-dir` - the directory uploads go in when using a local uploader - - `--static-dir` - the directory custom public files should be read from (custom emojis, frontend bundle overrides, robots.txt, etc.) - - `--listen-ip` - the ip the app should listen to, defaults to 127.0.0.1 - - `--listen-port` - the port the app should listen to, defaults to 4000 - """ def run(["gen" | rest]) do {options, [], []} = -- cgit v1.2.3 From 808d0a0170577155d0f1097c66c4e0b23c8303b9 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 3 Oct 2019 09:10:31 +0300 Subject: Move relay docs to a separate file --- lib/mix/tasks/pleroma/relay.ex | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/relay.ex b/lib/mix/tasks/pleroma/relay.ex index 200721163..519f2d1b5 100644 --- a/lib/mix/tasks/pleroma/relay.ex +++ b/lib/mix/tasks/pleroma/relay.ex @@ -9,25 +9,7 @@ defmodule Mix.Tasks.Pleroma.Relay do alias Pleroma.Web.ActivityPub.Relay @shortdoc "Manages remote relays" - @moduledoc """ - Manages remote relays - ## Follow a remote relay - - ``mix pleroma.relay follow `` - - Example: ``mix pleroma.relay follow https://example.org/relay`` - - ## Unfollow a remote relay - - ``mix pleroma.relay unfollow `` - - Example: ``mix pleroma.relay unfollow https://example.org/relay`` - - ## List relay subscriptions - - ``mix pleroma.relay list`` - """ def run(["follow", target]) do start_pleroma() -- cgit v1.2.3 From d39ccc2e7ffd019f8fe2438f388c0a0bb8aac34a Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 3 Oct 2019 09:35:21 +0300 Subject: Move uploads task docs to a separate file --- lib/mix/tasks/pleroma/uploads.ex | 9 --------- 1 file changed, 9 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/uploads.ex b/lib/mix/tasks/pleroma/uploads.ex index 95392d81b..bc2248a76 100644 --- a/lib/mix/tasks/pleroma/uploads.ex +++ b/lib/mix/tasks/pleroma/uploads.ex @@ -12,16 +12,7 @@ defmodule Mix.Tasks.Pleroma.Uploads do @log_every 50 @shortdoc "Migrates uploads from local to remote storage" - @moduledoc """ - Manages uploads - ## Migrate uploads from local to remote storage - mix pleroma.uploads migrate_local TARGET_UPLOADER [OPTIONS...] - Options: - - `--delete` - delete local uploads after migrating them to the target uploader - - A list of available uploaders can be seen in config.exs - """ def run(["migrate_local", target_uploader | args]) do delete? = Enum.member?(args, "--delete") start_pleroma() -- cgit v1.2.3 From b4ca864c6b2e6ee9addea7fbc0b09fca581816ce Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 3 Oct 2019 10:15:24 +0300 Subject: Move user tasks docs to a separate file --- lib/mix/tasks/pleroma/user.ex | 79 ------------------------------------------- 1 file changed, 79 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index d93ba8dee..3cf3ad2c6 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -10,86 +10,7 @@ defmodule Mix.Tasks.Pleroma.User do alias Pleroma.Web.OAuth @shortdoc "Manages Pleroma users" - @moduledoc """ - Manages Pleroma users. - ## Create a new user. - - mix pleroma.user new NICKNAME EMAIL [OPTION...] - - Options: - - `--name NAME` - the user's name (i.e., "Lain Iwakura") - - `--bio BIO` - the user's bio - - `--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 - - ## Generate an invite link. - - mix pleroma.user invite [OPTION...] - - Options: - - `--expires-at DATE` - last day on which token is active (e.g. "2019-04-05") - - `--max-use NUMBER` - maximum numbers of token uses - - ## List generated invites - - mix pleroma.user invites - - ## Revoke invite - - mix pleroma.user revoke_invite TOKEN OR TOKEN_ID - - ## Delete the user's account. - - mix pleroma.user rm NICKNAME - - ## Delete the user's activities. - - mix pleroma.user delete_activities NICKNAME - - ## Sign user out from all applications (delete user's OAuth tokens and authorizations). - - mix pleroma.user sign_out NICKNAME - - ## Deactivate or activate the user's account. - - mix pleroma.user toggle_activated NICKNAME - - ## Unsubscribe local users from user's account and deactivate it - - mix pleroma.user unsubscribe NICKNAME - - ## Unsubscribe local users from an entire instance and deactivate all accounts - - mix pleroma.user unsubscribe_all_from_instance INSTANCE - - ## Create a password reset link. - - mix pleroma.user reset_password NICKNAME - - ## Set the value of the given user's settings. - - mix pleroma.user set NICKNAME [OPTION...] - - Options: - - `--locked`/`--no-locked` - whether the user's account is locked - - `--moderator`/`--no-moderator` - whether the user is a moderator - - `--admin`/`--no-admin` - whether the user is an admin - - ## Add tags to a user. - - mix pleroma.user tag NICKNAME TAGS - - ## Delete tags from a user. - - mix pleroma.user untag NICKNAME TAGS - - ## Toggle confirmation of the user's account. - - mix pleroma.user toggle_confirmed NICKNAME - """ def run(["new", nickname, email | rest]) do {options, [], []} = OptionParser.parse( -- cgit v1.2.3 From 6baa037903e06c80a5b5f1c34b2cfdd471ba2f8f Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 3 Oct 2019 11:17:29 +0300 Subject: Move database maintenance tasks docs to a separate file --- lib/mix/tasks/pleroma/database.ex | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/database.ex b/lib/mix/tasks/pleroma/database.ex index 890a383df..81e687f64 100644 --- a/lib/mix/tasks/pleroma/database.ex +++ b/lib/mix/tasks/pleroma/database.ex @@ -13,34 +13,7 @@ defmodule Mix.Tasks.Pleroma.Database do use Mix.Task @shortdoc "A collection of database related tasks" - @moduledoc """ - A collection of database related tasks - ## Replace embedded objects with their references - - Replaces embedded objects with references to them in the `objects` table. Only needs to be ran once. The reason why this is not a migration is because it could significantly increase the database size after being ran, however after this `VACUUM FULL` will be able to reclaim about 20% (really depends on what is in the database, your mileage may vary) of the db size before the migration. - - mix pleroma.database remove_embedded_objects - - Options: - - `--vacuum` - run `VACUUM FULL` after the embedded objects are replaced with their references - - ## Prune old objects from the database - - mix pleroma.database prune_objects - - ## Create a conversation for all existing DMs. Can be safely re-run. - - mix pleroma.database bump_all_conversations - - ## Remove duplicated items from following and update followers count for all users - - mix pleroma.database update_users_following_followers_counts - - ## Fix the pre-existing "likes" collections for all objects - - mix pleroma.database fix_likes_collections - """ def run(["remove_embedded_objects" | args]) do {options, [], []} = OptionParser.parse( -- cgit v1.2.3 From e00403af232548fdef8ad8f2923a51561b3064f6 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 3 Oct 2019 13:59:49 +0300 Subject: Mix tasks: derive moduledoc from doc files --- lib/mix/tasks/pleroma/database.ex | 1 + lib/mix/tasks/pleroma/digest.ex | 1 + lib/mix/tasks/pleroma/emoji.ex | 1 + lib/mix/tasks/pleroma/instance.ex | 1 + lib/mix/tasks/pleroma/relay.ex | 1 + lib/mix/tasks/pleroma/uploads.ex | 1 + lib/mix/tasks/pleroma/user.ex | 1 + 7 files changed, 7 insertions(+) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/database.ex b/lib/mix/tasks/pleroma/database.ex index 81e687f64..cfd9eeada 100644 --- a/lib/mix/tasks/pleroma/database.ex +++ b/lib/mix/tasks/pleroma/database.ex @@ -13,6 +13,7 @@ defmodule Mix.Tasks.Pleroma.Database do use Mix.Task @shortdoc "A collection of database related tasks" + @moduledoc File.read!("docs/administration/CLI_tasks/database.md") def run(["remove_embedded_objects" | args]) do {options, [], []} = diff --git a/lib/mix/tasks/pleroma/digest.ex b/lib/mix/tasks/pleroma/digest.ex index 100a81060..7d09e70c5 100644 --- a/lib/mix/tasks/pleroma/digest.ex +++ b/lib/mix/tasks/pleroma/digest.ex @@ -2,6 +2,7 @@ defmodule Mix.Tasks.Pleroma.Digest do use Mix.Task @shortdoc "Manages digest emails" + @moduledoc File.read!("docs/administration/CLI_tasks/digest.md") def run(["test", nickname | opts]) do Mix.Pleroma.start_pleroma() diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index 32b92e6af..6ef0a635d 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -6,6 +6,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do use Mix.Task @shortdoc "Manages emoji packs" + @moduledoc File.read!("docs/administration/CLI_tasks/emoji.md") def run(["ls-packs" | args]) do Application.ensure_all_started(:hackney) diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 25f94eceb..9af6cda30 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -7,6 +7,7 @@ defmodule Mix.Tasks.Pleroma.Instance do import Mix.Pleroma @shortdoc "Manages Pleroma instance" + @moduledoc File.read!("docs/administration/CLI_tasks/instance.md") def run(["gen" | rest]) do {options, [], []} = diff --git a/lib/mix/tasks/pleroma/relay.ex b/lib/mix/tasks/pleroma/relay.ex index 519f2d1b5..d7a7b599f 100644 --- a/lib/mix/tasks/pleroma/relay.ex +++ b/lib/mix/tasks/pleroma/relay.ex @@ -9,6 +9,7 @@ defmodule Mix.Tasks.Pleroma.Relay do alias Pleroma.Web.ActivityPub.Relay @shortdoc "Manages remote relays" + @moduledoc File.read!("docs/administration/CLI_tasks/relay.md") def run(["follow", target]) do start_pleroma() diff --git a/lib/mix/tasks/pleroma/uploads.ex b/lib/mix/tasks/pleroma/uploads.ex index bc2248a76..3e6fc7ee0 100644 --- a/lib/mix/tasks/pleroma/uploads.ex +++ b/lib/mix/tasks/pleroma/uploads.ex @@ -12,6 +12,7 @@ defmodule Mix.Tasks.Pleroma.Uploads do @log_every 50 @shortdoc "Migrates uploads from local to remote storage" + @moduledoc File.read!("docs/administration/CLI_tasks/uploads.md") def run(["migrate_local", target_uploader | args]) do delete? = Enum.member?(args, "--delete") diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 3cf3ad2c6..134b5bccc 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -10,6 +10,7 @@ defmodule Mix.Tasks.Pleroma.User do alias Pleroma.Web.OAuth @shortdoc "Manages Pleroma users" + @moduledoc File.read!("docs/administration/CLI_tasks/user.md") def run(["new", nickname, email | rest]) do {options, [], []} = -- cgit v1.2.3 From 1cae564b5d749a23f29a5303a82e27e2952a55ed Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 3 Oct 2019 14:12:57 +0300 Subject: Move config task docs to a separate file and mark it as WIP --- lib/mix/tasks/pleroma/config.ex | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index 462940e7e..11e4fde43 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -8,18 +8,7 @@ defmodule Mix.Tasks.Pleroma.Config do alias Pleroma.Repo alias Pleroma.Web.AdminAPI.Config @shortdoc "Manages the location of the config" - @moduledoc """ - Manages the location of the config. - - ## Transfers config from file to DB. - - mix pleroma.config migrate_to_db - - ## Transfers config from DB to file `config/env.exported_from_db.secret.exs` - - mix pleroma.config migrate_from_db ENV - """ - + @moduledoc File.read!("docs/administration/CLI_tasks/config.md") def run(["migrate_to_db"]) do start_pleroma() -- cgit v1.2.3 From d537bfd4e1e3119188519a4b1839fdbe3f6fad39 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Wed, 9 Oct 2019 13:11:57 +0700 Subject: Add a task to re-count statuses for all users --- lib/mix/tasks/pleroma/count_statuses.ex | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lib/mix/tasks/pleroma/count_statuses.ex (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/count_statuses.ex b/lib/mix/tasks/pleroma/count_statuses.ex new file mode 100644 index 000000000..e1e8195dd --- /dev/null +++ b/lib/mix/tasks/pleroma/count_statuses.ex @@ -0,0 +1,22 @@ +defmodule Mix.Tasks.Pleroma.CountStatuses do + @shortdoc "Re-counts statuses for all users" + + use Mix.Task + alias Pleroma.User + import Ecto.Query + + def run([]) do + Mix.Pleroma.start_pleroma() + + stream = + User + |> where(local: true) + |> Pleroma.Repo.stream() + + Pleroma.Repo.transaction(fn -> + Enum.each(stream, &User.update_note_count/1) + end) + + Mix.Pleroma.shell_info("Done") + end +end -- cgit v1.2.3 From 059005ff829c0313c62ddf5fbcd95f8892920228 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Fri, 11 Oct 2019 02:35:32 +0700 Subject: Replace `user.following` with Pleroma.FollowingRelationship --- lib/mix/tasks/pleroma/database.ex | 6 +++--- lib/mix/tasks/pleroma/relay.ex | 5 +++-- lib/mix/tasks/pleroma/user.ex | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/database.ex b/lib/mix/tasks/pleroma/database.ex index cfd9eeada..72b706e1a 100644 --- a/lib/mix/tasks/pleroma/database.ex +++ b/lib/mix/tasks/pleroma/database.ex @@ -52,9 +52,9 @@ defmodule Mix.Tasks.Pleroma.Database do def run(["update_users_following_followers_counts"]) do start_pleroma() - users = Repo.all(User) - Enum.each(users, &User.remove_duplicated_following/1) - Enum.each(users, &User.update_follower_count/1) + User + |> Repo.all() + |> Enum.each(&User.update_follower_count/1) end def run(["prune_objects" | args]) do diff --git a/lib/mix/tasks/pleroma/relay.ex b/lib/mix/tasks/pleroma/relay.ex index d7a7b599f..eafddada6 100644 --- a/lib/mix/tasks/pleroma/relay.ex +++ b/lib/mix/tasks/pleroma/relay.ex @@ -36,8 +36,9 @@ defmodule Mix.Tasks.Pleroma.Relay do def run(["list"]) do start_pleroma() - with %User{following: following} = _user <- Relay.get_actor() do - following + with %User{} = user <- Relay.get_actor() do + user + |> User.following() |> Enum.map(fn entry -> URI.parse(entry).host end) |> Enum.uniq() |> Enum.each(&shell_info(&1)) diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 134b5bccc..8866afdf6 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -162,7 +162,7 @@ defmodule Mix.Tasks.Pleroma.User do user = User.get_cached_by_id(user.id) - if Enum.empty?(user.following) do + if Enum.empty?(User.get_friends(user)) do shell_info("Successfully unsubscribed all followers from #{user.nickname}") end else -- cgit v1.2.3 From cc6875b582df49d2cb780e0940b85d5b04fe0e74 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Fri, 11 Oct 2019 19:12:29 +0300 Subject: Add `GET /api/pleroma/admin/relay` endpoint - lists all followed relays --- lib/mix/tasks/pleroma/relay.ex | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/relay.ex b/lib/mix/tasks/pleroma/relay.ex index d7a7b599f..7ef5f9678 100644 --- a/lib/mix/tasks/pleroma/relay.ex +++ b/lib/mix/tasks/pleroma/relay.ex @@ -5,7 +5,6 @@ defmodule Mix.Tasks.Pleroma.Relay do use Mix.Task import Mix.Pleroma - alias Pleroma.User alias Pleroma.Web.ActivityPub.Relay @shortdoc "Manages remote relays" @@ -36,13 +35,10 @@ defmodule Mix.Tasks.Pleroma.Relay do def run(["list"]) do start_pleroma() - with %User{following: following} = _user <- Relay.get_actor() do - following - |> Enum.map(fn entry -> URI.parse(entry).host end) - |> Enum.uniq() - |> Enum.each(&shell_info(&1)) + with {:ok, list} <- Relay.list() do + list |> Enum.each(&shell_info(&1)) else - e -> shell_error("Error while fetching relay subscription list: #{inspect(e)}") + {:error, e} -> shell_error("Error while fetching relay subscription list: #{inspect(e)}") end end end -- cgit v1.2.3 From fbe5a00475331962d7112ed5a0d5cf8bb5bf3ece Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Mon, 30 Sep 2019 16:04:30 +0300 Subject: For pleroma.emoji downloaded packs, generate pack.json instead --- lib/mix/tasks/pleroma/emoji.ex | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index 881a6f725..1470b9b72 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -158,19 +158,21 @@ defmodule Mix.Tasks.Pleroma.Emoji do file_list: files_to_unzip ) - IO.puts(IO.ANSI.format(["Writing emoji.txt for ", :bright, pack_name])) - - emoji_txt_str = - Enum.map( - files, - fn {shortcode, path} -> - emojo_path = Path.join("/emoji/#{pack_name}", path) - "#{shortcode}, #{emojo_path}" - end - ) - |> Enum.join("\n") - - File.write!(Path.join(pack_path, "emoji.txt"), emoji_txt_str) + IO.puts(IO.ANSI.format(["Writing pack.json for ", :bright, pack_name])) + + pack_json = %{ + pack: %{ + "license" => pack["license"], + "homepage" => pack["homepage"], + "description" => pack["description"], + "fallback-src" => pack["src"], + "fallback-src-sha256" => pack["src_sha256"], + "share-files" => true + }, + files: files + } + + File.write!(Path.join(pack_path, "pack.json"), Jason.encode!(pack_json, pretty: true)) else IO.puts(IO.ANSI.format([:bright, :red, "No pack named \"#{pack_name}\" found"])) end -- cgit v1.2.3 From 10ff01acd95d42314b4eb923e5b7a7191356b73e Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 16 Oct 2019 21:59:21 +0300 Subject: [#1304] Moved all non-mutes / non-blocks fields from User.Info to User. WIP. --- lib/mix/tasks/pleroma/user.ex | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 134b5bccc..265c5f1a7 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -109,10 +109,10 @@ defmodule Mix.Tasks.Pleroma.User do start_pleroma() with %User{} = user <- User.get_cached_by_nickname(nickname) do - {:ok, user} = User.deactivate(user, !user.info.deactivated) + {:ok, user} = User.deactivate(user, !user.deactivated) shell_info( - "Activation status of #{nickname}: #{if(user.info.deactivated, do: "de", else: "")}activated" + "Activation status of #{nickname}: #{if(user.deactivated, do: "de", else: "")}activated" ) else _ -> @@ -340,7 +340,7 @@ defmodule Mix.Tasks.Pleroma.User do with %User{} = user <- User.get_cached_by_nickname(nickname) do {:ok, user} = User.toggle_confirmation(user) - message = if user.info.confirmation_pending, do: "needs", else: "doesn't need" + message = if user.confirmation_pending, do: "needs", else: "doesn't need" shell_info("#{nickname} #{message} confirmation.") else @@ -364,23 +364,23 @@ defmodule Mix.Tasks.Pleroma.User do end defp set_moderator(user, value) do - {:ok, user} = User.update_info(user, &User.Info.admin_api_update(&1, %{is_moderator: value})) + {:ok, user} = User.update_and_set_cache(user, %{is_moderator: value}) - shell_info("Moderator status of #{user.nickname}: #{user.info.is_moderator}") + shell_info("Moderator status of #{user.nickname}: #{user.is_moderator}") user end defp set_admin(user, value) do - {:ok, user} = User.update_info(user, &User.Info.admin_api_update(&1, %{is_admin: value})) + {:ok, user} = User.update_and_set_cache(user, %{is_admin: value}) - shell_info("Admin status of #{user.nickname}: #{user.info.is_admin}") + shell_info("Admin status of #{user.nickname}: #{user.is_admin}") user end defp set_locked(user, value) do - {:ok, user} = User.update_info(user, &User.Info.user_upgrade(&1, %{locked: value})) + {:ok, user} = User.update_and_set_cache(user, %{locked: value}) - shell_info("Locked status of #{user.nickname}: #{user.info.locked}") + shell_info("Locked status of #{user.nickname}: #{user.locked}") user end end -- cgit v1.2.3 From 39e996528c1e7551675c0d0f140dcfa01e671004 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 18 Oct 2019 14:11:30 +0300 Subject: Fix a migration wiping user info of users that don't have any mutes And introduce safe_jsonb_set --- lib/mix/tasks/pleroma/database.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/database.ex b/lib/mix/tasks/pleroma/database.ex index cfd9eeada..8a827ca80 100644 --- a/lib/mix/tasks/pleroma/database.ex +++ b/lib/mix/tasks/pleroma/database.ex @@ -28,7 +28,7 @@ defmodule Mix.Tasks.Pleroma.Database do Logger.info("Removing embedded objects") Repo.query!( - "update activities set data = jsonb_set(data, '{object}'::text[], data->'object'->'id') where data->'object'->>'id' is not null;", + "update activities set data = safe_jsonb_set(data, '{object}'::text[], data->'object'->'id') where data->'object'->>'id' is not null;", [], timeout: :infinity ) @@ -126,7 +126,7 @@ defmodule Mix.Tasks.Pleroma.Database do set: [ data: fragment( - "jsonb_set(?, '{likes}', '[]'::jsonb, true)", + "safe_jsonb_set(?, '{likes}', '[]'::jsonb, true)", object.data ) ] -- cgit v1.2.3 From e8843974cb9b8adfe8798bb8f7ff17b7a92f5ab8 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Sun, 20 Oct 2019 13:42:42 +0300 Subject: [#1304] Moved remaining fields from User.Info to User. Misc. fixes / improvements. --- lib/mix/tasks/pleroma/user.ex | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 265c5f1a7..d7bdc2310 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -5,6 +5,7 @@ defmodule Mix.Tasks.Pleroma.User do use Mix.Task import Mix.Pleroma + alias Ecto.Changeset alias Pleroma.User alias Pleroma.UserInviteToken alias Pleroma.Web.OAuth @@ -364,21 +365,30 @@ defmodule Mix.Tasks.Pleroma.User do end defp set_moderator(user, value) do - {:ok, user} = User.update_and_set_cache(user, %{is_moderator: value}) + {:ok, user} = + user + |> Changeset.change(%{is_moderator: value}) + |> User.update_and_set_cache() shell_info("Moderator status of #{user.nickname}: #{user.is_moderator}") user end defp set_admin(user, value) do - {:ok, user} = User.update_and_set_cache(user, %{is_admin: value}) + {:ok, user} = + user + |> Changeset.change(%{is_admin: value}) + |> User.update_and_set_cache() shell_info("Admin status of #{user.nickname}: #{user.is_admin}") user end defp set_locked(user, value) do - {:ok, user} = User.update_and_set_cache(user, %{locked: value}) + {:ok, user} = + user + |> Changeset.change(%{locked: value}) + |> User.update_and_set_cache() shell_info("Locked status of #{user.nickname}: #{user.locked}") user -- cgit v1.2.3 From 6a4201e0b444748318845caddf0e972d0fac87d7 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 10 Nov 2019 22:54:37 +0300 Subject: fix for migrate task --- lib/mix/tasks/pleroma/config.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index 11e4fde43..0e21408b2 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -45,7 +45,7 @@ defmodule Mix.Tasks.Pleroma.Config do if Pleroma.Config.get([:instance, :dynamic_configuration]) do config_path = "config/#{env}.exported_from_db.secret.exs" - {:ok, file} = File.open(config_path, [:write]) + {:ok, file} = File.open(config_path, [:write, :utf8]) IO.write(file, "use Mix.Config\r\n") Repo.all(Config) -- cgit v1.2.3 From ff9133b978edb637081882e7efd49e2f538e9e15 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 19 Nov 2019 16:01:17 -0600 Subject: Allow mix tasks to always run with debug logging --- lib/mix/pleroma.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/mix') diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex index faeb30e1d..94eeb7d68 100644 --- a/lib/mix/pleroma.ex +++ b/lib/mix/pleroma.ex @@ -6,6 +6,7 @@ defmodule Mix.Pleroma do @doc "Common functions to be reused in mix tasks" def start_pleroma do Application.put_env(:phoenix, :serve_endpoints, false, persistent: true) + Application.put_env(:logger, :console, level: :debug) {:ok, _} = Application.ensure_all_started(:pleroma) end -- cgit v1.2.3 From edaae845afc63d558c22019b3b3f87bc510a3bdf Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 20 Nov 2019 11:55:30 -0600 Subject: Some tasks try to set log level in test environment, but we were stripping logs belog :warn. Ensure console backend logs in test environment are :warn, but mix tasks run in test env do not run with :debug because it's far too verbose. --- lib/mix/pleroma.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/mix') diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex index 94eeb7d68..73a076a53 100644 --- a/lib/mix/pleroma.ex +++ b/lib/mix/pleroma.ex @@ -6,7 +6,11 @@ defmodule Mix.Pleroma do @doc "Common functions to be reused in mix tasks" def start_pleroma do Application.put_env(:phoenix, :serve_endpoints, false, persistent: true) - Application.put_env(:logger, :console, level: :debug) + + if Pleroma.Config.get(:env) != :test do + Application.put_env(:logger, :console, level: :debug) + end + {:ok, _} = Application.ensure_all_started(:pleroma) end -- cgit v1.2.3 From fbc379d68990b166e1034cfff252f975f793eba1 Mon Sep 17 00:00:00 2001 From: Alex Schroeder Date: Sun, 17 Nov 2019 21:58:30 +0100 Subject: Add CLI list users command --- lib/mix/tasks/pleroma/user.ex | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 4e3b80db3..bc8eacda8 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -364,6 +364,24 @@ defmodule Mix.Tasks.Pleroma.User do end end + def run(["list"]) do + start_pleroma() + + Pleroma.User.Query.build(%{local: true}) + |> Pleroma.RepoStreamer.chunk_stream(500) + |> Stream.each(fn users -> + users + |> Enum.each(fn user -> + shell_info( + "#{user.nickname} moderator: #{user.info.is_moderator}, admin: #{user.info.is_admin}, locked: #{ + user.info.locked + }, deactivated: #{user.info.deactivated}" + ) + end) + end) + |> Stream.run() + end + defp set_moderator(user, value) do {:ok, user} = user -- cgit v1.2.3 From a36607c27e6a50aeca450570f7b8e4c9c0233bb1 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Wed, 30 Oct 2019 22:59:04 +0300 Subject: add mix task to set\unset privacy option of notification --- lib/mix/tasks/pleroma/notification_settings.ex | 83 ++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 lib/mix/tasks/pleroma/notification_settings.ex (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/notification_settings.ex b/lib/mix/tasks/pleroma/notification_settings.ex new file mode 100644 index 000000000..7d65f0587 --- /dev/null +++ b/lib/mix/tasks/pleroma/notification_settings.ex @@ -0,0 +1,83 @@ +defmodule Mix.Tasks.Pleroma.NotificationSettings do + @shortdoc "Enable&Disable privacy option for push notifications" + @moduledoc """ + Example: + + > mix pleroma.notification_settings --privacy-option=false --nickname-users="parallel588" # set false only for parallel588 user + > mix pleroma.notification_settings --privacy-option=true # set true for all users + + """ + + use Mix.Task + import Mix.Pleroma + import Ecto.Query + + def run(args) do + start_pleroma() + + {options, _, _} = + OptionParser.parse( + args, + strict: [ + privacy_option: :boolean, + email_users: :string, + nickname_users: :string + ] + ) + + privacy_option = Keyword.get(options, :privacy_option) + + if not is_nil(privacy_option) do + privacy_option + |> build_query(options) + |> Pleroma.Repo.update_all([]) + end + + shell_info("Done") + end + + defp build_query(privacy_option, options) do + query = + from(u in Pleroma.User, + update: [ + set: [ + notification_settings: + fragment( + "jsonb_set(notification_settings, '{privacy_option}', ?)", + ^privacy_option + ) + ] + ] + ) + + user_emails = + options + |> Keyword.get(:email_users, "") + |> String.split(",") + |> Enum.map(&String.trim(&1)) + |> Enum.reject(&(&1 == "")) + + query = + if length(user_emails) > 0 do + where(query, [u], u.email in ^user_emails) + else + query + end + + user_nicknames = + options + |> Keyword.get(:nickname_users, "") + |> String.split(",") + |> Enum.map(&String.trim(&1)) + |> Enum.reject(&(&1 == "")) + + query = + if length(user_nicknames) > 0 do + where(query, [u], u.nickname in ^user_nicknames) + else + query + end + + query + end +end -- cgit v1.2.3 From 356a936ecbddf6bbdfada2ef70264b99e9d9723c Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Mon, 2 Dec 2019 18:11:45 +0700 Subject: Fix `mix pleroma.user list` task --- lib/mix/tasks/pleroma/user.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index bc8eacda8..0adb78fe3 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -373,9 +373,9 @@ defmodule Mix.Tasks.Pleroma.User do users |> Enum.each(fn user -> shell_info( - "#{user.nickname} moderator: #{user.info.is_moderator}, admin: #{user.info.is_admin}, locked: #{ - user.info.locked - }, deactivated: #{user.info.deactivated}" + "#{user.nickname} moderator: #{user.is_moderator}, admin: #{user.is_admin}, locked: #{ + user.locked + }, deactivated: #{user.deactivated}" ) end) end) -- cgit v1.2.3 From af42c00cfffb2cd8e93857cd1cf2901113c45bd2 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 6 Dec 2019 00:25:44 +0300 Subject: [#1427] Reworked admin scopes support. Requalified users.is_admin flag as legacy accessor to admin actions in case token lacks admin scope(s). --- lib/mix/tasks/pleroma/user.ex | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 4e3b80db3..8c4739221 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -8,7 +8,6 @@ defmodule Mix.Tasks.Pleroma.User do alias Ecto.Changeset alias Pleroma.User alias Pleroma.UserInviteToken - alias Pleroma.Web.OAuth @shortdoc "Manages Pleroma users" @moduledoc File.read!("docs/administration/CLI_tasks/user.md") @@ -354,8 +353,7 @@ defmodule Mix.Tasks.Pleroma.User do start_pleroma() with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do - OAuth.Token.delete_user_tokens(user) - OAuth.Authorization.delete_user_authorizations(user) + User.global_sign_out(user) shell_info("#{nickname} signed out from all apps.") else @@ -375,10 +373,7 @@ defmodule Mix.Tasks.Pleroma.User do end defp set_admin(user, value) do - {:ok, user} = - user - |> Changeset.change(%{is_admin: value}) - |> User.update_and_set_cache() + {:ok, user} = User.admin_api_update(user, %{is_admin: value}) shell_info("Admin status of #{user.nickname}: #{user.is_admin}") user -- cgit v1.2.3 From 9dfaa0b832ddb09f0937c96e5e30b83957f8185f Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Mon, 9 Dec 2019 22:29:44 +0300 Subject: fix loads config variable with large value from db --- lib/mix/tasks/pleroma/config.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index 0e21408b2..590c7a914 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -52,7 +52,9 @@ defmodule Mix.Tasks.Pleroma.Config do |> Enum.each(fn config -> IO.write( file, - "config :#{config.group}, #{config.key}, #{inspect(Config.from_binary(config.value))}\r\n\r\n" + "config :#{config.group}, #{config.key}, #{ + inspect(Config.from_binary(config.value), limit: :infinity) + }\r\n\r\n" ) if delete? do -- cgit v1.2.3 From 2753285b7722fdb47f0ebb2180e997cf72f65d1a Mon Sep 17 00:00:00 2001 From: Alex S Date: Sun, 29 Sep 2019 11:17:38 +0300 Subject: config editing through database --- lib/mix/tasks/pleroma/config.ex | 107 +++++++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 40 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index 590c7a914..bb126463c 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -9,27 +9,29 @@ defmodule Mix.Tasks.Pleroma.Config do alias Pleroma.Web.AdminAPI.Config @shortdoc "Manages the location of the config" @moduledoc File.read!("docs/administration/CLI_tasks/config.md") + + @groups [ + :pleroma, + :logger, + :quack, + :mime, + :tesla, + :phoenix, + :cors_plug, + :auto_linker, + :esshd, + :ueberauth, + :prometheus, + :http_signatures, + :web_push_encryption, + :joken + ] + def run(["migrate_to_db"]) do start_pleroma() if Pleroma.Config.get([:instance, :dynamic_configuration]) do - Application.get_all_env(:pleroma) - |> Enum.reject(fn {k, _v} -> k in [Pleroma.Repo, :env] end) - |> Enum.each(fn {k, v} -> - key = to_string(k) |> String.replace("Elixir.", "") - - key = - if String.starts_with?(key, "Pleroma.") do - key - else - ":" <> key - end - - {:ok, _} = Config.update_or_create(%{group: "pleroma", key: key, value: v}) - Mix.shell().info("#{key} is migrated.") - end) - - Mix.shell().info("Settings migrated.") + Enum.each(@groups, &load_and_create(&1)) else Mix.shell().info( "Migration is not allowed by config. You can change this behavior in instance settings." @@ -37,38 +39,63 @@ defmodule Mix.Tasks.Pleroma.Config do end end - def run(["migrate_from_db", env, delete?]) do + def run(["migrate_from_db" | options]) do start_pleroma() - delete? = if delete? == "true", do: true, else: false - - if Pleroma.Config.get([:instance, :dynamic_configuration]) do - config_path = "config/#{env}.exported_from_db.secret.exs" + {opts, _} = + OptionParser.parse!(options, + strict: [env: :string, delete_from_db: :boolean], + aliases: [d: :delete_from_db] + ) - {:ok, file} = File.open(config_path, [:write, :utf8]) + with {:active?, true} <- {:active?, Pleroma.Config.get([:instance, :dynamic_configuration])}, + env_path when is_binary(env_path) <- opts[:env], + config_path <- "config/#{env_path}.exported_from_db.secret.exs", + {:ok, file} <- File.open(config_path, [:write, :utf8]) do IO.write(file, "use Mix.Config\r\n") - Repo.all(Config) - |> Enum.each(fn config -> - IO.write( - file, - "config :#{config.group}, #{config.key}, #{ - inspect(Config.from_binary(config.value), limit: :infinity) - }\r\n\r\n" - ) - - if delete? do - {:ok, _} = Repo.delete(config) - Mix.shell().info("#{config.key} deleted from DB.") - end - end) + Config + |> Repo.all() + |> Enum.each(&write_to_file_with_deletion(&1, file, opts[:delete_from_db])) File.close(file) System.cmd("mix", ["format", config_path]) else - Mix.shell().info( - "Migration is not allowed by config. You can change this behavior in instance settings." - ) + {:active?, false} -> + Mix.shell().info( + "migration is not allowed by config. You can change this behavior in instance settings." + ) + + error -> + Mix.shell().info("error occuried while opening file. #{inspect(error)}") + end + end + + defp load_and_create(group) do + group + |> Application.get_all_env() + |> Enum.reject(fn {k, _v} -> k in [Pleroma.Repo, :env] end) + |> Enum.each(fn {key, value} -> + key_str = inspect(key) + + {:ok, _} = Config.update_or_create(%{group: ":#{group}", key: key_str, value: value}) + Mix.shell().info("settings for key #{key_str} migrated.") + end) + + Mix.shell().info("settings for group :#{group} migrated.") + end + + defp write_to_file_with_deletion(config, file, with_deletion) do + IO.write( + file, + "config #{config.group}, #{config.key}, #{ + inspect(Config.from_binary(config.value), limit: :infinity) + }\r\n\r\n" + ) + + if with_deletion do + {:ok, _} = Repo.delete(config) + Mix.shell().info("#{config.key} deleted from DB.") end end end -- cgit v1.2.3 From 0656816c77875d87d64d89e0e549f73104104cfb Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 6 Dec 2019 08:21:30 +0300 Subject: tests for setttings without an explicit key --- lib/mix/tasks/pleroma/config.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index bb126463c..cef02b864 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -76,10 +76,10 @@ defmodule Mix.Tasks.Pleroma.Config do |> Application.get_all_env() |> Enum.reject(fn {k, _v} -> k in [Pleroma.Repo, :env] end) |> Enum.each(fn {key, value} -> - key_str = inspect(key) + key = inspect(key) + {:ok, _} = Config.update_or_create(%{group: inspect(group), key: key, value: value}) - {:ok, _} = Config.update_or_create(%{group: ":#{group}", key: key_str, value: value}) - Mix.shell().info("settings for key #{key_str} migrated.") + Mix.shell().info("settings for key #{key} migrated.") end) Mix.shell().info("settings for group :#{group} migrated.") -- cgit v1.2.3 From a71393dd29488eb86d6da23250b05a9b5b04eb81 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 10 Dec 2019 12:00:40 +0300 Subject: fix for endpoints after env update --- lib/mix/tasks/pleroma/config.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index cef02b864..257a0dfe5 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -74,7 +74,9 @@ defmodule Mix.Tasks.Pleroma.Config do defp load_and_create(group) do group |> Application.get_all_env() - |> Enum.reject(fn {k, _v} -> k in [Pleroma.Repo, :env] end) + |> Enum.reject(fn {k, _v} -> + k in [Pleroma.Repo, :env] or (group == :phoenix and k == :serve_endpoints) + end) |> Enum.each(fn {key, value} -> key = inspect(key) {:ok, _} = Config.update_or_create(%{group: inspect(group), key: key, value: value}) -- cgit v1.2.3 From 7d128ca2083d83486a05d8c4456aa4090006e781 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Fri, 10 Jan 2020 19:34:19 +0300 Subject: dynamic_configuration renaming and moving it from instance settings --- lib/mix/tasks/pleroma/config.ex | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index 257a0dfe5..3f80af5a7 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -30,7 +30,7 @@ defmodule Mix.Tasks.Pleroma.Config do def run(["migrate_to_db"]) do start_pleroma() - if Pleroma.Config.get([:instance, :dynamic_configuration]) do + if Pleroma.Config.get([:configurable_from_database]) do Enum.each(@groups, &load_and_create(&1)) else Mix.shell().info( @@ -48,7 +48,8 @@ defmodule Mix.Tasks.Pleroma.Config do aliases: [d: :delete_from_db] ) - with {:active?, true} <- {:active?, Pleroma.Config.get([:instance, :dynamic_configuration])}, + with {:active?, true} <- + {:active?, Pleroma.Config.get([:configurable_from_database])}, env_path when is_binary(env_path) <- opts[:env], config_path <- "config/#{env_path}.exported_from_db.secret.exs", {:ok, file} <- File.open(config_path, [:write, :utf8]) do -- cgit v1.2.3 From eadb674c41dea27346aad43fa5514aa4f461273b Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Fri, 10 Jan 2020 19:44:30 +0300 Subject: don't migrate configurable_from_database setting --- lib/mix/tasks/pleroma/config.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index 3f80af5a7..e7c6e8810 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -76,7 +76,8 @@ defmodule Mix.Tasks.Pleroma.Config do group |> Application.get_all_env() |> Enum.reject(fn {k, _v} -> - k in [Pleroma.Repo, :env] or (group == :phoenix and k == :serve_endpoints) + k in [Pleroma.Repo, :env, :configurable_from_database] or + (group == :phoenix and k == :serve_endpoints) end) |> Enum.each(fn {key, value} -> key = inspect(key) -- cgit v1.2.3 From 3453b27015dfa26bc6fd59899541eadfce2cacee Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Fri, 10 Jan 2020 21:24:06 +0300 Subject: don't migrate prometheus settings --- lib/mix/tasks/pleroma/config.ex | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index e7c6e8810..b69c49b45 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -21,7 +21,6 @@ defmodule Mix.Tasks.Pleroma.Config do :auto_linker, :esshd, :ueberauth, - :prometheus, :http_signatures, :web_push_encryption, :joken -- cgit v1.2.3 From 66de2b159b2e03fcac7fece01d39e1238e02dbf7 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Wed, 15 Jan 2020 17:08:45 +0300 Subject: don't migrate Pleroma.Web.EndPoint settings don't set Logger level to all tasks --- lib/mix/pleroma.ex | 7 ++++--- lib/mix/tasks/pleroma/config.ex | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex index 73a076a53..ea9923440 100644 --- a/lib/mix/pleroma.ex +++ b/lib/mix/pleroma.ex @@ -4,11 +4,12 @@ defmodule Mix.Pleroma do @doc "Common functions to be reused in mix tasks" - def start_pleroma do + def start_pleroma(change_logger_level \\ true) do Application.put_env(:phoenix, :serve_endpoints, false, persistent: true) - if Pleroma.Config.get(:env) != :test do - Application.put_env(:logger, :console, level: :debug) + if Pleroma.Config.get(:env) != :test and change_logger_level do + require Logger + Logger.configure(level: :debug) end {:ok, _} = Application.ensure_all_started(:pleroma) diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index b69c49b45..92487dd51 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -27,7 +27,8 @@ defmodule Mix.Tasks.Pleroma.Config do ] def run(["migrate_to_db"]) do - start_pleroma() + # we want to save original logger level + start_pleroma(false) if Pleroma.Config.get([:configurable_from_database]) do Enum.each(@groups, &load_and_create(&1)) @@ -75,7 +76,7 @@ defmodule Mix.Tasks.Pleroma.Config do group |> Application.get_all_env() |> Enum.reject(fn {k, _v} -> - k in [Pleroma.Repo, :env, :configurable_from_database] or + k in [Pleroma.Repo, Pleroma.Web.Endpoint, :env, :configurable_from_database] or (group == :phoenix and k == :serve_endpoints) end) |> Enum.each(fn {key, value} -> -- cgit v1.2.3 From 29155137fdae15fccfaa68fb9c954e98078ce0c4 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Thu, 16 Jan 2020 08:50:27 +0300 Subject: renaming Pleroma.Web.AdminAPI.Config -> Pleroma.ConfigDB --- lib/mix/tasks/pleroma/config.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index 92487dd51..57952aeba 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -5,8 +5,8 @@ defmodule Mix.Tasks.Pleroma.Config do use Mix.Task import Mix.Pleroma + alias Pleroma.ConfigDB alias Pleroma.Repo - alias Pleroma.Web.AdminAPI.Config @shortdoc "Manages the location of the config" @moduledoc File.read!("docs/administration/CLI_tasks/config.md") @@ -55,7 +55,7 @@ defmodule Mix.Tasks.Pleroma.Config do {:ok, file} <- File.open(config_path, [:write, :utf8]) do IO.write(file, "use Mix.Config\r\n") - Config + ConfigDB |> Repo.all() |> Enum.each(&write_to_file_with_deletion(&1, file, opts[:delete_from_db])) @@ -81,7 +81,7 @@ defmodule Mix.Tasks.Pleroma.Config do end) |> Enum.each(fn {key, value} -> key = inspect(key) - {:ok, _} = Config.update_or_create(%{group: inspect(group), key: key, value: value}) + {:ok, _} = ConfigDB.update_or_create(%{group: inspect(group), key: key, value: value}) Mix.shell().info("settings for key #{key} migrated.") end) @@ -93,7 +93,7 @@ defmodule Mix.Tasks.Pleroma.Config do IO.write( file, "config #{config.group}, #{config.key}, #{ - inspect(Config.from_binary(config.value), limit: :infinity) + inspect(ConfigDB.from_binary(config.value), limit: :infinity) }\r\n\r\n" ) -- cgit v1.2.3 From 60ba2339a244290f7353e8026032b1a5d185227c Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Fri, 17 Jan 2020 11:45:44 +0300 Subject: saving to DB only added by user settings --- lib/mix/tasks/pleroma/config.ex | 65 +++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 28 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index 57952aeba..3157e7b20 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -4,42 +4,25 @@ defmodule Mix.Tasks.Pleroma.Config do use Mix.Task + import Mix.Pleroma + alias Pleroma.ConfigDB alias Pleroma.Repo + + require Logger + @shortdoc "Manages the location of the config" @moduledoc File.read!("docs/administration/CLI_tasks/config.md") - @groups [ - :pleroma, - :logger, - :quack, - :mime, - :tesla, - :phoenix, - :cors_plug, - :auto_linker, - :esshd, - :ueberauth, - :http_signatures, - :web_push_encryption, - :joken - ] - def run(["migrate_to_db"]) do # we want to save original logger level start_pleroma(false) - - if Pleroma.Config.get([:configurable_from_database]) do - Enum.each(@groups, &load_and_create(&1)) - else - Mix.shell().info( - "Migration is not allowed by config. You can change this behavior in instance settings." - ) - end + migrate_to_db() end def run(["migrate_from_db" | options]) do + # TODO: add support for releases start_pleroma() {opts, _} = @@ -72,10 +55,36 @@ defmodule Mix.Tasks.Pleroma.Config do end end - defp load_and_create(group) do - group - |> Application.get_all_env() - |> Enum.reject(fn {k, _v} -> + @spec migrate_to_db(Path.t() | nil) :: any() + def migrate_to_db(file_path \\ nil) do + if Pleroma.Config.get([:configurable_from_database]) do + # TODO: add support for releases + config_file = file_path || "config/#{Pleroma.Config.get(:env)}.secret.exs" + do_migrate_to_db(config_file) + else + Mix.shell().info( + "migration is not allowed by config. You can change this behavior in instance settings." + ) + end + end + + defp do_migrate_to_db(config_file) do + if File.exists?(config_file) do + {custom_config, _paths} = + if Code.ensure_loaded?(Config.Reader), + do: Config.Reader.read_imports!(config_file), + else: Mix.Config.eval!(config_file) + + custom_config + |> Keyword.keys() + |> Enum.each(&create(&1, custom_config[&1])) + else + Logger.warn("to migrate settings, you must define custom settings in #{config_file}") + end + end + + defp create(group, settings) do + Enum.reject(settings, fn {k, _v} -> k in [Pleroma.Repo, Pleroma.Web.Endpoint, :env, :configurable_from_database] or (group == :phoenix and k == :serve_endpoints) end) -- cgit v1.2.3 From b310feeccb03a9bc232b49d93fb03805e3d5c2d8 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Fri, 17 Jan 2020 15:00:20 +0300 Subject: compile fix --- lib/mix/tasks/pleroma/config.ex | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index 3157e7b20..d2abbd885 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -68,12 +68,15 @@ defmodule Mix.Tasks.Pleroma.Config do end end + if Code.ensure_loaded?(Config.Reader) do + defp read_file(config_file), do: Config.Reader.read_imports!(config_file) + else + defp read_file(config_file), do: Mix.Config.eval!(config_file) + end + defp do_migrate_to_db(config_file) do if File.exists?(config_file) do - {custom_config, _paths} = - if Code.ensure_loaded?(Config.Reader), - do: Config.Reader.read_imports!(config_file), - else: Mix.Config.eval!(config_file) + {custom_config, _paths} = read_file(config_file) custom_config |> Keyword.keys() -- cgit v1.2.3 From 9e10b90b5bdf0f1ae327a44f44187918ab8dbf4f Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Fri, 17 Jan 2020 15:06:42 +0300 Subject: configure only console backend --- lib/mix/pleroma.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/mix') diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex index ea9923440..a6b00d4be 100644 --- a/lib/mix/pleroma.ex +++ b/lib/mix/pleroma.ex @@ -9,7 +9,7 @@ defmodule Mix.Pleroma do if Pleroma.Config.get(:env) != :test and change_logger_level do require Logger - Logger.configure(level: :debug) + Logger.configure(:console, level: :debug) end {:ok, _} = Application.ensure_all_started(:pleroma) -- cgit v1.2.3 From ce027fd0ef1080b03e7982e5939b0c7db6e3b783 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Fri, 17 Jan 2020 15:13:24 +0300 Subject: revert non needable --- lib/mix/pleroma.ex | 7 +++---- lib/mix/tasks/pleroma/config.ex | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex index a6b00d4be..73a076a53 100644 --- a/lib/mix/pleroma.ex +++ b/lib/mix/pleroma.ex @@ -4,12 +4,11 @@ defmodule Mix.Pleroma do @doc "Common functions to be reused in mix tasks" - def start_pleroma(change_logger_level \\ true) do + def start_pleroma do Application.put_env(:phoenix, :serve_endpoints, false, persistent: true) - if Pleroma.Config.get(:env) != :test and change_logger_level do - require Logger - Logger.configure(:console, level: :debug) + if Pleroma.Config.get(:env) != :test do + Application.put_env(:logger, :console, level: :debug) end {:ok, _} = Application.ensure_all_started(:pleroma) diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index d2abbd885..43039ae77 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -17,7 +17,7 @@ defmodule Mix.Tasks.Pleroma.Config do def run(["migrate_to_db"]) do # we want to save original logger level - start_pleroma(false) + start_pleroma() migrate_to_db() end -- cgit v1.2.3 From 7676ed82397d73a20aad1ae4b47690923ddfb162 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Fri, 17 Jan 2020 16:28:44 +0300 Subject: some clean up --- lib/mix/tasks/pleroma/config.ex | 1 - lib/mix/tasks/pleroma/docs.ex | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index 43039ae77..148d18141 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -16,7 +16,6 @@ defmodule Mix.Tasks.Pleroma.Config do @moduledoc File.read!("docs/administration/CLI_tasks/config.md") def run(["migrate_to_db"]) do - # we want to save original logger level start_pleroma() migrate_to_db() end diff --git a/lib/mix/tasks/pleroma/docs.ex b/lib/mix/tasks/pleroma/docs.ex index 0d2663648..3c870f876 100644 --- a/lib/mix/tasks/pleroma/docs.ex +++ b/lib/mix/tasks/pleroma/docs.ex @@ -28,7 +28,7 @@ defmodule Mix.Tasks.Pleroma.Docs do defp do_run(implementation) do start_pleroma() - with {descriptions, _paths} <- Mix.Config.eval!("config/description.exs"), + with descriptions <- Pleroma.Config.Loader.load("config/description.exs"), {:ok, file_path} <- Pleroma.Docs.Generator.process( implementation, -- cgit v1.2.3 From efb8ef5abee1a8defa2bfba40ad1065db4c09ddf Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Sat, 18 Jan 2020 16:55:33 +0300 Subject: releases support --- lib/mix/tasks/pleroma/config.ex | 49 +++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 16 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index 148d18141..715b72dbe 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -10,8 +10,6 @@ defmodule Mix.Tasks.Pleroma.Config do alias Pleroma.ConfigDB alias Pleroma.Repo - require Logger - @shortdoc "Manages the location of the config" @moduledoc File.read!("docs/administration/CLI_tasks/config.md") @@ -32,10 +30,10 @@ defmodule Mix.Tasks.Pleroma.Config do with {:active?, true} <- {:active?, Pleroma.Config.get([:configurable_from_database])}, - env_path when is_binary(env_path) <- opts[:env], - config_path <- "config/#{env_path}.exported_from_db.secret.exs", + env when is_binary(env) <- opts[:env] || "prod", + config_path <- config_path(env), {:ok, file} <- File.open(config_path, [:write, :utf8]) do - IO.write(file, "use Mix.Config\r\n") + IO.write(file, config_header()) ConfigDB |> Repo.all() @@ -45,31 +43,50 @@ defmodule Mix.Tasks.Pleroma.Config do System.cmd("mix", ["format", config_path]) else {:active?, false} -> - Mix.shell().info( - "migration is not allowed by config. You can change this behavior in instance settings." + shell_info( + "Migration is not allowed by config. You can change this behavior in instance settings." ) error -> - Mix.shell().info("error occuried while opening file. #{inspect(error)}") + shell_info("Error occuried while opening file. #{inspect(error)}") end end + defp config_path(env) do + path = + if Pleroma.Config.get(:release) do + :config_path + |> Pleroma.Config.get() + |> Path.dirname() + else + "config" + end + + Path.join(path, "#{env}.exported_from_db.secret.exs") + end + @spec migrate_to_db(Path.t() | nil) :: any() def migrate_to_db(file_path \\ nil) do if Pleroma.Config.get([:configurable_from_database]) do - # TODO: add support for releases - config_file = file_path || "config/#{Pleroma.Config.get(:env)}.secret.exs" + user_config_file = + if Pleroma.Config.get(:release), + do: Pleroma.Config.get(:config_path), + else: "config/#{Pleroma.Config.get(:env)}.secret.exs" + + config_file = file_path || user_config_file do_migrate_to_db(config_file) else - Mix.shell().info( - "migration is not allowed by config. You can change this behavior in instance settings." + shell_info( + "Migration is not allowed by config. You can change this behavior in instance settings." ) end end if Code.ensure_loaded?(Config.Reader) do + defp config_header, do: "import Config\r\n\r\n" defp read_file(config_file), do: Config.Reader.read_imports!(config_file) else + defp config_header, do: "use Mix.Config\r\n\r\n" defp read_file(config_file), do: Mix.Config.eval!(config_file) end @@ -81,7 +98,7 @@ defmodule Mix.Tasks.Pleroma.Config do |> Keyword.keys() |> Enum.each(&create(&1, custom_config[&1])) else - Logger.warn("to migrate settings, you must define custom settings in #{config_file}") + shell_info("To migrate settings, you must define custom settings in #{config_file}.") end end @@ -94,10 +111,10 @@ defmodule Mix.Tasks.Pleroma.Config do key = inspect(key) {:ok, _} = ConfigDB.update_or_create(%{group: inspect(group), key: key, value: value}) - Mix.shell().info("settings for key #{key} migrated.") + shell_info("Settings for key #{key} migrated.") end) - Mix.shell().info("settings for group :#{group} migrated.") + shell_info("Settings for group :#{group} migrated.") end defp write_to_file_with_deletion(config, file, with_deletion) do @@ -110,7 +127,7 @@ defmodule Mix.Tasks.Pleroma.Config do if with_deletion do {:ok, _} = Repo.delete(config) - Mix.shell().info("#{config.key} deleted from DB.") + shell_info("#{config.key} deleted from DB.") end end end -- cgit v1.2.3 From f01ab6cd29aaae39fef6a95ec8490223fb692499 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Tue, 21 Jan 2020 17:49:22 +0300 Subject: some refactor and tests --- lib/mix/tasks/pleroma/config.ex | 154 ++++++++++++++++++++++------------------ 1 file changed, 84 insertions(+), 70 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index 715b72dbe..861832451 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -19,94 +19,55 @@ defmodule Mix.Tasks.Pleroma.Config do end def run(["migrate_from_db" | options]) do - # TODO: add support for releases start_pleroma() {opts, _} = OptionParser.parse!(options, - strict: [env: :string, delete_from_db: :boolean], - aliases: [d: :delete_from_db] + strict: [env: :string, delete: :boolean], + aliases: [d: :delete] ) - with {:active?, true} <- - {:active?, Pleroma.Config.get([:configurable_from_database])}, - env when is_binary(env) <- opts[:env] || "prod", - config_path <- config_path(env), - {:ok, file} <- File.open(config_path, [:write, :utf8]) do - IO.write(file, config_header()) - - ConfigDB - |> Repo.all() - |> Enum.each(&write_to_file_with_deletion(&1, file, opts[:delete_from_db])) - - File.close(file) - System.cmd("mix", ["format", config_path]) - else - {:active?, false} -> - shell_info( - "Migration is not allowed by config. You can change this behavior in instance settings." - ) - - error -> - shell_info("Error occuried while opening file. #{inspect(error)}") - end - end - - defp config_path(env) do - path = - if Pleroma.Config.get(:release) do - :config_path - |> Pleroma.Config.get() - |> Path.dirname() - else - "config" - end - - Path.join(path, "#{env}.exported_from_db.secret.exs") + migrate_from_db(opts) end @spec migrate_to_db(Path.t() | nil) :: any() def migrate_to_db(file_path \\ nil) do if Pleroma.Config.get([:configurable_from_database]) do - user_config_file = - if Pleroma.Config.get(:release), - do: Pleroma.Config.get(:config_path), - else: "config/#{Pleroma.Config.get(:env)}.secret.exs" + config_file = + if file_path do + file_path + else + if Pleroma.Config.get(:release) do + Pleroma.Config.get(:config_path) + else + "config/#{Pleroma.Config.get(:env)}.secret.exs" + end + end - config_file = file_path || user_config_file do_migrate_to_db(config_file) else - shell_info( - "Migration is not allowed by config. You can change this behavior in instance settings." - ) + migration_error() end end - if Code.ensure_loaded?(Config.Reader) do - defp config_header, do: "import Config\r\n\r\n" - defp read_file(config_file), do: Config.Reader.read_imports!(config_file) - else - defp config_header, do: "use Mix.Config\r\n\r\n" - defp read_file(config_file), do: Mix.Config.eval!(config_file) - end - defp do_migrate_to_db(config_file) do if File.exists?(config_file) do - {custom_config, _paths} = read_file(config_file) + custom_config = + config_file + |> read_file() + |> elem(0) custom_config |> Keyword.keys() - |> Enum.each(&create(&1, custom_config[&1])) + |> Enum.each(&create(&1, custom_config)) else shell_info("To migrate settings, you must define custom settings in #{config_file}.") end end defp create(group, settings) do - Enum.reject(settings, fn {k, _v} -> - k in [Pleroma.Repo, Pleroma.Web.Endpoint, :env, :configurable_from_database] or - (group == :phoenix and k == :serve_endpoints) - end) + group + |> Pleroma.Config.Loader.filter_group(settings) |> Enum.each(fn {key, value} -> key = inspect(key) {:ok, _} = ConfigDB.update_or_create(%{group: inspect(group), key: key, value: value}) @@ -117,17 +78,70 @@ defmodule Mix.Tasks.Pleroma.Config do shell_info("Settings for group :#{group} migrated.") end - defp write_to_file_with_deletion(config, file, with_deletion) do - IO.write( - file, - "config #{config.group}, #{config.key}, #{ - inspect(ConfigDB.from_binary(config.value), limit: :infinity) - }\r\n\r\n" - ) + defp migrate_from_db(opts) do + if Pleroma.Config.get([:configurable_from_database]) do + env = opts[:env] || "prod" + + config_path = + if Pleroma.Config.get(:release) do + :config_path + |> Pleroma.Config.get() + |> Path.dirname() + else + "config" + end + |> Path.join("#{env}.exported_from_db.secret.exs") + + file = File.open!(config_path, [:write, :utf8]) + + IO.write(file, config_header()) + + ConfigDB + |> Repo.all() + |> Enum.each(&write_and_delete(&1, file, opts[:delete])) - if with_deletion do - {:ok, _} = Repo.delete(config) - shell_info("#{config.key} deleted from DB.") + :ok = File.close(file) + System.cmd("mix", ["format", config_path]) + else + migration_error() end end + + defp migration_error do + shell_error( + "Migration is not allowed in config. You can change this behavior by setting `configurable_from_database` to true." + ) + end + + if Code.ensure_loaded?(Config.Reader) do + defp config_header, do: "import Config\r\n\r\n" + defp read_file(config_file), do: Config.Reader.read_imports!(config_file) + else + defp config_header, do: "use Mix.Config\r\n\r\n" + defp read_file(config_file), do: Mix.Config.eval!(config_file) + end + + defp write_and_delete(config, file, delete?) do + config + |> write(file) + |> delete(delete?) + end + + defp write(config, file) do + value = + config.value + |> ConfigDB.from_binary() + |> inspect(limit: :infinity) + + IO.write(file, "config #{config.group}, #{config.key}, #{value}\r\n\r\n") + + config + end + + defp delete(config, true) do + {:ok, _} = Repo.delete(config) + shell_info("#{config.key} deleted from DB.") + end + + defp delete(_config, _), do: :ok end -- cgit v1.2.3 From 4344c5d5b99cedcd08e168650af2f641ef8c6f0b Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Thu, 23 Jan 2020 17:23:02 +0300 Subject: truncate config table on migrate to db task --- lib/mix/tasks/pleroma/config.ex | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index 861832451..8098e9bab 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -52,6 +52,8 @@ defmodule Mix.Tasks.Pleroma.Config do defp do_migrate_to_db(config_file) do if File.exists?(config_file) do + Ecto.Adapters.SQL.query!(Repo, "TRUNCATE config;") + custom_config = config_file |> read_file() -- cgit v1.2.3 From e8e57e398f701497b9989c19c36c20fd227393ac Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Thu, 23 Jan 2020 17:48:45 +0300 Subject: restart config id after truncate --- lib/mix/tasks/pleroma/config.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index 8098e9bab..3e76d2c97 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -53,6 +53,7 @@ defmodule Mix.Tasks.Pleroma.Config do defp do_migrate_to_db(config_file) do if File.exists?(config_file) do Ecto.Adapters.SQL.query!(Repo, "TRUNCATE config;") + Ecto.Adapters.SQL.query!(Repo, "ALTER SEQUENCE config_id_seq RESTART;") custom_config = config_file -- cgit v1.2.3 From 6252e82f85d84c909871d3741da5c835ca2ca944 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Sat, 25 Jan 2020 10:33:27 +0300 Subject: respect settings from database in mix tasks --- lib/mix/tasks/pleroma/emoji.ex | 2 ++ lib/mix/tasks/pleroma/robotstxt.ex | 1 + 2 files changed, 3 insertions(+) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index 35669af27..24d999707 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -9,6 +9,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do @moduledoc File.read!("docs/administration/CLI_tasks/emoji.md") def run(["ls-packs" | args]) do + Mix.Pleroma.start_pleroma() Application.ensure_all_started(:hackney) {options, [], []} = parse_global_opts(args) @@ -35,6 +36,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do end def run(["get-packs" | args]) do + Mix.Pleroma.start_pleroma() Application.ensure_all_started(:hackney) {options, pack_names, []} = parse_global_opts(args) diff --git a/lib/mix/tasks/pleroma/robotstxt.ex b/lib/mix/tasks/pleroma/robotstxt.ex index 2128e1cd6..e99dd8502 100644 --- a/lib/mix/tasks/pleroma/robotstxt.ex +++ b/lib/mix/tasks/pleroma/robotstxt.ex @@ -18,6 +18,7 @@ defmodule Mix.Tasks.Pleroma.RobotsTxt do """ def run(["disallow_all"]) do + Mix.Pleroma.start_pleroma() static_dir = Pleroma.Config.get([:instance, :static_dir], "instance/static/") if !File.exists?(static_dir) do -- cgit v1.2.3 From 4eb935be78eeaf1decb7fc109cec09ca18d82854 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 20 Jan 2020 13:23:21 +0100 Subject: Create pleroma.email mix task Closes: https://git.pleroma.social/pleroma/pleroma/issues/1061 --- lib/mix/tasks/pleroma/email.ex | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/mix/tasks/pleroma/email.ex (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/email.ex b/lib/mix/tasks/pleroma/email.ex new file mode 100644 index 000000000..2c3801429 --- /dev/null +++ b/lib/mix/tasks/pleroma/email.ex @@ -0,0 +1,25 @@ +defmodule Mix.Tasks.Pleroma.Email do + use Mix.Task + + @shortdoc "Simple Email test" + @moduledoc File.read!("docs/administration/CLI_tasks/email.md") + + def run(["test" | args]) do + Mix.Pleroma.start_pleroma() + + {options, [], []} = + OptionParser.parse( + args, + strict: [ + to: :string + ] + ) + + email = Pleroma.Emails.AdminEmail.test_email(options[:to]) + {:ok, _} = Pleroma.Emails.Mailer.deliver(email) + + Mix.shell().info( + "Test email has been sent to #{inspect(email.to)} from #{inspect(email.from)}" + ) + end +end -- cgit v1.2.3 From 8fda6303ba6dcc3ccfc5a978e6baa0f280d85b7b Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sun, 9 Feb 2020 03:27:29 +0300 Subject: Fix email mix task on OTP releases Closes pleroma#1548 --- lib/mix/tasks/pleroma/email.ex | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/email.ex b/lib/mix/tasks/pleroma/email.ex index 2c3801429..d3fac6ec8 100644 --- a/lib/mix/tasks/pleroma/email.ex +++ b/lib/mix/tasks/pleroma/email.ex @@ -1,5 +1,6 @@ defmodule Mix.Tasks.Pleroma.Email do use Mix.Task + import Mix.Pleroma @shortdoc "Simple Email test" @moduledoc File.read!("docs/administration/CLI_tasks/email.md") @@ -18,8 +19,6 @@ defmodule Mix.Tasks.Pleroma.Email do email = Pleroma.Emails.AdminEmail.test_email(options[:to]) {:ok, _} = Pleroma.Emails.Mailer.deliver(email) - Mix.shell().info( - "Test email has been sent to #{inspect(email.to)} from #{inspect(email.from)}" - ) + shell_info("Test email has been sent to #{inspect(email.to)} from #{inspect(email.from)}") end end -- cgit v1.2.3 From 7ad5c51f23102e89c491a2ef731e108873a09d71 Mon Sep 17 00:00:00 2001 From: eugenijm Date: Thu, 9 Jan 2020 22:18:55 +0300 Subject: Admin API: `GET /api/pleroma/admin/stats` to get status count by visibility scope --- lib/mix/tasks/pleroma/refresh_counter_cache.ex | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 lib/mix/tasks/pleroma/refresh_counter_cache.ex (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/refresh_counter_cache.ex b/lib/mix/tasks/pleroma/refresh_counter_cache.ex new file mode 100644 index 000000000..bc2571efd --- /dev/null +++ b/lib/mix/tasks/pleroma/refresh_counter_cache.ex @@ -0,0 +1,46 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Mix.Tasks.Pleroma.RefreshCounterCache do + @shortdoc "Refreshes counter cache" + + use Mix.Task + + alias Pleroma.Activity + alias Pleroma.CounterCache + alias Pleroma.Repo + + require Logger + import Ecto.Query + + def run([]) do + Mix.Pleroma.start_pleroma() + + ["public", "unlisted", "private", "direct"] + |> Enum.each(fn visibility -> + count = status_visibility_count_query(visibility) + name = "status_visibility_#{visibility}" + CounterCache.set(name, count) + Mix.Pleroma.shell_info("Set #{name} to #{count}") + end) + + Mix.Pleroma.shell_info("Done") + end + + defp status_visibility_count_query(visibility) do + Activity + |> where( + [a], + fragment( + "activity_visibility(?, ?, ?) = ?", + a.actor, + a.recipients, + a.data, + ^visibility + ) + ) + |> where([a], fragment("(? ->> 'type'::text) = 'Create'", a.data)) + |> Repo.aggregate(:count, :id, timeout: :timer.minutes(30)) + end +end -- cgit v1.2.3 From 5e4fe0e8f7fcfefc037885421d41de3a4328a881 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Mon, 24 Feb 2020 22:52:38 +0300 Subject: instance.gen task: fix crash when using custom static directory Closes #1082 --- lib/mix/tasks/pleroma/instance.ex | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 9af6cda30..2d8b8d673 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -6,6 +6,8 @@ defmodule Mix.Tasks.Pleroma.Instance do use Mix.Task import Mix.Pleroma + alias Pleroma.Config + @shortdoc "Manages Pleroma instance" @moduledoc File.read!("docs/administration/CLI_tasks/instance.md") @@ -153,6 +155,8 @@ defmodule Mix.Tasks.Pleroma.Instance do Pleroma.Config.get([:instance, :static_dir]) ) + Config.put([:instance, :static_dir], static_dir) + secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) jwt_secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) signing_salt = :crypto.strong_rand_bytes(8) |> Base.encode64() |> binary_part(0, 8) -- cgit v1.2.3 From 22018adae67ae0b2047a410dc1f5cf9463ade3dc Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 25 Feb 2020 18:34:56 +0400 Subject: Fix Dialyzer warnings --- lib/mix/tasks/pleroma/emoji.ex | 6 +----- lib/mix/tasks/pleroma/user.ex | 3 +-- 2 files changed, 2 insertions(+), 7 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index 24d999707..74bf968fc 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -186,11 +186,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do tmp_pack_dir = Path.join(System.tmp_dir!(), "emoji-pack-#{name}") - {:ok, _} = - :zip.unzip( - binary_archive, - cwd: tmp_pack_dir - ) + {:ok, _} = :zip.unzip(binary_archive, cwd: String.to_charlist(tmp_pack_dir)) emoji_map = Pleroma.Emoji.Loader.make_shortcode_to_file_map(tmp_pack_dir, exts) diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 85c9e4954..ba10a705a 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -100,8 +100,7 @@ defmodule Mix.Tasks.Pleroma.User do User.perform(:delete, user) shell_info("User #{nickname} deleted.") else - _ -> - shell_error("No local user #{nickname}") + _ -> shell_error("No local user #{nickname}") end end -- cgit v1.2.3 From cfa28dee32d3608cab2e2fb42a59c50f3cc0c083 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 25 Feb 2020 21:59:37 +0300 Subject: instance.gen task: make instance name default to the domain --- lib/mix/tasks/pleroma/instance.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 2d8b8d673..fee2ab9d9 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -65,7 +65,8 @@ defmodule Mix.Tasks.Pleroma.Instance do get_option( options, :instance_name, - "What is the name of your instance? (e.g. Pleroma/Soykaf)" + "What is the name of your instance? (e.g. Pleroma/Soykaf)", + domain ) email = get_option(options, :admin_email, "What is your admin email address?") -- cgit v1.2.3 From 359faa8645b48c05e5b477e43d144ed4ac92b249 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 25 Feb 2020 22:13:08 +0300 Subject: instance.gen task: remind to transfer the config to the database after migrations --- lib/mix/tasks/pleroma/instance.ex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index fee2ab9d9..216dec296 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -207,8 +207,14 @@ defmodule Mix.Tasks.Pleroma.Instance do write_robots_txt(indexable, template_dir) shell_info( - "\n All files successfully written! Refer to the installation instructions for your platform for next steps" + "\n All files successfully written! Refer to the installation instructions for your platform for next steps." ) + + if db_configurable? do + shell_info( + " Please transfer your config to the database after running database migrations. Refer to \"Transfering the config to/from the database\" section of the docs for more information." + ) + end else shell_error( "The task would have overwritten the following files:\n" <> -- cgit v1.2.3 From 3bbfebd1c2f0e997a16c7938dd09b1621918cd12 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 26 Feb 2020 00:32:34 +0300 Subject: instance.gen task: make example instance name less confusing See https://git.pleroma.social/pleroma/pleroma/merge_requests/2245#note_52217 --- lib/mix/tasks/pleroma/instance.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 216dec296..54d34e42f 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -65,7 +65,7 @@ defmodule Mix.Tasks.Pleroma.Instance do get_option( options, :instance_name, - "What is the name of your instance? (e.g. Pleroma/Soykaf)", + "What is the name of your instance? (e.g. The Corndog Emporium)", domain ) -- cgit v1.2.3 From 6da65400362d2189a995a182789c099b108b26bc Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 2 Mar 2020 06:08:45 +0100 Subject: Bump copyright years of files changed after 2020-01-07 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Done via the following command: git diff fcd5dd259a1700a045be902b43391b0d1bd58a5b --stat --name-only | xargs sed -i '/Pleroma Authors/c# Copyright © 2017-2020 Pleroma Authors ' --- lib/mix/tasks/pleroma/config.ex | 2 +- lib/mix/tasks/pleroma/emoji.ex | 2 +- lib/mix/tasks/pleroma/instance.ex | 2 +- lib/mix/tasks/pleroma/refresh_counter_cache.ex | 2 +- lib/mix/tasks/pleroma/robotstxt.ex | 2 +- lib/mix/tasks/pleroma/user.ex | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index 3e76d2c97..5c9ef6904 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.Config do diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index 74bf968fc..2b03a3009 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.Emoji do diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 54d34e42f..bc842a59f 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.Instance do diff --git a/lib/mix/tasks/pleroma/refresh_counter_cache.ex b/lib/mix/tasks/pleroma/refresh_counter_cache.ex index bc2571efd..15b4dbfa6 100644 --- a/lib/mix/tasks/pleroma/refresh_counter_cache.ex +++ b/lib/mix/tasks/pleroma/refresh_counter_cache.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.RefreshCounterCache do diff --git a/lib/mix/tasks/pleroma/robotstxt.ex b/lib/mix/tasks/pleroma/robotstxt.ex index e99dd8502..24f08180e 100644 --- a/lib/mix/tasks/pleroma/robotstxt.ex +++ b/lib/mix/tasks/pleroma/robotstxt.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.RobotsTxt do diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index ba10a705a..40dd9bdc0 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.User do -- cgit v1.2.3 From 05da5f5cca00c8b061858ff85e4a4640f3d91cb6 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 3 Mar 2020 16:44:49 -0600 Subject: Update Copyrights --- lib/mix/pleroma.ex | 2 +- lib/mix/tasks/pleroma/benchmark.ex | 2 +- lib/mix/tasks/pleroma/database.ex | 2 +- lib/mix/tasks/pleroma/ecto/ecto.ex | 2 +- lib/mix/tasks/pleroma/ecto/migrate.ex | 2 +- lib/mix/tasks/pleroma/ecto/rollback.ex | 2 +- lib/mix/tasks/pleroma/relay.ex | 2 +- lib/mix/tasks/pleroma/uploads.ex | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/mix') diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex index 73a076a53..90f8c8008 100644 --- a/lib/mix/pleroma.ex +++ b/lib/mix/pleroma.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Pleroma do diff --git a/lib/mix/tasks/pleroma/benchmark.ex b/lib/mix/tasks/pleroma/benchmark.ex index 84dccf7f3..a4885b70c 100644 --- a/lib/mix/tasks/pleroma/benchmark.ex +++ b/lib/mix/tasks/pleroma/benchmark.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.Benchmark do diff --git a/lib/mix/tasks/pleroma/database.ex b/lib/mix/tasks/pleroma/database.ex index e2b5251bc..778de162f 100644 --- a/lib/mix/tasks/pleroma/database.ex +++ b/lib/mix/tasks/pleroma/database.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.Database do diff --git a/lib/mix/tasks/pleroma/ecto/ecto.ex b/lib/mix/tasks/pleroma/ecto/ecto.ex index 36808b93f..3363cd45f 100644 --- a/lib/mix/tasks/pleroma/ecto/ecto.ex +++ b/lib/mix/tasks/pleroma/ecto/ecto.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-onl defmodule Mix.Tasks.Pleroma.Ecto do diff --git a/lib/mix/tasks/pleroma/ecto/migrate.ex b/lib/mix/tasks/pleroma/ecto/migrate.ex index d87b6957d..bc8ed29fb 100644 --- a/lib/mix/tasks/pleroma/ecto/migrate.ex +++ b/lib/mix/tasks/pleroma/ecto/migrate.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-onl defmodule Mix.Tasks.Pleroma.Ecto.Migrate do diff --git a/lib/mix/tasks/pleroma/ecto/rollback.ex b/lib/mix/tasks/pleroma/ecto/rollback.ex index a1af73fa1..f43bd0b98 100644 --- a/lib/mix/tasks/pleroma/ecto/rollback.ex +++ b/lib/mix/tasks/pleroma/ecto/rollback.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-onl defmodule Mix.Tasks.Pleroma.Ecto.Rollback do diff --git a/lib/mix/tasks/pleroma/relay.ex b/lib/mix/tasks/pleroma/relay.ex index 7ef5f9678..c6ca888d4 100644 --- a/lib/mix/tasks/pleroma/relay.ex +++ b/lib/mix/tasks/pleroma/relay.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.Relay do diff --git a/lib/mix/tasks/pleroma/uploads.ex b/lib/mix/tasks/pleroma/uploads.ex index 3e6fc7ee0..c47b7531e 100644 --- a/lib/mix/tasks/pleroma/uploads.ex +++ b/lib/mix/tasks/pleroma/uploads.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.Uploads do -- cgit v1.2.3 From 474ef512df5c7833f29e6201c52238b5d561a785 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Tue, 18 Feb 2020 18:10:39 +0300 Subject: wait in mix task while pleroma is rebooted --- lib/mix/pleroma.ex | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/mix') diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex index 90f8c8008..3ad6edbfb 100644 --- a/lib/mix/pleroma.ex +++ b/lib/mix/pleroma.ex @@ -12,6 +12,19 @@ defmodule Mix.Pleroma do end {:ok, _} = Application.ensure_all_started(:pleroma) + + if Pleroma.Config.get(:env) not in [:test, :benchmark] do + pleroma_rebooted?() + end + end + + defp pleroma_rebooted? do + if Restarter.Pleroma.rebooted?() do + :ok + else + Process.sleep(10) + pleroma_rebooted?() + end end def load_pleroma do -- cgit v1.2.3