This commit is contained in:
2026-04-20 21:04:16 +03:00
parent b24cbc97f3
commit 19f82768e4
18 changed files with 1851 additions and 131 deletions

View File

@@ -1,11 +1,15 @@
-module(logic_calendar).
-include("records.hrl").
-export([create_calendar/4, get_calendar/2, list_calendars/1,
-export([create_calendar/3, create_calendar/4, get_calendar/2, list_calendars/1,
update_calendar/3, delete_calendar/2]).
-export([can_access/2, can_edit/2]).
%% Создание календаря
%% Создание календаря с политикой по умолчанию (manual)
create_calendar(UserId, Title, Description) ->
create_calendar(UserId, Title, Description, manual).
%% Создание календаря с указанной политикой подтверждения
create_calendar(UserId, Title, Description, Confirmation) ->
case core_user:get_by_id(UserId) of
{ok, User} ->
@@ -41,7 +45,6 @@ update_calendar(UserId, CalendarId, Updates) ->
{ok, Calendar} ->
case can_edit(UserId, Calendar) of
true ->
% Валидация обновлений
ValidUpdates = validate_updates(Updates),
core_calendar:update(CalendarId, ValidUpdates);
false ->
@@ -66,13 +69,20 @@ delete_calendar(UserId, CalendarId) ->
end.
%% Проверка прав доступа (просмотр)
can_access(UserId, #calendar{owner_id = UserId, status = active}) -> true;
can_access(_UserId, #calendar{type = commercial, status = active}) -> true;
can_access(_UserId, _) -> false.
can_access(UserId, #calendar{owner_id = UserId, status = active}) ->
true;
can_access(_UserId, #calendar{type = commercial, status = active}) ->
true;
can_access(_UserId, _) ->
false.
%% Проверка прав редактирования
can_edit(UserId, #calendar{owner_id = UserId, status = active}) -> true;
can_edit(_, _) -> false.
can_edit(UserId, #calendar{owner_id = UserId, status = active}) ->
true;
can_edit(_UserId, #calendar{owner_id = _OwnerId}) ->
false;
can_edit(_, _) ->
false.
%% Валидация полей обновления
validate_updates(Updates) ->