Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Change admin_uri to admin_contact in config and errors #3758

Merged
merged 3 commits into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3758.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix 'admin_uri' config variable and error parameter to be 'admin_contact' to match the spec.
4 changes: 2 additions & 2 deletions synapse/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ def check_auth_blocking(self, user_id=None):
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:
Expand All @@ -812,7 +812,7 @@ def check_auth_blocking(self, user_id=None):
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"
)
6 changes: 3 additions & 3 deletions synapse/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,18 @@ 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)

def error_dict(self):
return cs_error(
self.msg,
self.errcode,
admin_uri=self.admin_uri,
admin_contact=self.admin_contact,
limit_type=self.limit_type
)

Expand Down
4 changes: 2 additions & 2 deletions synapse/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def read_config(self, 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
Expand Down Expand Up @@ -357,7 +357,7 @@ def default_config(self, server_name, **kwargs):
# 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
#
Expand Down
2 changes: 1 addition & 1 deletion synapse/server_notices/resource_limits_server_notices.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def maybe_send_server_notice_to_user(self, user_id):
'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(
Expand Down
4 changes: 2 additions & 2 deletions tests/api/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def test_blocking_mau(self):

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)

Expand All @@ -473,7 +473,7 @@ def test_hs_disabled(self):
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)

Expand Down
4 changes: 2 additions & 2 deletions tests/server_notices/test_resource_limits_server_notices.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def setUp(self):
returnValue=""
)
self._rlsn._store.add_tag_to_room = Mock()
self.hs.config.admin_uri = "mailto:user@test.com"
self.hs.config.admin_contact = "mailto:user@test.com"

@defer.inlineCallbacks
def test_maybe_send_server_notice_to_user_flag_off(self):
Expand Down Expand Up @@ -172,7 +172,7 @@ def setUp(self):

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):
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down