Перенести все админские эндпоинты на порт 8445 и добавить отдельную авторизацию для админов. Часть 1

This commit is contained in:
2026-04-27 15:54:48 +03:00
parent 62bc62f990
commit 4ed6a961ab
40 changed files with 3573 additions and 800 deletions

View File

@@ -1,6 +1,5 @@
-module(admin_handler_stats).
-include("records.hrl").
-export([init/2]).
-export([count_users/0, count_calendars/0, count_events/0, count_bookings/0,
count_reviews/0, count_reports/0, count_tickets/0, count_subscriptions/0]).
@@ -41,33 +40,21 @@ get_stats(Req) ->
%% Вспомогательные функции
is_admin(UserId) ->
case core_user:get_by_id(UserId) of
{ok, User} -> User#user.role =:= admin;
{ok, User} ->
Role = User#user.role,
Role =:= admin orelse Role =:= superadmin orelse
Role =:= moderator orelse Role =:= support;
_ -> false
end.
count_users() ->
length(mnesia:dirty_match_object(#user{_ = '_'})).
count_calendars() ->
length(mnesia:dirty_match_object(#calendar{_ = '_'})).
count_events() ->
length(mnesia:dirty_match_object(#event{is_instance = false, _ = '_'})).
count_bookings() ->
length(mnesia:dirty_match_object(#booking{_ = '_'})).
count_reviews() ->
length(mnesia:dirty_match_object(#review{_ = '_'})).
count_reports() ->
length(mnesia:dirty_match_object(#report{_ = '_'})).
count_tickets() ->
length(mnesia:dirty_match_object(#ticket{_ = '_'})).
count_subscriptions() ->
length(mnesia:dirty_match_object(#subscription{_ = '_'})).
count_users() -> length(mnesia:dirty_match_object(#user{_ = '_'})).
count_calendars() -> length(mnesia:dirty_match_object(#calendar{_ = '_'})).
count_events() -> length(mnesia:dirty_match_object(#event{is_instance = false, _ = '_'})).
count_bookings() -> length(mnesia:dirty_match_object(#booking{_ = '_'})).
count_reviews() -> length(mnesia:dirty_match_object(#review{_ = '_'})).
count_reports() -> length(mnesia:dirty_match_object(#report{_ = '_'})).
count_tickets() -> length(mnesia:dirty_match_object(#ticket{_ = '_'})).
count_subscriptions() -> length(mnesia:dirty_match_object(#subscription{_ = '_'})).
send_json(Req, Status, Data) ->
Body = jsx:encode(Data),