mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-24 20:19:21 -05:00
Fix bugs so lazy room joining works as intended.
This commit is contained in:
parent
ab3c897ce1
commit
f7cac2f7b6
@ -41,7 +41,7 @@ class ApplicationServiceApi(SimpleHttpClient):
|
|||||||
response = yield self.get_json(uri, {
|
response = yield self.get_json(uri, {
|
||||||
"access_token": service.hs_token
|
"access_token": service.hs_token
|
||||||
})
|
})
|
||||||
if response: # just an empty json object
|
if response is not None: # just an empty json object
|
||||||
defer.returnValue(True)
|
defer.returnValue(True)
|
||||||
except CodeMessageException as e:
|
except CodeMessageException as e:
|
||||||
if e.code == 404:
|
if e.code == 404:
|
||||||
@ -60,13 +60,13 @@ class ApplicationServiceApi(SimpleHttpClient):
|
|||||||
response = yield self.get_json(uri, {
|
response = yield self.get_json(uri, {
|
||||||
"access_token": service.hs_token
|
"access_token": service.hs_token
|
||||||
})
|
})
|
||||||
if response: # just an empty json object
|
if response is not None: # just an empty json object
|
||||||
defer.returnValue(True)
|
defer.returnValue(True)
|
||||||
except CodeMessageException as e:
|
except CodeMessageException as e:
|
||||||
|
logger.warning("query_alias to %s received %s", uri, e.code)
|
||||||
if e.code == 404:
|
if e.code == 404:
|
||||||
defer.returnValue(False)
|
defer.returnValue(False)
|
||||||
return
|
return
|
||||||
logger.warning("query_alias to %s received %s", uri, e.code)
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.warning("query_alias to %s threw exception %s", uri, ex)
|
logger.warning("query_alias to %s threw exception %s", uri, ex)
|
||||||
defer.returnValue(False)
|
defer.returnValue(False)
|
||||||
|
@ -124,15 +124,15 @@ class ApplicationServicesHandler(object):
|
|||||||
namedtuple: with keys "room_id" and "servers" or None if no
|
namedtuple: with keys "room_id" and "servers" or None if no
|
||||||
association can be found.
|
association can be found.
|
||||||
"""
|
"""
|
||||||
room_alias = room_alias.to_string()
|
room_alias_str = room_alias.to_string()
|
||||||
alias_query_services = yield self._get_services_for_event(
|
alias_query_services = yield self._get_services_for_event(
|
||||||
event=None,
|
event=None,
|
||||||
restrict_to=ApplicationService.NS_ALIASES,
|
restrict_to=ApplicationService.NS_ALIASES,
|
||||||
alias_list=[room_alias]
|
alias_list=[room_alias_str]
|
||||||
)
|
)
|
||||||
for alias_service in alias_query_services:
|
for alias_service in alias_query_services:
|
||||||
is_known_alias = yield self.appservice_api.query_alias(
|
is_known_alias = yield self.appservice_api.query_alias(
|
||||||
alias_service, room_alias
|
alias_service, room_alias_str
|
||||||
)
|
)
|
||||||
if is_known_alias:
|
if is_known_alias:
|
||||||
# the alias exists now so don't query more ASes.
|
# the alias exists now so don't query more ASes.
|
||||||
|
@ -64,8 +64,11 @@ class DirectoryHandler(BaseHandler):
|
|||||||
# association creation for human users
|
# association creation for human users
|
||||||
# TODO(erikj): Do user auth.
|
# TODO(erikj): Do user auth.
|
||||||
|
|
||||||
is_claimed = yield self.is_alias_exclusive_to_appservices(room_alias)
|
can_create = yield self.can_modify_alias(
|
||||||
if is_claimed:
|
room_alias,
|
||||||
|
user_id=user_id
|
||||||
|
)
|
||||||
|
if not can_create:
|
||||||
raise SynapseError(
|
raise SynapseError(
|
||||||
400, "This alias is reserved by an application service.",
|
400, "This alias is reserved by an application service.",
|
||||||
errcode=Codes.EXCLUSIVE
|
errcode=Codes.EXCLUSIVE
|
||||||
@ -91,8 +94,11 @@ class DirectoryHandler(BaseHandler):
|
|||||||
|
|
||||||
# TODO Check if server admin
|
# TODO Check if server admin
|
||||||
|
|
||||||
is_claimed = yield self.is_alias_exclusive_to_appservices(room_alias)
|
can_delete = yield self.can_modify_alias(
|
||||||
if is_claimed:
|
room_alias,
|
||||||
|
user_id=user_id
|
||||||
|
)
|
||||||
|
if not can_delete:
|
||||||
raise SynapseError(
|
raise SynapseError(
|
||||||
400, "This alias is reserved by an application service.",
|
400, "This alias is reserved by an application service.",
|
||||||
errcode=Codes.EXCLUSIVE
|
errcode=Codes.EXCLUSIVE
|
||||||
@ -228,9 +234,14 @@ class DirectoryHandler(BaseHandler):
|
|||||||
defer.returnValue(result)
|
defer.returnValue(result)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def is_alias_exclusive_to_appservices(self, alias):
|
def can_modify_alias(self, alias, user_id=None):
|
||||||
services = yield self.store.get_app_services()
|
services = yield self.store.get_app_services()
|
||||||
interested_services = [
|
interested_services = [
|
||||||
s for s in services if s.is_interested_in_alias(alias.to_string())
|
s for s in services if s.is_interested_in_alias(alias.to_string())
|
||||||
]
|
]
|
||||||
defer.returnValue(len(interested_services) > 0)
|
for service in interested_services:
|
||||||
|
if user_id == service.sender:
|
||||||
|
# this user IS the app service
|
||||||
|
defer.returnValue(True)
|
||||||
|
return
|
||||||
|
defer.returnValue(len(interested_services) == 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user