From 48b95a9b954b6d9e1b6f98097b35fcca4172c8a0 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 30 Nov 2018 17:08:02 +0100 Subject: [PATCH] Assorted fixes. --- lib/pleroma/user/info.ex | 6 +++++- lib/pleroma/web/websub/websub.ex | 4 ++-- test/web/ostatus/ostatus_test.exs | 2 +- test/web/twitter_api/views/user_view_test.exs | 20 +++++++++---------- test/web/websub/websub_test.exs | 2 +- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 49387163a..4e2c5472d 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -20,6 +20,8 @@ defmodule Pleroma.User.Info do field(:settings, :map, default: nil) field(:magic_key, :string, default: nil) field(:uri, :string, default: nil) + field(:topic, :string, default: nil) + field(:hub, :string, default: nil) # topic, subject, salmon, subscribe_address, uri end @@ -99,7 +101,9 @@ def remote_user_creation(info, params) do :banner, :locked, :magic_key, - :uri + :uri, + :hub, + :topic ]) end diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index e494811f9..440b48665 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -146,7 +146,7 @@ defp valid_topic(%{"hub.topic" => topic}, user) do end def subscribe(subscriber, subscribed, requester \\ &request_subscription/1) do - topic = subscribed.info["topic"] + topic = subscribed.info.topic # FIXME: Race condition, use transactions {:ok, subscription} = with subscription when not is_nil(subscription) <- @@ -158,7 +158,7 @@ def subscribe(subscriber, subscribed, requester \\ &request_subscription/1) do _e -> subscription = %WebsubClientSubscription{ topic: topic, - hub: subscribed.info["hub"], + hub: subscribed.info.hub, subscribers: [subscriber.ap_id], state: "requested", secret: :crypto.strong_rand_bytes(8) |> Base.url_encode64(), diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index b2f25d215..6e5263014 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -447,7 +447,7 @@ test "it works for atom notes, too" do end end - test "it doesn't add nil in the do field" do + test "it doesn't add nil in the to field" do incoming = File.read!("test/fixtures/nil_mention_entry.xml") {:ok, [activity]} = OStatus.handle_incoming(incoming) diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 2c583c0d3..e69ca24a9 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -31,10 +31,10 @@ test "A user with emoji in username", %{user: user} do expected = "\"karjalanpiirakka\" man" - user = %{ - user - | info: %{ - "source_data" => %{ + user = + insert(:user, %{ + info: %{ + source_data: %{ "tag" => [ %{ "type" => "Emoji", @@ -43,10 +43,10 @@ test "A user with emoji in username", %{user: user} do } ] } - } - } + }, + name: ":karjalanpiirakka: man" + }) - user = %{user | name: ":karjalanpiirakka: man"} represented = UserView.render("show.json", %{user: user}) assert represented["name_html"] == expected end @@ -103,7 +103,7 @@ test "A user" do end test "A user for a given other follower", %{user: user} do - {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]}) + follower = insert(:user, %{following: [User.ap_followers(user)]}) {:ok, user} = User.update_follower_count(user) image = "http://localhost:4001/images/avi.png" banner = "http://localhost:4001/images/banner.png" @@ -186,7 +186,7 @@ test "A user that follows you", %{user: user} do end test "a user that is a moderator" do - user = insert(:user, %{info: %{"is_moderator" => true}}) + user = insert(:user, %{info: %{is_moderator: true}}) represented = UserView.render("show.json", %{user: user, for: user}) assert represented["rights"]["delete_others_notice"] @@ -250,7 +250,7 @@ test "a user with mastodon fields" do user = insert(:user, %{ info: %{ - "source_data" => %{ + source_data: %{ "attachment" => Enum.map(fields, fn field -> Map.put(field, "type", "PropertyValue") end) } diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs index 5914a37fc..da7bc9112 100644 --- a/test/web/websub/websub_test.exs +++ b/test/web/websub/websub_test.exs @@ -99,7 +99,7 @@ def accepting_verifier(subscription) do test "initiate a subscription for a given user and topic" do subscriber = insert(:user) - user = insert(:user, %{info: %{"topic" => "some_topic", "hub" => "some_hub"}}) + user = insert(:user, %{info: %Pleroma.User.Info{topic: "some_topic", hub: "some_hub"}}) {:ok, websub} = Websub.subscribe(subscriber, user, &accepting_verifier/1) assert websub.subscribers == [subscriber.ap_id]