From bf43f055ddbfdd8be065eace43de1a742674b1bc Mon Sep 17 00:00:00 2001 From: KokaKiwi Date: Mon, 18 Feb 2019 00:21:13 +0100 Subject: [PATCH 01/37] Set content types settings on mastofe endpoint. --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 056be49b0..2874dfb6d 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1128,7 +1128,8 @@ def index(%{assigns: %{user: user}} = conn, _params) do compose: %{ me: "#{user.id}", default_privacy: user.info.default_scope, - default_sensitive: false + default_sensitive: false, + allow_content_types: Config.get([:instance, :allowed_post_formats]) }, media_attachments: %{ accept_content_types: [ From 3474066f6dc98003583dcd8537028b515be0e126 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 11 Mar 2019 15:18:32 +0100 Subject: [PATCH 02/37] MastoAPI Accounts: Add fetching by nickname. This is to make it easier for the frontends to handle domain.com/users/nickname urls. --- docs/Differences-in-MastodonAPI-Responses.md | 4 ++++ .../web/mastodon_api/mastodon_api_controller.ex | 4 ++-- .../mastodon_api/mastodon_api_controller_test.exs | 13 ++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/Differences-in-MastodonAPI-Responses.md b/docs/Differences-in-MastodonAPI-Responses.md index 667664f4e..7b11fe90f 100644 --- a/docs/Differences-in-MastodonAPI-Responses.md +++ b/docs/Differences-in-MastodonAPI-Responses.md @@ -19,3 +19,7 @@ Adding the parameter `with_muted=true` to the timeline queries will also return Has these additional fields under the `pleroma` object: - `local`: true if the post was made on the local instance. + +## Accounts + +- `/api/v1/accounts/:id`: The `id` parameter can also be the `nickname` of the user. This only works in this endpoint, not the deeper nested ones for following etc. diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 26921d386..e7ca96114 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -131,8 +131,8 @@ def verify_credentials(%{assigns: %{user: user}} = conn, _) do json(conn, account) end - def user(%{assigns: %{user: for_user}} = conn, %{"id" => id}) do - with %User{} = user <- Repo.get(User, id), + def user(%{assigns: %{user: for_user}} = conn, %{"id" => nickname_or_id}) do + with %User{} = user <- User.get_cached_by_nickname_or_id(nickname_or_id), true <- User.auth_active?(user) || user.id == for_user.id || User.superuser?(for_user) do account = AccountView.render("account.json", %{user: user, for: for_user}) json(conn, account) diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 8a20eef2c..8e14e03c8 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -1064,6 +1064,17 @@ test "account fetching", %{conn: conn} do assert %{"error" => "Can't find user"} = json_response(conn, 404) end + test "account fetching also works nickname", %{conn: conn} do + user = insert(:user) + + conn = + conn + |> get("/api/v1/accounts/#{user.nickname}") + + assert %{"id" => id} = json_response(conn, 200) + assert id == user.id + end + test "media upload", %{conn: conn} do file = %Plug.Upload{ content_type: "image/jpg", @@ -1950,7 +1961,7 @@ test "submit a report with statuses and comment", %{ |> json_response(200) end - test "accound_id is required", %{ + test "account_id is required", %{ conn: conn, reporter: reporter, activity: activity From 600f428db4752114cff31283896d960299f80355 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 11 Mar 2019 19:23:21 +0100 Subject: [PATCH 03/37] WebPush: Add activity id to the push messages. Makes it easier to relate the push to a given status. --- lib/pleroma/web/push/impl.ex | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/push/impl.ex b/lib/pleroma/web/push/impl.ex index 33f912d34..4d65ca5d5 100644 --- a/lib/pleroma/web/push/impl.ex +++ b/lib/pleroma/web/push/impl.ex @@ -20,7 +20,7 @@ defmodule Pleroma.Web.Push.Impl do @doc "Performs sending notifications for user subscriptions" @spec perform_send(Notification.t()) :: list(any) - def perform_send(%{activity: %{data: %{"type" => activity_type}}, user_id: user_id} = notif) + def perform_send(%{activity: %{data: %{"type" => activity_type}, id: activity_id}, user_id: user_id} = notif) when activity_type in @types do actor = User.get_cached_by_ap_id(notif.activity.data["actor"]) @@ -37,7 +37,10 @@ def perform_send(%{activity: %{data: %{"type" => activity_type}}, user_id: user_ notification_id: notif.id, notification_type: type, icon: avatar_url, - preferred_locale: "en" + preferred_locale: "en", + pleroma: %{ + activity_id: activity_id + } } |> Jason.encode!() |> push_message(build_sub(subscription), gcm_api_key, subscription) From 07277879e595e803f903ac88d66f4b4eb98cc263 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 11 Mar 2019 19:32:21 +0100 Subject: [PATCH 04/37] Linting. --- lib/pleroma/web/push/impl.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/push/impl.ex b/lib/pleroma/web/push/impl.ex index 4d65ca5d5..0437ffd00 100644 --- a/lib/pleroma/web/push/impl.ex +++ b/lib/pleroma/web/push/impl.ex @@ -20,7 +20,10 @@ defmodule Pleroma.Web.Push.Impl do @doc "Performs sending notifications for user subscriptions" @spec perform_send(Notification.t()) :: list(any) - def perform_send(%{activity: %{data: %{"type" => activity_type}, id: activity_id}, user_id: user_id} = notif) + def perform_send( + %{activity: %{data: %{"type" => activity_type}, id: activity_id}, user_id: user_id} = + notif + ) when activity_type in @types do actor = User.get_cached_by_ap_id(notif.activity.data["actor"]) From 7b227d935d96e81be46b0643124d8443f2842ce8 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Mon, 11 Mar 2019 22:36:02 +0300 Subject: [PATCH 05/37] Switch the CI to Elixir 1.8.1 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6deb0a1de..30589c9c5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: elixir:1.7.2 +image: elixir:1.8.1 services: - name: postgres:9.6.2 From 5a73cae2be8e9b490ed4a610347998f1120740f0 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 12 Mar 2019 09:10:19 +0300 Subject: [PATCH 06/37] WIP: Stop mangling filenames --- lib/pleroma/plugs/uploaded_media.ex | 10 ++++++++++ lib/pleroma/upload.ex | 10 ++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/plugs/uploaded_media.ex b/lib/pleroma/plugs/uploaded_media.ex index 13aa8641a..15f447ded 100644 --- a/lib/pleroma/plugs/uploaded_media.ex +++ b/lib/pleroma/plugs/uploaded_media.ex @@ -24,6 +24,16 @@ def init(_opts) do end def call(%{request_path: <<"/", @path, "/", file::binary>>} = conn, opts) do + conn = + case fetch_query_params(conn) do + %{query_params: %{"name" => name}} = conn -> + conn + |> put_resp_header("Content-Disposition", "filename=\"#{name}\"") + + conn -> + conn + end + config = Pleroma.Config.get([Pleroma.Upload]) with uploader <- Keyword.fetch!(config, :uploader), diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index 1a97e9fde..ae461d434 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -70,7 +70,7 @@ def store(upload, opts \\ []) do %{ "type" => "Link", "mediaType" => upload.content_type, - "href" => url_from_spec(opts.base_url, url_spec) + "href" => url_from_spec(opts.base_url, url_spec, upload.name) } ], "name" => Map.get(opts, :description) || upload.name @@ -219,14 +219,12 @@ defp tempfile_for_image(data) do tmp_path end - defp url_from_spec(base_url, {:file, path}) do - path = - path - |> URI.encode(&char_unescaped?/1) + defp url_from_spec(base_url, {:file, path}, name) do + path = URI.encode(path, &char_unescaped?/1) <> "?name=#{URI.encode(name, &char_unescaped?/1)}" [base_url, "media", path] |> Path.join() end - defp url_from_spec(_base_url, {:url, url}), do: url + defp url_from_spec(_base_url, {:url, url}, _name), do: url end From 92a69bddce10da92a6a418f08c134ebdd6217ca4 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 12 Mar 2019 09:21:13 +0300 Subject: [PATCH 07/37] escape quotation marks in Content-Disposition header --- lib/pleroma/plugs/uploaded_media.ex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/pleroma/plugs/uploaded_media.ex b/lib/pleroma/plugs/uploaded_media.ex index 15f447ded..bc913f408 100644 --- a/lib/pleroma/plugs/uploaded_media.ex +++ b/lib/pleroma/plugs/uploaded_media.ex @@ -27,6 +27,8 @@ def call(%{request_path: <<"/", @path, "/", file::binary>>} = conn, opts) do conn = case fetch_query_params(conn) do %{query_params: %{"name" => name}} = conn -> + name = String.replace(name, "\"", "\\\"") + conn |> put_resp_header("Content-Disposition", "filename=\"#{name}\"") From faf238c1b0b4d814ce3b2e041ed6b18b498233bf Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 12 Mar 2019 15:33:15 +0300 Subject: [PATCH 08/37] Fix upload tests --- test/upload_test.exs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/upload_test.exs b/test/upload_test.exs index bdda01b3f..c38280d4c 100644 --- a/test/upload_test.exs +++ b/test/upload_test.exs @@ -56,7 +56,7 @@ test "copies the file to the configured folder with deduping" do assert List.first(data["url"])["href"] == Pleroma.Web.base_url() <> - "/media/e7a6d0cf595bff76f14c9a98b6c199539559e8b844e02e51e5efcfd1f614a2df.jpg" + "/media/e7a6d0cf595bff76f14c9a98b6c199539559e8b844e02e51e5efcfd1f614a2df.jpg?name=an%20%5Bimage.jpg" end test "copies the file to the configured folder without deduping" do @@ -150,7 +150,8 @@ test "escapes invalid characters in url" do {:ok, data} = Upload.store(file) [attachment_url | _] = data["url"] - assert Path.basename(attachment_url["href"]) == "an%E2%80%A6%20image.jpg" + assert Path.basename(attachment_url["href"]) == + "an%E2%80%A6%20image.jpg?name=an%E2%80%A6%20image.jpg" end test "escapes reserved uri characters" do @@ -166,7 +167,7 @@ test "escapes reserved uri characters" do [attachment_url | _] = data["url"] assert Path.basename(attachment_url["href"]) == - "%3A%3F%23%5B%5D%40%21%24%26%5C%27%28%29%2A%2B%2C%3B%3D.jpg" + "%3A%3F%23%5B%5D%40%21%24%26%5C%27%28%29%2A%2B%2C%3B%3D.jpg?name=%3A%3F%23%5B%5D%40%21%24%26%5C%27%28%29%2A%2B%2C%3B%3D.jpg" end end end From 984b5f8adfd1e7b981a270193d1ebd76f468576c Mon Sep 17 00:00:00 2001 From: eugenijm Date: Mon, 11 Mar 2019 21:03:30 +0300 Subject: [PATCH 09/37] MastoAPI followers/following endpoints --- lib/pleroma/web/mastodon_api/mastodon_api.ex | 62 ++++++++++++++ .../mastodon_api/mastodon_api_controller.ex | 11 ++- .../mastodon_api_controller_test.exs | 82 +++++++++++++++++++ 3 files changed, 151 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api.ex b/lib/pleroma/web/mastodon_api/mastodon_api.ex index 8b1378917..c952c5806 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api.ex @@ -1 +1,63 @@ +defmodule Pleroma.Web.MastodonAPI.MastodonAPI do + import Ecto.Query + import Ecto.Changeset + alias Pleroma.User + alias Pleroma.Repo + + @default_limit 20 + + def get_followers(user, params \\ %{}) do + user + |> User.get_followers_query() + |> paginate(params) + |> Repo.all() + end + + def get_friends(user, params \\ %{}) do + user + |> User.get_friends_query() + |> paginate(params) + |> Repo.all() + end + + def paginate(query, params \\ %{}) do + options = cast_params(params) + + query + |> restrict(:max_id, options) + |> restrict(:since_id, options) + |> restrict(:limit, options) + |> order_by([u], fragment("? desc nulls last", u.id)) + end + + def cast_params(params) do + param_types = %{ + max_id: :string, + since_id: :string, + limit: :integer + } + + changeset = cast({%{}, param_types}, params, Map.keys(param_types)) + changeset.changes + end + + defp restrict(query, :max_id, %{max_id: max_id}) do + query + |> where([q], q.id < ^max_id) + end + + defp restrict(query, :since_id, %{since_id: since_id}) do + query + |> where([q], q.id > ^since_id) + end + + defp restrict(query, :limit, options) do + limit = Map.get(options, :limit, @default_limit) + + query + |> limit(^limit) + end + + defp restrict(query, _, _), do: query +end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 26921d386..bfc8dcd0a 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -22,6 +22,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do alias Pleroma.Web.MastodonAPI.MastodonView alias Pleroma.Web.MastodonAPI.StatusView alias Pleroma.Web.MastodonAPI.ReportView + alias Pleroma.Web.MastodonAPI.MastodonAPI alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.Visibility @@ -652,9 +653,9 @@ def hashtag_timeline(%{assigns: %{user: user}} = conn, params) do |> render("index.json", %{activities: activities, for: user, as: :activity}) end - def followers(%{assigns: %{user: for_user}} = conn, %{"id" => id}) do + def followers(%{assigns: %{user: for_user}} = conn, %{"id" => id} = params) do with %User{} = user <- Repo.get(User, id), - {:ok, followers} <- User.get_followers(user) do + followers <- MastodonAPI.get_followers(user, params) do followers = cond do for_user && user.id == for_user.id -> followers @@ -663,14 +664,15 @@ def followers(%{assigns: %{user: for_user}} = conn, %{"id" => id}) do end conn + |> add_link_headers(:followers, followers, user) |> put_view(AccountView) |> render("accounts.json", %{users: followers, as: :user}) end end - def following(%{assigns: %{user: for_user}} = conn, %{"id" => id}) do + def following(%{assigns: %{user: for_user}} = conn, %{"id" => id} = params) do with %User{} = user <- Repo.get(User, id), - {:ok, followers} <- User.get_friends(user) do + followers <- MastodonAPI.get_friends(user, params) do followers = cond do for_user && user.id == for_user.id -> followers @@ -679,6 +681,7 @@ def following(%{assigns: %{user: for_user}} = conn, %{"id" => id}) do end conn + |> add_link_headers(:following, followers, user) |> put_view(AccountView) |> render("accounts.json", %{users: followers, as: :user}) end diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 8a20eef2c..d9e41d356 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -1184,6 +1184,47 @@ test "getting followers, hide_followers, same user requesting", %{conn: conn} do refute [] == json_response(conn, 200) end + test "getting followers, pagination", %{conn: conn} do + user = insert(:user) + follower1 = insert(:user) + follower2 = insert(:user) + follower3 = insert(:user) + {:ok, _} = User.follow(follower1, user) + {:ok, _} = User.follow(follower2, user) + {:ok, _} = User.follow(follower3, user) + + conn = + conn + |> assign(:user, user) + + res_conn = + conn + |> get("/api/v1/accounts/#{user.id}/followers?since_id=#{follower1.id}") + + assert [%{"id" => id3}, %{"id" => id2}] = json_response(res_conn, 200) + assert id3 == follower3.id + assert id2 == follower2.id + + res_conn = + conn + |> get("/api/v1/accounts/#{user.id}/followers?max_id=#{follower3.id}") + + assert [%{"id" => id2}, %{"id" => id1}] = json_response(res_conn, 200) + assert id2 == follower2.id + assert id1 == follower1.id + + res_conn = + conn + |> get("/api/v1/accounts/#{user.id}/followers?limit=1&max_id=#{follower3.id}") + + assert [%{"id" => id2}] = json_response(res_conn, 200) + assert id2 == follower2.id + + assert [link_header] = get_resp_header(res_conn, "link") + assert link_header =~ ~r/since_id=#{follower2.id}/ + assert link_header =~ ~r/max_id=#{follower2.id}/ + end + test "getting following", %{conn: conn} do user = insert(:user) other_user = insert(:user) @@ -1222,6 +1263,47 @@ test "getting following, hide_follows, same user requesting", %{conn: conn} do refute [] == json_response(conn, 200) end + test "getting following, pagination", %{conn: conn} do + user = insert(:user) + following1 = insert(:user) + following2 = insert(:user) + following3 = insert(:user) + {:ok, _} = User.follow(user, following1) + {:ok, _} = User.follow(user, following2) + {:ok, _} = User.follow(user, following3) + + conn = + conn + |> assign(:user, user) + + res_conn = + conn + |> get("/api/v1/accounts/#{user.id}/following?since_id=#{following1.id}") + + assert [%{"id" => id3}, %{"id" => id2}] = json_response(res_conn, 200) + assert id3 == following3.id + assert id2 == following2.id + + res_conn = + conn + |> get("/api/v1/accounts/#{user.id}/following?max_id=#{following3.id}") + + assert [%{"id" => id2}, %{"id" => id1}] = json_response(res_conn, 200) + assert id2 == following2.id + assert id1 == following1.id + + res_conn = + conn + |> get("/api/v1/accounts/#{user.id}/following?limit=1&max_id=#{following3.id}") + + assert [%{"id" => id2}] = json_response(res_conn, 200) + assert id2 == following2.id + + assert [link_header] = get_resp_header(res_conn, "link") + assert link_header =~ ~r/since_id=#{following2.id}/ + assert link_header =~ ~r/max_id=#{following2.id}/ + end + test "following / unfollowing a user", %{conn: conn} do user = insert(:user) other_user = insert(:user) From 25eb6cf1cbbfe78618f13a7218238a69807a051c Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Tue, 12 Mar 2019 22:15:28 +0300 Subject: [PATCH 10/37] Add "roles" to users admin API --- lib/pleroma/user/info.ex | 9 +++++++ .../mastodon_api/views/admin/account_view.ex | 4 ++- .../admin_api/admin_api_controller_test.exs | 27 ++++++++++++------- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 818b64645..e3fd65a6e 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -6,6 +6,8 @@ defmodule Pleroma.User.Info do use Ecto.Schema import Ecto.Changeset + alias Pleroma.User.Info + embedded_schema do field(:banner, :map, default: %{}) field(:background, :map, default: %{}) @@ -250,4 +252,11 @@ def remove_pinnned_activity(info, %Pleroma.Activity{id: id}) do cast(info, params, [:pinned_activities]) end + + def roles(%Info{is_moderator: is_moderator, is_admin: is_admin}) do + %{ + admin: is_admin, + moderator: is_moderator + } + end end diff --git a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex b/lib/pleroma/web/mastodon_api/views/admin/account_view.ex index 74ca13564..66ad20ec4 100644 --- a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/admin/account_view.ex @@ -6,6 +6,7 @@ defmodule Pleroma.Web.MastodonAPI.Admin.AccountView do use Pleroma.Web, :view alias Pleroma.Web.MastodonAPI.Admin.AccountView + alias Pleroma.User.Info def render("index.json", %{users: users, count: count, page_size: page_size}) do %{ @@ -19,7 +20,8 @@ def render("show.json", %{user: user}) do %{ "id" => user.id, "nickname" => user.nickname, - "deactivated" => user.info.deactivated + "deactivated" => user.info.deactivated, + "roles" => Info.roles(user.info) } end end diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index 1b8b4d4b7..0470a439b 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -348,12 +348,14 @@ test "renders users array for the first page" do %{ "deactivated" => admin.info.deactivated, "id" => admin.id, - "nickname" => admin.nickname + "nickname" => admin.nickname, + "roles" => %{"admin" => true, "moderator" => false} }, %{ "deactivated" => user.info.deactivated, "id" => user.id, - "nickname" => user.nickname + "nickname" => user.nickname, + "roles" => %{"admin" => false, "moderator" => false} } ] } @@ -391,7 +393,8 @@ test "regular search" do %{ "deactivated" => user.info.deactivated, "id" => user.id, - "nickname" => user.nickname + "nickname" => user.nickname, + "roles" => %{"admin" => false, "moderator" => false} } ] } @@ -414,7 +417,8 @@ test "regular search with page size" do %{ "deactivated" => user.info.deactivated, "id" => user.id, - "nickname" => user.nickname + "nickname" => user.nickname, + "roles" => %{"admin" => false, "moderator" => false} } ] } @@ -431,7 +435,8 @@ test "regular search with page size" do %{ "deactivated" => user2.info.deactivated, "id" => user2.id, - "nickname" => user2.nickname + "nickname" => user2.nickname, + "roles" => %{"admin" => false, "moderator" => false} } ] } @@ -455,7 +460,8 @@ test "only local users" do %{ "deactivated" => user.info.deactivated, "id" => user.id, - "nickname" => user.nickname + "nickname" => user.nickname, + "roles" => %{"admin" => false, "moderator" => false} } ] } @@ -479,12 +485,14 @@ test "only local users with no query" do %{ "deactivated" => admin.info.deactivated, "id" => admin.id, - "nickname" => admin.nickname + "nickname" => admin.nickname, + "roles" => %{"admin" => true, "moderator" => false} }, %{ "deactivated" => user.info.deactivated, "id" => user.id, - "nickname" => user.nickname + "nickname" => user.nickname, + "roles" => %{"admin" => false, "moderator" => false} } ] } @@ -504,7 +512,8 @@ test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do %{ "deactivated" => !user.info.deactivated, "id" => user.id, - "nickname" => user.nickname + "nickname" => user.nickname, + "roles" => %{"admin" => false, "moderator" => false} } end end From d93ab4817b9e0cd5f29851722aa8ed9e39a04f32 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 5 Mar 2019 02:24:12 +0100 Subject: [PATCH 11/37] .gitlab-ci.yml: Adds credo to the chain Not really sure about the order in which this is but it feels right because credo is more about checking if a ~working code could need some improvements. --- .gitlab-ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 30589c9c5..187381af7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,6 +19,7 @@ cache: stages: - lint - test + - analysis before_script: - mix local.hex --force @@ -37,3 +38,8 @@ unit-testing: stage: test script: - mix test --trace --preload-modules + +analysis: + stage: analysis + script: + - mix credo list From 6c8743d0c00e5bb6edffced4b60d3802004f9dc4 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 5 Mar 2019 02:30:19 +0100 Subject: [PATCH 12/37] [Credo] Fix the warnings --- .gitlab-ci.yml | 2 +- lib/pleroma/web/federator/federator.ex | 2 +- test/web/twitter_api/twitter_api_controller_test.exs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 187381af7..6c86097ad 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -42,4 +42,4 @@ unit-testing: analysis: stage: analysis script: - - mix credo list + - mix credo list --only=warnings diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index fbfe97dbc..b1fabf0e9 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -24,7 +24,7 @@ defmodule Pleroma.Web.Federator do def init() do # 1 minute - Process.sleep(1000 * 60 * 1) + Process.sleep(1000 * 60) refresh_subscriptions() end diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index ce0812308..ec4d07f17 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -490,7 +490,7 @@ test "does not show DMs in mentions timeline", %{conn: conn, user: current_user} response = json_response(conn, 200) - assert length(response) == 0 + assert Enum.empty?(response) end end From ddcd0910d32c157f4d89c51bc40c85a79c799692 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 5 Mar 2019 02:32:12 +0100 Subject: [PATCH 13/37] [Credo][CI] Do not make TODO/FIXME fail --- .credo.exs | 4 ++-- .gitlab-ci.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.credo.exs b/.credo.exs index 580cb2705..947280f56 100644 --- a/.credo.exs +++ b/.credo.exs @@ -69,8 +69,8 @@ # You can also customize the exit_status of each check. # If you don't want TODO comments to cause `mix credo` to fail, just # set this value to 0 (zero). - {Credo.Check.Design.TagTODO, exit_status: 2}, - {Credo.Check.Design.TagFIXME}, + {Credo.Check.Design.TagTODO, exit_status: 0}, + {Credo.Check.Design.TagFIXME, exit_status: 0}, {Credo.Check.Readability.FunctionNames}, {Credo.Check.Readability.LargeNumbers}, diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6c86097ad..bd94d146b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -42,4 +42,4 @@ unit-testing: analysis: stage: analysis script: - - mix credo list --only=warnings + - mix credo list --only=warnings,todo,fixme From 1d373d91f39d5adc83254ba3f879fdb8c6842e0d Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 5 Mar 2019 02:38:42 +0100 Subject: [PATCH 14/37] .credo.exs: Clear removed tests --- .credo.exs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.credo.exs b/.credo.exs index 947280f56..620b4abdd 100644 --- a/.credo.exs +++ b/.credo.exs @@ -126,10 +126,6 @@ # Deprecated checks (these will be deleted after a grace period) {Credo.Check.Readability.Specs, false}, - {Credo.Check.Warning.NameRedeclarationByAssignment, false}, - {Credo.Check.Warning.NameRedeclarationByCase, false}, - {Credo.Check.Warning.NameRedeclarationByDef, false}, - {Credo.Check.Warning.NameRedeclarationByFn, false}, # Custom checks can be created using `mix credo.gen.check`. # From 4c440f12c345eeb1bc5092f9440706b2a220aa38 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 5 Mar 2019 02:45:07 +0100 Subject: [PATCH 15/37] [Credo] Fix the consistency --- .gitlab-ci.yml | 2 +- lib/pleroma/thread_mute.ex | 4 +++- .../web/twitter_api/twitter_api_controller.ex | 12 ++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bd94d146b..d5b463000 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -42,4 +42,4 @@ unit-testing: analysis: stage: analysis script: - - mix credo list --only=warnings,todo,fixme + - mix credo list --only=warnings,todo,fixme,consistency diff --git a/lib/pleroma/thread_mute.ex b/lib/pleroma/thread_mute.ex index 0b577113d..7353d8476 100644 --- a/lib/pleroma/thread_mute.ex +++ b/lib/pleroma/thread_mute.ex @@ -4,7 +4,9 @@ defmodule Pleroma.ThreadMute do use Ecto.Schema - alias Pleroma.{Repo, User, ThreadMute} + alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.ThreadMute require Ecto.Query schema "thread_mutes" do diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 5e4ebb8e8..224dd6300 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -8,9 +8,17 @@ defmodule Pleroma.Web.TwitterAPI.Controller do import Pleroma.Web.ControllerHelper, only: [json_response: 3] alias Ecto.Changeset - alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView, NotificationView, TokenView} + alias Pleroma.Web.TwitterAPI.TwitterAPI + alias Pleroma.Web.TwitterAPI.UserView + alias Pleroma.Web.TwitterAPI.ActivityView + alias Pleroma.Web.TwitterAPI.NotificationView + alias Pleroma.Web.TwitterAPI.TokenView alias Pleroma.Web.CommonAPI - alias Pleroma.{Repo, Activity, Object, User, Notification} + alias Pleroma.Repo + alias Pleroma.Activity + alias Pleroma.Object + alias Pleroma.User + alias Pleroma.Notification alias Pleroma.Web.OAuth.Token alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Visibility From a3a9cec4835738216800d2cebd295fb8dbf10f34 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 5 Mar 2019 03:52:23 +0100 Subject: [PATCH 16/37] [Credo] fix Credo.Check.Readability.AliasOrder --- lib/mix/tasks/pleroma/relay.ex | 2 +- lib/mix/tasks/pleroma/uploads.ex | 2 +- lib/mix/tasks/pleroma/user.ex | 2 +- lib/pleroma/PasswordResetToken.ex | 4 +- lib/pleroma/activity.ex | 2 +- lib/pleroma/filter.ex | 2 +- lib/pleroma/gopher/server.ex | 6 +-- lib/pleroma/instances/instance.ex | 2 +- lib/pleroma/notification.ex | 4 +- lib/pleroma/object.ex | 6 +-- lib/pleroma/plugs/http_signature.ex | 2 +- lib/pleroma/plugs/oauth_plug.ex | 2 +- lib/pleroma/plugs/user_fetcher_plug.ex | 2 +- lib/pleroma/stats.ex | 2 +- lib/pleroma/thread_mute.ex | 4 +- lib/pleroma/user.ex | 20 +++++----- lib/pleroma/user_invite_token.ex | 2 +- lib/pleroma/web/activity_pub/activity_pub.ex | 10 ++--- .../activity_pub/activity_pub_controller.ex | 8 ++-- lib/pleroma/web/activity_pub/relay.ex | 4 +- .../web/activity_pub/transmogrifier.ex | 2 +- lib/pleroma/web/activity_pub/utils.ex | 18 ++++----- .../web/activity_pub/views/user_view.ex | 8 ++-- lib/pleroma/web/auth/pleroma_authenticator.ex | 2 +- lib/pleroma/web/chat_channel.ex | 2 +- lib/pleroma/web/common_api/common_api.ex | 6 +-- lib/pleroma/web/common_api/utils.ex | 4 +- lib/pleroma/web/federator/federator.ex | 10 ++--- lib/pleroma/web/mastodon_api/mastodon_api.ex | 2 +- .../mastodon_api/mastodon_api_controller.ex | 20 +++++----- .../mastodon_api/views/admin/account_view.ex | 2 +- .../web/mastodon_api/websocket_handler.ex | 2 +- lib/pleroma/web/metadata/utils.ex | 4 +- lib/pleroma/web/oauth/authorization.ex | 4 +- lib/pleroma/web/oauth/oauth_controller.ex | 10 ++--- lib/pleroma/web/oauth/token.ex | 4 +- .../web/ostatus/activity_representer.ex | 2 +- lib/pleroma/web/ostatus/feed_representer.ex | 2 +- .../web/ostatus/handlers/delete_handler.ex | 2 +- .../web/ostatus/handlers/follow_handler.ex | 6 +-- .../web/ostatus/handlers/note_handler.ex | 5 ++- .../web/ostatus/handlers/unfollow_handler.ex | 6 +-- lib/pleroma/web/ostatus/ostatus.ex | 12 +++--- lib/pleroma/web/ostatus/ostatus_controller.ex | 6 +-- lib/pleroma/web/push/impl.ex | 8 ++-- lib/pleroma/web/rich_media/helpers.ex | 2 +- lib/pleroma/web/router.ex | 2 +- lib/pleroma/web/salmon/salmon.ex | 2 +- lib/pleroma/web/streamer.ex | 4 +- .../controllers/util_controller.ex | 4 +- lib/pleroma/web/twitter_api/twitter_api.ex | 12 +++--- .../web/twitter_api/twitter_api_controller.ex | 40 +++++++++---------- .../web/twitter_api/views/activity_view.ex | 2 +- lib/pleroma/web/web_finger/web_finger.ex | 6 +-- lib/pleroma/web/websub/websub.ex | 12 +++--- lib/pleroma/web/websub/websub_controller.ex | 2 +- test/integration/mastodon_websocket_test.exs | 2 +- test/jobs_test.exs | 2 +- test/notification_test.exs | 6 +-- test/object_test.exs | 2 +- test/support/builders/user_builder.ex | 2 +- test/tasks/relay_test.exs | 6 +-- test/user_test.exs | 2 +- .../activity_pub_controller_test.exs | 8 ++-- test/web/activity_pub/activity_pub_test.exs | 10 ++--- test/web/activity_pub/transmogrifier_test.exs | 8 ++-- test/web/activity_pub/utils_test.exs | 2 +- .../activity_pub/views/object_view_test.exs | 2 +- test/web/activity_pub/visibilty_test.exs | 2 +- test/web/common_api/common_api_test.exs | 4 +- test/web/common_api/common_api_utils_test.exs | 2 +- test/web/federator_test.exs | 2 +- test/web/instances/instance_test.exs | 2 +- test/web/mastodon_api/account_view_test.exs | 2 +- .../mastodon_api_controller_test.exs | 14 +++---- test/web/mastodon_api/status_view_test.exs | 8 ++-- test/web/oauth/authorization_test.exs | 2 +- test/web/oauth/token_test.exs | 2 +- .../web/ostatus/activity_representer_test.exs | 4 +- test/web/ostatus/feed_representer_test.exs | 2 +- .../delete_handling_test.exs | 2 +- test/web/ostatus/ostatus_controller_test.exs | 4 +- test/web/ostatus/ostatus_test.exs | 8 ++-- test/web/salmon/salmon_test.exs | 2 +- test/web/streamer_test.exs | 2 +- .../activity_representer_test.exs | 4 +- .../twitter_api_controller_test.exs | 30 +++++++------- test/web/twitter_api/twitter_api_test.exs | 6 +-- .../twitter_api/views/activity_view_test.exs | 10 ++--- .../views/notification_view_test.exs | 12 +++--- test/web/twitter_api/views/user_view_test.exs | 2 +- test/web/websub/websub_controller_test.exs | 2 +- test/web/websub/websub_test.exs | 10 +++-- 93 files changed, 261 insertions(+), 256 deletions(-) diff --git a/lib/mix/tasks/pleroma/relay.ex b/lib/mix/tasks/pleroma/relay.ex index cbe23f82e..fbec473c5 100644 --- a/lib/mix/tasks/pleroma/relay.ex +++ b/lib/mix/tasks/pleroma/relay.ex @@ -4,8 +4,8 @@ defmodule Mix.Tasks.Pleroma.Relay do use Mix.Task - alias Pleroma.Web.ActivityPub.Relay alias Mix.Tasks.Pleroma.Common + alias Pleroma.Web.ActivityPub.Relay @shortdoc "Manages remote relays" @moduledoc """ diff --git a/lib/mix/tasks/pleroma/uploads.ex b/lib/mix/tasks/pleroma/uploads.ex index a01e61627..9ca123a9b 100644 --- a/lib/mix/tasks/pleroma/uploads.ex +++ b/lib/mix/tasks/pleroma/uploads.ex @@ -4,9 +4,9 @@ defmodule Mix.Tasks.Pleroma.Uploads do use Mix.Task + alias Mix.Tasks.Pleroma.Common alias Pleroma.Upload alias Pleroma.Uploaders.Local - alias Mix.Tasks.Pleroma.Common require Logger @log_every 50 diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 037e44716..f6cca0d06 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -5,9 +5,9 @@ defmodule Mix.Tasks.Pleroma.User do use Mix.Task import Ecto.Changeset + alias Mix.Tasks.Pleroma.Common alias Pleroma.Repo alias Pleroma.User - alias Mix.Tasks.Pleroma.Common @shortdoc "Manages Pleroma users" @moduledoc """ diff --git a/lib/pleroma/PasswordResetToken.ex b/lib/pleroma/PasswordResetToken.ex index 750ddd3c0..772c239a1 100644 --- a/lib/pleroma/PasswordResetToken.ex +++ b/lib/pleroma/PasswordResetToken.ex @@ -7,9 +7,9 @@ defmodule Pleroma.PasswordResetToken do import Ecto.Changeset - alias Pleroma.User - alias Pleroma.Repo alias Pleroma.PasswordResetToken + alias Pleroma.Repo + alias Pleroma.User schema "password_reset_tokens" do belongs_to(:user, User, type: Pleroma.FlakeId) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 18d5b70de..79dc26b01 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -5,9 +5,9 @@ defmodule Pleroma.Activity do use Ecto.Schema - alias Pleroma.Repo alias Pleroma.Activity alias Pleroma.Notification + alias Pleroma.Repo import Ecto.Query diff --git a/lib/pleroma/filter.ex b/lib/pleroma/filter.ex index bdc34698c..79efc29f0 100644 --- a/lib/pleroma/filter.ex +++ b/lib/pleroma/filter.ex @@ -8,8 +8,8 @@ defmodule Pleroma.Filter do import Ecto.Changeset import Ecto.Query - alias Pleroma.User alias Pleroma.Repo + alias Pleroma.User schema "filters" do belongs_to(:user, User, type: Pleroma.FlakeId) diff --git a/lib/pleroma/gopher/server.ex b/lib/pleroma/gopher/server.ex index ba9614029..5b4e745e9 100644 --- a/lib/pleroma/gopher/server.ex +++ b/lib/pleroma/gopher/server.ex @@ -36,12 +36,12 @@ def init([ip, port]) do end defmodule Pleroma.Gopher.Server.ProtocolHandler do - alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.ActivityPub.Visibility alias Pleroma.Activity alias Pleroma.HTML - alias Pleroma.User alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Visibility def start_link(ref, socket, transport, opts) do pid = spawn_link(__MODULE__, :init, [ref, socket, transport, opts]) diff --git a/lib/pleroma/instances/instance.ex b/lib/pleroma/instances/instance.ex index 48bc939dd..e92006151 100644 --- a/lib/pleroma/instances/instance.ex +++ b/lib/pleroma/instances/instance.ex @@ -2,8 +2,8 @@ defmodule Pleroma.Instances.Instance do @moduledoc "Instance." alias Pleroma.Instances - alias Pleroma.Repo alias Pleroma.Instances.Instance + alias Pleroma.Repo use Ecto.Schema diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index c88512567..fe8181d8b 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -5,12 +5,12 @@ defmodule Pleroma.Notification do use Ecto.Schema - alias Pleroma.User alias Pleroma.Activity alias Pleroma.Notification alias Pleroma.Repo - alias Pleroma.Web.CommonAPI.Utils + alias Pleroma.User alias Pleroma.Web.CommonAPI + alias Pleroma.Web.CommonAPI.Utils import Ecto.Query diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index 7510a09bb..58e46ef1d 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -5,11 +5,11 @@ defmodule Pleroma.Object do use Ecto.Schema - alias Pleroma.Repo - alias Pleroma.Object - alias Pleroma.User alias Pleroma.Activity + alias Pleroma.Object alias Pleroma.ObjectTombstone + alias Pleroma.Repo + alias Pleroma.User import Ecto.Query import Ecto.Changeset diff --git a/lib/pleroma/plugs/http_signature.ex b/lib/pleroma/plugs/http_signature.ex index 51bec910e..21c195713 100644 --- a/lib/pleroma/plugs/http_signature.ex +++ b/lib/pleroma/plugs/http_signature.ex @@ -3,8 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do - alias Pleroma.Web.HTTPSignatures alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.Web.HTTPSignatures import Plug.Conn require Logger diff --git a/lib/pleroma/plugs/oauth_plug.ex b/lib/pleroma/plugs/oauth_plug.ex index 22f0406f4..6130c4570 100644 --- a/lib/pleroma/plugs/oauth_plug.ex +++ b/lib/pleroma/plugs/oauth_plug.ex @@ -6,8 +6,8 @@ defmodule Pleroma.Plugs.OAuthPlug do import Plug.Conn import Ecto.Query - alias Pleroma.User alias Pleroma.Repo + alias Pleroma.User alias Pleroma.Web.OAuth.Token @realm_reg Regex.compile!("Bearer\:?\s+(.*)$", "i") diff --git a/lib/pleroma/plugs/user_fetcher_plug.ex b/lib/pleroma/plugs/user_fetcher_plug.ex index 7ed4602bb..5a77f6833 100644 --- a/lib/pleroma/plugs/user_fetcher_plug.ex +++ b/lib/pleroma/plugs/user_fetcher_plug.ex @@ -3,8 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.UserFetcherPlug do - alias Pleroma.User alias Pleroma.Repo + alias Pleroma.User import Plug.Conn diff --git a/lib/pleroma/stats.ex b/lib/pleroma/stats.ex index fe0ce9051..2e7d747df 100644 --- a/lib/pleroma/stats.ex +++ b/lib/pleroma/stats.ex @@ -4,8 +4,8 @@ defmodule Pleroma.Stats do import Ecto.Query - alias Pleroma.User alias Pleroma.Repo + alias Pleroma.User def start_link do agent = Agent.start_link(fn -> {[], %{}} end, name: __MODULE__) diff --git a/lib/pleroma/thread_mute.ex b/lib/pleroma/thread_mute.ex index 7353d8476..10d31679d 100644 --- a/lib/pleroma/thread_mute.ex +++ b/lib/pleroma/thread_mute.ex @@ -4,9 +4,11 @@ defmodule Pleroma.ThreadMute do use Ecto.Schema + alias Pleroma.Repo - alias Pleroma.User alias Pleroma.ThreadMute + alias Pleroma.User + require Ecto.Query schema "thread_mutes" do diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index f49ede149..762cd8c46 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -8,21 +8,21 @@ defmodule Pleroma.User do import Ecto.Changeset import Ecto.Query + alias Comeonin.Pbkdf2 + alias Pleroma.Activity + alias Pleroma.Formatter + alias Pleroma.Notification + alias Pleroma.Object alias Pleroma.Repo alias Pleroma.User - alias Pleroma.Object alias Pleroma.Web - alias Pleroma.Activity - alias Pleroma.Notification - alias Comeonin.Pbkdf2 - alias Pleroma.Formatter - alias Pleroma.Web.CommonAPI.Utils, as: CommonUtils - alias Pleroma.Web.OStatus - alias Pleroma.Web.Websub - alias Pleroma.Web.OAuth - alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.Web.CommonAPI.Utils, as: CommonUtils + alias Pleroma.Web.OAuth + alias Pleroma.Web.OStatus alias Pleroma.Web.RelMe + alias Pleroma.Web.Websub require Logger diff --git a/lib/pleroma/user_invite_token.ex b/lib/pleroma/user_invite_token.ex index 5a448114c..9c5579934 100644 --- a/lib/pleroma/user_invite_token.ex +++ b/lib/pleroma/user_invite_token.ex @@ -7,8 +7,8 @@ defmodule Pleroma.UserInviteToken do import Ecto.Changeset - alias Pleroma.UserInviteToken alias Pleroma.Repo + alias Pleroma.UserInviteToken schema "user_invite_tokens" do field(:token, :string) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 2f11f8984..337dc0173 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -4,17 +4,17 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do alias Pleroma.Activity - alias Pleroma.Repo + alias Pleroma.Instances + alias Pleroma.Notification alias Pleroma.Object + alias Pleroma.Repo alias Pleroma.Upload alias Pleroma.User - alias Pleroma.Notification - alias Pleroma.Instances - alias Pleroma.Web.ActivityPub.Transmogrifier alias Pleroma.Web.ActivityPub.MRF - alias Pleroma.Web.WebFinger + alias Pleroma.Web.ActivityPub.Transmogrifier alias Pleroma.Web.Federator alias Pleroma.Web.OStatus + alias Pleroma.Web.WebFinger import Ecto.Query import Pleroma.Web.ActivityPub.Utils diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index ff924a536..7091d6927 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -6,15 +6,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do use Pleroma.Web, :controller alias Pleroma.Activity - alias Pleroma.User alias Pleroma.Object - alias Pleroma.Web.ActivityPub.ObjectView - alias Pleroma.Web.ActivityPub.UserView + alias Pleroma.User alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.ActivityPub.Visibility + alias Pleroma.Web.ActivityPub.ObjectView alias Pleroma.Web.ActivityPub.Relay alias Pleroma.Web.ActivityPub.Transmogrifier + alias Pleroma.Web.ActivityPub.UserView alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.Web.ActivityPub.Visibility alias Pleroma.Web.Federator require Logger diff --git a/lib/pleroma/web/activity_pub/relay.ex b/lib/pleroma/web/activity_pub/relay.ex index c496063ea..01fef71b9 100644 --- a/lib/pleroma/web/activity_pub/relay.ex +++ b/lib/pleroma/web/activity_pub/relay.ex @@ -3,9 +3,9 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.Relay do - alias Pleroma.User - alias Pleroma.Object alias Pleroma.Activity + alias Pleroma.Object + alias Pleroma.User alias Pleroma.Web.ActivityPub.ActivityPub require Logger diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 27d223a3e..f1ce15876 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -7,9 +7,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do A module to handle coding from internal to wire ActivityPub and back. """ alias Pleroma.Activity - alias Pleroma.User alias Pleroma.Object alias Pleroma.Repo + alias Pleroma.User alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.Visibility diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 629c39315..182f9cacb 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -3,17 +3,17 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.Utils do - alias Pleroma.Repo - alias Pleroma.Web - alias Pleroma.Object - alias Pleroma.Activity - alias Pleroma.Web.ActivityPub.Visibility - alias Pleroma.User - alias Pleroma.Notification - alias Pleroma.Web.Router.Helpers - alias Pleroma.Web.Endpoint alias Ecto.Changeset alias Ecto.UUID + alias Pleroma.Activity + alias Pleroma.Notification + alias Pleroma.Object + alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.Web + alias Pleroma.Web.ActivityPub.Visibility + alias Pleroma.Web.Endpoint + alias Pleroma.Web.Router.Helpers import Ecto.Query diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 415cbd47a..3d00dcbf2 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -5,15 +5,15 @@ defmodule Pleroma.Web.ActivityPub.UserView do use Pleroma.Web, :view - alias Pleroma.Web.WebFinger - alias Pleroma.Web.Salmon - alias Pleroma.User alias Pleroma.Repo + alias Pleroma.User alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Transmogrifier alias Pleroma.Web.ActivityPub.Utils - alias Pleroma.Web.Router.Helpers alias Pleroma.Web.Endpoint + alias Pleroma.Web.Router.Helpers + alias Pleroma.Web.Salmon + alias Pleroma.Web.WebFinger import Ecto.Query diff --git a/lib/pleroma/web/auth/pleroma_authenticator.ex b/lib/pleroma/web/auth/pleroma_authenticator.ex index 3cc19af01..333446bef 100644 --- a/lib/pleroma/web/auth/pleroma_authenticator.ex +++ b/lib/pleroma/web/auth/pleroma_authenticator.ex @@ -3,8 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Auth.PleromaAuthenticator do - alias Pleroma.User alias Comeonin.Pbkdf2 + alias Pleroma.User @behaviour Pleroma.Web.Auth.Authenticator diff --git a/lib/pleroma/web/chat_channel.ex b/lib/pleroma/web/chat_channel.ex index fe63ede66..efdbba5a1 100644 --- a/lib/pleroma/web/chat_channel.ex +++ b/lib/pleroma/web/chat_channel.ex @@ -4,8 +4,8 @@ defmodule Pleroma.Web.ChatChannel do use Phoenix.Channel - alias Pleroma.Web.ChatChannel.ChatChannelState alias Pleroma.User + alias Pleroma.Web.ChatChannel.ChatChannelState def join("chat:public", _message, socket) do send(self(), :after_join) diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 07bd6548a..2e39a16c3 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -3,14 +3,14 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.CommonAPI do - alias Pleroma.User - alias Pleroma.Repo alias Pleroma.Activity + alias Pleroma.Formatter alias Pleroma.Object + alias Pleroma.Repo alias Pleroma.ThreadMute + alias Pleroma.User alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils - alias Pleroma.Formatter import Pleroma.Web.CommonAPI.Utils diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index e4b9102c5..b7513ef28 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -6,14 +6,14 @@ defmodule Pleroma.Web.CommonAPI.Utils do alias Calendar.Strftime alias Comeonin.Pbkdf2 alias Pleroma.Activity + alias Pleroma.Config alias Pleroma.Formatter alias Pleroma.Object alias Pleroma.Repo alias Pleroma.User - alias Pleroma.Config + alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.Endpoint alias Pleroma.Web.MediaProxy - alias Pleroma.Web.ActivityPub.Utils # This is a hack for twidere. def get_by_id_or_ap_id(id) do diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index b1fabf0e9..b5b5049a4 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -4,18 +4,18 @@ defmodule Pleroma.Web.Federator do alias Pleroma.Activity + alias Pleroma.Jobs alias Pleroma.User - alias Pleroma.Web.WebFinger - alias Pleroma.Web.Websub - alias Pleroma.Web.Salmon alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.ActivityPub.Visibility alias Pleroma.Web.ActivityPub.Relay alias Pleroma.Web.ActivityPub.Transmogrifier alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.Web.ActivityPub.Visibility alias Pleroma.Web.Federator.RetryQueue alias Pleroma.Web.OStatus - alias Pleroma.Jobs + alias Pleroma.Web.Salmon + alias Pleroma.Web.WebFinger + alias Pleroma.Web.Websub require Logger diff --git a/lib/pleroma/web/mastodon_api/mastodon_api.ex b/lib/pleroma/web/mastodon_api/mastodon_api.ex index c952c5806..54cb6c97a 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api.ex @@ -2,8 +2,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do import Ecto.Query import Ecto.Changeset - alias Pleroma.User alias Pleroma.Repo + alias Pleroma.User @default_limit 20 diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index a97bc7569..2ead3eb5e 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -4,6 +4,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do use Pleroma.Web, :controller + alias Pleroma.Activity alias Pleroma.Config alias Pleroma.Filter @@ -13,19 +14,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do alias Pleroma.Stats alias Pleroma.User alias Pleroma.Web - alias Pleroma.Web.CommonAPI - alias Pleroma.Web.MediaProxy - - alias Pleroma.Web.MastodonAPI.AccountView - alias Pleroma.Web.MastodonAPI.FilterView - alias Pleroma.Web.MastodonAPI.ListView - alias Pleroma.Web.MastodonAPI.MastodonView - alias Pleroma.Web.MastodonAPI.StatusView - alias Pleroma.Web.MastodonAPI.ReportView - alias Pleroma.Web.MastodonAPI.MastodonAPI alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.Visibility + alias Pleroma.Web.CommonAPI + alias Pleroma.Web.MastodonAPI.AccountView + alias Pleroma.Web.MastodonAPI.FilterView + alias Pleroma.Web.MastodonAPI.ListView + alias Pleroma.Web.MastodonAPI.MastodonAPI + alias Pleroma.Web.MastodonAPI.MastodonView + alias Pleroma.Web.MastodonAPI.ReportView + alias Pleroma.Web.MastodonAPI.StatusView + alias Pleroma.Web.MediaProxy alias Pleroma.Web.OAuth.App alias Pleroma.Web.OAuth.Authorization alias Pleroma.Web.OAuth.Token diff --git a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex b/lib/pleroma/web/mastodon_api/views/admin/account_view.ex index 66ad20ec4..5ce017124 100644 --- a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/admin/account_view.ex @@ -5,8 +5,8 @@ defmodule Pleroma.Web.MastodonAPI.Admin.AccountView do use Pleroma.Web, :view - alias Pleroma.Web.MastodonAPI.Admin.AccountView alias Pleroma.User.Info + alias Pleroma.Web.MastodonAPI.Admin.AccountView def render("index.json", %{users: users, count: count, page_size: page_size}) do %{ diff --git a/lib/pleroma/web/mastodon_api/websocket_handler.ex b/lib/pleroma/web/mastodon_api/websocket_handler.ex index 8efe2efd5..9b262f461 100644 --- a/lib/pleroma/web/mastodon_api/websocket_handler.ex +++ b/lib/pleroma/web/mastodon_api/websocket_handler.ex @@ -5,9 +5,9 @@ defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do require Logger - alias Pleroma.Web.OAuth.Token alias Pleroma.Repo alias Pleroma.User + alias Pleroma.Web.OAuth.Token @behaviour :cowboy_websocket diff --git a/lib/pleroma/web/metadata/utils.ex b/lib/pleroma/web/metadata/utils.ex index 5fc9c9e7b..23bbde1a6 100644 --- a/lib/pleroma/web/metadata/utils.ex +++ b/lib/pleroma/web/metadata/utils.ex @@ -1,10 +1,10 @@ # Pleroma: A lightweight social networking server -# Copyright \xc2\xa9 2017-2019 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Metadata.Utils do - alias Pleroma.HTML alias Pleroma.Formatter + alias Pleroma.HTML alias Pleroma.Web.MediaProxy def scrub_html_and_truncate(%{data: %{"content" => content}} = object) do diff --git a/lib/pleroma/web/oauth/authorization.ex b/lib/pleroma/web/oauth/authorization.ex index d37c2cb83..a80543adf 100644 --- a/lib/pleroma/web/oauth/authorization.ex +++ b/lib/pleroma/web/oauth/authorization.ex @@ -5,10 +5,10 @@ defmodule Pleroma.Web.OAuth.Authorization do use Ecto.Schema - alias Pleroma.User alias Pleroma.Repo - alias Pleroma.Web.OAuth.Authorization + alias Pleroma.User alias Pleroma.Web.OAuth.App + alias Pleroma.Web.OAuth.Authorization import Ecto.Changeset import Ecto.Query diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex index 36318d69b..ec70b7ccc 100644 --- a/lib/pleroma/web/oauth/oauth_controller.ex +++ b/lib/pleroma/web/oauth/oauth_controller.ex @@ -5,13 +5,13 @@ defmodule Pleroma.Web.OAuth.OAuthController do use Pleroma.Web, :controller - alias Pleroma.Web.Auth.Authenticator - alias Pleroma.Web.OAuth.Authorization - alias Pleroma.Web.OAuth.Token - alias Pleroma.Web.OAuth.App + alias Comeonin.Pbkdf2 alias Pleroma.Repo alias Pleroma.User - alias Comeonin.Pbkdf2 + alias Pleroma.Web.Auth.Authenticator + alias Pleroma.Web.OAuth.App + alias Pleroma.Web.OAuth.Authorization + alias Pleroma.Web.OAuth.Token import Pleroma.Web.ControllerHelper, only: [oauth_scopes: 2] diff --git a/lib/pleroma/web/oauth/token.ex b/lib/pleroma/web/oauth/token.ex index ca67632ba..2b074b470 100644 --- a/lib/pleroma/web/oauth/token.ex +++ b/lib/pleroma/web/oauth/token.ex @@ -7,11 +7,11 @@ defmodule Pleroma.Web.OAuth.Token do import Ecto.Query - alias Pleroma.User alias Pleroma.Repo - alias Pleroma.Web.OAuth.Token + alias Pleroma.User alias Pleroma.Web.OAuth.App alias Pleroma.Web.OAuth.Authorization + alias Pleroma.Web.OAuth.Token schema "oauth_tokens" do field(:token, :string) diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index 9e1f24bc4..1a1b74bb0 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -4,8 +4,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do alias Pleroma.Activity - alias Pleroma.User alias Pleroma.Object + alias Pleroma.User alias Pleroma.Web.OStatus.UserRepresenter require Logger diff --git a/lib/pleroma/web/ostatus/feed_representer.ex b/lib/pleroma/web/ostatus/feed_representer.ex index 025d4731c..b7b97e505 100644 --- a/lib/pleroma/web/ostatus/feed_representer.ex +++ b/lib/pleroma/web/ostatus/feed_representer.ex @@ -4,8 +4,8 @@ defmodule Pleroma.Web.OStatus.FeedRepresenter do alias Pleroma.User - alias Pleroma.Web.OStatus alias Pleroma.Web.MediaProxy + alias Pleroma.Web.OStatus alias Pleroma.Web.OStatus.ActivityRepresenter alias Pleroma.Web.OStatus.UserRepresenter diff --git a/lib/pleroma/web/ostatus/handlers/delete_handler.ex b/lib/pleroma/web/ostatus/handlers/delete_handler.ex index 01b52f08f..b2f9f3946 100644 --- a/lib/pleroma/web/ostatus/handlers/delete_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/delete_handler.ex @@ -4,9 +4,9 @@ defmodule Pleroma.Web.OStatus.DeleteHandler do require Logger - alias Pleroma.Web.XML alias Pleroma.Object alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.XML def handle_delete(entry, _doc \\ nil) do with id <- XML.string_from_xpath("//id", entry), diff --git a/lib/pleroma/web/ostatus/handlers/follow_handler.ex b/lib/pleroma/web/ostatus/handlers/follow_handler.ex index 91ad4bc40..263d3b2dc 100644 --- a/lib/pleroma/web/ostatus/handlers/follow_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/follow_handler.ex @@ -3,10 +3,10 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OStatus.FollowHandler do - alias Pleroma.Web.XML - alias Pleroma.Web.OStatus - alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.User + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.OStatus + alias Pleroma.Web.XML def handle(entry, doc) do with {:ok, actor} <- OStatus.find_make_or_update_user(doc), diff --git a/lib/pleroma/web/ostatus/handlers/note_handler.ex b/lib/pleroma/web/ostatus/handlers/note_handler.ex index c2e585cac..50767a6a8 100644 --- a/lib/pleroma/web/ostatus/handlers/note_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/note_handler.ex @@ -4,13 +4,14 @@ defmodule Pleroma.Web.OStatus.NoteHandler do require Logger - alias Pleroma.Web.OStatus - alias Pleroma.Web.XML + alias Pleroma.Activity alias Pleroma.Object alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.CommonAPI + alias Pleroma.Web.OStatus + alias Pleroma.Web.XML @doc """ Get the context for this note. Uses this: diff --git a/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex b/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex index c9085894d..6596ada3b 100644 --- a/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex @@ -3,10 +3,10 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OStatus.UnfollowHandler do - alias Pleroma.Web.XML - alias Pleroma.Web.OStatus - alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.User + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.OStatus + alias Pleroma.Web.XML def handle(entry, doc) do with {:ok, actor} <- OStatus.find_make_or_update_user(doc), diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index b4f5761ac..266f86bf4 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -9,19 +9,19 @@ defmodule Pleroma.Web.OStatus do import Pleroma.Web.XML require Logger + alias Pleroma.Activity + alias Pleroma.Object alias Pleroma.Repo alias Pleroma.User alias Pleroma.Web - alias Pleroma.Object - alias Pleroma.Activity alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Transmogrifier + alias Pleroma.Web.OStatus.DeleteHandler + alias Pleroma.Web.OStatus.FollowHandler + alias Pleroma.Web.OStatus.NoteHandler + alias Pleroma.Web.OStatus.UnfollowHandler alias Pleroma.Web.WebFinger alias Pleroma.Web.Websub - alias Pleroma.Web.OStatus.FollowHandler - alias Pleroma.Web.OStatus.UnfollowHandler - alias Pleroma.Web.OStatus.NoteHandler - alias Pleroma.Web.OStatus.DeleteHandler def is_representable?(%Activity{data: data}) do object = Object.normalize(data["object"]) diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 4e963774a..0579a5f3d 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -9,13 +9,13 @@ defmodule Pleroma.Web.OStatus.OStatusController do alias Pleroma.Object alias Pleroma.User alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.ActivityPub.Visibility alias Pleroma.Web.ActivityPub.ActivityPubController alias Pleroma.Web.ActivityPub.ObjectView - alias Pleroma.Web.OStatus.ActivityRepresenter - alias Pleroma.Web.OStatus.FeedRepresenter + alias Pleroma.Web.ActivityPub.Visibility alias Pleroma.Web.Federator alias Pleroma.Web.OStatus + alias Pleroma.Web.OStatus.ActivityRepresenter + alias Pleroma.Web.OStatus.FeedRepresenter alias Pleroma.Web.XML plug(Pleroma.Web.FederatingPlug when action in [:salmon_incoming]) diff --git a/lib/pleroma/web/push/impl.ex b/lib/pleroma/web/push/impl.ex index 0437ffd00..863573185 100644 --- a/lib/pleroma/web/push/impl.ex +++ b/lib/pleroma/web/push/impl.ex @@ -5,13 +5,13 @@ defmodule Pleroma.Web.Push.Impl do @moduledoc "The module represents implementation push web notification" + alias Pleroma.Activity + alias Pleroma.Notification + alias Pleroma.Object alias Pleroma.Repo alias Pleroma.User - alias Pleroma.Activity - alias Pleroma.Object - alias Pleroma.Web.Push.Subscription alias Pleroma.Web.Metadata.Utils - alias Pleroma.Notification + alias Pleroma.Web.Push.Subscription require Logger import Ecto.Query diff --git a/lib/pleroma/web/rich_media/helpers.ex b/lib/pleroma/web/rich_media/helpers.ex index 8317a1162..92c61ff51 100644 --- a/lib/pleroma/web/rich_media/helpers.ex +++ b/lib/pleroma/web/rich_media/helpers.ex @@ -4,8 +4,8 @@ defmodule Pleroma.Web.RichMedia.Helpers do alias Pleroma.Activity - alias Pleroma.Object alias Pleroma.HTML + alias Pleroma.Object alias Pleroma.Web.RichMedia.Parser defp validate_page_url(page_url) when is_binary(page_url) do diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 65a90e31e..c56e4a421 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -631,8 +631,8 @@ defmodule Pleroma.Web.Router do defmodule Fallback.RedirectController do use Pleroma.Web, :controller - alias Pleroma.Web.Metadata alias Pleroma.User + alias Pleroma.Web.Metadata def redirector(conn, _params, code \\ 200) do conn diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index 0a69aa1ec..47f4bdd53 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -9,8 +9,8 @@ defmodule Pleroma.Web.Salmon do alias Pleroma.Instances alias Pleroma.User - alias Pleroma.Web.XML alias Pleroma.Web.OStatus.ActivityRepresenter + alias Pleroma.Web.XML require Logger diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex index ad888c361..aec11a79f 100644 --- a/lib/pleroma/web/streamer.ex +++ b/lib/pleroma/web/streamer.ex @@ -5,11 +5,11 @@ defmodule Pleroma.Web.Streamer do use GenServer require Logger - alias Pleroma.User - alias Pleroma.Notification alias Pleroma.Activity + alias Pleroma.Notification alias Pleroma.Object alias Pleroma.Repo + alias Pleroma.User alias Pleroma.Web.ActivityPub.Visibility @keepalive_interval :timer.seconds(30) diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index e2fdedb25..8ed02a93f 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -10,13 +10,13 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do alias Comeonin.Pbkdf2 alias Pleroma.Emoji alias Pleroma.PasswordResetToken - alias Pleroma.User alias Pleroma.Repo + alias Pleroma.User alias Pleroma.Web + alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.CommonAPI alias Pleroma.Web.OStatus alias Pleroma.Web.WebFinger - alias Pleroma.Web.ActivityPub.ActivityPub def show_password_reset(conn, %{"token" => token}) do with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}), diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index dcb15b9a9..39e868bef 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -3,16 +3,16 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.TwitterAPI.TwitterAPI do - alias Pleroma.UserInviteToken - alias Pleroma.User alias Pleroma.Activity - alias Pleroma.Repo - alias Pleroma.Object - alias Pleroma.UserEmail alias Pleroma.Mailer + alias Pleroma.Object + alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.UserEmail + alias Pleroma.UserInviteToken alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Web.CommonAPI + alias Pleroma.Web.TwitterAPI.UserView import Ecto.Query diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 224dd6300..05aae9eb1 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -8,31 +8,31 @@ defmodule Pleroma.Web.TwitterAPI.Controller do import Pleroma.Web.ControllerHelper, only: [json_response: 3] alias Ecto.Changeset - alias Pleroma.Web.TwitterAPI.TwitterAPI - alias Pleroma.Web.TwitterAPI.UserView + alias Pleroma.Activity + alias Pleroma.Activity + alias Pleroma.Notification + alias Pleroma.Notification + alias Pleroma.Object + alias Pleroma.Object + alias Pleroma.Repo + alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.User + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.Web.ActivityPub.Visibility + alias Pleroma.Web.CommonAPI + alias Pleroma.Web.CommonAPI + alias Pleroma.Web.OAuth.Token alias Pleroma.Web.TwitterAPI.ActivityView + alias Pleroma.Web.TwitterAPI.ActivityView + alias Pleroma.Web.TwitterAPI.NotificationView alias Pleroma.Web.TwitterAPI.NotificationView alias Pleroma.Web.TwitterAPI.TokenView - alias Pleroma.Web.CommonAPI - alias Pleroma.Repo - alias Pleroma.Activity - alias Pleroma.Object - alias Pleroma.User - alias Pleroma.Notification - alias Pleroma.Web.OAuth.Token - alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.ActivityPub.Visibility - alias Pleroma.Web.ActivityPub.Utils - alias Pleroma.Web.CommonAPI - alias Pleroma.Web.TwitterAPI.ActivityView - alias Pleroma.Web.TwitterAPI.NotificationView + alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.Web.TwitterAPI.UserView - alias Pleroma.Activity - alias Pleroma.Object - alias Pleroma.Notification - alias Pleroma.Repo - alias Pleroma.User + alias Pleroma.Web.TwitterAPI.UserView require Logger diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 02ca4ee42..4926f007e 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -14,9 +14,9 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.MastodonAPI.StatusView alias Pleroma.Web.TwitterAPI.ActivityView + alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.Web.TwitterAPI.UserView - alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter import Ecto.Query require Logger diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 5ea5ae48e..32c3455f5 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -6,11 +6,11 @@ defmodule Pleroma.Web.WebFinger do @httpoison Application.get_env(:pleroma, :httpoison) alias Pleroma.User - alias Pleroma.XmlBuilder alias Pleroma.Web - alias Pleroma.Web.XML - alias Pleroma.Web.Salmon alias Pleroma.Web.OStatus + alias Pleroma.Web.Salmon + alias Pleroma.Web.XML + alias Pleroma.XmlBuilder require Jason require Logger diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index c00ec0858..165440431 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -6,14 +6,14 @@ defmodule Pleroma.Web.Websub do alias Ecto.Changeset alias Pleroma.Instances alias Pleroma.Repo - alias Pleroma.Web.Websub.WebsubServerSubscription - alias Pleroma.Web.Websub.WebsubClientSubscription - alias Pleroma.Web.OStatus.FeedRepresenter - alias Pleroma.Web.XML alias Pleroma.Web.Endpoint - alias Pleroma.Web.OStatus - alias Pleroma.Web.Router.Helpers alias Pleroma.Web.Federator + alias Pleroma.Web.OStatus + alias Pleroma.Web.OStatus.FeedRepresenter + alias Pleroma.Web.Router.Helpers + alias Pleroma.Web.Websub.WebsubClientSubscription + alias Pleroma.Web.Websub.WebsubServerSubscription + alias Pleroma.Web.XML require Logger import Ecto.Query diff --git a/lib/pleroma/web/websub/websub_controller.ex b/lib/pleroma/web/websub/websub_controller.ex index ad40f1b94..9e8b48b80 100644 --- a/lib/pleroma/web/websub/websub_controller.ex +++ b/lib/pleroma/web/websub/websub_controller.ex @@ -7,8 +7,8 @@ defmodule Pleroma.Web.Websub.WebsubController do alias Pleroma.Repo alias Pleroma.User - alias Pleroma.Web.Websub alias Pleroma.Web.Federator + alias Pleroma.Web.Websub alias Pleroma.Web.Websub.WebsubClientSubscription require Logger diff --git a/test/integration/mastodon_websocket_test.exs b/test/integration/mastodon_websocket_test.exs index 0c513b6e7..b42c9ef07 100644 --- a/test/integration/mastodon_websocket_test.exs +++ b/test/integration/mastodon_websocket_test.exs @@ -7,9 +7,9 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do import Pleroma.Factory + alias Pleroma.Integration.WebsocketClient alias Pleroma.Web.CommonAPI alias Pleroma.Web.OAuth - alias Pleroma.Integration.WebsocketClient alias Pleroma.Web.Streamer @path Pleroma.Web.Endpoint.url() diff --git a/test/jobs_test.exs b/test/jobs_test.exs index ccb518dec..d55c86ccc 100644 --- a/test/jobs_test.exs +++ b/test/jobs_test.exs @@ -5,8 +5,8 @@ defmodule Pleroma.JobsTest do use ExUnit.Case, async: true - alias Pleroma.Jobs alias Jobs.WorkerMock + alias Pleroma.Jobs setup do state = %{ diff --git a/test/notification_test.exs b/test/notification_test.exs index 755874a3d..12b4292aa 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -4,11 +4,11 @@ defmodule Pleroma.NotificationTest do use Pleroma.DataCase - alias Pleroma.Web.TwitterAPI.TwitterAPI - alias Pleroma.Web.CommonAPI - alias Pleroma.User alias Pleroma.Notification + alias Pleroma.User alias Pleroma.Web.ActivityPub.Transmogrifier + alias Pleroma.Web.CommonAPI + alias Pleroma.Web.TwitterAPI.TwitterAPI import Pleroma.Factory describe "create_notifications" do diff --git a/test/object_test.exs b/test/object_test.exs index a820a34ee..911757d57 100644 --- a/test/object_test.exs +++ b/test/object_test.exs @@ -5,8 +5,8 @@ defmodule Pleroma.ObjectTest do use Pleroma.DataCase import Pleroma.Factory - alias Pleroma.Repo alias Pleroma.Object + alias Pleroma.Repo test "returns an object by it's AP id" do object = insert(:note) diff --git a/test/support/builders/user_builder.ex b/test/support/builders/user_builder.ex index 611a5be18..f58e1b0ad 100644 --- a/test/support/builders/user_builder.ex +++ b/test/support/builders/user_builder.ex @@ -1,6 +1,6 @@ defmodule Pleroma.Builders.UserBuilder do - alias Pleroma.User alias Pleroma.Repo + alias Pleroma.User def build(data \\ %{}) do user = %User{ diff --git a/test/tasks/relay_test.exs b/test/tasks/relay_test.exs index 64ff07753..c9d90fa2e 100644 --- a/test/tasks/relay_test.exs +++ b/test/tasks/relay_test.exs @@ -4,10 +4,10 @@ defmodule Mix.Tasks.Pleroma.RelayTest do alias Pleroma.Activity - alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.ActivityPub.Utils - alias Pleroma.Web.ActivityPub.Relay alias Pleroma.User + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Relay + alias Pleroma.Web.ActivityPub.Utils use Pleroma.DataCase setup_all do diff --git a/test/user_test.exs b/test/user_test.exs index 3a5f3c240..c57eb2c06 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -3,8 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.UserTest do - alias Pleroma.Builders.UserBuilder alias Pleroma.Activity + alias Pleroma.Builders.UserBuilder alias Pleroma.Repo alias Pleroma.User alias Pleroma.Web.CommonAPI diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 6bd4493f5..a1e83b380 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -5,13 +5,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do use Pleroma.Web.ConnCase import Pleroma.Factory - alias Pleroma.Web.ActivityPub.UserView - alias Pleroma.Web.ActivityPub.ObjectView + alias Pleroma.Activity + alias Pleroma.Instances alias Pleroma.Object alias Pleroma.Repo - alias Pleroma.Activity alias Pleroma.User - alias Pleroma.Instances + alias Pleroma.Web.ActivityPub.ObjectView + alias Pleroma.Web.ActivityPub.UserView setup_all do Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 10c5258d0..2b83bfb1d 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -4,14 +4,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do use Pleroma.DataCase + alias Pleroma.Activity + alias Pleroma.Builders.ActivityBuilder + alias Pleroma.Instances + alias Pleroma.Object + alias Pleroma.User alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.CommonAPI - alias Pleroma.Activity - alias Pleroma.Object - alias Pleroma.User - alias Pleroma.Instances - alias Pleroma.Builders.ActivityBuilder import Pleroma.Factory import Tesla.Mock diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 86c66deff..8184dbbae 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -4,13 +4,13 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do use Pleroma.DataCase + alias Pleroma.Activity + alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Transmogrifier alias Pleroma.Web.ActivityPub.Utils - alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.OStatus - alias Pleroma.Activity - alias Pleroma.User - alias Pleroma.Repo alias Pleroma.Web.Websub.WebsubClientSubscription import Pleroma.Factory diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs index 1300039aa..2bd3ddf93 100644 --- a/test/web/activity_pub/utils_test.exs +++ b/test/web/activity_pub/utils_test.exs @@ -1,7 +1,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do use Pleroma.DataCase - alias Pleroma.Web.CommonAPI alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.Web.CommonAPI import Pleroma.Factory diff --git a/test/web/activity_pub/views/object_view_test.exs b/test/web/activity_pub/views/object_view_test.exs index d144a77fc..d939fc5a7 100644 --- a/test/web/activity_pub/views/object_view_test.exs +++ b/test/web/activity_pub/views/object_view_test.exs @@ -2,8 +2,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do use Pleroma.DataCase import Pleroma.Factory - alias Pleroma.Web.CommonAPI alias Pleroma.Web.ActivityPub.ObjectView + alias Pleroma.Web.CommonAPI test "renders a note object" do note = insert(:note) diff --git a/test/web/activity_pub/visibilty_test.exs b/test/web/activity_pub/visibilty_test.exs index 1172b7455..24b96c4aa 100644 --- a/test/web/activity_pub/visibilty_test.exs +++ b/test/web/activity_pub/visibilty_test.exs @@ -1,8 +1,8 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do use Pleroma.DataCase - alias Pleroma.Web.CommonAPI alias Pleroma.Web.ActivityPub.Visibility + alias Pleroma.Web.CommonAPI import Pleroma.Factory setup do diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index 9ba320f59..181813c76 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -4,9 +4,9 @@ defmodule Pleroma.Web.CommonAPITest do use Pleroma.DataCase - alias Pleroma.Web.CommonAPI - alias Pleroma.User alias Pleroma.Activity + alias Pleroma.User + alias Pleroma.Web.CommonAPI import Pleroma.Factory diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs index 684f2a23f..4c97b0d62 100644 --- a/test/web/common_api/common_api_utils_test.exs +++ b/test/web/common_api/common_api_utils_test.exs @@ -3,9 +3,9 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.CommonAPI.UtilsTest do + alias Pleroma.Builders.UserBuilder alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.Endpoint - alias Pleroma.Builders.UserBuilder use Pleroma.DataCase test "it adds attachment links to a given text and attachment set" do diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs index 08279f230..52729eb50 100644 --- a/test/web/federator_test.exs +++ b/test/web/federator_test.exs @@ -3,9 +3,9 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.FederatorTest do + alias Pleroma.Instances alias Pleroma.Web.CommonAPI alias Pleroma.Web.Federator - alias Pleroma.Instances use Pleroma.DataCase import Pleroma.Factory import Mock diff --git a/test/web/instances/instance_test.exs b/test/web/instances/instance_test.exs index a158c0a42..d28730994 100644 --- a/test/web/instances/instance_test.exs +++ b/test/web/instances/instance_test.exs @@ -3,8 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Instances.InstanceTest do - alias Pleroma.Repo alias Pleroma.Instances.Instance + alias Pleroma.Repo use Pleroma.DataCase diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs index 6be66ef63..c2ffc21da 100644 --- a/test/web/mastodon_api/account_view_test.exs +++ b/test/web/mastodon_api/account_view_test.exs @@ -5,8 +5,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do use Pleroma.DataCase import Pleroma.Factory - alias Pleroma.Web.MastodonAPI.AccountView alias Pleroma.User + alias Pleroma.Web.MastodonAPI.AccountView test "Represent a user account" do source_data = %{ diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 2caf514bb..87b28e24e 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -5,17 +5,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do use Pleroma.Web.ConnCase - alias Pleroma.Web.TwitterAPI.TwitterAPI - alias Pleroma.Repo - alias Pleroma.User - alias Pleroma.Object + alias Ecto.Changeset alias Pleroma.Activity alias Pleroma.Notification - alias Pleroma.Web.OStatus - alias Pleroma.Web.CommonAPI + alias Pleroma.Object + alias Pleroma.Repo + alias Pleroma.User alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.CommonAPI alias Pleroma.Web.MastodonAPI.FilterView - alias Ecto.Changeset + alias Pleroma.Web.OStatus + alias Pleroma.Web.TwitterAPI.TwitterAPI import Pleroma.Factory import ExUnit.CaptureLog import Tesla.Mock diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index 485a0b4f7..3eec2cb5b 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -5,13 +5,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do use Pleroma.DataCase + alias Pleroma.Activity + alias Pleroma.User + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.CommonAPI alias Pleroma.Web.MastodonAPI.AccountView alias Pleroma.Web.MastodonAPI.StatusView - alias Pleroma.User alias Pleroma.Web.OStatus - alias Pleroma.Web.CommonAPI - alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Activity import Pleroma.Factory import Tesla.Mock diff --git a/test/web/oauth/authorization_test.exs b/test/web/oauth/authorization_test.exs index 306db2e62..d8b008437 100644 --- a/test/web/oauth/authorization_test.exs +++ b/test/web/oauth/authorization_test.exs @@ -4,8 +4,8 @@ defmodule Pleroma.Web.OAuth.AuthorizationTest do use Pleroma.DataCase - alias Pleroma.Web.OAuth.Authorization alias Pleroma.Web.OAuth.App + alias Pleroma.Web.OAuth.Authorization import Pleroma.Factory setup do diff --git a/test/web/oauth/token_test.exs b/test/web/oauth/token_test.exs index 62444a0fa..ad2a49f09 100644 --- a/test/web/oauth/token_test.exs +++ b/test/web/oauth/token_test.exs @@ -4,10 +4,10 @@ defmodule Pleroma.Web.OAuth.TokenTest do use Pleroma.DataCase + alias Pleroma.Repo alias Pleroma.Web.OAuth.App alias Pleroma.Web.OAuth.Authorization alias Pleroma.Web.OAuth.Token - alias Pleroma.Repo import Pleroma.Factory diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs index eebc5c040..5cb135b4c 100644 --- a/test/web/ostatus/activity_representer_test.exs +++ b/test/web/ostatus/activity_representer_test.exs @@ -5,12 +5,12 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do use Pleroma.DataCase - alias Pleroma.Web.OStatus.ActivityRepresenter alias Pleroma.Activity - alias Pleroma.User alias Pleroma.Object + alias Pleroma.User alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.OStatus + alias Pleroma.Web.OStatus.ActivityRepresenter import Pleroma.Factory import Tesla.Mock diff --git a/test/web/ostatus/feed_representer_test.exs b/test/web/ostatus/feed_representer_test.exs index efd4e7217..3c7b126e7 100644 --- a/test/web/ostatus/feed_representer_test.exs +++ b/test/web/ostatus/feed_representer_test.exs @@ -6,10 +6,10 @@ defmodule Pleroma.Web.OStatus.FeedRepresenterTest do use Pleroma.DataCase import Pleroma.Factory alias Pleroma.User + alias Pleroma.Web.OStatus alias Pleroma.Web.OStatus.ActivityRepresenter alias Pleroma.Web.OStatus.FeedRepresenter alias Pleroma.Web.OStatus.UserRepresenter - alias Pleroma.Web.OStatus test "returns a feed of the last 20 items of the user" do note_activity = insert(:note_activity) diff --git a/test/web/ostatus/incoming_documents/delete_handling_test.exs b/test/web/ostatus/incoming_documents/delete_handling_test.exs index d295cc539..412d894fd 100644 --- a/test/web/ostatus/incoming_documents/delete_handling_test.exs +++ b/test/web/ostatus/incoming_documents/delete_handling_test.exs @@ -4,9 +4,9 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do import Pleroma.Factory import Tesla.Mock - alias Pleroma.Repo alias Pleroma.Activity alias Pleroma.Object + alias Pleroma.Repo alias Pleroma.Web.OStatus setup do diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index da9c72be8..2950f11c0 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -5,9 +5,9 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do use Pleroma.Web.ConnCase import Pleroma.Factory - alias Pleroma.User - alias Pleroma.Repo alias Pleroma.Object + alias Pleroma.Repo + alias Pleroma.User alias Pleroma.Web.CommonAPI alias Pleroma.Web.OStatus.ActivityRepresenter diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index b4b19ab05..76b90e186 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -4,13 +4,13 @@ defmodule Pleroma.Web.OStatusTest do use Pleroma.DataCase - alias Pleroma.Web.OStatus - alias Pleroma.Web.XML + alias Pleroma.Activity + alias Pleroma.Instances alias Pleroma.Object alias Pleroma.Repo alias Pleroma.User - alias Pleroma.Activity - alias Pleroma.Instances + alias Pleroma.Web.OStatus + alias Pleroma.Web.XML import Pleroma.Factory import ExUnit.CaptureLog diff --git a/test/web/salmon/salmon_test.exs b/test/web/salmon/salmon_test.exs index 9e583ba40..265e1abbd 100644 --- a/test/web/salmon/salmon_test.exs +++ b/test/web/salmon/salmon_test.exs @@ -4,10 +4,10 @@ defmodule Pleroma.Web.Salmon.SalmonTest do use Pleroma.DataCase - alias Pleroma.Web.Salmon alias Pleroma.Activity alias Pleroma.Repo alias Pleroma.User + alias Pleroma.Web.Salmon import Pleroma.Factory @magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB" diff --git a/test/web/streamer_test.exs b/test/web/streamer_test.exs index a0969e1d7..0a2e91298 100644 --- a/test/web/streamer_test.exs +++ b/test/web/streamer_test.exs @@ -5,10 +5,10 @@ defmodule Pleroma.Web.StreamerTest do use Pleroma.DataCase - alias Pleroma.Web.Streamer alias Pleroma.List alias Pleroma.User alias Pleroma.Web.CommonAPI + alias Pleroma.Web.Streamer import Pleroma.Factory test "it sends to public" do diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index 0e554623c..03a15606a 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -4,12 +4,12 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do use Pleroma.DataCase - alias Pleroma.User alias Pleroma.Activity alias Pleroma.Object + alias Pleroma.User + alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter - alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.TwitterAPI.UserView import Pleroma.Factory diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index ec4d07f17..1b810c9a0 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -4,23 +4,23 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do use Pleroma.Web.ConnCase - alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter - alias Pleroma.Builders.ActivityBuilder - alias Pleroma.Builders.UserBuilder - alias Pleroma.Repo - alias Pleroma.Activity - alias Pleroma.User - alias Pleroma.Object - alias Pleroma.Notification - alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.OAuth.Token - alias Pleroma.Web.TwitterAPI.Controller - alias Pleroma.Web.TwitterAPI.UserView - alias Pleroma.Web.TwitterAPI.NotificationView - alias Pleroma.Web.CommonAPI - alias Pleroma.Web.TwitterAPI.TwitterAPI alias Comeonin.Pbkdf2 alias Ecto.Changeset + alias Pleroma.Activity + alias Pleroma.Builders.ActivityBuilder + alias Pleroma.Builders.UserBuilder + alias Pleroma.Notification + alias Pleroma.Object + alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.CommonAPI + alias Pleroma.Web.OAuth.Token + alias Pleroma.Web.TwitterAPI.Controller + alias Pleroma.Web.TwitterAPI.NotificationView + alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter + alias Pleroma.Web.TwitterAPI.TwitterAPI + alias Pleroma.Web.TwitterAPI.UserView import Pleroma.Factory import Mock diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index aa2a4d650..1eb8f77d2 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -4,15 +4,15 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do use Pleroma.DataCase - alias Pleroma.Web.TwitterAPI.TwitterAPI - alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Activity - alias Pleroma.User alias Pleroma.Object alias Pleroma.Repo + alias Pleroma.User alias Pleroma.UserInviteToken alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.TwitterAPI.ActivityView + alias Pleroma.Web.TwitterAPI.TwitterAPI + alias Pleroma.Web.TwitterAPI.UserView import Pleroma.Factory diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 0a5384f34..6f0786b1c 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -5,15 +5,15 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do use Pleroma.DataCase + alias Pleroma.Activity + alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.TwitterAPI.ActivityView - alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Web.TwitterAPI.TwitterAPI - alias Pleroma.Repo - alias Pleroma.Activity - alias Pleroma.User - alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.TwitterAPI.UserView import Pleroma.Factory import Tesla.Mock diff --git a/test/web/twitter_api/views/notification_view_test.exs b/test/web/twitter_api/views/notification_view_test.exs index 3a67f7292..6baeeaf63 100644 --- a/test/web/twitter_api/views/notification_view_test.exs +++ b/test/web/twitter_api/views/notification_view_test.exs @@ -5,14 +5,14 @@ defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do use Pleroma.DataCase - alias Pleroma.User alias Pleroma.Notification - alias Pleroma.Web.TwitterAPI.TwitterAPI - alias Pleroma.Web.TwitterAPI.NotificationView - alias Pleroma.Web.TwitterAPI.UserView - alias Pleroma.Web.TwitterAPI.ActivityView - alias Pleroma.Web.CommonAPI.Utils + alias Pleroma.User alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.CommonAPI.Utils + alias Pleroma.Web.TwitterAPI.ActivityView + alias Pleroma.Web.TwitterAPI.NotificationView + alias Pleroma.Web.TwitterAPI.TwitterAPI + alias Pleroma.Web.TwitterAPI.UserView import Pleroma.Factory diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 114f24a1c..4e7f94795 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -6,8 +6,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do use Pleroma.DataCase alias Pleroma.User - alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Web.CommonAPI.Utils + alias Pleroma.Web.TwitterAPI.UserView import Pleroma.Factory diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs index 87b01d89b..1e69ed01a 100644 --- a/test/web/websub/websub_controller_test.exs +++ b/test/web/websub/websub_controller_test.exs @@ -5,10 +5,10 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do use Pleroma.Web.ConnCase import Pleroma.Factory - alias Pleroma.Web.Websub.WebsubClientSubscription alias Pleroma.Activity alias Pleroma.Repo alias Pleroma.Web.Websub + alias Pleroma.Web.Websub.WebsubClientSubscription test "websub subscription request", %{conn: conn} do user = insert(:user) diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs index 9a9b9df02..74386d7db 100644 --- a/test/web/websub/websub_test.exs +++ b/test/web/websub/websub_test.exs @@ -4,11 +4,13 @@ defmodule Pleroma.Web.WebsubTest do use Pleroma.DataCase - alias Pleroma.Web.Websub - alias Pleroma.Web.Websub.WebsubServerSubscription - alias Pleroma.Web.Websub.WebsubClientSubscription - import Pleroma.Factory + alias Pleroma.Web.Router.Helpers + alias Pleroma.Web.Websub + alias Pleroma.Web.Websub.WebsubClientSubscription + alias Pleroma.Web.Websub.WebsubServerSubscription + + import Pleroma.Factory import Tesla.Mock setup do From fb82f6fc7c5453e34e619c54a88e64e99deb58b4 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 5 Mar 2019 04:18:43 +0100 Subject: [PATCH 17/37] [Credo] Remove parentesis on argument-less functions --- lib/pleroma/application.ex | 16 ++++++++-------- lib/pleroma/captcha/captcha.ex | 4 ++-- lib/pleroma/captcha/kocaptcha.ex | 2 +- lib/pleroma/clippy.ex | 4 ++-- lib/pleroma/config/deprecation_warnings.ex | 2 +- lib/pleroma/emoji.ex | 8 ++++---- lib/pleroma/flake_id.ex | 4 ++-- lib/pleroma/gopher/server.ex | 2 +- lib/pleroma/html.ex | 2 +- lib/pleroma/uploaders/swift/keystone.ex | 2 +- lib/pleroma/user.ex | 2 +- lib/pleroma/user/welcome_message.ex | 4 ++-- lib/pleroma/web/activity_pub/mrf.ex | 2 +- lib/pleroma/web/chat_channel.ex | 2 +- lib/pleroma/web/federator/federator.ex | 4 ++-- lib/pleroma/web/federator/retry_queue.ex | 10 +++++----- .../web/mastodon_api/mastodon_api_controller.ex | 2 +- lib/pleroma/web/push/push.ex | 6 +++--- test/support/captcha_mock.ex | 2 +- 19 files changed, 40 insertions(+), 40 deletions(-) diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index d2523c045..8756e9469 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -11,10 +11,10 @@ defmodule Pleroma.Application do @repository Mix.Project.config()[:source_url] def name, do: @name def version, do: @version - def named_version(), do: @name <> " " <> @version + def named_version, do: @name <> " " <> @version def repository, do: @repository - def user_agent() do + def user_agent do info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>" named_version() <> "; " <> info end @@ -127,7 +127,7 @@ def start(_type, _args) do Supervisor.start_link(children, opts) end - def enabled_hackney_pools() do + def enabled_hackney_pools do [:media] ++ if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Hackney do [:federation] @@ -142,14 +142,14 @@ def enabled_hackney_pools() do end if Mix.env() == :test do - defp streamer_child(), do: [] - defp chat_child(), do: [] + defp streamer_child, do: [] + defp chat_child, do: [] else - defp streamer_child() do + defp streamer_child do [worker(Pleroma.Web.Streamer, [])] end - defp chat_child() do + defp chat_child do if Pleroma.Config.get([:chat, :enabled]) do [worker(Pleroma.Web.ChatChannel.ChatChannelState, [])] else @@ -158,7 +158,7 @@ defp chat_child() do end end - defp hackney_pool_children() do + defp hackney_pool_children do for pool <- enabled_hackney_pools() do options = Pleroma.Config.get([:hackney_pools, pool]) :hackney_pool.child_spec(pool, options) diff --git a/lib/pleroma/captcha/captcha.ex b/lib/pleroma/captcha/captcha.ex index aa41acd1a..cecb5b5a7 100644 --- a/lib/pleroma/captcha/captcha.ex +++ b/lib/pleroma/captcha/captcha.ex @@ -10,7 +10,7 @@ defmodule Pleroma.Captcha do use GenServer @doc false - def start_link() do + def start_link do GenServer.start_link(__MODULE__, [], name: __MODULE__) end @@ -22,7 +22,7 @@ def init(_) do @doc """ Ask the configured captcha service for a new captcha """ - def new() do + def new do GenServer.call(__MODULE__, :new) end diff --git a/lib/pleroma/captcha/kocaptcha.ex b/lib/pleroma/captcha/kocaptcha.ex index 34a611492..61688e778 100644 --- a/lib/pleroma/captcha/kocaptcha.ex +++ b/lib/pleroma/captcha/kocaptcha.ex @@ -7,7 +7,7 @@ defmodule Pleroma.Captcha.Kocaptcha do @behaviour Service @impl Service - def new() do + def new do endpoint = Pleroma.Config.get!([__MODULE__, :endpoint]) case Tesla.get(endpoint <> "/new") do diff --git a/lib/pleroma/clippy.ex b/lib/pleroma/clippy.ex index 4e9bdbe19..1a1606a23 100644 --- a/lib/pleroma/clippy.ex +++ b/lib/pleroma/clippy.ex @@ -7,13 +7,13 @@ defmodule Pleroma.Clippy do # No software is complete until they have a Clippy implementation. # A ballmer peak _may_ be required to change this module. - def tip() do + def tip do tips() |> Enum.random() |> puts() end - def tips() do + def tips do host = Pleroma.Config.get([Pleroma.Web.Endpoint, :url, :host]) [ diff --git a/lib/pleroma/config/deprecation_warnings.ex b/lib/pleroma/config/deprecation_warnings.ex index 7451fd0a7..0345ac19c 100644 --- a/lib/pleroma/config/deprecation_warnings.ex +++ b/lib/pleroma/config/deprecation_warnings.ex @@ -5,7 +5,7 @@ defmodule Pleroma.Config.DeprecationWarnings do require Logger - def check_frontend_config_mechanism() do + def check_frontend_config_mechanism do if Pleroma.Config.get(:fe) do Logger.warn(""" !!!DEPRECATION WARNING!!! diff --git a/lib/pleroma/emoji.ex b/lib/pleroma/emoji.ex index bb3190e08..f3f08cd9d 100644 --- a/lib/pleroma/emoji.ex +++ b/lib/pleroma/emoji.ex @@ -17,13 +17,13 @@ defmodule Pleroma.Emoji do @ets_options [:ordered_set, :protected, :named_table, {:read_concurrency, true}] @doc false - def start_link() do + def start_link do GenServer.start_link(__MODULE__, [], name: __MODULE__) end @doc "Reloads the emojis from disk." @spec reload() :: :ok - def reload() do + def reload do GenServer.call(__MODULE__, :reload) end @@ -38,7 +38,7 @@ def get(name) do @doc "Returns all the emojos!!" @spec get_all() :: [{String.t(), String.t()}, ...] - def get_all() do + def get_all do :ets.tab2list(@ets) end @@ -72,7 +72,7 @@ def code_change(_old_vsn, state, _extra) do {:ok, state} end - defp load() do + defp load do emojis = (load_finmoji(Keyword.get(Application.get_env(:pleroma, :instance), :finmoji_enabled)) ++ load_from_file("config/emoji.txt") ++ diff --git a/lib/pleroma/flake_id.ex b/lib/pleroma/flake_id.ex index 9f098ce33..4259d5718 100644 --- a/lib/pleroma/flake_id.ex +++ b/lib/pleroma/flake_id.ex @@ -85,7 +85,7 @@ def dump(value) do {:ok, FlakeId.from_string(value)} end - def autogenerate(), do: get() + def autogenerate, do: get() # -- GenServer API def start_link do @@ -165,7 +165,7 @@ defp time do 1_000_000_000 * mega_seconds + seconds * 1000 + :erlang.trunc(micro_seconds / 1000) end - defp worker_id() do + defp worker_id do <> = :crypto.strong_rand_bytes(6) worker end diff --git a/lib/pleroma/gopher/server.ex b/lib/pleroma/gopher/server.ex index 5b4e745e9..6baacc566 100644 --- a/lib/pleroma/gopher/server.ex +++ b/lib/pleroma/gopher/server.ex @@ -6,7 +6,7 @@ defmodule Pleroma.Gopher.Server do use GenServer require Logger - def start_link() do + def start_link do config = Pleroma.Config.get(:gopher, []) ip = Keyword.get(config, :ip, {0, 0, 0, 0}) port = Keyword.get(config, :port, 1234) diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 4dc6998b1..05253157e 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -9,7 +9,7 @@ defp get_scrubbers(scrubber) when is_atom(scrubber), do: [scrubber] defp get_scrubbers(scrubbers) when is_list(scrubbers), do: scrubbers defp get_scrubbers(_), do: [Pleroma.HTML.Scrubber.Default] - def get_scrubbers() do + def get_scrubbers do Pleroma.Config.get([:markup, :scrub_policy]) |> get_scrubbers end diff --git a/lib/pleroma/uploaders/swift/keystone.ex b/lib/pleroma/uploaders/swift/keystone.ex index b4f250f9d..3046cdbd2 100644 --- a/lib/pleroma/uploaders/swift/keystone.ex +++ b/lib/pleroma/uploaders/swift/keystone.ex @@ -17,7 +17,7 @@ def process_response_body(body) do |> Poison.decode!() end - def get_token() do + def get_token do settings = Pleroma.Config.get(Pleroma.Uploaders.Swift) username = Keyword.fetch!(settings, :username) password = Keyword.fetch!(settings, :password) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 762cd8c46..7226e1613 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -1340,7 +1340,7 @@ defp normalize_tags(tags) do |> Enum.map(&String.downcase(&1)) end - defp local_nickname_regex() do + defp local_nickname_regex do if Pleroma.Config.get([:instance, :extended_nickname_format]) do @extended_local_nickname_regex else diff --git a/lib/pleroma/user/welcome_message.ex b/lib/pleroma/user/welcome_message.ex index 8018ac22f..2ba65b75a 100644 --- a/lib/pleroma/user/welcome_message.ex +++ b/lib/pleroma/user/welcome_message.ex @@ -14,7 +14,7 @@ def post_welcome_message_to_user(user) do end end - defp welcome_user() do + defp welcome_user do with nickname when is_binary(nickname) <- Pleroma.Config.get([:instance, :welcome_user_nickname]), %User{local: true} = user <- User.get_cached_by_nickname(nickname) do @@ -24,7 +24,7 @@ defp welcome_user() do end end - defp welcome_message() do + defp welcome_message do Pleroma.Config.get([:instance, :welcome_message]) end end diff --git a/lib/pleroma/web/activity_pub/mrf.ex b/lib/pleroma/web/activity_pub/mrf.ex index eebea207c..1aaa20050 100644 --- a/lib/pleroma/web/activity_pub/mrf.ex +++ b/lib/pleroma/web/activity_pub/mrf.ex @@ -16,7 +16,7 @@ def filter(object) do end) end - def get_policies() do + def get_policies do Application.get_env(:pleroma, :instance, []) |> Keyword.get(:rewrite_policy, []) |> get_policies() diff --git a/lib/pleroma/web/chat_channel.ex b/lib/pleroma/web/chat_channel.ex index efdbba5a1..f63f4bda1 100644 --- a/lib/pleroma/web/chat_channel.ex +++ b/lib/pleroma/web/chat_channel.ex @@ -48,7 +48,7 @@ def add_message(message) do end) end - def messages() do + def messages do Agent.get(__MODULE__, fn state -> state[:messages] |> Enum.reverse() end) end end diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index b5b5049a4..5e690ddb8 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -22,7 +22,7 @@ defmodule Pleroma.Web.Federator do @websub Application.get_env(:pleroma, :websub) @ostatus Application.get_env(:pleroma, :ostatus) - def init() do + def init do # 1 minute Process.sleep(1000 * 60) refresh_subscriptions() @@ -58,7 +58,7 @@ def request_subscription(sub) do Jobs.enqueue(:federator_outgoing, __MODULE__, [:request_subscription, sub]) end - def refresh_subscriptions() do + def refresh_subscriptions do Jobs.enqueue(:federator_outgoing, __MODULE__, [:refresh_subscriptions]) end diff --git a/lib/pleroma/web/federator/retry_queue.ex b/lib/pleroma/web/federator/retry_queue.ex index e0ce251d2..71e49494f 100644 --- a/lib/pleroma/web/federator/retry_queue.ex +++ b/lib/pleroma/web/federator/retry_queue.ex @@ -13,7 +13,7 @@ def init(args) do {:ok, %{args | queue_table: queue_table, running_jobs: :sets.new()}} end - def start_link() do + def start_link do enabled = if Mix.env() == :test, do: true, else: Pleroma.Config.get([__MODULE__, :enabled], false) @@ -39,11 +39,11 @@ def enqueue(data, transport, retries \\ 0) do GenServer.cast(__MODULE__, {:maybe_enqueue, data, transport, retries + 1}) end - def get_stats() do + def get_stats do GenServer.call(__MODULE__, :get_stats) end - def reset_stats() do + def reset_stats do GenServer.call(__MODULE__, :reset_stats) end @@ -55,7 +55,7 @@ def get_retry_params(retries) do end end - def get_retry_timer_interval() do + def get_retry_timer_interval do Pleroma.Config.get([:retry_queue, :interval], 1000) end @@ -231,7 +231,7 @@ defp growth_function(retries) do end end - defp maybe_kickoff_timer() do + defp maybe_kickoff_timer do GenServer.cast(__MODULE__, :kickoff_timer) end end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 2ead3eb5e..88e0249a6 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1274,7 +1274,7 @@ def login(conn, _) do end end - defp get_or_make_app() do + defp get_or_make_app do find_attrs = %{client_name: @local_mastodon_name, redirect_uris: "."} scopes = ["read", "write", "follow", "push"] diff --git a/lib/pleroma/web/push/push.ex b/lib/pleroma/web/push/push.ex index 951dab535..5259e8e33 100644 --- a/lib/pleroma/web/push/push.ex +++ b/lib/pleroma/web/push/push.ex @@ -13,15 +13,15 @@ defmodule Pleroma.Web.Push do # Client API # ############## - def start_link() do + def start_link do GenServer.start_link(__MODULE__, :ok, name: __MODULE__) end - def vapid_config() do + def vapid_config do Application.get_env(:web_push_encryption, :vapid_details, []) end - def enabled() do + def enabled do case vapid_config() do [] -> false list when is_list(list) -> true diff --git a/test/support/captcha_mock.ex b/test/support/captcha_mock.ex index 9061f2b45..ef4e68bc5 100644 --- a/test/support/captcha_mock.ex +++ b/test/support/captcha_mock.ex @@ -7,7 +7,7 @@ defmodule Pleroma.Captcha.Mock do @behaviour Service @impl Service - def new(), do: %{type: :mock} + def new, do: %{type: :mock} @impl Service def validate(_token, _captcha, _data), do: :ok From c3d41b2b6ec7b789c7d6d7ae3b15bb18c59cf2e3 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 5 Mar 2019 04:36:19 +0100 Subject: [PATCH 18/37] [Credo] make all variables use snake_case --- .../web/activity_pub/transmogrifier.ex | 12 ++++----- lib/pleroma/web/common_api/common_api.ex | 12 ++++----- .../web/ostatus/handlers/note_handler.ex | 27 ++++++++++--------- lib/pleroma/web/twitter_api/twitter_api.ex | 6 ++--- lib/pleroma/web/websub/websub.ex | 8 +++--- 5 files changed, 33 insertions(+), 32 deletions(-) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index f1ce15876..1247e4b61 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -650,10 +650,10 @@ def get_obj_helper(id) do if object = Object.normalize(id), do: {:ok, object}, else: nil end - def set_reply_to_uri(%{"inReplyTo" => inReplyTo} = object) when is_binary(inReplyTo) do - with false <- String.starts_with?(inReplyTo, "http"), - {:ok, %{data: replied_to_object}} <- get_obj_helper(inReplyTo) do - Map.put(object, "inReplyTo", replied_to_object["external_url"] || inReplyTo) + def set_reply_to_uri(%{"inReplyTo" => in_reply_to} = object) when is_binary(in_reply_to) do + with false <- String.starts_with?(in_reply_to, "http"), + {:ok, %{data: replied_to_object}} <- get_obj_helper(in_reply_to) do + Map.put(object, "inReplyTo", replied_to_object["external_url"] || in_reply_to) else _e -> object end @@ -830,10 +830,10 @@ def set_sensitive(object) do end def add_attributed_to(object) do - attributedTo = object["attributedTo"] || object["actor"] + attributed_to = object["attributedTo"] || object["actor"] object - |> Map.put("attributedTo", attributedTo) + |> Map.put("attributedTo", attributed_to) end def add_likes(%{"id" => id, "like_count" => likes} = object) do diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 2e39a16c3..12b3d308c 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -88,8 +88,8 @@ def get_visibility(%{"in_reply_to_status_id" => status_id}) when not is_nil(stat nil -> "public" - inReplyTo -> - Pleroma.Web.MastodonAPI.StatusView.get_visibility(inReplyTo.data["object"]) + in_reply_to -> + Pleroma.Web.MastodonAPI.StatusView.get_visibility(in_reply_to.data["object"]) end end @@ -101,15 +101,15 @@ def post(user, %{"status" => status} = data) do with status <- String.trim(status), attachments <- attachments_from_ids(data), - inReplyTo <- get_replied_to_activity(data["in_reply_to_status_id"]), + in_reply_to <- get_replied_to_activity(data["in_reply_to_status_id"]), {content_html, mentions, tags} <- make_content_html( status, attachments, data ), - {to, cc} <- to_for_user_and_mentions(user, mentions, inReplyTo, visibility), - context <- make_context(inReplyTo), + {to, cc} <- to_for_user_and_mentions(user, mentions, in_reply_to, visibility), + context <- make_context(in_reply_to), cw <- data["spoiler_text"], full_payload <- String.trim(status <> (data["spoiler_text"] || "")), length when length in 1..limit <- String.length(full_payload), @@ -120,7 +120,7 @@ def post(user, %{"status" => status} = data) do context, content_html, attachments, - inReplyTo, + in_reply_to, tags, cw, cc diff --git a/lib/pleroma/web/ostatus/handlers/note_handler.ex b/lib/pleroma/web/ostatus/handlers/note_handler.ex index 50767a6a8..770a71a0a 100644 --- a/lib/pleroma/web/ostatus/handlers/note_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/note_handler.ex @@ -19,13 +19,13 @@ defmodule Pleroma.Web.OStatus.NoteHandler do 2. The conversation reference in the ostatus xml 3. A newly generated context id. """ - def get_context(entry, inReplyTo) do + def get_context(entry, in_reply_to) do context = (XML.string_from_xpath("//ostatus:conversation[1]", entry) || XML.string_from_xpath("//ostatus:conversation[1]/@ref", entry) || "") |> String.trim() - with %{data: %{"context" => context}} <- Object.get_cached_by_ap_id(inReplyTo) do + with %{data: %{"context" => context}} <- Object.get_cached_by_ap_id(in_reply_to) do context else _e -> @@ -88,14 +88,14 @@ def add_external_url(note, entry) do Map.put(note, "external_url", url) end - def fetch_replied_to_activity(entry, inReplyTo) do - with %Activity{} = activity <- Activity.get_create_by_object_ap_id(inReplyTo) do + def fetch_replied_to_activity(entry, in_reply_to) do + with %Activity{} = activity <- Activity.get_create_by_object_ap_id(in_reply_to) do activity else _e -> - with inReplyToHref when not is_nil(inReplyToHref) <- + with in_reply_to_href when not is_nil(in_reply_to_href) <- XML.string_from_xpath("//thr:in-reply-to[1]/@href", entry), - {:ok, [activity | _]} <- OStatus.fetch_activity_from_url(inReplyToHref) do + {:ok, [activity | _]} <- OStatus.fetch_activity_from_url(in_reply_to_href) do activity else _e -> nil @@ -111,11 +111,12 @@ def handle_note(entry, doc \\ nil) do {:ok, actor} <- OStatus.find_make_or_update_user(author), content_html <- OStatus.get_content(entry), cw <- OStatus.get_cw(entry), - inReplyTo <- XML.string_from_xpath("//thr:in-reply-to[1]/@ref", entry), - inReplyToActivity <- fetch_replied_to_activity(entry, inReplyTo), - inReplyTo <- (inReplyToActivity && inReplyToActivity.data["object"]["id"]) || inReplyTo, + in_reply_to <- XML.string_from_xpath("//thr:in-reply-to[1]/@ref", entry), + in_reply_to_activity <- fetch_replied_to_activity(entry, in_reply_to), + in_reply_to <- + (in_reply_to_activity && in_reply_to_activity.data["object"]["id"]) || in_reply_to, attachments <- OStatus.get_attachments(entry), - context <- get_context(entry, inReplyTo), + context <- get_context(entry, in_reply_to), tags <- OStatus.get_tags(entry), mentions <- get_mentions(entry), to <- make_to_list(actor, mentions), @@ -129,7 +130,7 @@ def handle_note(entry, doc \\ nil) do context, content_html, attachments, - inReplyToActivity, + in_reply_to_activity, [], cw ), @@ -141,8 +142,8 @@ def handle_note(entry, doc \\ nil) do # TODO: Handle this case in make_note_data note <- if( - inReplyTo && !inReplyToActivity, - do: note |> Map.put("inReplyTo", inReplyTo), + in_reply_to && !in_reply_to_activity, + do: note |> Map.put("inReplyTo", in_reply_to), else: note ) do ActivityPub.create(%{ diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 39e868bef..a22e765c7 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -133,7 +133,7 @@ def upload(%Plug.Upload{} = file, %User{} = user, format \\ "xml") do end def register_user(params) do - tokenString = params["token"] + token_string = params["token"] params = %{ nickname: params["nickname"], @@ -170,8 +170,8 @@ def register_user(params) do # no need to query DB if registration is open token = - unless registrations_open || is_nil(tokenString) do - Repo.get_by(UserInviteToken, %{token: tokenString}) + unless registrations_open || is_nil(token_string) do + Repo.get_by(UserInviteToken, %{token: token_string}) end cond do diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index 165440431..3ffa6b416 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -200,8 +200,8 @@ def gather_feed_data(topic, getter \\ &@httpoison.get/1) do uri when not is_nil(uri) <- XML.string_from_xpath("/feed/author[1]/uri", doc), hub when not is_nil(hub) <- XML.string_from_xpath(~S{/feed/link[@rel="hub"]/@href}, doc) do name = XML.string_from_xpath("/feed/author[1]/name", doc) - preferredUsername = XML.string_from_xpath("/feed/author[1]/poco:preferredUsername", doc) - displayName = XML.string_from_xpath("/feed/author[1]/poco:displayName", doc) + preferred_username = XML.string_from_xpath("/feed/author[1]/poco:preferredUsername", doc) + display_name = XML.string_from_xpath("/feed/author[1]/poco:displayName", doc) avatar = OStatus.make_avatar_object(doc) bio = XML.string_from_xpath("/feed/author[1]/summary", doc) @@ -209,8 +209,8 @@ def gather_feed_data(topic, getter \\ &@httpoison.get/1) do %{ "uri" => uri, "hub" => hub, - "nickname" => preferredUsername || name, - "name" => displayName || name, + "nickname" => preferred_username || name, + "name" => display_name || name, "host" => URI.parse(uri).host, "avatar" => avatar, "bio" => bio From 8cd3eada7dec00f4e2ddd24c6a4286a4450281c1 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 5 Mar 2019 05:03:13 +0100 Subject: [PATCH 19/37] [Credo] write large numbers with underscore separation --- lib/pleroma/application.ex | 4 ++-- lib/pleroma/user.ex | 2 +- lib/pleroma/web/channels/user_socket.ex | 2 +- lib/pleroma/web/salmon/salmon.ex | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 8756e9469..cc81e1805 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -48,7 +48,7 @@ def start(_type, _args) do [ :user_cache, [ - default_ttl: 25000, + default_ttl: 25_000, ttl_interval: 1000, limit: 2500 ] @@ -60,7 +60,7 @@ def start(_type, _args) do [ :object_cache, [ - default_ttl: 25000, + default_ttl: 25_000, ttl_interval: 1000, limit: 2500 ] diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 7226e1613..dbb568ca0 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -285,7 +285,7 @@ def needs_update?(%User{local: true}), do: false def needs_update?(%User{local: false, last_refreshed_at: nil}), do: true def needs_update?(%User{local: false} = user) do - NaiveDateTime.diff(NaiveDateTime.utc_now(), user.last_refreshed_at) >= 86400 + NaiveDateTime.diff(NaiveDateTime.utc_now(), user.last_refreshed_at) >= 86_400 end def needs_update?(_), do: true diff --git a/lib/pleroma/web/channels/user_socket.ex b/lib/pleroma/web/channels/user_socket.ex index aed8475fd..3a700fa3b 100644 --- a/lib/pleroma/web/channels/user_socket.ex +++ b/lib/pleroma/web/channels/user_socket.ex @@ -23,7 +23,7 @@ defmodule Pleroma.Web.UserSocket do # performing token verification on connect. def connect(%{"token" => token}, socket) do with true <- Pleroma.Config.get([:chat, :enabled]), - {:ok, user_id} <- Phoenix.Token.verify(socket, "user socket", token, max_age: 84600), + {:ok, user_id} <- Phoenix.Token.verify(socket, "user socket", token, max_age: 84_600), %User{} = user <- Pleroma.Repo.get(User, user_id) do {:ok, assign(socket, :user_name, user.nickname)} else diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index 47f4bdd53..0a9e51656 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -86,10 +86,10 @@ def encode_key({:RSAPublicKey, modulus, exponent}) do # Native generation of RSA keys is only available since OTP 20+ and in default build conditions # We try at compile time to generate natively an RSA key otherwise we fallback on the old way. try do - _ = :public_key.generate_key({:rsa, 2048, 65537}) + _ = :public_key.generate_key({:rsa, 2048, 65_537}) def generate_rsa_pem do - key = :public_key.generate_key({:rsa, 2048, 65537}) + key = :public_key.generate_key({:rsa, 2048, 65_537}) entry = :public_key.pem_entry_encode(:RSAPrivateKey, key) pem = :public_key.pem_encode([entry]) |> String.trim_trailing() {:ok, pem} From c42d34b2ec2dacd9a038f721f7a817ee43cc0a4f Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 5 Mar 2019 05:37:33 +0100 Subject: [PATCH 20/37] [Credo] fix Credo.Check.Readability.MaxLineLength --- lib/pleroma/captcha/captcha.ex | 2 +- lib/pleroma/clippy.ex | 4 ++-- lib/pleroma/formatter.ex | 1 + lib/pleroma/plugs/oauth_plug.ex | 1 + lib/pleroma/reverse_proxy.ex | 10 ++++++---- lib/pleroma/uploaders/s3.ex | 3 ++- lib/pleroma/user.ex | 4 +++- lib/pleroma/web/activity_pub/activity_pub.ex | 6 ++++-- .../web/activity_pub/mrf/keyword_policy.ex | 15 ++++++++------- lib/pleroma/web/controller_helper.ex | 3 ++- lib/pleroma/web/endpoint.ex | 1 + lib/pleroma/web/media_proxy/media_proxy.ex | 3 ++- lib/pleroma/web/metadata/opengraph.ex | 2 +- lib/pleroma/web/metadata/twitter_card.ex | 3 ++- lib/pleroma/web/push/subscription.ex | 4 ++-- test/web/instances/instances_test.exs | 3 ++- test/web/twitter_api/twitter_api_test.exs | 1 + 17 files changed, 41 insertions(+), 25 deletions(-) diff --git a/lib/pleroma/captcha/captcha.ex b/lib/pleroma/captcha/captcha.ex index cecb5b5a7..f105cbb25 100644 --- a/lib/pleroma/captcha/captcha.ex +++ b/lib/pleroma/captcha/captcha.ex @@ -73,7 +73,7 @@ def handle_call({:validate, token, captcha, answer_data}, _from, state) do secret = KeyGenerator.generate(secret_key_base, token <> "_encrypt") sign_secret = KeyGenerator.generate(secret_key_base, token <> "_sign") - # If the time found is less than (current_time - seconds_valid), then the time has already passed. + # If the time found is less than (current_time-seconds_valid) then the time has already passed # Later we check that the time found is more than the presumed invalidatation time, that means # that the data is still valid and the captcha can be checked seconds_valid = Pleroma.Config.get!([Pleroma.Captcha, :seconds_valid]) diff --git a/lib/pleroma/clippy.ex b/lib/pleroma/clippy.ex index 1a1606a23..bd20952a6 100644 --- a/lib/pleroma/clippy.ex +++ b/lib/pleroma/clippy.ex @@ -92,8 +92,8 @@ def puts(text_or_lines) do # surrond one/five line clippy with blank lines around to not fuck up the layout # - # yes this fix sucks but it's good enough, have you ever seen a release of windows wihtout some butched - # features anyway? + # yes this fix sucks but it's good enough, have you ever seen a release of windows + # without some butched features anyway? lines = if length(lines) == 1 or length(lines) == 5 do [""] ++ lines ++ [""] diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 048c032ed..1e4ede3f2 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -10,6 +10,7 @@ defmodule Pleroma.Formatter do @markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/ @link_regex ~r{((?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+)|[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+}ui + # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength @auto_linker_config hashtag: true, hashtag_handler: &Pleroma.Formatter.hashtag_handler/4, diff --git a/lib/pleroma/plugs/oauth_plug.ex b/lib/pleroma/plugs/oauth_plug.ex index 6130c4570..5888d596a 100644 --- a/lib/pleroma/plugs/oauth_plug.ex +++ b/lib/pleroma/plugs/oauth_plug.ex @@ -38,6 +38,7 @@ defp fetch_user_and_token(token) do preload: [user: user] ) + # credo:disable-for-next-line Credo.Check.Readability.MaxLineLength with %Token{user: %{info: %{deactivated: false} = _} = user} = token_record <- Repo.one(query) do {:ok, user, token_record} end diff --git a/lib/pleroma/reverse_proxy.ex b/lib/pleroma/reverse_proxy.ex index a25b5ea4e..6298b92f4 100644 --- a/lib/pleroma/reverse_proxy.ex +++ b/lib/pleroma/reverse_proxy.ex @@ -3,10 +3,12 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.ReverseProxy do - @keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since if-unmodified-since if-none-match if-range range) + @keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since) ++ + ~w(if-unmodified-since if-none-match if-range range) @resp_cache_headers ~w(etag date last-modified cache-control) @keep_resp_headers @resp_cache_headers ++ - ~w(content-type content-disposition content-encoding content-range accept-ranges vary) + ~w(content-type content-disposition content-encoding content-range) ++ + ~w(accept-ranges vary) @default_cache_control_header "public, max-age=1209600" @valid_resp_codes [200, 206, 304] @max_read_duration :timer.seconds(30) @@ -282,8 +284,8 @@ defp build_resp_cache_headers(headers, _opts) do headers has_cache? -> - # There's caching header present but no cache-control -- we need to explicitely override it to public - # as Plug defaults to "max-age=0, private, must-revalidate" + # There's caching header present but no cache-control -- we need to explicitely override it + # to public as Plug defaults to "max-age=0, private, must-revalidate" List.keystore(headers, "cache-control", 0, {"cache-control", "public"}) true -> diff --git a/lib/pleroma/uploaders/s3.ex b/lib/pleroma/uploaders/s3.ex index 0038ba01f..e7de3f3e0 100644 --- a/lib/pleroma/uploaders/s3.ex +++ b/lib/pleroma/uploaders/s3.ex @@ -6,7 +6,8 @@ defmodule Pleroma.Uploaders.S3 do @behaviour Pleroma.Uploaders.Uploader require Logger - # The file name is re-encoded with S3's constraints here to comply with previous links with less strict filenames + # The file name is re-encoded with S3's constraints here to comply with previous + # links with less strict filenames def get_file(file) do config = Pleroma.Config.get([__MODULE__]) bucket = Keyword.fetch!(config, :bucket) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index dbb568ca0..1ce9882f6 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -30,6 +30,7 @@ defmodule Pleroma.User do @primary_key {:id, Pleroma.FlakeId, autogenerate: true} + # credo:disable-for-next-line Credo.Check.Readability.MaxLineLength @email_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/ @strict_local_nickname_regex ~r/^[a-zA-Z\d]+$/ @@ -435,7 +436,8 @@ def get_by_ap_id(ap_id) do Repo.get_by(User, ap_id: ap_id) end - # This is mostly an SPC migration fix. This guesses the user nickname (by taking the last part of the ap_id and the domain) and tries to get that user + # This is mostly an SPC migration fix. This guesses the user nickname by taking the last part + # of the ap_id and the domain and tries to get that user def get_by_guessed_nickname(ap_id) do domain = URI.parse(ap_id).host name = List.last(String.split(ap_id, "/")) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 337dc0173..fb8fe1ca2 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -170,7 +170,8 @@ def create(%{to: to, actor: actor, context: context, object: object} = params) d additional ), {:ok, activity} <- insert(create_data, local), - # Changing note count prior to enqueuing federation task in order to avoid race conditions on updating user.info + # Changing note count prior to enqueuing federation task in order to avoid + # race conditions on updating user.info {:ok, _actor} <- increase_note_count_if_public(actor, activity), :ok <- maybe_federate(activity) do {:ok, activity} @@ -320,7 +321,8 @@ def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ tru "deleted_activity_id" => activity && activity.id }, {:ok, activity} <- insert(data, local), - # Changing note count prior to enqueuing federation task in order to avoid race conditions on updating user.info + # Changing note count prior to enqueuing federation task in order to avoid + # race conditions on updating user.info {:ok, _actor} <- decrease_note_count_if_public(user, object), :ok <- maybe_federate(activity) do {:ok, activity} diff --git a/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex b/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex index 5fdc03414..25d5f9cd3 100644 --- a/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex @@ -45,13 +45,14 @@ defp check_ftl_removal( defp check_replace(%{"object" => %{"content" => content, "summary" => summary}} = message) do {content, summary} = - Enum.reduce(Pleroma.Config.get([:mrf_keyword, :replace]), {content, summary}, fn {pattern, - replacement}, - {content_acc, - summary_acc} -> - {String.replace(content_acc, pattern, replacement), - String.replace(summary_acc, pattern, replacement)} - end) + Enum.reduce( + Pleroma.Config.get([:mrf_keyword, :replace]), + {content, summary}, + fn {pattern, replacement}, {content_acc, summary_acc} -> + {String.replace(content_acc, pattern, replacement), + String.replace(summary_acc, pattern, replacement)} + end + ) {:ok, message diff --git a/lib/pleroma/web/controller_helper.ex b/lib/pleroma/web/controller_helper.ex index 5915ea40e..4d6192db0 100644 --- a/lib/pleroma/web/controller_helper.ex +++ b/lib/pleroma/web/controller_helper.ex @@ -6,7 +6,8 @@ defmodule Pleroma.Web.ControllerHelper do use Pleroma.Web, :controller def oauth_scopes(params, default) do - # Note: `scopes` is used by Mastodon — supporting it but sticking to OAuth's standard `scope` wherever we control it + # Note: `scopes` is used by Mastodon — supporting it but sticking to + # OAuth's standard `scope` wherever we control it Pleroma.Web.OAuth.parse_scopes(params["scope"] || params["scopes"], default) end diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex index 3eed047ca..697b1bc3a 100644 --- a/lib/pleroma/web/endpoint.ex +++ b/lib/pleroma/web/endpoint.ex @@ -26,6 +26,7 @@ defmodule Pleroma.Web.Endpoint do from: :pleroma, only: ~w(index.html static finmoji emoji packs sounds images instance sw.js sw-pleroma.js favicon.png schemas doc) + # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength ) # Code reloading can be explicitly enabled under the diff --git a/lib/pleroma/web/media_proxy/media_proxy.ex b/lib/pleroma/web/media_proxy/media_proxy.ex index 39a725a69..3bd2affe9 100644 --- a/lib/pleroma/web/media_proxy/media_proxy.ex +++ b/lib/pleroma/web/media_proxy/media_proxy.ex @@ -19,7 +19,8 @@ def url(url) do else secret = Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:secret_key_base] - # Must preserve `%2F` for compatibility with S3 (https://git.pleroma.social/pleroma/pleroma/issues/580) + # Must preserve `%2F` for compatibility with S3 + # https://git.pleroma.social/pleroma/pleroma/issues/580 replacement = get_replacement(url, ":2F:") # The URL is url-decoded and encoded again to ensure it is correctly encoded and not twice. diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index cafb8134b..357b80a2d 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -88,7 +88,7 @@ defp build_attachments(%{data: %{"attachment" => attachments}}) do # TODO: Add additional properties to objects when we have the data available. # Also, Whatsapp only wants JPEG or PNGs. It seems that if we add a second og:image - # object when a Video or GIF is attached it will display that in the Whatsapp Rich Preview. + # object when a Video or GIF is attached it will display that in Whatsapp Rich Preview. case media_type do "audio" -> [ diff --git a/lib/pleroma/web/metadata/twitter_card.ex b/lib/pleroma/web/metadata/twitter_card.ex index a0be383e5..040b872e7 100644 --- a/lib/pleroma/web/metadata/twitter_card.ex +++ b/lib/pleroma/web/metadata/twitter_card.ex @@ -97,7 +97,8 @@ defp build_attachments(id, %{data: %{"attachment" => attachments}}) do | acc ] - # TODO: Need the true width and height values here or Twitter renders an iFrame with a bad aspect ratio + # TODO: Need the true width and height values here or Twitter renders an iFrame with + # a bad aspect ratio "video" -> [ {:meta, [property: "twitter:card", content: "player"], []}, diff --git a/lib/pleroma/web/push/subscription.ex b/lib/pleroma/web/push/subscription.ex index c90bd2bda..da301fbbc 100644 --- a/lib/pleroma/web/push/subscription.ex +++ b/lib/pleroma/web/push/subscription.ex @@ -82,8 +82,8 @@ def delete_if_exists(user, token) do end # Some webpush clients (e.g. iOS Toot!) use an non urlsafe base64 as an encoding for the key. - # However, the web push rfs specify to use base64 urlsafe, and the `web_push_encryption` library we use - # requires the key to be properly encoded. So we just convert base64 to urlsafe base64. + # However, the web push rfs specify to use base64 urlsafe, and the `web_push_encryption` library + # we use requires the key to be properly encoded. So we just convert base64 to urlsafe base64. defp ensure_base64_urlsafe(string) do string |> String.replace("+", "-") diff --git a/test/web/instances/instances_test.exs b/test/web/instances/instances_test.exs index 2530c09fe..f0d84edea 100644 --- a/test/web/instances/instances_test.exs +++ b/test/web/instances/instances_test.exs @@ -102,7 +102,8 @@ test "returns error status on non-binary input" do end end - # Note: implementation-specific (e.g. Instance) details of set_unreachable/1 should be tested in implementation-specific tests + # Note: implementation-specific (e.g. Instance) details of set_unreachable/1 + # should be tested in implementation-specific tests describe "set_unreachable/1" do test "returns error status on non-binary input" do assert {:error, _} = Instances.set_unreachable(nil) diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 1eb8f77d2..c8dd3fd7a 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -472,6 +472,7 @@ test "fetches a user by uri" do # Also fetches the feed. # assert Activity.get_create_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status") + # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength end end end From 23960309a0677eac1cca93cbff59b31bd7e19961 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 5 Mar 2019 05:44:53 +0100 Subject: [PATCH 21/37] [Credo] Change quoted string with 3+ quotes to sigils --- lib/pleroma/web/activity_pub/activity_pub.ex | 12 ++++++------ .../mastodon_api/mastodon_api_controller_test.exs | 7 ++++--- .../representers/activity_representer_test.exs | 10 +++++++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index fb8fe1ca2..d5b03cd24 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -504,7 +504,7 @@ defp restrict_tag_reject(query, %{"tag_reject" => tag_reject}) when is_list(tag_reject) and tag_reject != [] do from( activity in query, - where: fragment("(not (? #> '{\"object\",\"tag\"}') \\?| ?)", activity.data, ^tag_reject) + where: fragment(~s(\(not \(? #> '{"object","tag"}'\) \\?| ?\)), activity.data, ^tag_reject) ) end @@ -514,7 +514,7 @@ defp restrict_tag_all(query, %{"tag_all" => tag_all}) when is_list(tag_all) and tag_all != [] do from( activity in query, - where: fragment("(? #> '{\"object\",\"tag\"}') \\?& ?", activity.data, ^tag_all) + where: fragment(~s(\(? #> '{"object","tag"}'\) \\?& ?), activity.data, ^tag_all) ) end @@ -523,14 +523,14 @@ defp restrict_tag_all(query, _), do: query defp restrict_tag(query, %{"tag" => tag}) when is_list(tag) do from( activity in query, - where: fragment("(? #> '{\"object\",\"tag\"}') \\?| ?", activity.data, ^tag) + where: fragment(~s(\(? #> '{"object","tag"}'\) \\?| ?), activity.data, ^tag) ) end defp restrict_tag(query, %{"tag" => tag}) when is_binary(tag) do from( activity in query, - where: fragment("? <@ (? #> '{\"object\",\"tag\"}')", ^tag, activity.data) + where: fragment(~s(? <@ (? #> '{"object","tag"}'\)), ^tag, activity.data) ) end @@ -603,7 +603,7 @@ defp restrict_type(query, _), do: query defp restrict_favorited_by(query, %{"favorited_by" => ap_id}) do from( activity in query, - where: fragment("? <@ (? #> '{\"object\",\"likes\"}')", ^ap_id, activity.data) + where: fragment(~s(? <@ (? #> '{"object","likes"}'\)), ^ap_id, activity.data) ) end @@ -612,7 +612,7 @@ defp restrict_favorited_by(query, _), do: query defp restrict_media(query, %{"only_media" => val}) when val == "true" or val == "1" do from( activity in query, - where: fragment("not (? #> '{\"object\",\"attachment\"}' = ?)", activity.data, ^[]) + where: fragment(~s(not (? #> '{"object","attachment"}' = ?\)), activity.data, ^[]) ) end diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 87b28e24e..059d5237d 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -1632,9 +1632,10 @@ test "updates the user's bio", %{conn: conn} do assert user = json_response(conn, 200) assert user["note"] == - "I drink #cofe with @#{user2.nickname}" + ~s(I drink #cofe with @) <> user2.nickname <> ~s() end test "updates the user's locking status", %{conn: conn} do diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index 03a15606a..d154385a0 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -101,10 +101,14 @@ test "an activity" do recipients: to } + corndog_emojo = ~s(2hu) + expected_html = - "

2hu \"2hu\"

alert('YAY')Some \"2hu\" content mentioning @shp" + ~s(

2hu ) <> + corndog_emojo <> + ~s(

alert\('YAY'\)Some ) <> + corndog_emojo <> + ~s( content mentioning @shp) expected_status = %{ "id" => activity.id, From 4b73ca638ec8194e96b7d8199022f519b3499109 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 5 Mar 2019 06:07:21 +0100 Subject: [PATCH 22/37] =?UTF-8?q?[Credo][CI]=20Add=20readability=20as=20it?= =?UTF-8?q?=E2=80=99s=20fixed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .credo.exs | 4 +++- .gitlab-ci.yml | 2 +- lib/mix/tasks/pleroma/uploads.ex | 1 - lib/pleroma/uploaders/uploader.ex | 1 - lib/pleroma/web/nodeinfo/nodeinfo.ex | 1 - 5 files changed, 4 insertions(+), 5 deletions(-) delete mode 100644 lib/pleroma/web/nodeinfo/nodeinfo.ex diff --git a/.credo.exs b/.credo.exs index 620b4abdd..46d45d015 100644 --- a/.credo.exs +++ b/.credo.exs @@ -81,7 +81,9 @@ {Credo.Check.Readability.ParenthesesOnZeroArityDefs}, {Credo.Check.Readability.ParenthesesInCondition}, {Credo.Check.Readability.PredicateFunctionNames}, - {Credo.Check.Readability.PreferImplicitTry}, + # lanodan: I think PreferImplicitTry should be consistency, and the behaviour seems + # inconsistent, see: https://github.com/rrrene/credo/issues/224 + {Credo.Check.Readability.PreferImplicitTry, false}, {Credo.Check.Readability.RedundantBlankLines}, {Credo.Check.Readability.StringSigils}, {Credo.Check.Readability.TrailingBlankLine}, diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d5b463000..0d7f92c9e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -42,4 +42,4 @@ unit-testing: analysis: stage: analysis script: - - mix credo list --only=warnings,todo,fixme,consistency + - mix credo list --only=warnings,todo,fixme,consistency,readability diff --git a/lib/mix/tasks/pleroma/uploads.ex b/lib/mix/tasks/pleroma/uploads.ex index 9ca123a9b..106fcf443 100644 --- a/lib/mix/tasks/pleroma/uploads.ex +++ b/lib/mix/tasks/pleroma/uploads.ex @@ -20,7 +20,6 @@ defmodule Mix.Tasks.Pleroma.Uploads do 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 diff --git a/lib/pleroma/uploaders/uploader.ex b/lib/pleroma/uploaders/uploader.ex index ce83cbbbc..bf15389fc 100644 --- a/lib/pleroma/uploaders/uploader.ex +++ b/lib/pleroma/uploaders/uploader.ex @@ -29,7 +29,6 @@ defmodule Pleroma.Uploaders.Uploader do * `{:error, String.t}` error information if the file failed to be saved to the backend. * `:wait_callback` will wait for an http post request at `/api/pleroma/upload_callback/:upload_path` and call the uploader's `http_callback/3` method. - """ @type file_spec :: {:file | :url, String.t()} @callback put_file(Pleroma.Upload.t()) :: diff --git a/lib/pleroma/web/nodeinfo/nodeinfo.ex b/lib/pleroma/web/nodeinfo/nodeinfo.ex deleted file mode 100644 index 8b1378917..000000000 --- a/lib/pleroma/web/nodeinfo/nodeinfo.ex +++ /dev/null @@ -1 +0,0 @@ - From f62867dde669c79680229412b2ac46ad5e65a979 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 5 Mar 2019 06:11:21 +0100 Subject: [PATCH 23/37] .gitlab-ci.yml: Use --strict instead of list This makes the output to be more compact while not loosing readability --format=flycheck // --format=json could also be used but they are not very human readable --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0d7f92c9e..d5f2a762a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -42,4 +42,4 @@ unit-testing: analysis: stage: analysis script: - - mix credo list --only=warnings,todo,fixme,consistency,readability + - mix credo --strict --only=warnings,todo,fixme,consistency,readability From d43b1c0b5d203fd4f195951ac7b60b666a43914f Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 8 Mar 2019 00:34:36 +0100 Subject: [PATCH 24/37] Pleroma.Web.TwitterAPI.Controller: Remove duplicated alias/es --- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 05aae9eb1..8221b2324 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -9,29 +9,19 @@ defmodule Pleroma.Web.TwitterAPI.Controller do alias Ecto.Changeset alias Pleroma.Activity - alias Pleroma.Activity - alias Pleroma.Notification alias Pleroma.Notification alias Pleroma.Object - alias Pleroma.Object alias Pleroma.Repo - alias Pleroma.Repo - alias Pleroma.User alias Pleroma.User alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.Visibility alias Pleroma.Web.CommonAPI - alias Pleroma.Web.CommonAPI alias Pleroma.Web.OAuth.Token alias Pleroma.Web.TwitterAPI.ActivityView - alias Pleroma.Web.TwitterAPI.ActivityView - alias Pleroma.Web.TwitterAPI.NotificationView alias Pleroma.Web.TwitterAPI.NotificationView alias Pleroma.Web.TwitterAPI.TokenView alias Pleroma.Web.TwitterAPI.TwitterAPI - alias Pleroma.Web.TwitterAPI.TwitterAPI - alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Web.TwitterAPI.UserView require Logger From cc0f2f8ba3f8a8f2909722d34d95523218536267 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 13 Mar 2019 04:13:28 +0100 Subject: [PATCH 25/37] =?UTF-8?q?MastodonAPI.Admin.AccountView=20=E2=86=92?= =?UTF-8?q?=20AdminAPI.AccountView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pleroma/web/admin_api/admin_api_controller.ex | 2 +- .../views/admin => admin_api/views}/account_view.ex | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename lib/pleroma/web/{mastodon_api/views/admin => admin_api/views}/account_view.ex (85%) diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index 75c2c6061..6d9bf2895 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -8,7 +8,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do use Pleroma.Web, :controller alias Pleroma.User alias Pleroma.Web.ActivityPub.Relay - alias Pleroma.Web.MastodonAPI.Admin.AccountView + alias Pleroma.Web.AdminAPI.AccountView import Pleroma.Web.ControllerHelper, only: [json_response: 3] diff --git a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex b/lib/pleroma/web/admin_api/views/account_view.ex similarity index 85% rename from lib/pleroma/web/mastodon_api/views/admin/account_view.ex rename to lib/pleroma/web/admin_api/views/account_view.ex index 5ce017124..c022fb07d 100644 --- a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex +++ b/lib/pleroma/web/admin_api/views/account_view.ex @@ -2,11 +2,11 @@ # Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only -defmodule Pleroma.Web.MastodonAPI.Admin.AccountView do +defmodule Pleroma.Web.AdminAPI.AccountView do use Pleroma.Web, :view alias Pleroma.User.Info - alias Pleroma.Web.MastodonAPI.Admin.AccountView + alias Pleroma.Web.AdminAPI.AccountView def render("index.json", %{users: users, count: count, page_size: page_size}) do %{ From 490d9cf7b149bbb93f6065fc807eafd339bcc0ea Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Wed, 13 Mar 2019 16:04:44 +0300 Subject: [PATCH 26/37] Add "local" to users admin API --- .../mastodon_api/views/admin/account_view.ex | 1 + .../admin_api/admin_api_controller_test.exs | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex b/lib/pleroma/web/mastodon_api/views/admin/account_view.ex index 5ce017124..1bed11089 100644 --- a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/admin/account_view.ex @@ -21,6 +21,7 @@ def render("show.json", %{user: user}) do "id" => user.id, "nickname" => user.nickname, "deactivated" => user.info.deactivated, + "local" => user.local, "roles" => Info.roles(user.info) } end diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index 0470a439b..c72e6b975 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -394,7 +394,8 @@ test "regular search" do "deactivated" => user.info.deactivated, "id" => user.id, "nickname" => user.nickname, - "roles" => %{"admin" => false, "moderator" => false} + "roles" => %{"admin" => false, "moderator" => false}, + "local" => true } ] } @@ -418,7 +419,8 @@ test "regular search with page size" do "deactivated" => user.info.deactivated, "id" => user.id, "nickname" => user.nickname, - "roles" => %{"admin" => false, "moderator" => false} + "roles" => %{"admin" => false, "moderator" => false}, + "local" => true } ] } @@ -436,7 +438,8 @@ test "regular search with page size" do "deactivated" => user2.info.deactivated, "id" => user2.id, "nickname" => user2.nickname, - "roles" => %{"admin" => false, "moderator" => false} + "roles" => %{"admin" => false, "moderator" => false}, + "local" => true } ] } @@ -461,7 +464,8 @@ test "only local users" do "deactivated" => user.info.deactivated, "id" => user.id, "nickname" => user.nickname, - "roles" => %{"admin" => false, "moderator" => false} + "roles" => %{"admin" => false, "moderator" => false}, + "local" => true } ] } @@ -486,13 +490,15 @@ test "only local users with no query" do "deactivated" => admin.info.deactivated, "id" => admin.id, "nickname" => admin.nickname, - "roles" => %{"admin" => true, "moderator" => false} + "roles" => %{"admin" => true, "moderator" => false}, + "local" => true }, %{ "deactivated" => user.info.deactivated, "id" => user.id, "nickname" => user.nickname, - "roles" => %{"admin" => false, "moderator" => false} + "roles" => %{"admin" => false, "moderator" => false}, + "local" => true } ] } @@ -513,7 +519,8 @@ test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do "deactivated" => !user.info.deactivated, "id" => user.id, "nickname" => user.nickname, - "roles" => %{"admin" => false, "moderator" => false} + "roles" => %{"admin" => false, "moderator" => false}, + "local" => true } end end From d5edff6ce6e62d003984760df6110bf47806d468 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Wed, 13 Mar 2019 16:14:31 +0300 Subject: [PATCH 27/37] Fix test --- test/web/admin_api/admin_api_controller_test.exs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index c72e6b975..96cb95da6 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -349,13 +349,15 @@ test "renders users array for the first page" do "deactivated" => admin.info.deactivated, "id" => admin.id, "nickname" => admin.nickname, - "roles" => %{"admin" => true, "moderator" => false} + "roles" => %{"admin" => true, "moderator" => false}, + "local" => true }, %{ "deactivated" => user.info.deactivated, "id" => user.id, "nickname" => user.nickname, - "roles" => %{"admin" => false, "moderator" => false} + "roles" => %{"admin" => false, "moderator" => false}, + "local" => true } ] } From 4872914d3253d673071220cb2149f32fe3ca9e26 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Wed, 13 Mar 2019 17:56:15 +0300 Subject: [PATCH 28/37] Add test when local is false --- test/web/admin_api/admin_api_controller_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index 96cb95da6..555272d05 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -334,7 +334,7 @@ test "/api/pleroma/admin/password_reset" do describe "GET /api/pleroma/admin/users" do test "renders users array for the first page" do admin = insert(:user, info: %{is_admin: true}) - user = insert(:user) + user = insert(:user, local: false) conn = build_conn() @@ -357,7 +357,7 @@ test "renders users array for the first page" do "id" => user.id, "nickname" => user.nickname, "roles" => %{"admin" => false, "moderator" => false}, - "local" => true + "local" => false } ] } From e416c344dd3e71447c49f8626750a56c35e389f6 Mon Sep 17 00:00:00 2001 From: eugenijm Date: Wed, 13 Mar 2019 09:04:49 +0300 Subject: [PATCH 29/37] Unify unfollow, accept and reject follow requests using CommonAPI --- lib/pleroma/web/common_api/common_api.ex | 36 +++++++++++++++++++ .../mastodon_api/mastodon_api_controller.ex | 25 ++----------- lib/pleroma/web/twitter_api/twitter_api.ex | 5 +-- .../web/twitter_api/twitter_api_controller.ex | 22 ++---------- 4 files changed, 42 insertions(+), 46 deletions(-) diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 12b3d308c..de0759fb0 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -27,6 +27,42 @@ def follow(follower, followed) do end end + def unfollow(follower, unfollowed) do + with {:ok, follower, _follow_activity} <- User.unfollow(follower, unfollowed), + {:ok, _activity} <- ActivityPub.unfollow(follower, unfollowed) do + {:ok, follower} + end + end + + def accept_follow_request(follower, followed) do + with {:ok, follower} <- User.maybe_follow(follower, followed), + %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed), + {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "accept"), + {:ok, _activity} <- + ActivityPub.accept(%{ + to: [follower.ap_id], + actor: followed, + object: follow_activity.data["id"], + type: "Accept" + }) do + {:ok, follower} + end + end + + def reject_follow_request(follower, followed) do + with %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed), + {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "reject"), + {:ok, _activity} <- + ActivityPub.reject(%{ + to: [follower.ap_id], + actor: followed, + object: follow_activity.data["id"], + type: "Reject" + }) do + {:ok, follower} + end + end + def delete(activity_id, user) do with %Activity{data: %{"object" => %{"id" => object_id}}} <- Repo.get(Activity, activity_id), %Object{} = object <- Object.normalize(object_id), diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 88e0249a6..277c64fa4 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -15,7 +15,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do alias Pleroma.User alias Pleroma.Web alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.Visibility alias Pleroma.Web.CommonAPI alias Pleroma.Web.MastodonAPI.AccountView @@ -697,16 +696,7 @@ def follow_requests(%{assigns: %{user: followed}} = conn, _params) do def authorize_follow_request(%{assigns: %{user: followed}} = conn, %{"id" => id}) do with %User{} = follower <- Repo.get(User, id), - {:ok, follower} <- User.maybe_follow(follower, followed), - %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed), - {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "accept"), - {:ok, _activity} <- - ActivityPub.accept(%{ - to: [follower.ap_id], - actor: followed, - object: follow_activity.data["id"], - type: "Accept" - }) do + {:ok, follower} <- CommonAPI.accept_follow_request(follower, followed) do conn |> put_view(AccountView) |> render("relationship.json", %{user: followed, target: follower}) @@ -720,15 +710,7 @@ def authorize_follow_request(%{assigns: %{user: followed}} = conn, %{"id" => id} def reject_follow_request(%{assigns: %{user: followed}} = conn, %{"id" => id}) do with %User{} = follower <- Repo.get(User, id), - %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed), - {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "reject"), - {:ok, _activity} <- - ActivityPub.reject(%{ - to: [follower.ap_id], - actor: followed, - object: follow_activity.data["id"], - type: "Reject" - }) do + {:ok, follower} <- CommonAPI.reject_follow_request(follower, followed) do conn |> put_view(AccountView) |> render("relationship.json", %{user: followed, target: follower}) @@ -770,8 +752,7 @@ def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do def unfollow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do with %User{} = followed <- Repo.get(User, id), - {:ok, _activity} <- ActivityPub.unfollow(follower, followed), - {:ok, follower, _} <- User.unfollow(follower, followed) do + {:ok, follower} <- CommonAPI.unfollow(follower, followed) do conn |> put_view(AccountView) |> render("relationship.json", %{user: follower, target: followed}) diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index a22e765c7..d57100491 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -35,11 +35,8 @@ def follow(%User{} = follower, params) do def unfollow(%User{} = follower, params) do with {:ok, %User{} = unfollowed} <- get_user(params), - {:ok, follower, _follow_activity} <- User.unfollow(follower, unfollowed), - {:ok, _activity} <- ActivityPub.unfollow(follower, unfollowed) do + {:ok, follower} <- CommonAPI.unfollow(follower, unfollowed) do {:ok, follower, unfollowed} - else - err -> err end end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 8221b2324..6ea0b110b 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -14,7 +14,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do alias Pleroma.Repo alias Pleroma.User alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.Visibility alias Pleroma.Web.CommonAPI alias Pleroma.Web.OAuth.Token @@ -588,16 +587,7 @@ def friend_requests(conn, params) do def approve_friend_request(conn, %{"user_id" => uid} = _params) do with followed <- conn.assigns[:user], %User{} = follower <- Repo.get(User, uid), - {:ok, follower} <- User.maybe_follow(follower, followed), - %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed), - {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "accept"), - {:ok, _activity} <- - ActivityPub.accept(%{ - to: [follower.ap_id], - actor: followed, - object: follow_activity.data["id"], - type: "Accept" - }) do + {:ok, follower} <- CommonAPI.accept_follow_request(follower, followed) do conn |> put_view(UserView) |> render("show.json", %{user: follower, for: followed}) @@ -609,15 +599,7 @@ def approve_friend_request(conn, %{"user_id" => uid} = _params) do def deny_friend_request(conn, %{"user_id" => uid} = _params) do with followed <- conn.assigns[:user], %User{} = follower <- Repo.get(User, uid), - %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed), - {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "reject"), - {:ok, _activity} <- - ActivityPub.reject(%{ - to: [follower.ap_id], - actor: followed, - object: follow_activity.data["id"], - type: "Reject" - }) do + {:ok, follower} <- CommonAPI.reject_follow_request(follower, followed) do conn |> put_view(UserView) |> render("show.json", %{user: follower, for: followed}) From 257d8e78e54a7b2d27bcb129bface01a543fc68f Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Thu, 14 Mar 2019 01:52:24 +0300 Subject: [PATCH 30/37] Add tags --- .../mastodon_api/views/admin/account_view.ex | 3 +- .../admin_api/admin_api_controller_test.exs | 29 ++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex b/lib/pleroma/web/mastodon_api/views/admin/account_view.ex index 1bed11089..efb26be64 100644 --- a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/admin/account_view.ex @@ -22,7 +22,8 @@ def render("show.json", %{user: user}) do "nickname" => user.nickname, "deactivated" => user.info.deactivated, "local" => user.local, - "roles" => Info.roles(user.info) + "roles" => Info.roles(user.info), + "tags" => user.tags } end end diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index 555272d05..e50f0edde 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -334,7 +334,7 @@ test "/api/pleroma/admin/password_reset" do describe "GET /api/pleroma/admin/users" do test "renders users array for the first page" do admin = insert(:user, info: %{is_admin: true}) - user = insert(:user, local: false) + user = insert(:user, local: false, tags: ["foo", "bar"]) conn = build_conn() @@ -350,14 +350,16 @@ test "renders users array for the first page" do "id" => admin.id, "nickname" => admin.nickname, "roles" => %{"admin" => true, "moderator" => false}, - "local" => true + "local" => true, + "tags" => [] }, %{ "deactivated" => user.info.deactivated, "id" => user.id, "nickname" => user.nickname, "roles" => %{"admin" => false, "moderator" => false}, - "local" => false + "local" => false, + "tags" => ["foo", "bar"] } ] } @@ -397,7 +399,8 @@ test "regular search" do "id" => user.id, "nickname" => user.nickname, "roles" => %{"admin" => false, "moderator" => false}, - "local" => true + "local" => true, + "tags" => [] } ] } @@ -422,7 +425,8 @@ test "regular search with page size" do "id" => user.id, "nickname" => user.nickname, "roles" => %{"admin" => false, "moderator" => false}, - "local" => true + "local" => true, + "tags" => [] } ] } @@ -441,7 +445,8 @@ test "regular search with page size" do "id" => user2.id, "nickname" => user2.nickname, "roles" => %{"admin" => false, "moderator" => false}, - "local" => true + "local" => true, + "tags" => [] } ] } @@ -467,7 +472,8 @@ test "only local users" do "id" => user.id, "nickname" => user.nickname, "roles" => %{"admin" => false, "moderator" => false}, - "local" => true + "local" => true, + "tags" => [] } ] } @@ -493,14 +499,16 @@ test "only local users with no query" do "id" => admin.id, "nickname" => admin.nickname, "roles" => %{"admin" => true, "moderator" => false}, - "local" => true + "local" => true, + "tags" => [] }, %{ "deactivated" => user.info.deactivated, "id" => user.id, "nickname" => user.nickname, "roles" => %{"admin" => false, "moderator" => false}, - "local" => true + "local" => true, + "tags" => [] } ] } @@ -522,7 +530,8 @@ test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do "id" => user.id, "nickname" => user.nickname, "roles" => %{"admin" => false, "moderator" => false}, - "local" => true + "local" => true, + "tags" => [] } end end From f3964f4024d5f5c0738e1ca8ce44742330bc0a80 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Thu, 14 Mar 2019 03:17:09 +0300 Subject: [PATCH 31/37] Ensure empty array is returned for tags --- lib/pleroma/web/mastodon_api/views/admin/account_view.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex b/lib/pleroma/web/mastodon_api/views/admin/account_view.ex index efb26be64..787b049a3 100644 --- a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/admin/account_view.ex @@ -23,7 +23,7 @@ def render("show.json", %{user: user}) do "deactivated" => user.info.deactivated, "local" => user.local, "roles" => Info.roles(user.info), - "tags" => user.tags + "tags" => user.tags || [] } end end From e630e5e13543ae9bdf1867495ebbe6b3a2582b38 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 14 Mar 2019 20:43:14 +0300 Subject: [PATCH 32/37] Fix delete activities not federating --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index adb42b9ab..96b774c21 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -309,7 +309,7 @@ def unfollow(follower, followed, activity_id \\ nil, local \\ true) do def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ true) do user = User.get_cached_by_ap_id(actor) - to = object.data["to"] || [] ++ object.data["cc"] || [] + to = (object.data["to"] || []) ++ (object.data["cc"] || []) data = %{ "type" => "Delete", From e2fe796c63f9df18d30810ad9daa1e7027da120f Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 14 Mar 2019 22:02:48 +0300 Subject: [PATCH 33/37] Add some tests --- config/config.exs | 1 + config/test.exs | 2 ++ docs/config.md | 1 + lib/pleroma/plugs/uploaded_media.ex | 2 +- lib/pleroma/upload.ex | 14 ++++++--- test/plugs/uploaded_media_plug_test.exs | 40 +++++++++++++++++++++++++ test/upload_test.exs | 6 ++-- 7 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 test/plugs/uploaded_media_plug_test.exs diff --git a/config/config.exs b/config/config.exs index cd4c8e562..f889e3259 100644 --- a/config/config.exs +++ b/config/config.exs @@ -35,6 +35,7 @@ config :pleroma, Pleroma.Upload, uploader: Pleroma.Uploaders.Local, filters: [], + link_name: true, proxy_remote: false, proxy_opts: [ redirect_on_failure: false, diff --git a/config/test.exs b/config/test.exs index 6dfa698c8..a3f36c9e1 100644 --- a/config/test.exs +++ b/config/test.exs @@ -17,6 +17,8 @@ # Print only warnings and errors during test config :logger, level: :warn +config :pleroma, Pleroma.Upload, link_name: false + config :pleroma, Pleroma.Uploaders.Local, uploads: "test/uploads" config :pleroma, Pleroma.Mailer, adapter: Swoosh.Adapters.Test diff --git a/docs/config.md b/docs/config.md index a09ea95f3..e34ffe980 100644 --- a/docs/config.md +++ b/docs/config.md @@ -6,6 +6,7 @@ If you run Pleroma with ``MIX_ENV=prod`` the file is ``prod.secret.exs``, otherw ## Pleroma.Upload * `uploader`: Select which `Pleroma.Uploaders` to use * `filters`: List of `Pleroma.Upload.Filter` to use. +* `link_name`: When enabled Pleroma will add a `name` parameter to the url of the upload, for example `https://instance.tld/media/corndog.png?name=corndog.png`. This is needed to provide the correct filename in Content-Disposition headers when using filters like `Pleroma.Upload.Filter.Dedupe` * `base_url`: The base URL to access a user-uploaded file. Useful when you want to proxy the media files via another host. * `proxy_remote`: If you\'re using a remote uploader, Pleroma will proxy media requests instead of redirecting to it. * `proxy_opts`: Proxy options, see `Pleroma.ReverseProxy` documentation. diff --git a/lib/pleroma/plugs/uploaded_media.ex b/lib/pleroma/plugs/uploaded_media.ex index bc913f408..fd77b8d8f 100644 --- a/lib/pleroma/plugs/uploaded_media.ex +++ b/lib/pleroma/plugs/uploaded_media.ex @@ -30,7 +30,7 @@ def call(%{request_path: <<"/", @path, "/", file::binary>>} = conn, opts) do name = String.replace(name, "\"", "\\\"") conn - |> put_resp_header("Content-Disposition", "filename=\"#{name}\"") + |> put_resp_header("content-disposition", "filename=\"#{name}\"") conn -> conn diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index ae461d434..f72334930 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -70,7 +70,7 @@ def store(upload, opts \\ []) do %{ "type" => "Link", "mediaType" => upload.content_type, - "href" => url_from_spec(opts.base_url, url_spec, upload.name) + "href" => url_from_spec(upload, opts.base_url, url_spec) } ], "name" => Map.get(opts, :description) || upload.name @@ -219,12 +219,18 @@ defp tempfile_for_image(data) do tmp_path end - defp url_from_spec(base_url, {:file, path}, name) do - path = URI.encode(path, &char_unescaped?/1) <> "?name=#{URI.encode(name, &char_unescaped?/1)}" + defp url_from_spec(%__MODULE__{name: name}, base_url, {:file, path}) do + path = + URI.encode(path, &char_unescaped?/1) <> + if Pleroma.Config.get([__MODULE__, :link_name], false) do + "?name=#{URI.encode(name, &char_unescaped?/1)}" + else + "" + end [base_url, "media", path] |> Path.join() end - defp url_from_spec(_base_url, {:url, url}, _name), do: url + defp url_from_spec(_upload, _base_url, {:url, url}), do: url end diff --git a/test/plugs/uploaded_media_plug_test.exs b/test/plugs/uploaded_media_plug_test.exs new file mode 100644 index 000000000..414cf9186 --- /dev/null +++ b/test/plugs/uploaded_media_plug_test.exs @@ -0,0 +1,40 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.UploadedMediaPlugTest do + use Pleroma.Web.ConnCase + alias Pleroma.Upload + + setup_all do + File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg") + + file = %Plug.Upload{ + content_type: "image/jpg", + path: Path.absname("test/fixtures/image_tmp.jpg"), + filename: "nice_tf.jpg" + } + + {:ok, data} = Upload.store(file) + [%{"href" => attachment_url} | _] = data["url"] + [attachment_url: attachment_url] + end + + test "does not send Content-Disposition header when name param is not set", %{ + attachment_url: attachment_url + } do + conn = get(build_conn(), attachment_url) + refute Enum.any?(conn.resp_headers, &(elem(&1, 0) == "content-disposition")) + end + + test "sends Content-Disposition header when name param is set", %{ + attachment_url: attachment_url + } do + conn = get(build_conn(), attachment_url <> "?name=\"cofe\".gif") + + assert Enum.any?( + conn.resp_headers, + &(&1 == {"content-disposition", "filename=\"\\\"cofe\\\".gif\""}) + ) + end +end diff --git a/test/upload_test.exs b/test/upload_test.exs index c38280d4c..770226478 100644 --- a/test/upload_test.exs +++ b/test/upload_test.exs @@ -56,7 +56,7 @@ test "copies the file to the configured folder with deduping" do assert List.first(data["url"])["href"] == Pleroma.Web.base_url() <> - "/media/e7a6d0cf595bff76f14c9a98b6c199539559e8b844e02e51e5efcfd1f614a2df.jpg?name=an%20%5Bimage.jpg" + "/media/e7a6d0cf595bff76f14c9a98b6c199539559e8b844e02e51e5efcfd1f614a2df.jpg" end test "copies the file to the configured folder without deduping" do @@ -151,7 +151,7 @@ test "escapes invalid characters in url" do [attachment_url | _] = data["url"] assert Path.basename(attachment_url["href"]) == - "an%E2%80%A6%20image.jpg?name=an%E2%80%A6%20image.jpg" + "an%E2%80%A6%20image.jpg" end test "escapes reserved uri characters" do @@ -167,7 +167,7 @@ test "escapes reserved uri characters" do [attachment_url | _] = data["url"] assert Path.basename(attachment_url["href"]) == - "%3A%3F%23%5B%5D%40%21%24%26%5C%27%28%29%2A%2B%2C%3B%3D.jpg?name=%3A%3F%23%5B%5D%40%21%24%26%5C%27%28%29%2A%2B%2C%3B%3D.jpg" + "%3A%3F%23%5B%5D%40%21%24%26%5C%27%28%29%2A%2B%2C%3B%3D.jpg" end end end From 355f285a8693934fbc8205c2c9ecde0a758fc158 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 14 Mar 2019 22:26:54 +0300 Subject: [PATCH 34/37] Fix uploaded media plug test --- test/plugs/uploaded_media_plug_test.exs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/plugs/uploaded_media_plug_test.exs b/test/plugs/uploaded_media_plug_test.exs index 414cf9186..49cf5396a 100644 --- a/test/plugs/uploaded_media_plug_test.exs +++ b/test/plugs/uploaded_media_plug_test.exs @@ -6,7 +6,8 @@ defmodule Pleroma.Web.UploadedMediaPlugTest do use Pleroma.Web.ConnCase alias Pleroma.Upload - setup_all do + defp upload_file(context) do + Pleroma.DataCase.ensure_local_uploader(context) File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg") file = %Plug.Upload{ @@ -20,6 +21,8 @@ defmodule Pleroma.Web.UploadedMediaPlugTest do [attachment_url: attachment_url] end + setup_all :upload_file + test "does not send Content-Disposition header when name param is not set", %{ attachment_url: attachment_url } do From 100413bf2c506ab96bc80927b9e774a91d179684 Mon Sep 17 00:00:00 2001 From: eugenijm Date: Thu, 14 Mar 2019 21:39:58 +0300 Subject: [PATCH 35/37] Add `is_seen` to MastoAPI notifications, extract rendering logic into separate NotificationView, add tests --- .../mastodon_api/mastodon_api_controller.ex | 52 +-------- .../mastodon_api/views/notification_view.ex | 64 +++++++++++ lib/pleroma/web/streamer.ex | 9 +- .../mastodon_api/notification_view_test.exs | 104 ++++++++++++++++++ 4 files changed, 179 insertions(+), 50 deletions(-) create mode 100644 lib/pleroma/web/mastodon_api/views/notification_view.ex create mode 100644 test/web/mastodon_api/notification_view_test.exs diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index e578f707e..265bf837e 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -22,6 +22,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do alias Pleroma.Web.MastodonAPI.ListView alias Pleroma.Web.MastodonAPI.MastodonAPI alias Pleroma.Web.MastodonAPI.MastodonView + alias Pleroma.Web.MastodonAPI.NotificationView alias Pleroma.Web.MastodonAPI.ReportView alias Pleroma.Web.MastodonAPI.StatusView alias Pleroma.Web.MediaProxy @@ -503,19 +504,17 @@ def unmute_conversation(%{assigns: %{user: user}} = conn, %{"id" => id}) do def notifications(%{assigns: %{user: user}} = conn, params) do notifications = Notification.for_user(user, params) - result = - notifications - |> Enum.map(fn x -> render_notification(user, x) end) - |> Enum.filter(& &1) - conn |> add_link_headers(:notifications, notifications) - |> json(result) + |> put_view(NotificationView) + |> render("index.json", %{notifications: notifications, for: user}) end def get_notification(%{assigns: %{user: user}} = conn, %{"id" => id} = _params) do with {:ok, notification} <- Notification.get(user, id) do - json(conn, render_notification(user, notification)) + conn + |> put_view(NotificationView) + |> render("show.json", %{notification: notification, for: user}) else {:error, reason} -> conn @@ -1309,45 +1308,6 @@ def empty_object(conn, _) do json(conn, %{}) end - def render_notification(user, %{id: id, activity: activity, inserted_at: created_at} = _params) do - actor = User.get_cached_by_ap_id(activity.data["actor"]) - parent_activity = Activity.get_create_by_object_ap_id(activity.data["object"]) - mastodon_type = Activity.mastodon_notification_type(activity) - - response = %{ - id: to_string(id), - type: mastodon_type, - created_at: CommonAPI.Utils.to_masto_date(created_at), - account: AccountView.render("account.json", %{user: actor, for: user}) - } - - case mastodon_type do - "mention" -> - response - |> Map.merge(%{ - status: StatusView.render("status.json", %{activity: activity, for: user}) - }) - - "favourite" -> - response - |> Map.merge(%{ - status: StatusView.render("status.json", %{activity: parent_activity, for: user}) - }) - - "reblog" -> - response - |> Map.merge(%{ - status: StatusView.render("status.json", %{activity: parent_activity, for: user}) - }) - - "follow" -> - response - - _ -> - nil - end - end - def get_filters(%{assigns: %{user: user}} = conn, _) do filters = Filter.get_filters(user) res = FilterView.render("filters.json", filters: filters) diff --git a/lib/pleroma/web/mastodon_api/views/notification_view.ex b/lib/pleroma/web/mastodon_api/views/notification_view.ex new file mode 100644 index 000000000..27e9cab06 --- /dev/null +++ b/lib/pleroma/web/mastodon_api/views/notification_view.ex @@ -0,0 +1,64 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.MastodonAPI.NotificationView do + use Pleroma.Web, :view + + alias Pleroma.Activity + alias Pleroma.Notification + alias Pleroma.User + alias Pleroma.Web.CommonAPI + alias Pleroma.Web.MastodonAPI.AccountView + alias Pleroma.Web.MastodonAPI.NotificationView + alias Pleroma.Web.MastodonAPI.StatusView + + def render("index.json", %{notifications: notifications, for: user}) do + render_many(notifications, NotificationView, "show.json", %{for: user}) + end + + def render("show.json", %{ + notification: %Notification{activity: activity} = notification, + for: user + }) do + actor = User.get_cached_by_ap_id(activity.data["actor"]) + parent_activity = Activity.get_create_by_object_ap_id(activity.data["object"]) + mastodon_type = Activity.mastodon_notification_type(activity) + + response = %{ + id: to_string(notification.id), + type: mastodon_type, + created_at: CommonAPI.Utils.to_masto_date(notification.inserted_at), + account: AccountView.render("account.json", %{user: actor, for: user}), + pleroma: %{ + is_seen: notification.seen + } + } + + case mastodon_type do + "mention" -> + response + |> Map.merge(%{ + status: StatusView.render("status.json", %{activity: activity, for: user}) + }) + + "favourite" -> + response + |> Map.merge(%{ + status: StatusView.render("status.json", %{activity: parent_activity, for: user}) + }) + + "reblog" -> + response + |> Map.merge(%{ + status: StatusView.render("status.json", %{activity: parent_activity, for: user}) + }) + + "follow" -> + response + + _ -> + nil + end + end +end diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex index aec11a79f..5850a9579 100644 --- a/lib/pleroma/web/streamer.ex +++ b/lib/pleroma/web/streamer.ex @@ -11,6 +11,7 @@ defmodule Pleroma.Web.Streamer do alias Pleroma.Repo alias Pleroma.User alias Pleroma.Web.ActivityPub.Visibility + alias Pleroma.Web.MastodonAPI.NotificationView @keepalive_interval :timer.seconds(30) @@ -106,10 +107,10 @@ def handle_cast(%{action: :stream, topic: "user", item: %Notification{} = item}, %{ event: "notification", payload: - Pleroma.Web.MastodonAPI.MastodonAPIController.render_notification( - socket.assigns["user"], - item - ) + NotificationView.render("show.json", %{ + notification: item, + for: socket.assigns["user"] + }) |> Jason.encode!() } |> Jason.encode!() diff --git a/test/web/mastodon_api/notification_view_test.exs b/test/web/mastodon_api/notification_view_test.exs new file mode 100644 index 000000000..b826a7e61 --- /dev/null +++ b/test/web/mastodon_api/notification_view_test.exs @@ -0,0 +1,104 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do + use Pleroma.DataCase + + alias Pleroma.Activity + alias Pleroma.Notification + alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.Web.CommonAPI + alias Pleroma.Web.CommonAPI.Utils + alias Pleroma.Web.MastodonAPI.AccountView + alias Pleroma.Web.MastodonAPI.NotificationView + alias Pleroma.Web.MastodonAPI.StatusView + import Pleroma.Factory + + test "Mention notification" do + user = insert(:user) + mentioned_user = insert(:user) + {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{mentioned_user.nickname}"}) + {:ok, [notification]} = Notification.create_notifications(activity) + user = Repo.get(User, user.id) + + expected = %{ + id: to_string(notification.id), + pleroma: %{is_seen: false}, + type: "mention", + account: AccountView.render("account.json", %{user: user, for: mentioned_user}), + status: StatusView.render("status.json", %{activity: activity, for: mentioned_user}), + created_at: Utils.to_masto_date(notification.inserted_at) + } + + result = + NotificationView.render("index.json", %{notifications: [notification], for: mentioned_user}) + + assert [expected] == result + end + + test "Favourite notification" do + user = insert(:user) + another_user = insert(:user) + {:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"}) + {:ok, favorite_activity, _object} = CommonAPI.favorite(create_activity.id, another_user) + {:ok, [notification]} = Notification.create_notifications(favorite_activity) + create_activity = Repo.get(Activity, create_activity.id) + + expected = %{ + id: to_string(notification.id), + pleroma: %{is_seen: false}, + type: "favourite", + account: AccountView.render("account.json", %{user: another_user, for: user}), + status: StatusView.render("status.json", %{activity: create_activity, for: user}), + created_at: Utils.to_masto_date(notification.inserted_at) + } + + result = NotificationView.render("index.json", %{notifications: [notification], for: user}) + + assert [expected] == result + end + + test "Reblog notification" do + user = insert(:user) + another_user = insert(:user) + {:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"}) + {:ok, reblog_activity, _object} = CommonAPI.repeat(create_activity.id, another_user) + {:ok, [notification]} = Notification.create_notifications(reblog_activity) + reblog_activity = Repo.get(Activity, create_activity.id) + + expected = %{ + id: to_string(notification.id), + pleroma: %{is_seen: false}, + type: "reblog", + account: AccountView.render("account.json", %{user: another_user, for: user}), + status: StatusView.render("status.json", %{activity: reblog_activity, for: user}), + created_at: Utils.to_masto_date(notification.inserted_at) + } + + result = NotificationView.render("index.json", %{notifications: [notification], for: user}) + + assert [expected] == result + end + + test "Follow notification" do + follower = insert(:user) + followed = insert(:user) + {:ok, follower, followed, _activity} = CommonAPI.follow(follower, followed) + notification = Notification |> Repo.one() |> Repo.preload(:activity) + + expected = %{ + id: to_string(notification.id), + pleroma: %{is_seen: false}, + type: "follow", + account: AccountView.render("account.json", %{user: follower, for: followed}), + created_at: Utils.to_masto_date(notification.inserted_at) + } + + result = + NotificationView.render("index.json", %{notifications: [notification], for: followed}) + + assert [expected] == result + end +end From 3dadaa4432b442d75b0ac0425aa05527d52f0e7a Mon Sep 17 00:00:00 2001 From: William Pearson Date: Sun, 20 Jan 2019 01:44:00 +0000 Subject: [PATCH 36/37] robots.txt Add default robots.txt that allows bots access to all paths. Add mix task to generate robots.txt taht allows bots access to no paths. Document custom emojis, MRF and static_dir static_dir documentation includes docs for the robots.txt Mix task. --- docs/Custom-Emoji.md | 16 +++ .../Message-Rewrite-Facility-configuration.md | 118 ++++++++++++++++++ docs/static_dir.md | 20 +++ lib/mix/tasks/pleroma/robotstxt.ex | 32 +++++ lib/pleroma/plugs/instance_static.ex | 3 +- lib/pleroma/web/endpoint.ex | 2 +- priv/static/robots.txt | 2 + 7 files changed, 191 insertions(+), 2 deletions(-) create mode 100644 docs/Custom-Emoji.md create mode 100644 docs/Message-Rewrite-Facility-configuration.md create mode 100644 docs/static_dir.md create mode 100644 lib/mix/tasks/pleroma/robotstxt.ex create mode 100644 priv/static/robots.txt diff --git a/docs/Custom-Emoji.md b/docs/Custom-Emoji.md new file mode 100644 index 000000000..d4af5c97c --- /dev/null +++ b/docs/Custom-Emoji.md @@ -0,0 +1,16 @@ +To add custom emoji: +* Add the image file(s) to `priv/static/emoji/custom` +* In case of conflicts: add the desired shortcode with the path to `config/custom_emoji.txt`, comma-separated and one per line +* Force recompilation (``mix clean && mix compile``) + +Example: + +image files (in `/priv/static/emoji/custom`): `happy.png` and `sad.png` + +content of `config/custom_emoji.txt`: +``` +happy, /emoji/custom/happy.png +sad, /emoji/custom/sad.png +``` + +The files should be PNG (APNG is okay with `.png` for `image/png` Content-type) and under 50kb for compatibility with mastodon. diff --git a/docs/Message-Rewrite-Facility-configuration.md b/docs/Message-Rewrite-Facility-configuration.md new file mode 100644 index 000000000..708098b41 --- /dev/null +++ b/docs/Message-Rewrite-Facility-configuration.md @@ -0,0 +1,118 @@ +The Message Rewrite Facility (MRF) is a subsystem that is implemented as a series of hooks that allows the administrator to rewrite or discard messages. + +Possible uses include: + +* marking incoming messages with media from a given account or instance as sensitive +* rejecting messages from a specific instance +* removing/unlisting messages from the public timelines +* removing media from messages +* sending only public messages to a specific instance + +The MRF provides user-configurable policies. The default policy is `NoOpPolicy`, which disables the MRF functionality. Pleroma also includes an easy to use policy called `SimplePolicy` which maps messages matching certain pre-defined criterion to actions built into the policy module. +It is possible to use multiple, active MRF policies at the same time. + +## Quarantine Instances + +You have the ability to prevent from private / followers-only messages from federating with specific instances. Which means they will only get the public or unlisted messages from your instance. + +If, for example, you're using `MIX_ENV=prod` aka using production mode, you would open your configuration file located in `config/prod.secret.exs` and edit or add the option under your `:instance` config object. Then you would specify the instance within quotes. +``` +config :pleroma, :instance, + [...] + quarantined_instances: ["instance.example", "other.example"] +``` + +## Using `SimplePolicy` + +`SimplePolicy` is capable of handling most common admin tasks. + +To use `SimplePolicy`, you must enable it. Do so by adding the following to your `:instance` config object, so that it looks like this: + +``` +config :pleroma, :instance, + [...] + rewrite_policy: Pleroma.Web.ActivityPub.MRF.SimplePolicy +``` + +Once `SimplePolicy` is enabled, you can configure various groups in the `:mrf_simple` config object. These groups are: + +* `media_removal`: Servers in this group will have media stripped from incoming messages. +* `media_nsfw`: Servers in this group will have the #nsfw tag and sensitive setting injected into incoming messages which contain media. +* `reject`: Servers in this group will have their messages rejected. +* `federated_timeline_removal`: Servers in this group will have their messages unlisted from the public timelines by flipping the `to` and `cc` fields. + +Servers should be configured as lists. + +### Example + +This example will enable `SimplePolicy`, block media from `illegalporn.biz`, mark media as NSFW from `porn.biz` and `porn.business`, reject messages from `spam.com` and remove messages from `spam.university` from the federated timeline: + +``` +config :pleroma, :instance, + rewrite_policy: [Pleroma.Web.ActivityPub.MRF.SimplePolicy] + +config :pleroma, :mrf_simple, + media_removal: ["illegalporn.biz"], + media_nsfw: ["porn.biz", "porn.business"], + reject: ["spam.com"], + federated_timeline_removal: ["spam.university"] + +``` + +### Use with Care + +The effects of MRF policies can be very drastic. It is important to use this functionality carefully. Always try to talk to an admin before writing an MRF policy concerning their instance. + +## Writing your own MRF Policy + +As discussed above, the MRF system is a modular system that supports pluggable policies. This means that an admin may write a custom MRF policy in Elixir or any other language that runs on the Erlang VM, by specifying the module name in the `rewrite_policy` config setting. + +For example, here is a sample policy module which rewrites all messages to "new message content": + +```!elixir +# This is a sample MRF policy which rewrites all Notes to have "new message +# content." +defmodule Site.RewritePolicy do + @behavior Pleroma.Web.ActivityPub.MRF + + # Catch messages which contain Note objects with actual data to filter. + # Capture the object as `object`, the message content as `content` and the + # message itself as `message`. + @impl true + def filter(%{"type" => Create", "object" => {"type" => "Note", "content" => content} = object} = message) + when is_binary(content) do + # Subject / CW is stored as summary instead of `name` like other AS2 objects + # because of Mastodon doing it that way. + summary = object["summary"] + + # Message edits go here. + content = "new message content" + + # Assemble the mutated object. + object = + object + |> Map.put("content", content) + |> Map.put("summary", summary) + + # Assemble the mutated message. + message = Map.put(message, "object", object) + {:ok, message} + end + + # Let all other messages through without modifying them. + @impl true + def filter(message), do: {:ok, message} +end +``` + +If you save this file as `lib/site/mrf/rewrite_policy.ex`, it will be included when you next rebuild Pleroma. You can enable it in the configuration like so: + +``` +config :pleroma, :instance, + rewrite_policy: [ + Pleroma.Web.ActivityPub.MRF.SimplePolicy, + Site.RewritePolicy + ] +``` + +Please note that the Pleroma developers consider custom MRF policy modules to fall under the purview of the AGPL. As such, you are obligated to release the sources to your custom MRF policy modules upon request. \ No newline at end of file diff --git a/docs/static_dir.md b/docs/static_dir.md new file mode 100644 index 000000000..0cc52b99a --- /dev/null +++ b/docs/static_dir.md @@ -0,0 +1,20 @@ +# Static Directory + +Static frontend files are shipped in `priv/static/` and tracked by version control in this repository. If you want to overwrite or update these without the possibility of merge conflicts, you can write your custom versions to `instance/static/`. + +``` +config :pleroma, :instance, + static_dir: "instance/static/", +``` + +You can overwrite this value in your configuration to use a different static instance directory. + +## robots.txt + +By default, the `robots.txt` that ships in `priv/static/` is permissive. It allows well-behaved search engines to index all of your instance's URIs. + +If you want to generate a restrictive `robots.txt`, you can run the following mix task. The generated `robots.txt` will be written in your instance static directory. + +``` +mix pleroma.robots_txt disallow_all +``` diff --git a/lib/mix/tasks/pleroma/robotstxt.ex b/lib/mix/tasks/pleroma/robotstxt.ex new file mode 100644 index 000000000..2128e1cd6 --- /dev/null +++ b/lib/mix/tasks/pleroma/robotstxt.ex @@ -0,0 +1,32 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Mix.Tasks.Pleroma.RobotsTxt do + use Mix.Task + + @shortdoc "Generate robots.txt" + @moduledoc """ + Generates robots.txt + + ## Overwrite robots.txt to disallow all + + mix pleroma.robots_txt disallow_all + + This will write a robots.txt that will hide all paths on your instance + from search engines and other robots that obey robots.txt + + """ + def run(["disallow_all"]) do + static_dir = Pleroma.Config.get([:instance, :static_dir], "instance/static/") + + if !File.exists?(static_dir) do + File.mkdir_p!(static_dir) + end + + robots_txt_path = Path.join(static_dir, "robots.txt") + robots_txt_content = "User-Agent: *\nDisallow: /\n" + + File.write!(robots_txt_path, robots_txt_content, [:write]) + end +end diff --git a/lib/pleroma/plugs/instance_static.ex b/lib/pleroma/plugs/instance_static.ex index 41125921a..a64f1ea80 100644 --- a/lib/pleroma/plugs/instance_static.ex +++ b/lib/pleroma/plugs/instance_static.ex @@ -21,7 +21,8 @@ def file_path(path) do end end - @only ~w(index.html static emoji packs sounds images instance favicon.png sw.js sw-pleroma.js) + @only ~w(index.html robots.txt static emoji packs sounds images instance favicon.png sw.js + sw-pleroma.js) def init(opts) do opts diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex index 697b1bc3a..fa2d1cbe7 100644 --- a/lib/pleroma/web/endpoint.ex +++ b/lib/pleroma/web/endpoint.ex @@ -25,7 +25,7 @@ defmodule Pleroma.Web.Endpoint do at: "/", from: :pleroma, only: - ~w(index.html static finmoji emoji packs sounds images instance sw.js sw-pleroma.js favicon.png schemas doc) + ~w(index.html robots.txt static finmoji emoji packs sounds images instance sw.js sw-pleroma.js favicon.png schemas doc) # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength ) diff --git a/priv/static/robots.txt b/priv/static/robots.txt new file mode 100644 index 000000000..25781b7d7 --- /dev/null +++ b/priv/static/robots.txt @@ -0,0 +1,2 @@ +User-Agent: * +Disallow: From d7a34b604b15f9e7f73cda834f513d6f62643005 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 15 Mar 2019 11:58:12 +0300 Subject: [PATCH 37/37] Extend MastoAPI to provide attachment mimetypes --- docs/Differences-in-MastodonAPI-Responses.md | 6 ++++++ lib/pleroma/web/mastodon_api/views/status_view.ex | 3 ++- test/web/mastodon_api/status_view_test.exs | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/Differences-in-MastodonAPI-Responses.md b/docs/Differences-in-MastodonAPI-Responses.md index 7b11fe90f..621de6603 100644 --- a/docs/Differences-in-MastodonAPI-Responses.md +++ b/docs/Differences-in-MastodonAPI-Responses.md @@ -20,6 +20,12 @@ Has these additional fields under the `pleroma` object: - `local`: true if the post was made on the local instance. +## Attachments + +Has these additional fields under the `pleroma` object: + +- `mime_type`: mime type of the attachment. + ## Accounts - `/api/v1/accounts/:id`: The `id` parameter can also be the `nickname` of the user. This only works in this endpoint, not the deeper nested ones for following etc. diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index bf3aaf025..209119dd5 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -257,7 +257,8 @@ def render("attachment.json", %{attachment: attachment}) do preview_url: href, text_url: href, type: type, - description: attachment["name"] + description: attachment["name"], + pleroma: %{mime_type: media_type} } end diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index 3eec2cb5b..ade0ca9f9 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -196,7 +196,8 @@ test "attachments" do remote_url: "someurl", preview_url: "someurl", text_url: "someurl", - description: nil + description: nil, + pleroma: %{mime_type: "image/png"} } assert expected == StatusView.render("attachment.json", %{attachment: object})