forked from MirrorHub/synapse
clean up config error logic and imports
This commit is contained in:
parent
1ccafb0c5e
commit
c6584f4b5f
3 changed files with 21 additions and 20 deletions
|
@ -1 +1 @@
|
||||||
Servers with auto join rooms, should autocreate those rooms when first user registers
|
Servers with auto-join rooms, should automatically create those rooms when first user registers
|
||||||
|
|
|
@ -15,11 +15,10 @@
|
||||||
|
|
||||||
from distutils.util import strtobool
|
from distutils.util import strtobool
|
||||||
|
|
||||||
from synapse.config._base import ConfigError
|
|
||||||
from synapse.types import RoomAlias
|
from synapse.types import RoomAlias
|
||||||
from synapse.util.stringutils import random_string_with_symbols
|
from synapse.util.stringutils import random_string_with_symbols
|
||||||
|
|
||||||
from ._base import Config
|
from ._base import Config, ConfigError
|
||||||
|
|
||||||
|
|
||||||
class RegistrationConfig(Config):
|
class RegistrationConfig(Config):
|
||||||
|
@ -48,7 +47,7 @@ class RegistrationConfig(Config):
|
||||||
self.auto_join_rooms = config.get("auto_join_rooms", [])
|
self.auto_join_rooms = config.get("auto_join_rooms", [])
|
||||||
for room_alias in self.auto_join_rooms:
|
for room_alias in self.auto_join_rooms:
|
||||||
if not RoomAlias.is_valid(room_alias):
|
if not RoomAlias.is_valid(room_alias):
|
||||||
raise ConfigError('Invalid auto_join_rooms entry %s' % room_alias)
|
raise ConfigError('Invalid auto_join_rooms entry %s' % (room_alias,))
|
||||||
self.autocreate_auto_join_rooms = config.get("autocreate_auto_join_rooms", True)
|
self.autocreate_auto_join_rooms = config.get("autocreate_auto_join_rooms", True)
|
||||||
|
|
||||||
def default_config(self, **kwargs):
|
def default_config(self, **kwargs):
|
||||||
|
@ -106,10 +105,10 @@ class RegistrationConfig(Config):
|
||||||
# - "#example:example.com"
|
# - "#example:example.com"
|
||||||
|
|
||||||
# Where auto_join_rooms are specified, setting this flag ensures that the
|
# Where auto_join_rooms are specified, setting this flag ensures that the
|
||||||
# the rooms exists by creating them when the first user on the
|
# the rooms exist by creating them when the first user on the
|
||||||
# homeserver registers.
|
# homeserver registers.
|
||||||
# Setting to false means that if the rooms are not manually created,
|
# Setting to false means that if the rooms are not manually created,
|
||||||
# users cannot be auto joined since they do not exist.
|
# users cannot be auto-joined since they do not exist.
|
||||||
autocreate_auto_join_rooms: true
|
autocreate_auto_join_rooms: true
|
||||||
""" % locals()
|
""" % locals()
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ from synapse.api.errors import (
|
||||||
RegistrationError,
|
RegistrationError,
|
||||||
SynapseError,
|
SynapseError,
|
||||||
)
|
)
|
||||||
from synapse.config._base import ConfigError
|
|
||||||
from synapse.http.client import CaptchaServerHttpClient
|
from synapse.http.client import CaptchaServerHttpClient
|
||||||
from synapse.types import RoomAlias, RoomID, UserID, create_requester
|
from synapse.types import RoomAlias, RoomID, UserID, create_requester
|
||||||
from synapse.util.async_helpers import Linearizer
|
from synapse.util.async_helpers import Linearizer
|
||||||
|
@ -51,6 +50,7 @@ class RegistrationHandler(BaseHandler):
|
||||||
self._auth_handler = hs.get_auth_handler()
|
self._auth_handler = hs.get_auth_handler()
|
||||||
self.profile_handler = hs.get_profile_handler()
|
self.profile_handler = hs.get_profile_handler()
|
||||||
self.user_directory_handler = hs.get_user_directory_handler()
|
self.user_directory_handler = hs.get_user_directory_handler()
|
||||||
|
self.room_creation_handler = self.hs.get_room_creation_handler()
|
||||||
self.captcha_client = CaptchaServerHttpClient(hs)
|
self.captcha_client = CaptchaServerHttpClient(hs)
|
||||||
|
|
||||||
self._next_generated_user_id = None
|
self._next_generated_user_id = None
|
||||||
|
@ -231,21 +231,23 @@ class RegistrationHandler(BaseHandler):
|
||||||
for r in self.hs.config.auto_join_rooms:
|
for r in self.hs.config.auto_join_rooms:
|
||||||
try:
|
try:
|
||||||
if should_auto_create_rooms:
|
if should_auto_create_rooms:
|
||||||
room_creation_handler = self.hs.get_room_creation_handler()
|
|
||||||
if self.hs.hostname != RoomAlias.from_string(r).domain:
|
if self.hs.hostname != RoomAlias.from_string(r).domain:
|
||||||
raise ConfigError(
|
logger.warn(
|
||||||
'Cannot create room alias %s, it does not match server domain'
|
'Cannot create room alias %s, '
|
||||||
|
'it does not match server domain' % (r,)
|
||||||
|
)
|
||||||
|
raise SynapseError()
|
||||||
|
else:
|
||||||
|
# create room expects the localpart of the room alias
|
||||||
|
room_alias_localpart = RoomAlias.from_string(r).localpart
|
||||||
|
yield self.room_creation_handler.create_room(
|
||||||
|
fake_requester,
|
||||||
|
config={
|
||||||
|
"preset": "public_chat",
|
||||||
|
"room_alias_name": room_alias_localpart
|
||||||
|
},
|
||||||
|
ratelimit=False,
|
||||||
)
|
)
|
||||||
# create room expects the localpart of the room alias
|
|
||||||
room_alias_localpart = RoomAlias.from_string(r).localpart
|
|
||||||
yield room_creation_handler.create_room(
|
|
||||||
fake_requester,
|
|
||||||
config={
|
|
||||||
"preset": "public_chat",
|
|
||||||
"room_alias_name": room_alias_localpart
|
|
||||||
},
|
|
||||||
ratelimit=False,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
yield self._join_user_to_room(fake_requester, r)
|
yield self._join_user_to_room(fake_requester, r)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Reference in a new issue