From f07003e2183c4e13a428614bd0ce39c9e84e2da2 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 20 Jun 2019 17:54:16 +0300 Subject: [PATCH 1/7] Fixed mix version computed for underscore-containing branches to be of SemVer format. --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 7f8e36cbb..30584cc92 100644 --- a/mix.exs +++ b/mix.exs @@ -212,7 +212,7 @@ defmodule Pleroma.Mixfile do true <- branch_name != "master" do branch_name = String.trim(branch_name) - |> String.replace(~r/\W+/, "-") + |> String.replace(~r/[\W_]+/, "-") "-" <> branch_name end From 259ffe00620ae8dd0cbfd5313024107e59f96ffc Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 21 Jun 2019 17:19:29 +0300 Subject: [PATCH 2/7] Fixed branch name substitutions for mix version (to comply to SemVer format). --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 30584cc92..0981ee856 100644 --- a/mix.exs +++ b/mix.exs @@ -212,7 +212,7 @@ defmodule Pleroma.Mixfile do true <- branch_name != "master" do branch_name = String.trim(branch_name) - |> String.replace(~r/[\W_]+/, "-") + |> String.replace(~r/[^0-9a-z\-\.]+/i, "-") "-" <> branch_name end From f4009b6706781f7d6caf75a29cc6e700e7c7e88f Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 22 Jun 2019 02:29:49 +0300 Subject: [PATCH 3/7] Fallback to Config if Mix.Config does not exist, even if Config does not exist either For some weird reason Code.ensure_loaded?(Config) is false on OTP releases even though `use Config` from config files works just fine. --- priv/templates/sample_config.eex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/priv/templates/sample_config.eex b/priv/templates/sample_config.eex index 526593d0a..8cadb995e 100644 --- a/priv/templates/sample_config.eex +++ b/priv/templates/sample_config.eex @@ -3,7 +3,7 @@ # NOTE: This file should not be committed to a repo or otherwise made public # without removing sensitive information. -<%= if Code.ensure_loaded?(Config) do +<%= if Code.ensure_loaded?(Config) or not Code.ensure_loaded?(Mix.Config) do "import Config" else "use Mix.Config" From 481932309fdec83b1cfb46afda3b982d5e388497 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 21 Jun 2019 23:42:50 +0000 Subject: [PATCH 4/7] mix: update bbcode dependency to v0.1.1 --- mix.exs | 2 +- mix.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index 9fdf6e83a..0f57c4dae 100644 --- a/mix.exs +++ b/mix.exs @@ -108,7 +108,7 @@ defmodule Pleroma.Mixfile do {:ex_aws, "~> 2.0"}, {:ex_aws_s3, "~> 2.0"}, {:earmark, "~> 1.3"}, - {:bbcode, "~> 0.1"}, + {:bbcode, "~> 0.1.1"}, {:ex_machina, "~> 2.3", only: :test}, {:credo, "~> 0.9.3", only: [:dev, :test]}, {:mock, "~> 0.3.3", only: :test}, diff --git a/mix.lock b/mix.lock index 6528db98d..cae8d7d84 100644 --- a/mix.lock +++ b/mix.lock @@ -2,7 +2,7 @@ "accept": {:hex, :accept, "0.3.5", "b33b127abca7cc948bbe6caa4c263369abf1347cfa9d8e699c6d214660f10cd1", [:rebar3], [], "hexpm"}, "auto_linker": {:git, "https://git.pleroma.social/pleroma/auto_linker.git", "95e8188490e97505c56636c1379ffdf036c1fdde", [ref: "95e8188490e97505c56636c1379ffdf036c1fdde"]}, "base64url": {:hex, :base64url, "0.0.1", "36a90125f5948e3afd7be97662a1504b934dd5dac78451ca6e9abf85a10286be", [:rebar], [], "hexpm"}, - "bbcode": {:hex, :bbcode, "0.1.0", "400e618b640b635261611d7fb7f79d104917fc5b084aae371ab6b08477cb035b", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"}, + "bbcode": {:hex, :bbcode, "0.1.1", "0023e2c7814119b2e620b7add67182e3f6019f92bfec9a22da7e99821aceba70", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"}, "benchee": {:hex, :benchee, "1.0.1", "66b211f9bfd84bd97e6d1beaddf8fc2312aaabe192f776e8931cb0c16f53a521", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}], "hexpm"}, "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"}, "cachex": {:hex, :cachex, "3.0.2", "1351caa4e26e29f7d7ec1d29b53d6013f0447630bbf382b4fb5d5bad0209f203", [:mix], [{:eternal, "~> 1.2", [hex: :eternal, repo: "hexpm", optional: false]}, {:unsafe, "~> 1.0", [hex: :unsafe, repo: "hexpm", optional: false]}], "hexpm"}, From ebee9f59d84c31b755611033d4abe2938201a65e Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 22 Jun 2019 04:17:04 +0300 Subject: [PATCH 5/7] Ecto tasks: Resolve relative path using the application directory instead of cwd and load the application before doing anything In OTP releases cwd != app directory and the configuration is read only if the application is loaded --- lib/mix/pleroma.ex | 4 ++++ lib/mix/tasks/pleroma/ecto/ecto.ex | 11 ++++++++++- lib/mix/tasks/pleroma/ecto/migrate.ex | 2 ++ lib/mix/tasks/pleroma/ecto/rollback.ex | 2 ++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex index 548c8a0a4..1b758ea33 100644 --- a/lib/mix/pleroma.ex +++ b/lib/mix/pleroma.ex @@ -9,6 +9,10 @@ defmodule Mix.Pleroma do {:ok, _} = Application.ensure_all_started(:pleroma) end + def load_pleroma do + Application.load(:pleroma) + end + def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do Keyword.get(options, opt) || shell_prompt(prompt, defval, defname) end diff --git a/lib/mix/tasks/pleroma/ecto/ecto.ex b/lib/mix/tasks/pleroma/ecto/ecto.ex index af09cb289..324f57fdd 100644 --- a/lib/mix/tasks/pleroma/ecto/ecto.ex +++ b/lib/mix/tasks/pleroma/ecto/ecto.ex @@ -9,6 +9,15 @@ defmodule Mix.Tasks.Pleroma.Ecto do def ensure_migrations_path(repo, opts) do path = opts[:migrations_path] || Path.join(source_repo_priv(repo), "migrations") + path = + case Path.type(path) do + :relative -> + Path.join(Application.app_dir(:pleroma), path) + + :absolute -> + path + end + if not File.dir?(path) do raise_missing_migrations(Path.relative_to_cwd(path), repo) end @@ -22,7 +31,7 @@ defmodule Mix.Tasks.Pleroma.Ecto do def source_repo_priv(repo) do config = repo.config() priv = config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}" - Path.join(File.cwd!(), priv) + Path.join(Application.app_dir(:pleroma), priv) end defp raise_missing_migrations(path, repo) do diff --git a/lib/mix/tasks/pleroma/ecto/migrate.ex b/lib/mix/tasks/pleroma/ecto/migrate.ex index 22eafe76f..855c977f6 100644 --- a/lib/mix/tasks/pleroma/ecto/migrate.ex +++ b/lib/mix/tasks/pleroma/ecto/migrate.ex @@ -4,6 +4,7 @@ defmodule Mix.Tasks.Pleroma.Ecto.Migrate do use Mix.Task + import Mix.Pleroma require Logger @shortdoc "Wrapper on `ecto.migrate` task." @@ -37,6 +38,7 @@ defmodule Mix.Tasks.Pleroma.Ecto.Migrate do @impl true def run(args \\ []) do + load_pleroma() {opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases) opts = diff --git a/lib/mix/tasks/pleroma/ecto/rollback.ex b/lib/mix/tasks/pleroma/ecto/rollback.ex index 0033ceba4..2ffb0901c 100644 --- a/lib/mix/tasks/pleroma/ecto/rollback.ex +++ b/lib/mix/tasks/pleroma/ecto/rollback.ex @@ -4,6 +4,7 @@ defmodule Mix.Tasks.Pleroma.Ecto.Rollback do use Mix.Task + import Mix.Pleroma require Logger @shortdoc "Wrapper on `ecto.rollback` task" @@ -36,6 +37,7 @@ defmodule Mix.Tasks.Pleroma.Ecto.Rollback do @impl true def run(args \\ []) do + load_pleroma() {opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases) opts = From 19f16e829d2f5f800483aeb1f48aefca2504d1e6 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 22 Jun 2019 04:33:46 +0300 Subject: [PATCH 6/7] Load the application before executing the create task --- lib/pleroma/release_tasks.ex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/pleroma/release_tasks.ex b/lib/pleroma/release_tasks.ex index d6720cd05..8afabf463 100644 --- a/lib/pleroma/release_tasks.ex +++ b/lib/pleroma/release_tasks.ex @@ -44,6 +44,8 @@ defmodule Pleroma.ReleaseTasks do end def create do + Application.load(:pleroma) + case @repo.__adapter__.storage_up(@repo.config) do :ok -> IO.puts("The database for #{inspect(@repo)} has been created") From 642630140702cb22cafc2f2307c2ce2c031c95c7 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 22 Jun 2019 06:44:47 +0000 Subject: [PATCH 7/7] notifications: fix notification generation for non-create activities in 300d94c62, an Object.normalize() call was introduced. calling Object.normalize() on an activity with a non-object URI (say, a user) causes Really Bad Things to happen. so don't do that. --- lib/pleroma/notification.ex | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index e25692006..a414afbbf 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -127,8 +127,7 @@ defmodule Pleroma.Notification do end end - def create_notifications(%Activity{data: %{"to" => _, "type" => type}} = activity) - when type in ["Create", "Like", "Announce", "Follow"] do + def create_notifications(%Activity{data: %{"to" => _, "type" => "Create"}} = activity) do object = Object.normalize(activity) unless object && object.data["type"] == "Answer" do @@ -140,6 +139,13 @@ defmodule Pleroma.Notification do end end + def create_notifications(%Activity{data: %{"to" => _, "type" => type}} = activity) + when type in ["Like", "Announce", "Follow"] do + users = get_notified_from_activity(activity) + notifications = Enum.map(users, fn user -> create_notification(activity, user) end) + {:ok, notifications} + end + def create_notifications(_), do: {:ok, []} # TODO move to sql, too.