Fix tests and regressions
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
bfc1ee8a82
commit
4cab6a9db0
7 changed files with 34 additions and 26 deletions
|
@ -292,16 +292,22 @@ def set_read_up_to(%{id: user_id} = user, id) do
|
|||
|> Repo.transaction()
|
||||
|
||||
Streamer.stream(["user", "user:notification"], marker)
|
||||
|
||||
{:ok, %{marker: marker}}
|
||||
end
|
||||
|
||||
@spec read_one(User.t(), String.t()) ::
|
||||
{:ok, Notification.t()} | {:error, Ecto.Changeset.t()} | nil
|
||||
def read_one(%User{} = user, notification_id) do
|
||||
with {:ok, %Notification{} = notification} <- get(user, notification_id) do
|
||||
Multi.new()
|
||||
|> Multi.update(:update, changeset(notification, %{seen: true}))
|
||||
|> Marker.multi_set_last_read_id(user, "notifications")
|
||||
|> Repo.transaction()
|
||||
with {:ok, %Notification{} = notification} <- get(user, notification_id),
|
||||
{:ok, %{marker: marker}} <-
|
||||
Multi.new()
|
||||
|> Multi.update(:update, changeset(notification, %{seen: true}))
|
||||
|> Marker.multi_set_last_read_id(user, "notifications")
|
||||
|> Repo.transaction() do
|
||||
Streamer.stream(["user", "user:notification"], marker)
|
||||
|
||||
{:ok, %{marker: marker}}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -188,6 +188,8 @@ defp get_language_from_content(%{"content" => content}) do
|
|||
|
||||
defp get_language_from_content(_), do: nil
|
||||
|
||||
def maybe_add_content_map(%{"contentMap" => %{}} = object), do: object
|
||||
|
||||
def maybe_add_content_map(%{"language" => language, "content" => content} = object)
|
||||
when not_empty_string(language) do
|
||||
Map.put(object, "contentMap", Map.put(%{}, language, content))
|
||||
|
|
|
@ -215,7 +215,7 @@ def fix_context(object) do
|
|||
def fix_attachments(%{"attachment" => attachment} = object) when is_list(attachment) do
|
||||
attachments =
|
||||
attachment
|
||||
|> Enum.filter(fn data -> Map.has_key?(data, "url") end)
|
||||
|> Enum.filter(fn data -> Map.has_key?(data, "url") or Map.has_key?(data, "href") end)
|
||||
|> Enum.map(fn data ->
|
||||
url =
|
||||
cond do
|
||||
|
@ -342,6 +342,7 @@ def fix_tag(%{"tag" => %{} = tag} = object) do
|
|||
|
||||
def fix_tag(object), do: object
|
||||
|
||||
# prefer content over contentMap
|
||||
def fix_content_map(%{"content" => content} = object) when not_empty_string(content), do: object
|
||||
|
||||
# content map usually only has one language so this will do for now.
|
||||
|
|
|
@ -142,7 +142,7 @@ defp maybe_filter_requests(conn) do
|
|||
end
|
||||
|
||||
defp rejected_domains do
|
||||
Config.get([:instance, :rejected_instances])
|
||||
Config.get([:instance, :rejected_instances], [])
|
||||
|> Pleroma.Web.ActivityPub.MRF.instance_list_from_tuples()
|
||||
|> Pleroma.Web.ActivityPub.MRF.subdomains_regex()
|
||||
end
|
||||
|
|
|
@ -31,35 +31,44 @@ def get_by_type(type) do
|
|||
|> Repo.all()
|
||||
end
|
||||
|
||||
def changeset(%__MODULE__{} = webhook, params) do
|
||||
def changeset(%__MODULE__{} = webhook, params, opts \\ []) do
|
||||
webhook
|
||||
|> cast(params, [:url, :events, :enabled])
|
||||
|> maybe_update_internal(params, opts)
|
||||
|> validate_required([:url, :events])
|
||||
|> unique_constraint(:url)
|
||||
|> strip_events()
|
||||
|> put_secret()
|
||||
end
|
||||
|
||||
def update_changeset(%__MODULE__{} = webhook, params \\ %{}) do
|
||||
def update_changeset(%__MODULE__{} = webhook, params \\ %{}, opts \\ []) do
|
||||
webhook
|
||||
|> cast(params, [:url, :events, :enabled])
|
||||
|> maybe_update_internal(params, opts)
|
||||
|> unique_constraint(:url)
|
||||
|> strip_events()
|
||||
end
|
||||
|
||||
def create(params) do
|
||||
defp maybe_update_internal(webhook, params, update_internal: true) do
|
||||
webhook
|
||||
|> cast(params, [:internal])
|
||||
end
|
||||
|
||||
defp maybe_update_internal(webhook, _params, _opts), do: webhook
|
||||
|
||||
def create(params, opts \\ []) do
|
||||
{:ok, webhook} =
|
||||
%__MODULE__{}
|
||||
|> changeset(params)
|
||||
|> changeset(params, opts)
|
||||
|> Repo.insert()
|
||||
|
||||
webhook
|
||||
end
|
||||
|
||||
def update(%__MODULE__{} = webhook, params) do
|
||||
def update(%__MODULE__{} = webhook, params, opts \\ []) do
|
||||
{:ok, webhook} =
|
||||
webhook
|
||||
|> update_changeset(params)
|
||||
|> update_changeset(params, opts)
|
||||
|> Repo.update()
|
||||
|
||||
webhook
|
||||
|
|
|
@ -349,18 +349,6 @@ test "custom emoji urls are URI encoded" do
|
|||
assert url == "http://localhost:4001/emoji/dino%20walking.gif"
|
||||
end
|
||||
|
||||
test "it adds contentMap if language is specified" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "тест", language: "uk"})
|
||||
|
||||
{:ok, prepared} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
assert prepared["object"]["contentMap"] == %{
|
||||
"uk" => "тест"
|
||||
}
|
||||
end
|
||||
|
||||
test "it prepares a quote post" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
|
@ -67,7 +67,9 @@ test "edits a webhook", %{conn: conn} do
|
|||
|
||||
test "can't edit an internal webhook", %{conn: conn} do
|
||||
%{id: id} =
|
||||
Webhook.create(%{url: "https://example.com/webhook1", events: [], internal: true})
|
||||
Webhook.create(%{url: "https://example.com/webhook1", events: [], internal: true},
|
||||
update_internal: true
|
||||
)
|
||||
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|
|
Loading…
Reference in a new issue