Added the ability to upload background, logo, default user avatar, instance thumbnail...
authoreugenijm <eugenijm@protonmail.com>
Sun, 12 Apr 2020 19:54:43 +0000 (22:54 +0300)
committereugenijm <eugenijm@protonmail.com>
Thu, 21 May 2020 01:41:42 +0000 (04:41 +0300)
config/description.exs
lib/pleroma/emails/new_users_digest_email.ex
lib/pleroma/helpers/uri_helper.ex
lib/pleroma/user.ex
lib/pleroma/web/mastodon_api/views/instance_view.ex
test/user_test.exs
test/workers/cron/new_users_digest_worker_test.exs

index 716bcf4ffa5ed94a64f57ad3172cd68e4957f4b6..cf7cc297a4d7ac4630dcc7a908a42064e6e77858 100644 (file)
@@ -969,6 +969,13 @@ config :pleroma, :config_description, [
             ]
           }
         ]
+      },
+      %{
+        key: :instance_thumbnail,
+        type: :string,
+        description:
+          "The instance thumbnail image. It will appear in [Pleroma Instances](http://distsn.org/pleroma-instances.html)",
+        suggestions: ["/instance/thumbnail.jpeg"]
       }
     ]
   },
@@ -1112,7 +1119,7 @@ config :pleroma, :config_description, [
             logoMask: true,
             minimalScopesMode: false,
             noAttachmentLinks: false,
-            nsfwCensorImage: "",
+            nsfwCensorImage: "/static/img/nsfw.74818f9.png",
             postContentType: "text/plain",
             redirectRootLogin: "/main/friends",
             redirectRootNoLogin: "/main/all",
@@ -1226,7 +1233,7 @@ config :pleroma, :config_description, [
             type: :string,
             description:
               "URL of the image to use for hiding NSFW media attachments in the timeline.",
-            suggestions: ["/static/img/nsfw.png"]
+            suggestions: ["/static/img/nsfw.74818f9.png"]
           },
           %{
             key: :postContentType,
@@ -1346,6 +1353,12 @@ config :pleroma, :config_description, [
         suggestions: [
           :pleroma_fox_tan
         ]
+      },
+      %{
+        key: :default_user_avatar,
+        type: :string,
+        description: "URL of the default user avatar.",
+        suggestions: ["/images/avi.png"]
       }
     ]
   },
index 7d16b807f60849d9ff33fa07b67c83d31d9cd91c..348cbac9c82a63cb338b9494103344f6dbdd2668 100644 (file)
@@ -14,8 +14,10 @@ defmodule Pleroma.Emails.NewUsersDigestEmail do
     styling = Pleroma.Config.get([Pleroma.Emails.UserEmail, :styling])
 
     logo_url =
-      Pleroma.Web.Endpoint.url() <>
-        Pleroma.Config.get([:frontend_configurations, :pleroma_fe, :logo])
+      Pleroma.Helpers.UriHelper.maybe_add_base(
+        Pleroma.Config.get([:frontend_configurations, :pleroma_fe, :logo]),
+        Pleroma.Web.Endpoint.url()
+      )
 
     new()
     |> to({to.name, to.email})
index 256252ddb1e099692f87dd7ee38bb5a681839661..69d8c8fe018dfb399764dec2eee25ad16bc8e0ef 100644 (file)
@@ -24,4 +24,7 @@ defmodule Pleroma.Helpers.UriHelper do
       params
     end
   end
+
+  def maybe_add_base("/" <> uri, base), do: Path.join([base, uri])
+  def maybe_add_base(uri, _base), do: uri
 end
index e8013bf4035344a6b843d0bb83af43a1e994c259..eb9533d78418d5b08039d4ace0cb091d8e4e34c6 100644 (file)
@@ -305,8 +305,13 @@ defmodule Pleroma.User do
 
   def avatar_url(user, options \\ []) do
     case user.avatar do
-      %{"url" => [%{"href" => href} | _]} -> href
-      _ -> !options[:no_default] && "#{Web.base_url()}/images/avi.png"
+      %{"url" => [%{"href" => href} | _]} ->
+        href
+
+      _ ->
+        unless options[:no_default] do
+          Config.get([:assets, :default_user_avatar], "#{Web.base_url()}/images/avi.png")
+        end
     end
   end
 
index 8088306c3bd0c01f6f4d0d4ae725f48067a448a8..6a630eafac491d87a524e39090a98be294ccd25d 100644 (file)
@@ -23,7 +23,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
         streaming_api: Pleroma.Web.Endpoint.websocket_url()
       },
       stats: Pleroma.Stats.get_stats(),
-      thumbnail: Pleroma.Web.base_url() <> "/instance/thumbnail.jpeg",
+      thumbnail: instance_thumbnail(),
       languages: ["en"],
       registrations: Keyword.get(instance, :registrations_open),
       # Extra (not present in Mastodon):
@@ -87,4 +87,9 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
     end
     |> Map.put(:enabled, Config.get([:instance, :federating]))
   end
+
+  defp instance_thumbnail do
+    Pleroma.Config.get([:instance, :instance_thumbnail]) ||
+      "#{Pleroma.Web.base_url()}/instance/thumbnail.jpeg"
+  end
 end
index 863e0106cfe0b84e27b43b9ef6274fb963556f17..ea192ad10af3519381a393b07c2146b83b2efd18 100644 (file)
@@ -1777,4 +1777,16 @@ defmodule Pleroma.UserTest do
       assert result.email_notifications["digest"] == false
     end
   end
+
+  test "avatar fallback" do
+    user = insert(:user)
+    assert User.avatar_url(user) =~ "/images/avi.png"
+
+    Pleroma.Config.put([:assets, :default_user_avatar], "avatar.png")
+
+    user = User.get_cached_by_nickname_or_id(user.nickname)
+    assert User.avatar_url(user) =~ "avatar.png"
+
+    assert User.avatar_url(user, no_default: true) == nil
+  end
 end
index 54cf0ca46feec52cf79b118f1cc69c268873ec36..ee589bb55facd8061b9dd91b13e6e9deb328b229 100644 (file)
@@ -28,6 +28,7 @@ defmodule Pleroma.Workers.Cron.NewUsersDigestWorkerTest do
     assert email.html_body =~ user.nickname
     assert email.html_body =~ user2.nickname
     assert email.html_body =~ "cofe"
+    assert email.html_body =~ "#{Pleroma.Web.Endpoint.url()}/static/logo.png"
   end
 
   test "it doesn't fail when admin has no email" do