feat(push): scope read clears to the enrolled cohort (#2935)

This commit is contained in:
Hampus
2026-09-24 15:15:45 +02:00
committed by GitHub
parent a90991612c
commit 963ffc5550
3 changed files with 35 additions and 1 deletions
@@ -81,6 +81,9 @@ env_gateway_base_config() ->
<<"push_clear_notifications_enabled">> => env_bool( <<"push_clear_notifications_enabled">> => env_bool(
"FLUXER_GATEWAY_PUSH_CLEAR_NOTIFICATIONS_ENABLED", true "FLUXER_GATEWAY_PUSH_CLEAR_NOTIFICATIONS_ENABLED", true
), ),
<<"push_enrolled_clear_notifications_enabled">> => env_bool(
"FLUXER_GATEWAY_PUSH_ENROLLED_CLEAR_NOTIFICATIONS_ENABLED", true
),
<<"push_endpoint_guard_enabled">> => env_bool( <<"push_endpoint_guard_enabled">> => env_bool(
"FLUXER_GATEWAY_PUSH_ENDPOINT_GUARD_ENABLED", true "FLUXER_GATEWAY_PUSH_ENDPOINT_GUARD_ENABLED", true
), ),
@@ -259,6 +262,9 @@ build_push_config(Service, Public) ->
push_clear_notifications_enabled => get_bool( push_clear_notifications_enabled => get_bool(
Service, <<"push_clear_notifications_enabled">>, true Service, <<"push_clear_notifications_enabled">>, true
), ),
push_enrolled_clear_notifications_enabled => get_bool(
Service, <<"push_enrolled_clear_notifications_enabled">>, true
),
push_endpoint_guard_enabled => get_bool( push_endpoint_guard_enabled => get_bool(
Service, <<"push_endpoint_guard_enabled">>, true Service, <<"push_endpoint_guard_enabled">>, true
), ),
+10 -1
View File
@@ -246,7 +246,9 @@ clear_channel_notifications(UserId, ChannelId, MessageId) ->
-spec clear_for_enrolment(boolean(), integer(), integer(), integer()) -> ok. -spec clear_for_enrolment(boolean(), integer(), integer(), integer()) -> ok.
clear_for_enrolment(true, UserId, ChannelId, MessageId) -> clear_for_enrolment(true, UserId, ChannelId, MessageId) ->
ok = push_outbox:truncate_read(UserId, ChannelId, MessageId), ok = push_outbox:truncate_read(UserId, ChannelId, MessageId),
cast_clear_if_enabled(clear_notifications_enabled(), UserId, ChannelId, MessageId); cast_clear_if_enabled(
enrolled_clear_notifications_enabled(), UserId, ChannelId, MessageId
);
clear_for_enrolment(false, UserId, ChannelId, MessageId) -> clear_for_enrolment(false, UserId, ChannelId, MessageId) ->
cast_clear_if_enabled(clear_notifications_enabled(), UserId, ChannelId, MessageId). cast_clear_if_enabled(clear_notifications_enabled(), UserId, ChannelId, MessageId).
@@ -256,6 +258,13 @@ cast_clear_if_enabled(true, UserId, ChannelId, MessageId) ->
cast_clear_if_enabled(false, _UserId, _ChannelId, _MessageId) -> cast_clear_if_enabled(false, _UserId, _ChannelId, _MessageId) ->
ok. ok.
-spec enrolled_clear_notifications_enabled() -> boolean().
enrolled_clear_notifications_enabled() ->
case persistent_term:get(push_enrolled_clear_notifications_enabled, undefined) of
OperatorChoice when is_boolean(OperatorChoice) -> OperatorChoice;
_ -> env_boolean(push_enrolled_clear_notifications_enabled, true)
end.
-spec clear_notifications_enabled() -> boolean(). -spec clear_notifications_enabled() -> boolean().
clear_notifications_enabled() -> clear_notifications_enabled() ->
case persistent_term:get(push_clear_notifications_enabled, undefined) of case persistent_term:get(push_clear_notifications_enabled, undefined) of
+19
View File
@@ -47,6 +47,25 @@ a_clear_is_dropped_only_after_the_retry_budget_is_spent_test() ->
meck:unload(push_dispatcher) meck:unload(push_dispatcher)
end. end.
an_enrolled_user_gets_clears_while_the_fleet_switch_is_off_test() ->
erase_persistent_term(push_noop),
erase_persistent_term(push_enrolled_clear_notifications_enabled),
persistent_term:put(push_clear_notifications_enabled, false),
try
?assertEqual(ok, push:clear_channel_notifications(1, 2, 3))
after
erase_persistent_term(push_clear_notifications_enabled)
end.
the_cohort_switch_can_be_turned_off_on_its_own_test() ->
erase_persistent_term(push_noop),
persistent_term:put(push_enrolled_clear_notifications_enabled, false),
try
?assertEqual(ok, push:clear_channel_notifications(1, 2, 3))
after
erase_persistent_term(push_enrolled_clear_notifications_enabled)
end.
push_owner_key_prefers_first_recipient_test() -> push_owner_key_prefers_first_recipient_test() ->
?assertEqual( ?assertEqual(
42, 42,