From 312676f71192889a9d3d1948f8afa53ec32b53e2 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 20 Nov 2018 18:41:44 +0000 Subject: [PATCH 1/8] user: fix user.info lookup in User.locked?() --- lib/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 03fe2f1d4..c7de03347 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -286,7 +286,7 @@ def following?(%User{} = follower, %User{} = followed) do end def locked?(%User{} = user) do - user.info["locked"] || false + user.info.locked || false end def get_by_ap_id(ap_id) do From 4ac849cb4ad1ce10b4d8edd5c371f225c17ce757 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 20 Nov 2018 18:42:28 +0000 Subject: [PATCH 2/8] common api: fix moderator check when deleting posts --- lib/pleroma/web/common_api/common_api.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 77e4dbbd7..e9bad8d04 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -8,7 +8,7 @@ defmodule Pleroma.Web.CommonAPI do def delete(activity_id, user) do with %Activity{data: %{"object" => %{"id" => object_id}}} <- Repo.get(Activity, activity_id), %Object{} = object <- Object.normalize(object_id), - true <- user.info["is_moderator"] || user.ap_id == object.data["actor"], + true <- user.info.is_moderator || user.ap_id == object.data["actor"], {:ok, delete} <- ActivityPub.delete(object) do {:ok, delete} end From 3356c7d1e9c0abd7573768e63e004d51aa0e52b9 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 20 Nov 2018 18:47:00 +0000 Subject: [PATCH 3/8] oauth plug: fix deactivated check --- lib/pleroma/plugs/oauth_plug.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/plugs/oauth_plug.ex b/lib/pleroma/plugs/oauth_plug.ex index 0380ce14d..630f15eec 100644 --- a/lib/pleroma/plugs/oauth_plug.ex +++ b/lib/pleroma/plugs/oauth_plug.ex @@ -20,7 +20,7 @@ def call(conn, _) do with token when not is_nil(token) <- token, %Token{user_id: user_id} <- Repo.get_by(Token, token: token), %User{} = user <- Repo.get(User, user_id), - false <- !!user.info["deactivated"] do + false <- !!user.info.deactivated do conn |> assign(:user, user) else From ece86567335ece6325ebde05995b53735319fbe0 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 20 Nov 2018 18:47:12 +0000 Subject: [PATCH 4/8] streamer: fix fetching the user's block list --- lib/pleroma/web/streamer.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex index 6b6d40346..209450383 100644 --- a/lib/pleroma/web/streamer.ex +++ b/lib/pleroma/web/streamer.ex @@ -173,7 +173,7 @@ def push_to_socket(topics, topic, %Activity{data: %{"type" => "Announce"}} = ite Enum.each(topics[topic] || [], fn socket -> # Get the current user so we have up-to-date blocks etc. user = User.get_cached_by_ap_id(socket.assigns[:user].ap_id) - blocks = user.info["blocks"] || [] + blocks = user.info.blocks || [] parent = Object.normalize(item.data["object"]) @@ -187,7 +187,7 @@ def push_to_socket(topics, topic, item) do Enum.each(topics[topic] || [], fn socket -> # Get the current user so we have up-to-date blocks etc. user = User.get_cached_by_ap_id(socket.assigns[:user].ap_id) - blocks = user.info["blocks"] || [] + blocks = user.info.blocks || [] unless item.actor in blocks do send(socket.transport_pid, {:text, represent_update(item, user)}) From c196754b4ddf53a68f42ac26a98c42eeba78a12b Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 20 Nov 2018 18:54:48 +0000 Subject: [PATCH 5/8] mastodon api: account view: fix tests --- lib/pleroma/web/mastodon_api/views/account_view.ex | 6 +++--- test/web/mastodon_api/account_view_test.exs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index b68845e16..bcfa8836e 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -14,10 +14,10 @@ def render("account.json", %{user: user} = opts) do image = User.avatar_url(user) |> MediaProxy.url() header = User.banner_url(user) |> MediaProxy.url() user_info = User.user_info(user) - bot = (user.info["source_data"]["type"] || "Person") in ["Application", "Service"] + bot = (user.info.source_data["type"] || "Person") in ["Application", "Service"] emojis = - (user.info["source_data"]["tag"] || []) + (user.info.source_data["tag"] || []) |> Enum.filter(fn %{"type" => t} -> t == "Emoji" end) |> Enum.map(fn %{"icon" => %{"url" => url}, "name" => name} -> %{ @@ -29,7 +29,7 @@ def render("account.json", %{user: user} = opts) do end) fields = - (user.info["source_data"]["attachment"] || []) + (user.info.source_data["attachment"] || []) |> Enum.filter(fn %{"type" => t} -> t == "PropertyValue" end) |> Enum.map(fn fields -> Map.take(fields, ["name", "value"]) end) diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs index dc52b92bc..a2d3a2547 100644 --- a/test/web/mastodon_api/account_view_test.exs +++ b/test/web/mastodon_api/account_view_test.exs @@ -17,7 +17,7 @@ test "Represent a user account" do user = insert(:user, %{ - info: %{"note_count" => 5, "follower_count" => 3, "source_data" => source_data}, + info: %{note_count: 5, follower_count: 3, source_data: source_data}, nickname: "shp@shitposter.club", name: ":karjalanpiirakka: shp", bio: "valid html", @@ -63,7 +63,7 @@ test "Represent a user account" do test "Represent a Service(bot) account" do user = insert(:user, %{ - info: %{"note_count" => 5, "follower_count" => 3, "source_data" => %{"type" => "Service"}}, + info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}}, nickname: "shp@shitposter.club", inserted_at: ~N[2017-08-15 15:47:06.597036] }) From ef6c64a5d24085b05162ebd3a60cf2975386edea Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 20 Nov 2018 18:58:08 +0000 Subject: [PATCH 6/8] activitypub: fix restrict_blocked() --- lib/pleroma/web/activity_pub/activity_pub.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 54ca891b9..47836ae13 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -509,8 +509,8 @@ defp restrict_recent(query, _) do end defp restrict_blocked(query, %{"blocking_user" => %User{info: info}}) do - blocks = info["blocks"] || [] - domain_blocks = info["domain_blocks"] || [] + blocks = info.blocks || [] + domain_blocks = info.domain_blocks || [] from( activity in query, From 3456948cd15a14e419abb73a3cb660624b5c32c2 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 20 Nov 2018 19:02:23 +0000 Subject: [PATCH 7/8] mastodon api: fix up quite a few test failures --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index a0b74311b..280bd78fc 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -659,7 +659,7 @@ def unblock(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do # TODO: Use proper query def blocks(%{assigns: %{user: user}} = conn, _) do - with blocked_users <- user.info["blocks"] || [], + with blocked_users <- user.info.blocks || [], accounts <- Enum.map(blocked_users, fn ap_id -> User.get_cached_by_ap_id(ap_id) end) do res = AccountView.render("accounts.json", users: accounts, for: user, as: :user) json(conn, res) @@ -667,7 +667,7 @@ def blocks(%{assigns: %{user: user}} = conn, _) do end def domain_blocks(%{assigns: %{user: %{info: info}}} = conn, _) do - json(conn, info["domain_blocks"] || []) + json(conn, info.domain_blocks || []) end def block_domain(%{assigns: %{user: blocker}} = conn, %{"domain" => domain}) do @@ -915,11 +915,11 @@ def index(%{assigns: %{user: user}} = conn, _params) do max_toot_chars: limit }, rights: %{ - delete_others_notice: !!user.info["is_moderator"] + delete_others_notice: !!user.info.is_moderator }, compose: %{ me: "#{user.id}", - default_privacy: user.info["default_scope"] || "public", + default_privacy: user.info.default_scope || "public", default_sensitive: false }, media_attachments: %{ From 5b3480d896ac71e264ffd4ae27fcba9897a81f00 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 20 Nov 2018 19:08:41 +0000 Subject: [PATCH 8/8] tests: fix up some more broken mastodon api testcases --- test/web/mastodon_api/mastodon_api_controller_test.exs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index ad67cae6b..020a2276e 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -252,7 +252,7 @@ test "verify_credentials", %{conn: conn} do end test "verify_credentials default scope unlisted", %{conn: conn} do - user = insert(:user, %{info: %{"default_scope" => "unlisted"}}) + user = insert(:user, %{info: %{default_scope: "unlisted"}}) conn = conn @@ -845,7 +845,7 @@ test "returns the relationships for the current user", %{conn: conn} do describe "locked accounts" do test "/api/v1/follow_requests works" do - user = insert(:user, %{info: %{"locked" => true}}) + user = insert(:user, %{info: %{locked: true}}) other_user = insert(:user) {:ok, activity} = ActivityPub.follow(other_user, user) @@ -865,7 +865,7 @@ test "/api/v1/follow_requests works" do end test "/api/v1/follow_requests/:id/authorize works" do - user = insert(:user, %{info: %{"locked" => true}}) + user = insert(:user, %{info: %{locked: true}}) other_user = insert(:user) {:ok, activity} = ActivityPub.follow(other_user, user) @@ -890,7 +890,7 @@ test "/api/v1/follow_requests/:id/authorize works" do end test "verify_credentials", %{conn: conn} do - user = insert(:user, %{info: %{"default_scope" => "private"}}) + user = insert(:user, %{info: %{default_scope: "private"}}) conn = conn @@ -902,7 +902,7 @@ test "verify_credentials", %{conn: conn} do end test "/api/v1/follow_requests/:id/reject works" do - user = insert(:user, %{info: %{"locked" => true}}) + user = insert(:user, %{info: %{locked: true}}) other_user = insert(:user) {:ok, activity} = ActivityPub.follow(other_user, user)