Модерация писала #{reason => ...} — UI падал с React #31.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -101,7 +101,7 @@ apply_moderation(<<"user">>, Id, Action, Reason, Req, AdminId) ->
|
||||
handle_calendar(Id, <<"freeze">>, Reason, Req, AdminId) ->
|
||||
case core_calendar:freeze(Id, Reason) of
|
||||
{ok, Calendar} ->
|
||||
admin_utils:log_admin_action(AdminId, <<"freeze_calendar">>, <<"calendar">>, #{id => Id}, #{reason => Reason}, Req),
|
||||
admin_utils:log_admin_action(AdminId, <<"freeze_calendar">>, <<"calendar">>, Id, Reason, Req),
|
||||
handler_utils:send_json(Req, 200, handler_utils:calendar_to_json(Calendar));
|
||||
{error, not_found} ->
|
||||
handler_utils:send_error(Req, 404, <<"Calendar not found">>)
|
||||
@@ -109,7 +109,7 @@ handle_calendar(Id, <<"freeze">>, Reason, Req, AdminId) ->
|
||||
handle_calendar(Id, <<"unfreeze">>, Reason, Req, AdminId) ->
|
||||
case core_calendar:unfreeze(Id, Reason) of
|
||||
{ok, Calendar} ->
|
||||
admin_utils:log_admin_action(AdminId, <<"unfreeze_calendar">>, <<"calendar">>, #{id => Id}, #{reason => Reason}, Req),
|
||||
admin_utils:log_admin_action(AdminId, <<"unfreeze_calendar">>, <<"calendar">>, Id, Reason, Req),
|
||||
handler_utils:send_json(Req, 200, handler_utils:calendar_to_json(Calendar));
|
||||
{error, not_found} ->
|
||||
handler_utils:send_error(Req, 404, <<"Calendar not found">>)
|
||||
@@ -120,7 +120,7 @@ handle_calendar(_Id, _Action, _Reason, Req, _AdminId) ->
|
||||
handle_event(Id, <<"freeze">>, Reason, Req, AdminId) ->
|
||||
case core_event:freeze(Id, Reason) of
|
||||
{ok, Event} ->
|
||||
admin_utils:log_admin_action(AdminId, <<"freeze_event">>, <<"event">>, #{id => Id}, #{reason => Reason}, Req),
|
||||
admin_utils:log_admin_action(AdminId, <<"freeze_event">>, <<"event">>, Id, Reason, Req),
|
||||
handler_utils:send_json(Req, 200, handler_utils:event_to_json(Event));
|
||||
{error, not_found} ->
|
||||
handler_utils:send_error(Req, 404, <<"Event not found">>)
|
||||
@@ -128,7 +128,7 @@ handle_event(Id, <<"freeze">>, Reason, Req, AdminId) ->
|
||||
handle_event(Id, <<"unfreeze">>, Reason, Req, AdminId) ->
|
||||
case core_event:unfreeze(Id, Reason) of
|
||||
{ok, Event} ->
|
||||
admin_utils:log_admin_action(AdminId, <<"unfreeze_event">>, <<"event">>, #{id => Id}, #{reason => Reason}, Req),
|
||||
admin_utils:log_admin_action(AdminId, <<"unfreeze_event">>, <<"event">>, Id, Reason, Req),
|
||||
handler_utils:send_json(Req, 200, handler_utils:event_to_json(Event));
|
||||
{error, not_found} ->
|
||||
handler_utils:send_error(Req, 404, <<"Event not found">>)
|
||||
@@ -139,7 +139,7 @@ handle_event(_Id, _Action, _Reason, Req, _AdminId) ->
|
||||
handle_review(Id, <<"hide">>, Reason, Req, AdminId) ->
|
||||
case core_review:hide(Id, Reason) of
|
||||
{ok, Review} ->
|
||||
admin_utils:log_admin_action(AdminId, <<"hide_review">>, <<"review">>, #{id => Id}, #{reason => Reason}, Req),
|
||||
admin_utils:log_admin_action(AdminId, <<"hide_review">>, <<"review">>, Id, Reason, Req),
|
||||
handler_utils:send_json(Req, 200, handler_utils:review_to_json(Review));
|
||||
{error, not_found} ->
|
||||
handler_utils:send_error(Req, 404, <<"Review not found">>)
|
||||
@@ -147,7 +147,7 @@ handle_review(Id, <<"hide">>, Reason, Req, AdminId) ->
|
||||
handle_review(Id, <<"unhide">>, Reason, Req, AdminId) ->
|
||||
case core_review:unhide(Id, Reason) of
|
||||
{ok, Review} ->
|
||||
admin_utils:log_admin_action(AdminId, <<"unhide_review">>, <<"review">>, #{id => Id}, #{reason => Reason}, Req),
|
||||
admin_utils:log_admin_action(AdminId, <<"unhide_review">>, <<"review">>, Id, Reason, Req),
|
||||
handler_utils:send_json(Req, 200, handler_utils:review_to_json(Review));
|
||||
{error, not_found} ->
|
||||
handler_utils:send_error(Req, 404, <<"Review not found">>)
|
||||
@@ -158,7 +158,7 @@ handle_review(_Id, _Action, _Reason, Req, _AdminId) ->
|
||||
handle_user(Id, <<"block">>, Reason, Req, AdminId) ->
|
||||
case core_user:block(Id, Reason) of
|
||||
{ok, User} ->
|
||||
admin_utils:log_admin_action(AdminId, <<"block_user">>, <<"user">>, #{id => Id}, #{reason => Reason}, Req),
|
||||
admin_utils:log_admin_action(AdminId, <<"block_user">>, <<"user">>, Id, Reason, Req),
|
||||
handler_utils:send_json(Req, 200, handler_utils:user_to_json(User));
|
||||
{error, not_found} ->
|
||||
handler_utils:send_error(Req, 404, <<"User not found">>)
|
||||
@@ -166,7 +166,7 @@ handle_user(Id, <<"block">>, Reason, Req, AdminId) ->
|
||||
handle_user(Id, <<"unblock">>, Reason, Req, AdminId) ->
|
||||
case core_user:unblock(Id, Reason) of
|
||||
{ok, User} ->
|
||||
admin_utils:log_admin_action(AdminId, <<"unblock_user">>, <<"user">>, #{id => Id}, #{reason => Reason}, Req),
|
||||
admin_utils:log_admin_action(AdminId, <<"unblock_user">>, <<"user">>, Id, Reason, Req),
|
||||
handler_utils:send_json(Req, 200, handler_utils:user_to_json(User));
|
||||
{error, not_found} ->
|
||||
handler_utils:send_error(Req, 404, <<"User not found">>)
|
||||
|
||||
@@ -202,12 +202,23 @@ audit_to_json(A) ->
|
||||
role => A#admin_audit.role,
|
||||
action => A#admin_audit.action,
|
||||
entity_type => A#admin_audit.entity_type,
|
||||
entity_id => A#admin_audit.entity_id,
|
||||
entity_id => audit_entity_id(A#admin_audit.entity_id),
|
||||
timestamp => handler_utils:datetime_to_iso8601(A#admin_audit.timestamp),
|
||||
ip => A#admin_audit.ip,
|
||||
reason => A#admin_audit.reason
|
||||
reason => audit_reason(A#admin_audit.reason)
|
||||
}.
|
||||
|
||||
audit_entity_id(Id) when is_binary(Id) -> Id;
|
||||
audit_entity_id(#{id := Id}) when is_binary(Id) -> Id;
|
||||
audit_entity_id(#{<<"id">> := Id}) when is_binary(Id) -> Id;
|
||||
audit_entity_id(V) ->
|
||||
iolist_to_binary(io_lib:format("~p", [V])).
|
||||
|
||||
audit_reason(R) when is_binary(R) -> R;
|
||||
audit_reason(#{reason := R}) when is_binary(R) -> R;
|
||||
audit_reason(#{<<"reason">> := R}) when is_binary(R) -> R;
|
||||
audit_reason(_) -> <<>>.
|
||||
|
||||
%% @doc Преобразует #event{} в JSON-карту.
|
||||
-spec event_to_json(#event{}) -> map().
|
||||
event_to_json(Event) ->
|
||||
|
||||
Reference in New Issue
Block a user