Implement commercial calendars: booking_open, specialists, expire without type downgrade.
Refs EventHub/EventHubBack#54
This commit is contained in:
Regular → Executable
+52
-26
@@ -176,33 +176,38 @@ update_event(UserId, EventId, Updates) ->
|
||||
{ok, Calendar} ->
|
||||
case logic_calendar:can_edit(UserId, Calendar) of
|
||||
true ->
|
||||
ValidUpdates = validate_updates(Updates, UserId),
|
||||
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});
|
||||
case validate_specialist_update(Calendar, Updates) of
|
||||
{error, _} = E ->
|
||||
E;
|
||||
ok ->
|
||||
ValidUpdates = validate_updates(Updates, UserId),
|
||||
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;
|
||||
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,
|
||||
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
|
||||
end;
|
||||
false ->
|
||||
@@ -378,6 +383,8 @@ validate_update({start_time, Value}, UserId) ->
|
||||
end;
|
||||
validate_update({duration, Value}, _) when is_integer(Value), Value > 0 -> true;
|
||||
validate_update({specialist_id, Value}, _) when is_binary(Value) -> true;
|
||||
validate_update({specialist_id, null}, _) -> true;
|
||||
validate_update({specialist_id, undefined}, _) -> true;
|
||||
validate_update({location, Value}, _) ->
|
||||
case Value of
|
||||
#location{} -> true;
|
||||
@@ -389,6 +396,25 @@ validate_update({online_link, Value}, _) when is_binary(Value) -> true;
|
||||
validate_update({status, Value}, _) when is_atom(Value) -> true;
|
||||
validate_update(_, _) -> false.
|
||||
|
||||
validate_specialist_update(Calendar, Updates) ->
|
||||
case lists:keyfind(specialist_id, 1, Updates) of
|
||||
false -> ok;
|
||||
{specialist_id, null} -> ok;
|
||||
{specialist_id, undefined} -> ok;
|
||||
{specialist_id, <<>>} -> ok;
|
||||
{specialist_id, SpecId} when is_binary(SpecId) ->
|
||||
case Calendar#calendar.type of
|
||||
commercial ->
|
||||
case core_calendar_specialist:is_active_specialist(Calendar#calendar.id, SpecId) of
|
||||
true -> ok;
|
||||
false -> {error, invalid_specialist}
|
||||
end;
|
||||
_ ->
|
||||
{error, invalid_specialist}
|
||||
end;
|
||||
_ -> ok
|
||||
end.
|
||||
|
||||
get_exceptions(MasterId) ->
|
||||
Match = #recurrence_exception{master_id = MasterId, _ = '_'},
|
||||
mnesia:dirty_match_object(Match).
|
||||
|
||||
Reference in New Issue
Block a user