switch config to a bool and write tests
This commit is contained in:
@@ -169,7 +169,7 @@ class ServerConfig(Config):
|
||||
)
|
||||
|
||||
self.mau_trial_days = config.get("mau_trial_days", 0)
|
||||
self.mau_alerting_threshold = config.get('mau_alerting_threshold', 0)
|
||||
self.mau_suppress_alerting = config.get('mau_suppress_alerting', False)
|
||||
|
||||
# How long to keep redacted events in the database in unredacted form
|
||||
# before redacting them.
|
||||
@@ -694,16 +694,15 @@ class ServerConfig(Config):
|
||||
# sign up in a short space of time never to return after their initial
|
||||
# session.
|
||||
#
|
||||
# 'mau_alerting_threshold' is a means of limiting client side alerting
|
||||
# 'mau_suppress_alerting' is a means of limiting client side alerting
|
||||
# should the mau limit be reached. This is useful for small instances
|
||||
# where the admin has 5 mau seats (say) for 5 specific people and no
|
||||
# interest increasing the mau limit further. Defaults to 0 which denotes
|
||||
# that the option is disabled.
|
||||
# interest increasing the mau limit further. Defaults to False.
|
||||
#
|
||||
#limit_usage_by_mau: False
|
||||
#max_mau_value: 50
|
||||
#mau_trial_days: 2
|
||||
#mau_alerting_threshold: 10
|
||||
#mau_suppress_alerting: True
|
||||
|
||||
# If enabled, the metrics for the number of monthly active users will
|
||||
# be populated, however no one will be limited. If limit_usage_by_mau
|
||||
|
||||
@@ -91,10 +91,7 @@ class ResourceLimitsServerNotices(object):
|
||||
currently_blocked, ref_events = yield self._is_room_currently_blocked(room_id)
|
||||
|
||||
try:
|
||||
if (
|
||||
self._config.mau_alerting_threshold > 0
|
||||
and self._config.mau_alerting_threshold > self._config.max_mau_value
|
||||
):
|
||||
if self._config.mau_suppress_alerting:
|
||||
# Alerting disabled, reset room if necessary and return
|
||||
if currently_blocked:
|
||||
content = {"pinned": ref_events}
|
||||
|
||||
@@ -158,6 +158,41 @@ class TestResourceLimitsServerNotices(unittest.HomeserverTestCase):
|
||||
|
||||
self._send_notice.assert_not_called()
|
||||
|
||||
def test_maybe_send_server_notice_when_alerting_suppressed_room_unblocked(self):
|
||||
"""
|
||||
Test that when server is over MAU limit and alerting is suppressed, then
|
||||
an alert message is not sent into the room
|
||||
"""
|
||||
self.hs.config.mau_suppress_alerting = True
|
||||
self._rlsn._auth.check_auth_blocking = Mock(
|
||||
side_effect=ResourceLimitError(403, "foo")
|
||||
)
|
||||
self.get_success(self._rlsn.maybe_send_server_notice_to_user(self.user_id))
|
||||
|
||||
self.assertTrue(self._send_notice.call_count == 0)
|
||||
|
||||
def test_maybe_send_server_notice_when_alerting_suppressed_room_blocked(self):
|
||||
"""
|
||||
When the room is already in a blocked state, test that when alerting
|
||||
is suppressed that the room is returned to an unblocked state.
|
||||
"""
|
||||
self.hs.config.mau_suppress_alerting = True
|
||||
self._rlsn._auth.check_auth_blocking = Mock(
|
||||
side_effect=ResourceLimitError(403, "foo")
|
||||
)
|
||||
self._rlsn._server_notices_manager.__is_room_currently_blocked = Mock(
|
||||
return_value=defer.succeed((True, []))
|
||||
)
|
||||
|
||||
mock_event = Mock(
|
||||
type=EventTypes.Message, content={"msgtype": ServerNoticeMsgType}
|
||||
)
|
||||
self._rlsn._store.get_events = Mock(
|
||||
return_value=defer.succeed({"123": mock_event})
|
||||
)
|
||||
self.get_success(self._rlsn.maybe_send_server_notice_to_user(self.user_id))
|
||||
|
||||
self._send_notice.assert_called_once()
|
||||
|
||||
class TestResourceLimitsServerNoticesWithRealRooms(unittest.HomeserverTestCase):
|
||||
def prepare(self, reactor, clock, hs):
|
||||
|
||||
Reference in New Issue
Block a user