Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9fbaed325f | ||
|
|
9db2476991 | ||
|
|
69f7f1418f | ||
|
|
48b04c4a4c | ||
|
|
08abe8e13c | ||
|
|
05077e06fa | ||
|
|
01a5a8b9e3 | ||
|
|
897d976c1e | ||
|
|
45fc0ead10 | ||
|
|
cdd24449ee | ||
|
|
14d49c51db |
1
changelog.d/3755.bugfix
Normal file
1
changelog.d/3755.bugfix
Normal file
@@ -0,0 +1 @@
|
||||
Fix tagging of server notice rooms
|
||||
1
changelog.d/3756.bugfix
Normal file
1
changelog.d/3756.bugfix
Normal file
@@ -0,0 +1 @@
|
||||
Fix tagging of server notice rooms
|
||||
1
changelog.d/3758.bugfix
Normal file
1
changelog.d/3758.bugfix
Normal file
@@ -0,0 +1 @@
|
||||
Fix 'admin_uri' config variable and error parameter to be 'admin_contact' to match the spec.
|
||||
@@ -793,7 +793,7 @@ class Auth(object):
|
||||
raise ResourceLimitError(
|
||||
403, self.hs.config.hs_disabled_message,
|
||||
errcode=Codes.RESOURCE_LIMIT_EXCEEDED,
|
||||
admin_uri=self.hs.config.admin_uri,
|
||||
admin_contact=self.hs.config.admin_contact,
|
||||
limit_type=self.hs.config.hs_disabled_limit_type
|
||||
)
|
||||
if self.hs.config.limit_usage_by_mau is True:
|
||||
@@ -812,7 +812,7 @@ class Auth(object):
|
||||
raise ResourceLimitError(
|
||||
403, "Monthly Active User Limit Exceeded",
|
||||
|
||||
admin_uri=self.hs.config.admin_uri,
|
||||
admin_contact=self.hs.config.admin_contact,
|
||||
errcode=Codes.RESOURCE_LIMIT_EXCEEDED,
|
||||
limit_type="monthly_active_user"
|
||||
)
|
||||
|
||||
@@ -239,10 +239,10 @@ class ResourceLimitError(SynapseError):
|
||||
def __init__(
|
||||
self, code, msg,
|
||||
errcode=Codes.RESOURCE_LIMIT_EXCEEDED,
|
||||
admin_uri=None,
|
||||
admin_contact=None,
|
||||
limit_type=None,
|
||||
):
|
||||
self.admin_uri = admin_uri
|
||||
self.admin_contact = admin_contact
|
||||
self.limit_type = limit_type
|
||||
super(ResourceLimitError, self).__init__(code, msg, errcode=errcode)
|
||||
|
||||
@@ -250,7 +250,7 @@ class ResourceLimitError(SynapseError):
|
||||
return cs_error(
|
||||
self.msg,
|
||||
self.errcode,
|
||||
admin_uri=self.admin_uri,
|
||||
admin_contact=self.admin_contact,
|
||||
limit_type=self.limit_type
|
||||
)
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ class ServerConfig(Config):
|
||||
|
||||
# Admin uri to direct users at should their instance become blocked
|
||||
# due to resource constraints
|
||||
self.admin_uri = config.get("admin_uri", None)
|
||||
self.admin_contact = config.get("admin_contact", None)
|
||||
|
||||
# FIXME: federation_domain_whitelist needs sytests
|
||||
self.federation_domain_whitelist = None
|
||||
@@ -357,7 +357,7 @@ class ServerConfig(Config):
|
||||
# Homeserver blocking
|
||||
#
|
||||
# How to reach the server admin, used in ResourceLimitError
|
||||
# admin_uri: 'mailto:admin@server.com'
|
||||
# admin_contact: 'mailto:admin@server.com'
|
||||
#
|
||||
# Global block config
|
||||
#
|
||||
|
||||
@@ -46,6 +46,8 @@ class ResourceLimitsServerNotices(object):
|
||||
self._message_handler = hs.get_message_handler()
|
||||
self._state = hs.get_state_handler()
|
||||
|
||||
self._notifier = hs.get_notifier()
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def maybe_send_server_notice_to_user(self, user_id):
|
||||
"""Check if we need to send a notice to this user, this will be true in
|
||||
@@ -116,7 +118,7 @@ class ResourceLimitsServerNotices(object):
|
||||
'body': event_content,
|
||||
'msgtype': ServerNoticeMsgType,
|
||||
'server_notice_type': ServerNoticeLimitReached,
|
||||
'admin_uri': self._config.admin_uri,
|
||||
'admin_contact': self._config.admin_contact,
|
||||
'limit_type': event_limit_type
|
||||
}
|
||||
event = yield self._server_notices_manager.send_notice(
|
||||
@@ -144,16 +146,18 @@ class ResourceLimitsServerNotices(object):
|
||||
user_id(str): the user in question
|
||||
room_id(str): the server notices room for that user
|
||||
"""
|
||||
tags = yield self._store.get_tags_for_user(user_id)
|
||||
server_notices_tags = tags.get(room_id)
|
||||
tags = yield self._store.get_tags_for_room(user_id, room_id)
|
||||
need_to_set_tag = True
|
||||
if server_notices_tags:
|
||||
if server_notices_tags.get(SERVER_NOTICE_ROOM_TAG):
|
||||
if tags:
|
||||
if SERVER_NOTICE_ROOM_TAG in tags:
|
||||
# tag already present, nothing to do here
|
||||
need_to_set_tag = False
|
||||
if need_to_set_tag:
|
||||
yield self._store.add_tag_to_room(
|
||||
user_id, room_id, SERVER_NOTICE_ROOM_TAG, None
|
||||
max_id = yield self._store.add_tag_to_room(
|
||||
user_id, room_id, SERVER_NOTICE_ROOM_TAG, {}
|
||||
)
|
||||
self._notifier.on_new_event(
|
||||
"account_data_key", max_id, users=[user_id]
|
||||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
|
||||
@@ -39,6 +39,8 @@ class ServerNoticesManager(object):
|
||||
self._event_creation_handler = hs.get_event_creation_handler()
|
||||
self._is_mine_id = hs.is_mine_id
|
||||
|
||||
self._notifier = hs.get_notifier()
|
||||
|
||||
def is_enabled(self):
|
||||
"""Checks if server notices are enabled on this server.
|
||||
|
||||
@@ -153,8 +155,12 @@ class ServerNoticesManager(object):
|
||||
creator_join_profile=join_profile,
|
||||
)
|
||||
room_id = info['room_id']
|
||||
yield self._store.add_tag_to_room(
|
||||
user_id, room_id, SERVER_NOTICE_ROOM_TAG, None
|
||||
|
||||
max_id = yield self._store.add_tag_to_room(
|
||||
user_id, room_id, SERVER_NOTICE_ROOM_TAG, {},
|
||||
)
|
||||
self._notifier.on_new_event(
|
||||
"account_data_key", max_id, users=[user_id]
|
||||
)
|
||||
|
||||
logger.info("Created server notices room %s for %s", room_id, user_id)
|
||||
|
||||
@@ -457,7 +457,7 @@ class AuthTestCase(unittest.TestCase):
|
||||
|
||||
with self.assertRaises(ResourceLimitError) as e:
|
||||
yield self.auth.check_auth_blocking()
|
||||
self.assertEquals(e.exception.admin_uri, self.hs.config.admin_uri)
|
||||
self.assertEquals(e.exception.admin_contact, self.hs.config.admin_contact)
|
||||
self.assertEquals(e.exception.errcode, Codes.RESOURCE_LIMIT_EXCEEDED)
|
||||
self.assertEquals(e.exception.code, 403)
|
||||
|
||||
@@ -473,7 +473,7 @@ class AuthTestCase(unittest.TestCase):
|
||||
self.hs.config.hs_disabled_message = "Reason for being disabled"
|
||||
with self.assertRaises(ResourceLimitError) as e:
|
||||
yield self.auth.check_auth_blocking()
|
||||
self.assertEquals(e.exception.admin_uri, self.hs.config.admin_uri)
|
||||
self.assertEquals(e.exception.admin_contact, self.hs.config.admin_contact)
|
||||
self.assertEquals(e.exception.errcode, Codes.RESOURCE_LIMIT_EXCEEDED)
|
||||
self.assertEquals(e.exception.code, 403)
|
||||
|
||||
|
||||
@@ -55,7 +55,8 @@ class TestResourceLimitsServerNotices(unittest.TestCase):
|
||||
returnValue=""
|
||||
)
|
||||
self._rlsn._store.add_tag_to_room = Mock()
|
||||
self.hs.config.admin_uri = "mailto:user@test.com"
|
||||
self._rlsn._store.get_tags_for_room = Mock(return_value={})
|
||||
self.hs.config.admin_contact = "mailto:user@test.com"
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_maybe_send_server_notice_to_user_flag_off(self):
|
||||
@@ -172,7 +173,7 @@ class TestResourceLimitsServerNoticesWithRealRooms(unittest.TestCase):
|
||||
|
||||
self.user_id = "@user_id:test"
|
||||
|
||||
self.hs.config.admin_uri = "mailto:user@test.com"
|
||||
self.hs.config.admin_contact = "mailto:user@test.com"
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_server_notice_only_sent_once(self):
|
||||
|
||||
@@ -142,7 +142,7 @@ def setup_test_homeserver(
|
||||
config.hs_disabled_limit_type = ""
|
||||
config.max_mau_value = 50
|
||||
config.mau_limits_reserved_threepids = []
|
||||
config.admin_uri = None
|
||||
config.admin_contact = None
|
||||
|
||||
# we need a sane default_room_version, otherwise attempts to create rooms will
|
||||
# fail.
|
||||
|
||||
Reference in New Issue
Block a user