diff options
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | config/config.exs | 3 | ||||
| -rw-r--r-- | config/test.exs | 5 | ||||
| -rw-r--r-- | docs/configuration/cheatsheet.md | 1 | ||||
| -rwxr-xr-x | installation/freebsd/rc.d/pleroma | 31 | ||||
| -rw-r--r-- | lib/mix/pleroma.ex | 2 | ||||
| -rw-r--r-- | lib/mix/tasks/pleroma/emoji.ex | 10 | ||||
| -rw-r--r-- | lib/pleroma/emails/user_email.ex | 31 | ||||
| -rw-r--r-- | lib/pleroma/upload.ex | 11 | ||||
| -rw-r--r-- | test/emails/mailer_test.exs | 4 | ||||
| -rw-r--r-- | test/tasks/digest_test.exs | 2 | ||||
| -rw-r--r-- | test/tasks/email_test.exs | 2 | ||||
| -rw-r--r-- | test/web/activity_pub/activity_pub_test.exs | 30 | 
13 files changed, 94 insertions, 39 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index d0ae2981c..cdc0cd8ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).  ## [unreleased]  ### Changed +- **Breaking:** The default descriptions on uploads are now empty. The old behavior (filename as default) can be configured, see the cheat sheet.  - **Breaking:** Added the ObjectAgePolicy to the default set of MRFs. This will delist and strip the follower collection of any message received that is older than 7 days. This will stop users from seeing very old messages in the timelines. The messages can still be viewed on the user's page and in conversations. They also still trigger notifications.  - **Breaking:** Elixir >=1.9 is now required (was >= 1.8)  - **Breaking:** Configuration: `:auto_linker, :opts` moved to `:pleroma, Pleroma.Formatter`. Old config namespace is deprecated. diff --git a/config/config.exs b/config/config.exs index a7c9e54b1..1ed3157c3 100644 --- a/config/config.exs +++ b/config/config.exs @@ -72,7 +72,8 @@ config :pleroma, Pleroma.Upload,        pool: :upload      ]    ], -  filename_display_max_length: 30 +  filename_display_max_length: 30, +  default_description: nil  config :pleroma, Pleroma.Uploaders.Local, uploads: "uploads" diff --git a/config/test.exs b/config/test.exs index 413c7f0b9..f0358e384 100644 --- a/config/test.exs +++ b/config/test.exs @@ -21,7 +21,10 @@ config :logger, :console,  config :pleroma, :auth, oauth_consumer_strategies: [] -config :pleroma, Pleroma.Upload, filters: [], link_name: false +config :pleroma, Pleroma.Upload, +  filters: [], +  link_name: false, +  default_description: :filename  config :pleroma, Pleroma.Uploaders.Local, uploads: "test/uploads" diff --git a/docs/configuration/cheatsheet.md b/docs/configuration/cheatsheet.md index e68b6c6dc..4758fca66 100644 --- a/docs/configuration/cheatsheet.md +++ b/docs/configuration/cheatsheet.md @@ -552,6 +552,7 @@ the source code is here: [kocaptcha](https://github.com/koto-bank/kocaptcha). Th  * `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.  * `filename_display_max_length`: Set max length of a filename to display. 0 = no limit. Default: 30. +* `default_description`: Sets which default description an image has if none is set explicitly. Options: nil (default) - Don't set a default, :filename - use the filename of the file, a string (e.g. "attachment") - Use this string  !!! warning      `strip_exif` has been replaced by `Pleroma.Upload.Filter.Mogrify`. diff --git a/installation/freebsd/rc.d/pleroma b/installation/freebsd/rc.d/pleroma index 1e41e57e6..f62aef18d 100755 --- a/installation/freebsd/rc.d/pleroma +++ b/installation/freebsd/rc.d/pleroma @@ -1,28 +1,27 @@  #!/bin/sh -# REQUIRE: DAEMON postgresql +# $FreeBSD$  # PROVIDE: pleroma +# REQUIRE: DAEMON postgresql +# KEYWORD: shutdown  # sudo -u pleroma MIX_ENV=prod elixir --erl \"-detached\" -S mix phx.server  . /etc/rc.subr -name="pleroma" +name=pleroma +rcvar=pleroma_enable +  desc="Pleroma Social Media Platform" -rcvar=${name}_enable -command="/usr/local/bin/elixir" -command_args="--erl \"-detached\" -S /usr/local/bin/mix phx.server" -pidfile="/dev/null" -pleroma_user="pleroma" -pleroma_home="/home/pleroma" -pleroma_chdir="${pleroma_home}/pleroma" -pleroma_env="HOME=${pleroma_home} MIX_ENV=prod" +load_rc_config ${name} -check_pidfile() -{ -	pid=$(pgrep beam.smp$) -	echo -n "${pid}" -} +: ${pleroma_user:=pleroma} +: ${pleroma_home:=$(getent passwd ${pleroma_user} | awk -F: '{print $6}')} +: ${pleroma_chdir:="${pleroma_home}/pleroma"} +: ${pleroma_env:="HOME=${pleroma_home} MIX_ENV=prod"} + +command=/usr/local/bin/elixir +command_args="--erl \"-detached\" -S /usr/local/bin/mix phx.server" +procname="*beam.smp" -load_rc_config ${name}  run_rc_command "$1" diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex index 074492a46..fe9b0d16c 100644 --- a/lib/mix/pleroma.ex +++ b/lib/mix/pleroma.ex @@ -14,7 +14,7 @@ defmodule Mix.Pleroma do      :swoosh,      :timex    ] -  @cachex_children ["object", "user"] +  @cachex_children ["object", "user", "scrubber"]    @doc "Common functions to be reused in mix tasks"    def start_pleroma do      Pleroma.Config.Holder.save_default() diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index f4eaeac98..8f52ee98d 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -15,7 +15,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do      {options, [], []} = parse_global_opts(args)      url_or_path = options[:manifest] || default_manifest() -    manifest = fetch_and_decode(url_or_path) +    manifest = fetch_and_decode!(url_or_path)      Enum.each(manifest, fn {name, info} ->        to_print = [ @@ -42,7 +42,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do      url_or_path = options[:manifest] || default_manifest() -    manifest = fetch_and_decode(url_or_path) +    manifest = fetch_and_decode!(url_or_path)      for pack_name <- pack_names do        if Map.has_key?(manifest, pack_name) do @@ -92,7 +92,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do            ])          ) -        files = fetch_and_decode(files_loc) +        files = fetch_and_decode!(files_loc)          IO.puts(IO.ANSI.format(["Unpacking ", :bright, pack_name])) @@ -243,9 +243,11 @@ defmodule Mix.Tasks.Pleroma.Emoji do      IO.puts("Emoji packs have been reloaded.")    end -  defp fetch_and_decode(from) do +  defp fetch_and_decode!(from) do      with {:ok, json} <- fetch(from) do        Jason.decode!(json) +    else +      {:error, error} -> raise "#{from} cannot be fetched. Error: #{error} occur."      end    end diff --git a/lib/pleroma/emails/user_email.ex b/lib/pleroma/emails/user_email.ex index 313533859..1d8c72ae9 100644 --- a/lib/pleroma/emails/user_email.ex +++ b/lib/pleroma/emails/user_email.ex @@ -107,25 +107,34 @@ defmodule Pleroma.Emails.UserEmail do        |> Enum.filter(&(&1.activity.data["type"] == "Create"))        |> Enum.map(fn notification ->          object = Pleroma.Object.normalize(notification.activity) -        object = update_in(object.data["content"], &format_links/1) -        %{ -          data: notification, -          object: object, -          from: User.get_by_ap_id(notification.activity.actor) -        } +        if not is_nil(object) do +          object = update_in(object.data["content"], &format_links/1) + +          %{ +            data: notification, +            object: object, +            from: User.get_by_ap_id(notification.activity.actor) +          } +        end        end) +      |> Enum.filter(& &1)      followers =        notifications        |> Enum.filter(&(&1.activity.data["type"] == "Follow"))        |> Enum.map(fn notification -> -        %{ -          data: notification, -          object: Pleroma.Object.normalize(notification.activity), -          from: User.get_by_ap_id(notification.activity.actor) -        } +        from = User.get_by_ap_id(notification.activity.actor) + +        if not is_nil(from) do +          %{ +            data: notification, +            object: Pleroma.Object.normalize(notification.activity), +            from: User.get_by_ap_id(notification.activity.actor) +          } +        end        end) +      |> Enum.filter(& &1)      unless Enum.empty?(mentions) do        styling = Config.get([__MODULE__, :styling]) diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index 0fa6b89dc..015c87593 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -56,6 +56,15 @@ defmodule Pleroma.Upload do          }    defstruct [:id, :name, :tempfile, :content_type, :path] +  defp get_description(opts, upload) do +    case {opts[:description], Pleroma.Config.get([Pleroma.Upload, :default_description])} do +      {description, _} when is_binary(description) -> description +      {_, :filename} -> upload.name +      {_, str} when is_binary(str) -> str +      _ -> "" +    end +  end +    @spec store(source, options :: [option()]) :: {:ok, Map.t()} | {:error, any()}    def store(upload, opts \\ []) do      opts = get_opts(opts) @@ -63,7 +72,7 @@ defmodule Pleroma.Upload do      with {:ok, upload} <- prepare_upload(upload, opts),           upload = %__MODULE__{upload | path: upload.path || "#{upload.id}/#{upload.name}"},           {:ok, upload} <- Pleroma.Upload.Filter.filter(opts.filters, upload), -         description = Map.get(opts, :description) || upload.name, +         description = get_description(opts, upload),           {_, true} <-             {:description_limit,              String.length(description) <= Pleroma.Config.get([:instance, :description_limit])}, diff --git a/test/emails/mailer_test.exs b/test/emails/mailer_test.exs index 3da45056b..9e232d2a0 100644 --- a/test/emails/mailer_test.exs +++ b/test/emails/mailer_test.exs @@ -14,10 +14,10 @@ defmodule Pleroma.Emails.MailerTest do      subject: "Pleroma test email",      to: [{"Test User", "user1@example.com"}]    } -  setup do: clear_config([Pleroma.Emails.Mailer, :enabled]) +  setup do: clear_config([Pleroma.Emails.Mailer, :enabled], true)    test "not send email when mailer is disabled" do -    Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false) +    clear_config([Pleroma.Emails.Mailer, :enabled], false)      Mailer.deliver(@email)      :timer.sleep(100) diff --git a/test/tasks/digest_test.exs b/test/tasks/digest_test.exs index eefbc8936..0b444c86d 100644 --- a/test/tasks/digest_test.exs +++ b/test/tasks/digest_test.exs @@ -17,6 +17,8 @@ defmodule Mix.Tasks.Pleroma.DigestTest do      :ok    end +  setup do: clear_config([Pleroma.Emails.Mailer, :enabled], true) +    describe "pleroma.digest test" do      test "Sends digest to the given user" do        user1 = insert(:user) diff --git a/test/tasks/email_test.exs b/test/tasks/email_test.exs index 944c07064..c3af7ef68 100644 --- a/test/tasks/email_test.exs +++ b/test/tasks/email_test.exs @@ -16,6 +16,8 @@ defmodule Mix.Tasks.Pleroma.EmailTest do      :ok    end +  setup do: clear_config([Pleroma.Emails.Mailer, :enabled], true) +    describe "pleroma.email test" do      test "Sends test email with no given address" do        mail_to = Config.get([:instance, :email]) diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index d6eab7337..03f968aaf 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -990,13 +990,39 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do    end    describe "uploading files" do -    test "copies the file to the configured folder" do -      file = %Plug.Upload{ +    setup do +      test_file = %Plug.Upload{          content_type: "image/jpg",          path: Path.absname("test/fixtures/image.jpg"),          filename: "an_image.jpg"        } +      %{test_file: test_file} +    end + +    test "sets a description if given", %{test_file: file} do +      {:ok, %Object{} = object} = ActivityPub.upload(file, description: "a cool file") +      assert object.data["name"] == "a cool file" +    end + +    test "it sets the default description depending on the configuration", %{test_file: file} do +      clear_config([Pleroma.Upload, :default_description]) + +      Pleroma.Config.put([Pleroma.Upload, :default_description], nil) +      {:ok, %Object{} = object} = ActivityPub.upload(file) +      assert object.data["name"] == "" + +      Pleroma.Config.put([Pleroma.Upload, :default_description], :filename) +      {:ok, %Object{} = object} = ActivityPub.upload(file) +      assert object.data["name"] == "an_image.jpg" + +      Pleroma.Config.put([Pleroma.Upload, :default_description], "unnamed attachment") +      {:ok, %Object{} = object} = ActivityPub.upload(file) +      assert object.data["name"] == "unnamed attachment" +    end + +    test "copies the file to the configured folder", %{test_file: file} do +      clear_config([Pleroma.Upload, :default_description], :filename)        {:ok, %Object{} = object} = ActivityPub.upload(file)        assert object.data["name"] == "an_image.jpg"      end  | 
