Fix ModerationLog FunctionClauseError for unknown actions
Add catchall clause to handle log entries with unknown actions or malformed data. Prevents HTTP 500 errors in admin moderation log view. Fixes #3385
This commit is contained in:
parent
d24e6eaf39
commit
bde52824d3
2 changed files with 39 additions and 0 deletions
|
|
@ -575,6 +575,12 @@ defmodule Pleroma.ModerationLog do
|
||||||
"@#{actor_nickname} requested account backup for @#{user_nickname}"
|
"@#{actor_nickname} requested account backup for @#{user_nickname}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_log_entry_message(%ModerationLog{data: data}) do
|
||||||
|
actor_name = get_in(data, ["actor", "nickname"]) || "unknown"
|
||||||
|
action = data["action"] || "unknown"
|
||||||
|
"@#{actor_name} performed action #{action}"
|
||||||
|
end
|
||||||
|
|
||||||
defp nicknames_to_string(nicknames) do
|
defp nicknames_to_string(nicknames) do
|
||||||
nicknames
|
nicknames
|
||||||
|> Enum.map(&"@#{&1}")
|
|> Enum.map(&"@#{&1}")
|
||||||
|
|
|
||||||
|
|
@ -308,4 +308,37 @@ defmodule Pleroma.ModerationLogTest do
|
||||||
assert log.data["message"] == "@#{moderator.nickname} deleted status ##{note.id}"
|
assert log.data["message"] == "@#{moderator.nickname} deleted status ##{note.id}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "get_log_entry_message/1" do
|
||||||
|
setup do
|
||||||
|
moderator = insert(:user, is_moderator: true)
|
||||||
|
[moderator: moderator]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "handles unknown action types gracefully", %{moderator: moderator} do
|
||||||
|
log_entry = %ModerationLog{
|
||||||
|
data: %{
|
||||||
|
"actor" => %{"nickname" => moderator.nickname},
|
||||||
|
"action" => "unknown_action",
|
||||||
|
"some_data" => "test_value"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert ModerationLog.get_log_entry_message(log_entry) =~ moderator.nickname
|
||||||
|
assert ModerationLog.get_log_entry_message(log_entry) =~ "unknown_action"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "handles malformed log entries gracefully" do
|
||||||
|
log_entry = %ModerationLog{
|
||||||
|
data: %{
|
||||||
|
"action" => "force_password_reset"
|
||||||
|
# Missing "actor" and "subject" fields
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message = ModerationLog.get_log_entry_message(log_entry)
|
||||||
|
assert is_binary(message)
|
||||||
|
assert message =~ "force_password_reset"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue