Provide known-good user.uri, remove User.profile_url/1
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Mon, 30 Mar 2020 00:01:09 +0000 (02:01 +0200)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Tue, 31 Mar 2020 21:55:29 +0000 (23:55 +0200)
lib/pleroma/user.ex
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/mastodon_api/views/account_view.ex
lib/pleroma/web/metadata/opengraph.ex
lib/pleroma/web/templates/static_fe/static_fe/_user_card.html.eex
lib/pleroma/web/templates/static_fe/static_fe/profile.html.eex
test/web/mastodon_api/views/account_view_test.exs

index ca0bfca116d9b424d198fb9bd0cfa0504576b798..ff828aa17f33478cd3759ea1f6e9d48d7093397e 100644 (file)
@@ -305,11 +305,6 @@ defmodule Pleroma.User do
     end
   end
 
-  def profile_url(%User{uri: url}) when url != nil, do: url
-  def profile_url(%User{source_data: %{"url" => url}}) when is_binary(url), do: url
-  def profile_url(%User{ap_id: ap_id}), do: ap_id
-  def profile_url(_), do: nil
-
   def ap_id(%User{nickname: nickname}), do: "#{Web.base_url()}/users/#{nickname}"
 
   def ap_followers(%User{follower_address: fa}) when is_binary(fa), do: fa
index 9c0f5d77111670a33d2d2322175a15a336892a72..53b6ad654b692d652ebf64ce81e59d30de653ad4 100644 (file)
@@ -1379,6 +1379,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     end
   end
 
+  @spec get_actor_url(any()) :: binary() | nil
+  defp get_actor_url(url) when is_binary(url), do: url
+  defp get_actor_url(%{"href" => href}) when is_binary(href), do: href
+
+  defp get_actor_url(url) when is_list(url) do
+    url
+    |> List.first()
+    |> get_actor_url()
+  end
+
+  defp get_actor_url(_url), do: nil
+
   defp object_to_user_data(data) do
     avatar =
       data["icon"]["url"] &&
@@ -1408,6 +1420,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
 
     user_data = %{
       ap_id: data["id"],
+      uri: get_actor_url(data["url"]),
       ap_enabled: true,
       source_data: data,
       banner: banner,
index 0efcabc019b420f56c7b3a0e7f7c9f844b1ea07f..c482bba6498d4c806e37a9b540663c84eb8506b6 100644 (file)
@@ -43,7 +43,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
       id: to_string(user.id),
       acct: user.nickname,
       username: username_from_nickname(user.nickname),
-      url: User.profile_url(user)
+      url: user.uri || user.ap_id
     }
   end
 
@@ -207,7 +207,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
       following_count: following_count,
       statuses_count: user.note_count,
       note: user.bio || "",
-      url: User.profile_url(user),
+      url: user.uri || user.ap_id,
       avatar: image,
       avatar_static: image,
       header: header,
index 21446ac7799eb2c40100d8be5d71500de1e3a78c..68c871e71b19aa750bdeb7e67c6105b9bfa47c59 100644 (file)
@@ -68,7 +68,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do
            property: "og:title",
            content: Utils.user_name_string(user)
          ], []},
-        {:meta, [property: "og:url", content: User.profile_url(user)], []},
+        {:meta, [property: "og:url", content: user.uri || user.ap_id], []},
         {:meta, [property: "og:description", content: truncated_bio], []},
         {:meta, [property: "og:type", content: "website"], []},
         {:meta, [property: "og:image", content: Utils.attachment_url(User.avatar_url(user))], []},
index c7789f9acb146096d8b772ff9393687161c4f5f7..2a7582d45565a789a0ad811a038ddb63c415a9ea 100644 (file)
@@ -1,5 +1,5 @@
 <div class="p-author h-card">
-  <a class="u-url" rel="author noopener" href="<%= User.profile_url(@user) %>">
+  <a class="u-url" rel="author noopener" href="<%= (@user.uri || @user.ap_id) %>">
     <div class="avatar">
       <img src="<%= User.avatar_url(@user) |> MediaProxy.url %>" width="48" height="48" alt="">
     </div>
index 94063c92d631b2fd854b9e4b69f55eb20eb71884..e7d2aecadf41e38502c6393d5b53e3f7f06f09b8 100644 (file)
@@ -8,7 +8,7 @@
       <button type="submit" class="collapse">Remote follow</button>
     </form>
     <%= raw Formatter.emojify(@user.name, emoji_for_user(@user)) %> |
-    <%= link "@#{@user.nickname}@#{Endpoint.host()}", to: User.profile_url(@user) %>
+    <%= link "@#{@user.nickname}@#{Endpoint.host()}", to: (@user.uri || @user.ap_id) %>
   </h3>
   <p><%= raw @user.bio %></p>
 </header>
index ef3f3eff17f8b3f41d23af0d8d8d5696f97d7668..8d00e3c21ba935aaf9b618425e38b0ed0bf1335e 100644 (file)
@@ -178,9 +178,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
 
     assert represented = AccountView.render("show.json", %{user: user})
     assert represented.acct == "compositions@channels.tests.funkwhale.audio"
-    # assert represented.url == "https://channels.tests.funkwhale.audio/channels/compositions"
-    assert represented.url ==
-             "https://channels.tests.funkwhale.audio/federation/actors/compositions"
+    assert represented.url == "https://channels.tests.funkwhale.audio/channels/compositions"
   end
 
   test "Represent a deactivated user for an admin" do