Ролевая модель и аудит Часть 1.

This commit is contained in:
2026-04-28 19:12:02 +03:00
parent 7ea4efd7d9
commit b2cea7896d
32 changed files with 369 additions and 320 deletions
+11 -17
View File
@@ -43,20 +43,20 @@ create_report(ReporterId, TargetType, TargetId, Reason) ->
end.
get_reports(AdminId) ->
case is_admin(AdminId) of
case admin_utils:is_admin(AdminId) of
true -> core_report:list_all();
false -> {error, access_denied}
end.
get_reports_by_target(AdminId, TargetType, TargetId) ->
case is_admin(AdminId) of
case admin_utils:is_admin(AdminId) of
true -> core_report:list_by_target(TargetType, TargetId);
false -> {error, access_denied}
end.
resolve_report(AdminId, ReportId, Action)
when Action =:= reviewed; Action =:= dismissed ->
case is_admin(AdminId) of
case admin_utils:is_admin(AdminId) of
true ->
case core_report:get_by_id(ReportId) of
{ok, Report} ->
@@ -99,19 +99,19 @@ auto_freeze(_, _) -> ok.
%% ============ Бан-лист ===================================
add_banned_word(AdminId, Word) ->
case is_admin(AdminId) of
case admin_utils:is_admin(AdminId) of
true -> core_banned_words:add_banned_word(Word, AdminId);
false -> {error, access_denied}
end.
remove_banned_word(AdminId, Word) ->
case is_admin(AdminId) of
case admin_utils:is_admin(AdminId) of
true -> core_banned_words:remove_banned_word(Word);
false -> {error, access_denied}
end.
list_banned_words(AdminId) ->
case is_admin(AdminId) of
case admin_utils:is_admin(AdminId) of
true -> {ok, core_banned_words:list_banned_words()};
false -> {error, access_denied}
end.
@@ -143,7 +143,7 @@ auto_moderate(Text) ->
%% ============ Заморозка/разморозка =======================
freeze_calendar(AdminId, CalendarId) ->
case is_admin(AdminId) of
case admin_utils:is_admin(AdminId) of
true ->
case core_calendar:get_by_id(CalendarId) of
{ok, _Calendar} ->
@@ -154,7 +154,7 @@ freeze_calendar(AdminId, CalendarId) ->
end.
unfreeze_calendar(AdminId, CalendarId) ->
case is_admin(AdminId) of
case admin_utils:is_admin(AdminId) of
true ->
case core_calendar:get_by_id(CalendarId) of
{ok, _Calendar} ->
@@ -165,7 +165,7 @@ unfreeze_calendar(AdminId, CalendarId) ->
end.
freeze_event(AdminId, EventId) ->
case is_admin(AdminId) of
case admin_utils:is_admin(AdminId) of
true ->
case core_event:get_by_id(EventId) of
{ok, _Event} ->
@@ -176,7 +176,7 @@ freeze_event(AdminId, EventId) ->
end.
unfreeze_event(AdminId, EventId) ->
case is_admin(AdminId) of
case admin_utils:is_admin(AdminId) of
true ->
case core_event:get_by_id(EventId) of
{ok, _Event} ->
@@ -198,10 +198,4 @@ target_exists(calendar, CalendarId) ->
{ok, _} -> true;
_ -> false
end;
target_exists(_, _) -> false.
is_admin(UserId) ->
case core_user:get_by_id(UserId) of
{ok, User} -> User#user.role =:= admin;
_ -> false
end.
target_exists(_, _) -> false.