Добавить автомодерацию: политики, порог жалоб, settings/hits API и тесты.
CI / test (push) Failing after 37m9s
CI / deploy-ift (push) Has been skipped
CI / e2e-ift (push) Has been skipped
CI / deploy-stage (push) Has been skipped
CI / e2e-stage (push) Has been skipped

Refs EventHub/EventHubBack#37
Refs EventHub/EventHubBack#38
Refs EventHub/EventHubBack#39
Refs EventHub/EventHubBack#40
This commit is contained in:
2026-07-17 18:09:31 +03:00
parent 4fa802702f
commit e9d1a13900
27 changed files with 1779 additions and 85 deletions
+68 -5
View File
@@ -1,8 +1,8 @@
-module(logic_event).
-include("records.hrl").
-export([create_event/5, create_recurring_event/6, get_event/2, list_events/2,
update_event/3, delete_event/2]).
-export([create_event/5, create_event/6, create_recurring_event/6, create_recurring_event/7,
get_event/2, list_events/2, update_event/3, delete_event/2]).
-export([validate_event_time/1, validate_event_time/2, get_occurrences/3, cancel_occurrence/3]).
-export([materialize_for_booking/3]).
-export([list_all_events/1, get_event_admin/1, update_event_admin/2, delete_event_admin/1]).
@@ -12,13 +12,31 @@
%% Создание одиночного события
create_event(UserId, CalendarId, Title, StartTime, Duration) ->
create_event(UserId, CalendarId, Title, StartTime, Duration, <<>>).
create_event(UserId, CalendarId, Title, StartTime, Duration, Description) ->
case logic_calendar:get_calendar(UserId, CalendarId) of
{ok, Calendar} ->
case logic_calendar:can_edit(UserId, Calendar) of
true ->
case validate_event_time(StartTime, UserId) of
ok ->
core_event:create(CalendarId, Title, StartTime, Duration);
case logic_automoderation:evaluate_texts([Title, Description]) of
{reject, Words} ->
{error, {content_banned, Words}};
{ok, Action, [Title2, Desc2], Words} ->
case core_event:create(CalendarId, Title2, StartTime, Duration) of
{ok, Event} ->
case Desc2 of
<<>> -> ok;
_ -> _ = core_event:update(Event#event.id, [{description, Desc2}])
end,
logic_automoderation:apply_after_save(event, Event#event.id, Action, Words),
core_event:get_by_id(Event#event.id);
Error ->
Error
end
end;
{error, _} = Error ->
Error
end;
@@ -31,6 +49,9 @@ create_event(UserId, CalendarId, Title, StartTime, Duration) ->
%% Создание повторяющегося события
create_recurring_event(UserId, CalendarId, Title, StartTime, Duration, RRule) ->
create_recurring_event(UserId, CalendarId, Title, StartTime, Duration, RRule, <<>>).
create_recurring_event(UserId, CalendarId, Title, StartTime, Duration, RRule, Description) ->
case logic_calendar:get_calendar(UserId, CalendarId) of
{ok, Calendar} ->
case logic_calendar:can_edit(UserId, Calendar) of
@@ -39,7 +60,22 @@ create_recurring_event(UserId, CalendarId, Title, StartTime, Duration, RRule) ->
ok ->
case logic_recurrence:validate_rrule(RRule) of
true ->
core_event:create_recurring(CalendarId, Title, StartTime, Duration, RRule);
case logic_automoderation:evaluate_texts([Title, Description]) of
{reject, Words} ->
{error, {content_banned, Words}};
{ok, Action, [Title2, Desc2], Words} ->
case core_event:create_recurring(CalendarId, Title2, StartTime, Duration, RRule) of
{ok, Event} ->
case Desc2 of
<<>> -> ok;
_ -> _ = core_event:update(Event#event.id, [{description, Desc2}])
end,
logic_automoderation:apply_after_save(event, Event#event.id, Action, Words),
core_event:get_by_id(Event#event.id);
Error ->
Error
end
end;
false ->
{error, invalid_rrule}
end;
@@ -141,7 +177,34 @@ update_event(UserId, EventId, Updates) ->
case logic_calendar:can_edit(UserId, Calendar) of
true ->
ValidUpdates = validate_updates(Updates, UserId),
core_event:update(EventId, ValidUpdates);
Title = proplists:get_value(title, ValidUpdates, Event#event.title),
Desc = proplists:get_value(description, ValidUpdates, Event#event.description),
case logic_automoderation:evaluate_texts([Title, Desc]) of
{reject, Words} ->
{error, {content_banned, Words}};
{ok, Action, [Title2, Desc2], Words} ->
Final0 = case lists:keymember(title, 1, ValidUpdates) of
true -> lists:keystore(title, 1, ValidUpdates, {title, Title2});
false -> ValidUpdates
end,
Final = case lists:keymember(description, 1, Final0) orelse Desc2 =/= Event#event.description of
true when Action =:= censor ->
lists:keystore(description, 1, Final0, {description, Desc2});
true ->
case lists:keymember(description, 1, Final0) of
true -> lists:keystore(description, 1, Final0, {description, Desc2});
false -> Final0
end;
false -> Final0
end,
case core_event:update(EventId, Final) of
{ok, _} ->
logic_automoderation:apply_after_save(event, EventId, Action, Words),
core_event:get_by_id(EventId);
Error ->
Error
end
end;
false ->
{error, access_denied}
end;