summaryrefslogtreecommitdiff
path: root/lib/pleroma
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pleroma')
-rw-r--r--lib/pleroma/application.ex2
-rw-r--r--lib/pleroma/conversation/participation.ex4
-rw-r--r--lib/pleroma/emoji.ex4
-rw-r--r--lib/pleroma/plugs/http_security_plug.ex4
-rw-r--r--lib/pleroma/release_tasks.ex64
-rw-r--r--lib/pleroma/web/activity_pub/transmogrifier.ex2
-rw-r--r--lib/pleroma/web/federator/retry_queue.ex6
-rw-r--r--lib/pleroma/web/rel_me.ex2
-rw-r--r--lib/pleroma/web/rich_media/parser.ex2
-rw-r--r--lib/pleroma/web/router.ex2
-rw-r--r--lib/pleroma/web/views/error_view.ex2
11 files changed, 81 insertions, 13 deletions
diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex
index 69a8a5761..5627d20af 100644
--- a/lib/pleroma/application.ex
+++ b/lib/pleroma/application.ex
@@ -194,7 +194,7 @@ defmodule Pleroma.Application do
end
end
- if Mix.env() == :test do
+ if Pleroma.Config.get(:env) == :test do
defp streamer_child, do: []
defp chat_child, do: []
else
diff --git a/lib/pleroma/conversation/participation.ex b/lib/pleroma/conversation/participation.ex
index 2c13c4b40..5883e4183 100644
--- a/lib/pleroma/conversation/participation.ex
+++ b/lib/pleroma/conversation/participation.ex
@@ -59,10 +59,10 @@ defmodule Pleroma.Conversation.Participation do
def for_user(user, params \\ %{}) do
from(p in __MODULE__,
where: p.user_id == ^user.id,
- order_by: [desc: p.updated_at]
+ order_by: [desc: p.updated_at],
+ preload: [conversation: [:users]]
)
|> Pleroma.Pagination.fetch_paginated(params)
- |> Repo.preload(conversation: [:users])
end
def for_user_with_last_activity_id(user, params \\ %{}) do
diff --git a/lib/pleroma/emoji.ex b/lib/pleroma/emoji.ex
index de7fcc1ce..b77b26f7f 100644
--- a/lib/pleroma/emoji.ex
+++ b/lib/pleroma/emoji.ex
@@ -98,7 +98,9 @@ defmodule Pleroma.Emoji do
Logger.error("Could not access the custom emoji directory #{emoji_dir_path}: #{e}")
{:ok, results} ->
- grouped = Enum.group_by(results, &File.dir?/1)
+ grouped =
+ Enum.group_by(results, fn file -> File.dir?(Path.join(emoji_dir_path, file)) end)
+
packs = grouped[true] || []
files = grouped[false] || []
diff --git a/lib/pleroma/plugs/http_security_plug.ex b/lib/pleroma/plugs/http_security_plug.ex
index 485ddfbc7..a7cc22831 100644
--- a/lib/pleroma/plugs/http_security_plug.ex
+++ b/lib/pleroma/plugs/http_security_plug.ex
@@ -56,14 +56,14 @@ defmodule Pleroma.Plugs.HTTPSecurityPlug do
connect_src = "connect-src 'self' #{static_url} #{websocket_url}"
connect_src =
- if Mix.env() == :dev do
+ if Pleroma.Config.get(:env) == :dev do
connect_src <> " http://localhost:3035/"
else
connect_src
end
script_src =
- if Mix.env() == :dev do
+ if Pleroma.Config.get(:env) == :dev do
"script-src 'self' 'unsafe-eval'"
else
"script-src 'self'"
diff --git a/lib/pleroma/release_tasks.ex b/lib/pleroma/release_tasks.ex
new file mode 100644
index 000000000..7726bc635
--- /dev/null
+++ b/lib/pleroma/release_tasks.ex
@@ -0,0 +1,64 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.ReleaseTasks do
+ @repo Pleroma.Repo
+
+ def run(args) do
+ Mix.Tasks.Pleroma.Common.start_pleroma()
+ [task | args] = String.split(args)
+
+ case task do
+ "migrate" -> migrate()
+ "create" -> create()
+ "rollback" -> rollback(String.to_integer(Enum.at(args, 0)))
+ task -> mix_task(task, args)
+ end
+ end
+
+ defp mix_task(task, args) do
+ {:ok, modules} = :application.get_key(:pleroma, :modules)
+
+ module =
+ Enum.find(modules, fn module ->
+ module = Module.split(module)
+
+ match?(["Mix", "Tasks", "Pleroma" | _], module) and
+ String.downcase(List.last(module)) == task
+ end)
+
+ if module do
+ module.run(args)
+ else
+ IO.puts("The task #{task} does not exist")
+ end
+ end
+
+ def migrate do
+ {:ok, _, _} = Ecto.Migrator.with_repo(@repo, &Ecto.Migrator.run(&1, :up, all: true))
+ end
+
+ def rollback(version) do
+ {:ok, _, _} = Ecto.Migrator.with_repo(@repo, &Ecto.Migrator.run(&1, :down, to: version))
+ end
+
+ def create do
+ case @repo.__adapter__.storage_up(@repo.config) do
+ :ok ->
+ IO.puts("The database for #{inspect(@repo)} has been created")
+
+ {:error, :already_up} ->
+ IO.puts("The database for #{inspect(@repo)} has already been created")
+
+ {:error, term} when is_binary(term) ->
+ IO.puts(:stderr, "The database for #{inspect(@repo)} couldn't be created: #{term}")
+
+ {:error, term} ->
+ IO.puts(
+ :stderr,
+ "The database for #{inspect(@repo)} couldn't be created: #{inspect(term)}"
+ )
+ end
+ end
+end
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index ff031a16e..3bb8b40b5 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -339,7 +339,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def fix_type(%{"inReplyTo" => reply_id} = object) when is_binary(reply_id) do
reply = Object.normalize(reply_id)
- if reply.data["type"] == "Question" and object["name"] do
+ if reply && (reply.data["type"] == "Question" and object["name"]) do
Map.put(object, "type", "Answer")
else
object
diff --git a/lib/pleroma/web/federator/retry_queue.ex b/lib/pleroma/web/federator/retry_queue.ex
index 71e49494f..3db948c2e 100644
--- a/lib/pleroma/web/federator/retry_queue.ex
+++ b/lib/pleroma/web/federator/retry_queue.ex
@@ -15,7 +15,9 @@ defmodule Pleroma.Web.Federator.RetryQueue do
def start_link do
enabled =
- if Mix.env() == :test, do: true, else: Pleroma.Config.get([__MODULE__, :enabled], false)
+ if Pleroma.Config.get(:env) == :test,
+ do: true,
+ else: Pleroma.Config.get([__MODULE__, :enabled], false)
if enabled do
Logger.info("Starting retry queue")
@@ -219,7 +221,7 @@ defmodule Pleroma.Web.Federator.RetryQueue do
{:noreply, state}
end
- if Mix.env() == :test do
+ if Pleroma.Config.get(:env) == :test do
defp growth_function(_retries) do
_shutit = Pleroma.Config.get([__MODULE__, :initial_timeout])
DateTime.to_unix(DateTime.utc_now()) - 1
diff --git a/lib/pleroma/web/rel_me.ex b/lib/pleroma/web/rel_me.ex
index 26eb614a6..d376e2069 100644
--- a/lib/pleroma/web/rel_me.ex
+++ b/lib/pleroma/web/rel_me.ex
@@ -10,7 +10,7 @@ defmodule Pleroma.Web.RelMe do
with_body: true
]
- if Mix.env() == :test do
+ if Pleroma.Config.get(:env) == :test do
def parse(url) when is_binary(url), do: parse_url(url)
else
def parse(url) when is_binary(url) do
diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex
index e4595800c..21cd47890 100644
--- a/lib/pleroma/web/rich_media/parser.ex
+++ b/lib/pleroma/web/rich_media/parser.ex
@@ -18,7 +18,7 @@ defmodule Pleroma.Web.RichMedia.Parser do
def parse(nil), do: {:error, "No URL provided"}
- if Mix.env() == :test do
+ if Pleroma.Config.get(:env) == :test do
def parse(url), do: parse_url(url)
else
def parse(url) do
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index e699f6ae2..1b37d6a93 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -699,7 +699,7 @@ defmodule Pleroma.Web.Router do
get("/:sig/:url/:filename", MediaProxyController, :remote)
end
- if Mix.env() == :dev do
+ if Pleroma.Config.get(:env) == :dev do
scope "/dev" do
pipe_through([:mailbox_preview])
diff --git a/lib/pleroma/web/views/error_view.ex b/lib/pleroma/web/views/error_view.ex
index f4c04131c..5cb8669fe 100644
--- a/lib/pleroma/web/views/error_view.ex
+++ b/lib/pleroma/web/views/error_view.ex
@@ -13,7 +13,7 @@ defmodule Pleroma.Web.ErrorView do
def render("500.json", assigns) do
Logger.error("Internal server error: #{inspect(assigns[:reason])}")
- if Mix.env() != :prod do
+ if Pleroma.Config.get(:env) != :prod do
%{errors: %{detail: "Internal server error", reason: inspect(assigns[:reason])}}
else
%{errors: %{detail: "Internal server error"}}