forked from MirrorHub/synapse
Change DomainSpecificString so that it doesn't use a HomeServer object
This commit is contained in:
parent
ec2b5d8c28
commit
9d53228158
12 changed files with 63 additions and 66 deletions
|
@ -58,7 +58,7 @@ class EventFactory(object):
|
||||||
|
|
||||||
local_part = str(int(self.clock.time())) + i + random_string(5)
|
local_part = str(int(self.clock.time())) + i + random_string(5)
|
||||||
|
|
||||||
e_id = EventID.create_local(local_part, self.hs)
|
e_id = EventID.create(local_part, self.hs.hostname)
|
||||||
|
|
||||||
return e_id.to_string()
|
return e_id.to_string()
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ class DirectoryHandler(BaseHandler):
|
||||||
|
|
||||||
# TODO(erikj): Do auth.
|
# TODO(erikj): Do auth.
|
||||||
|
|
||||||
if not room_alias.is_mine:
|
if not self.hs.is_mine(room_alias):
|
||||||
raise SynapseError(400, "Room alias must be local")
|
raise SynapseError(400, "Room alias must be local")
|
||||||
# TODO(erikj): Change this.
|
# TODO(erikj): Change this.
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ class DirectoryHandler(BaseHandler):
|
||||||
def delete_association(self, user_id, room_alias):
|
def delete_association(self, user_id, room_alias):
|
||||||
# TODO Check if server admin
|
# TODO Check if server admin
|
||||||
|
|
||||||
if not room_alias.is_mine:
|
if not self.hs.is_mine(room_alias):
|
||||||
raise SynapseError(400, "Room alias must be local")
|
raise SynapseError(400, "Room alias must be local")
|
||||||
|
|
||||||
room_id = yield self.store.delete_room_alias(room_alias)
|
room_id = yield self.store.delete_room_alias(room_alias)
|
||||||
|
@ -75,7 +75,7 @@ class DirectoryHandler(BaseHandler):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_association(self, room_alias):
|
def get_association(self, room_alias):
|
||||||
room_id = None
|
room_id = None
|
||||||
if room_alias.is_mine:
|
if self.hs.is_mine(room_alias):
|
||||||
result = yield self.store.get_association_from_room_alias(
|
result = yield self.store.get_association_from_room_alias(
|
||||||
room_alias
|
room_alias
|
||||||
)
|
)
|
||||||
|
@ -123,7 +123,7 @@ class DirectoryHandler(BaseHandler):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_directory_query(self, args):
|
def on_directory_query(self, args):
|
||||||
room_alias = self.hs.parse_roomalias(args["room_alias"])
|
room_alias = self.hs.parse_roomalias(args["room_alias"])
|
||||||
if not room_alias.is_mine:
|
if not self.hs.is_mine(room_alias):
|
||||||
raise SynapseError(
|
raise SynapseError(
|
||||||
400, "Room Alias is not hosted on this Home Server"
|
400, "Room Alias is not hosted on this Home Server"
|
||||||
)
|
)
|
||||||
|
|
|
@ -79,7 +79,7 @@ class MessageHandler(BaseHandler):
|
||||||
self.ratelimit(event.user_id)
|
self.ratelimit(event.user_id)
|
||||||
# TODO(paul): Why does 'event' not have a 'user' object?
|
# TODO(paul): Why does 'event' not have a 'user' object?
|
||||||
user = self.hs.parse_userid(event.user_id)
|
user = self.hs.parse_userid(event.user_id)
|
||||||
assert user.is_mine, "User must be our own: %s" % (user,)
|
assert self.hs.is_mine(user), "User must be our own: %s" % (user,)
|
||||||
|
|
||||||
snapshot = yield self.store.snapshot_room(event)
|
snapshot = yield self.store.snapshot_room(event)
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,7 @@ class PresenceHandler(BaseHandler):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def is_presence_visible(self, observer_user, observed_user):
|
def is_presence_visible(self, observer_user, observed_user):
|
||||||
assert(observed_user.is_mine)
|
assert(self.hs.is_mine(observed_user))
|
||||||
|
|
||||||
if observer_user == observed_user:
|
if observer_user == observed_user:
|
||||||
defer.returnValue(True)
|
defer.returnValue(True)
|
||||||
|
@ -165,7 +165,7 @@ class PresenceHandler(BaseHandler):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_state(self, target_user, auth_user, as_event=False):
|
def get_state(self, target_user, auth_user, as_event=False):
|
||||||
if target_user.is_mine:
|
if self.hs.is_mine(target_user):
|
||||||
visible = yield self.is_presence_visible(
|
visible = yield self.is_presence_visible(
|
||||||
observer_user=auth_user,
|
observer_user=auth_user,
|
||||||
observed_user=target_user
|
observed_user=target_user
|
||||||
|
@ -212,7 +212,7 @@ class PresenceHandler(BaseHandler):
|
||||||
# TODO (erikj): Turn this back on. Why did we end up sending EDUs
|
# TODO (erikj): Turn this back on. Why did we end up sending EDUs
|
||||||
# everywhere?
|
# everywhere?
|
||||||
|
|
||||||
if not target_user.is_mine:
|
if not self.hs.is_mine(target_user):
|
||||||
raise SynapseError(400, "User is not hosted on this Home Server")
|
raise SynapseError(400, "User is not hosted on this Home Server")
|
||||||
|
|
||||||
if target_user != auth_user:
|
if target_user != auth_user:
|
||||||
|
@ -291,7 +291,7 @@ class PresenceHandler(BaseHandler):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def user_joined_room(self, user, room_id):
|
def user_joined_room(self, user, room_id):
|
||||||
if user.is_mine:
|
if self.hs.is_mine(user):
|
||||||
statuscache = self._get_or_make_usercache(user)
|
statuscache = self._get_or_make_usercache(user)
|
||||||
|
|
||||||
# No actual update but we need to bump the serial anyway for the
|
# No actual update but we need to bump the serial anyway for the
|
||||||
|
@ -309,7 +309,7 @@ class PresenceHandler(BaseHandler):
|
||||||
rm_handler = self.homeserver.get_handlers().room_member_handler
|
rm_handler = self.homeserver.get_handlers().room_member_handler
|
||||||
curr_users = yield rm_handler.get_room_members(room_id)
|
curr_users = yield rm_handler.get_room_members(room_id)
|
||||||
|
|
||||||
for local_user in [c for c in curr_users if c.is_mine]:
|
for local_user in [c for c in curr_users if self.hs.is_mine(c)]:
|
||||||
self.push_update_to_local_and_remote(
|
self.push_update_to_local_and_remote(
|
||||||
observed_user=local_user,
|
observed_user=local_user,
|
||||||
users_to_push=[user],
|
users_to_push=[user],
|
||||||
|
@ -318,14 +318,14 @@ class PresenceHandler(BaseHandler):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def send_invite(self, observer_user, observed_user):
|
def send_invite(self, observer_user, observed_user):
|
||||||
if not observer_user.is_mine:
|
if not self.hs.is_mine(observer_user):
|
||||||
raise SynapseError(400, "User is not hosted on this Home Server")
|
raise SynapseError(400, "User is not hosted on this Home Server")
|
||||||
|
|
||||||
yield self.store.add_presence_list_pending(
|
yield self.store.add_presence_list_pending(
|
||||||
observer_user.localpart, observed_user.to_string()
|
observer_user.localpart, observed_user.to_string()
|
||||||
)
|
)
|
||||||
|
|
||||||
if observed_user.is_mine:
|
if self.hs.is_mine(observed_user):
|
||||||
yield self.invite_presence(observed_user, observer_user)
|
yield self.invite_presence(observed_user, observer_user)
|
||||||
else:
|
else:
|
||||||
yield self.federation.send_edu(
|
yield self.federation.send_edu(
|
||||||
|
@ -339,7 +339,7 @@ class PresenceHandler(BaseHandler):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _should_accept_invite(self, observed_user, observer_user):
|
def _should_accept_invite(self, observed_user, observer_user):
|
||||||
if not observed_user.is_mine:
|
if not self.hs.is_mine(observed_user):
|
||||||
defer.returnValue(False)
|
defer.returnValue(False)
|
||||||
|
|
||||||
row = yield self.store.has_presence_state(observed_user.localpart)
|
row = yield self.store.has_presence_state(observed_user.localpart)
|
||||||
|
@ -359,7 +359,7 @@ class PresenceHandler(BaseHandler):
|
||||||
observed_user.localpart, observer_user.to_string()
|
observed_user.localpart, observer_user.to_string()
|
||||||
)
|
)
|
||||||
|
|
||||||
if observer_user.is_mine:
|
if self.hs.is_mine(observer_user):
|
||||||
if accept:
|
if accept:
|
||||||
yield self.accept_presence(observed_user, observer_user)
|
yield self.accept_presence(observed_user, observer_user)
|
||||||
else:
|
else:
|
||||||
|
@ -396,7 +396,7 @@ class PresenceHandler(BaseHandler):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def drop(self, observed_user, observer_user):
|
def drop(self, observed_user, observer_user):
|
||||||
if not observer_user.is_mine:
|
if not self.hs.is_mine(observer_user):
|
||||||
raise SynapseError(400, "User is not hosted on this Home Server")
|
raise SynapseError(400, "User is not hosted on this Home Server")
|
||||||
|
|
||||||
yield self.store.del_presence_list(
|
yield self.store.del_presence_list(
|
||||||
|
@ -410,7 +410,7 @@ class PresenceHandler(BaseHandler):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_presence_list(self, observer_user, accepted=None):
|
def get_presence_list(self, observer_user, accepted=None):
|
||||||
if not observer_user.is_mine:
|
if not self.hs.is_mine(observer_user):
|
||||||
raise SynapseError(400, "User is not hosted on this Home Server")
|
raise SynapseError(400, "User is not hosted on this Home Server")
|
||||||
|
|
||||||
presence = yield self.store.get_presence_list(
|
presence = yield self.store.get_presence_list(
|
||||||
|
@ -465,7 +465,7 @@ class PresenceHandler(BaseHandler):
|
||||||
)
|
)
|
||||||
|
|
||||||
for target_user in target_users:
|
for target_user in target_users:
|
||||||
if target_user.is_mine:
|
if self.hs.is_mine(target_user):
|
||||||
self._start_polling_local(user, target_user)
|
self._start_polling_local(user, target_user)
|
||||||
|
|
||||||
# We want to tell the person that just came online
|
# We want to tell the person that just came online
|
||||||
|
@ -477,7 +477,7 @@ class PresenceHandler(BaseHandler):
|
||||||
)
|
)
|
||||||
|
|
||||||
deferreds = []
|
deferreds = []
|
||||||
remote_users = [u for u in target_users if not u.is_mine]
|
remote_users = [u for u in target_users if not self.hs.is_mine(u)]
|
||||||
remoteusers_by_domain = partition(remote_users, lambda u: u.domain)
|
remoteusers_by_domain = partition(remote_users, lambda u: u.domain)
|
||||||
# Only poll for people in our get_presence_list
|
# Only poll for people in our get_presence_list
|
||||||
for domain in remoteusers_by_domain:
|
for domain in remoteusers_by_domain:
|
||||||
|
@ -520,7 +520,7 @@ class PresenceHandler(BaseHandler):
|
||||||
def stop_polling_presence(self, user, target_user=None):
|
def stop_polling_presence(self, user, target_user=None):
|
||||||
logger.debug("Stop polling for presence from %s", user)
|
logger.debug("Stop polling for presence from %s", user)
|
||||||
|
|
||||||
if not target_user or target_user.is_mine:
|
if not target_user or self.hs.is_mine(target_user):
|
||||||
self._stop_polling_local(user, target_user=target_user)
|
self._stop_polling_local(user, target_user=target_user)
|
||||||
|
|
||||||
deferreds = []
|
deferreds = []
|
||||||
|
@ -579,7 +579,7 @@ class PresenceHandler(BaseHandler):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@log_function
|
@log_function
|
||||||
def push_presence(self, user, statuscache):
|
def push_presence(self, user, statuscache):
|
||||||
assert(user.is_mine)
|
assert(self.hs.is_mine(user))
|
||||||
|
|
||||||
logger.debug("Pushing presence update from %s", user)
|
logger.debug("Pushing presence update from %s", user)
|
||||||
|
|
||||||
|
@ -691,7 +691,7 @@ class PresenceHandler(BaseHandler):
|
||||||
for poll in content.get("poll", []):
|
for poll in content.get("poll", []):
|
||||||
user = self.hs.parse_userid(poll)
|
user = self.hs.parse_userid(poll)
|
||||||
|
|
||||||
if not user.is_mine:
|
if not self.hs.is_mine(user):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# TODO(paul) permissions checks
|
# TODO(paul) permissions checks
|
||||||
|
@ -706,7 +706,7 @@ class PresenceHandler(BaseHandler):
|
||||||
for unpoll in content.get("unpoll", []):
|
for unpoll in content.get("unpoll", []):
|
||||||
user = self.hs.parse_userid(unpoll)
|
user = self.hs.parse_userid(unpoll)
|
||||||
|
|
||||||
if not user.is_mine:
|
if not self.hs.is_mine(user):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if user in self._remote_sendmap:
|
if user in self._remote_sendmap:
|
||||||
|
@ -725,7 +725,7 @@ class PresenceHandler(BaseHandler):
|
||||||
|
|
||||||
localusers, remoteusers = partitionbool(
|
localusers, remoteusers = partitionbool(
|
||||||
users_to_push,
|
users_to_push,
|
||||||
lambda u: u.is_mine
|
lambda u: self.hs.is_mine(u)
|
||||||
)
|
)
|
||||||
|
|
||||||
localusers = set(localusers)
|
localusers = set(localusers)
|
||||||
|
@ -783,7 +783,7 @@ class PresenceEventSource(object):
|
||||||
[u.to_string() for u in observer_user, observed_user])):
|
[u.to_string() for u in observer_user, observed_user])):
|
||||||
defer.returnValue(True)
|
defer.returnValue(True)
|
||||||
|
|
||||||
if observed_user.is_mine:
|
if self.hs.is_mine(observed_user):
|
||||||
pushmap = presence._local_pushmap
|
pushmap = presence._local_pushmap
|
||||||
|
|
||||||
defer.returnValue(
|
defer.returnValue(
|
||||||
|
|
|
@ -51,7 +51,7 @@ class ProfileHandler(BaseHandler):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_displayname(self, target_user):
|
def get_displayname(self, target_user):
|
||||||
if target_user.is_mine:
|
if self.hs.is_mine(target_user):
|
||||||
displayname = yield self.store.get_profile_displayname(
|
displayname = yield self.store.get_profile_displayname(
|
||||||
target_user.localpart
|
target_user.localpart
|
||||||
)
|
)
|
||||||
|
@ -81,7 +81,7 @@ class ProfileHandler(BaseHandler):
|
||||||
def set_displayname(self, target_user, auth_user, new_displayname):
|
def set_displayname(self, target_user, auth_user, new_displayname):
|
||||||
"""target_user is the user whose displayname is to be changed;
|
"""target_user is the user whose displayname is to be changed;
|
||||||
auth_user is the user attempting to make this change."""
|
auth_user is the user attempting to make this change."""
|
||||||
if not target_user.is_mine:
|
if not self.hs.is_mine(target_user):
|
||||||
raise SynapseError(400, "User is not hosted on this Home Server")
|
raise SynapseError(400, "User is not hosted on this Home Server")
|
||||||
|
|
||||||
if target_user != auth_user:
|
if target_user != auth_user:
|
||||||
|
@ -101,7 +101,7 @@ class ProfileHandler(BaseHandler):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_avatar_url(self, target_user):
|
def get_avatar_url(self, target_user):
|
||||||
if target_user.is_mine:
|
if self.hs.is_mine(target_user):
|
||||||
avatar_url = yield self.store.get_profile_avatar_url(
|
avatar_url = yield self.store.get_profile_avatar_url(
|
||||||
target_user.localpart
|
target_user.localpart
|
||||||
)
|
)
|
||||||
|
@ -130,7 +130,7 @@ class ProfileHandler(BaseHandler):
|
||||||
def set_avatar_url(self, target_user, auth_user, new_avatar_url):
|
def set_avatar_url(self, target_user, auth_user, new_avatar_url):
|
||||||
"""target_user is the user whose avatar_url is to be changed;
|
"""target_user is the user whose avatar_url is to be changed;
|
||||||
auth_user is the user attempting to make this change."""
|
auth_user is the user attempting to make this change."""
|
||||||
if not target_user.is_mine:
|
if not self.hs.is_mine(target_user):
|
||||||
raise SynapseError(400, "User is not hosted on this Home Server")
|
raise SynapseError(400, "User is not hosted on this Home Server")
|
||||||
|
|
||||||
if target_user != auth_user:
|
if target_user != auth_user:
|
||||||
|
@ -150,7 +150,7 @@ class ProfileHandler(BaseHandler):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def collect_presencelike_data(self, user, state):
|
def collect_presencelike_data(self, user, state):
|
||||||
if not user.is_mine:
|
if not self.hs.is_mine(user):
|
||||||
defer.returnValue(None)
|
defer.returnValue(None)
|
||||||
|
|
||||||
with PreserveLoggingContext():
|
with PreserveLoggingContext():
|
||||||
|
@ -170,7 +170,7 @@ class ProfileHandler(BaseHandler):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_profile_query(self, args):
|
def on_profile_query(self, args):
|
||||||
user = self.hs.parse_userid(args["user_id"])
|
user = self.hs.parse_userid(args["user_id"])
|
||||||
if not user.is_mine:
|
if not self.hs.is_mine(user):
|
||||||
raise SynapseError(400, "User is not hosted on this Home Server")
|
raise SynapseError(400, "User is not hosted on this Home Server")
|
||||||
|
|
||||||
just_field = args.get("field", None)
|
just_field = args.get("field", None)
|
||||||
|
@ -191,7 +191,7 @@ class ProfileHandler(BaseHandler):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _update_join_states(self, user):
|
def _update_join_states(self, user):
|
||||||
if not user.is_mine:
|
if not self.hs.is_mine(user):
|
||||||
return
|
return
|
||||||
|
|
||||||
joins = yield self.store.get_rooms_for_user_where_membership_is(
|
joins = yield self.store.get_rooms_for_user_where_membership_is(
|
||||||
|
|
|
@ -52,9 +52,9 @@ class RoomCreationHandler(BaseHandler):
|
||||||
self.ratelimit(user_id)
|
self.ratelimit(user_id)
|
||||||
|
|
||||||
if "room_alias_name" in config:
|
if "room_alias_name" in config:
|
||||||
room_alias = RoomAlias.create_local(
|
room_alias = RoomAlias.create(
|
||||||
config["room_alias_name"],
|
config["room_alias_name"],
|
||||||
self.hs
|
self.hs.hostname,
|
||||||
)
|
)
|
||||||
mapping = yield self.store.get_association_from_room_alias(
|
mapping = yield self.store.get_association_from_room_alias(
|
||||||
room_alias
|
room_alias
|
||||||
|
@ -77,7 +77,7 @@ class RoomCreationHandler(BaseHandler):
|
||||||
if room_id:
|
if room_id:
|
||||||
# Ensure room_id is the correct type
|
# Ensure room_id is the correct type
|
||||||
room_id_obj = RoomID.from_string(room_id, self.hs)
|
room_id_obj = RoomID.from_string(room_id, self.hs)
|
||||||
if not room_id_obj.is_mine:
|
if not self.hs.is_mine(room_id_obj):
|
||||||
raise SynapseError(400, "Room id must be local")
|
raise SynapseError(400, "Room id must be local")
|
||||||
|
|
||||||
yield self.store.store_room(
|
yield self.store.store_room(
|
||||||
|
@ -93,7 +93,10 @@ class RoomCreationHandler(BaseHandler):
|
||||||
while attempts < 5:
|
while attempts < 5:
|
||||||
try:
|
try:
|
||||||
random_string = stringutils.random_string(18)
|
random_string = stringutils.random_string(18)
|
||||||
gen_room_id = RoomID.create_local(random_string, self.hs)
|
gen_room_id = RoomID.create(
|
||||||
|
random_string,
|
||||||
|
self.hs.hostname,
|
||||||
|
)
|
||||||
yield self.store.store_room(
|
yield self.store.store_room(
|
||||||
room_id=gen_room_id.to_string(),
|
room_id=gen_room_id.to_string(),
|
||||||
room_creator_user_id=user_id,
|
room_creator_user_id=user_id,
|
||||||
|
@ -287,7 +290,7 @@ class RoomMemberHandler(BaseHandler):
|
||||||
if ignore_user is not None and member == ignore_user:
|
if ignore_user is not None and member == ignore_user:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if member.is_mine:
|
if self.hs.is_mine(member):
|
||||||
if localusers is not None:
|
if localusers is not None:
|
||||||
localusers.add(member)
|
localusers.add(member)
|
||||||
else:
|
else:
|
||||||
|
@ -457,7 +460,7 @@ class RoomMemberHandler(BaseHandler):
|
||||||
prev_state.user_id, self.hs
|
prev_state.user_id, self.hs
|
||||||
)
|
)
|
||||||
|
|
||||||
should_do_dance = not inviter.is_mine and not room
|
should_do_dance = not self.hs.is_mine(inviter) and not room
|
||||||
room_host = inviter.domain
|
room_host = inviter.domain
|
||||||
else:
|
else:
|
||||||
should_do_dance = False
|
should_do_dance = False
|
||||||
|
@ -504,7 +507,7 @@ class RoomMemberHandler(BaseHandler):
|
||||||
prev_state.sender, self.hs
|
prev_state.sender, self.hs
|
||||||
)
|
)
|
||||||
|
|
||||||
is_remote_invite_join = not inviter.is_mine and not room
|
is_remote_invite_join = not self.hs.is_mine(inviter) and not room
|
||||||
room_host = inviter.domain
|
room_host = inviter.domain
|
||||||
else:
|
else:
|
||||||
is_remote_invite_join = False
|
is_remote_invite_join = False
|
||||||
|
@ -530,7 +533,7 @@ class RoomMemberHandler(BaseHandler):
|
||||||
# HS.
|
# HS.
|
||||||
target_user_id = event.state_key
|
target_user_id = event.state_key
|
||||||
target_user = self.hs.parse_userid(target_user_id)
|
target_user = self.hs.parse_userid(target_user_id)
|
||||||
if membership == Membership.INVITE and not target_user.is_mine:
|
if membership == Membership.INVITE and not self.hs.is_mine(target_user):
|
||||||
do_invite_host = target_user.domain
|
do_invite_host = target_user.domain
|
||||||
else:
|
else:
|
||||||
do_invite_host = None
|
do_invite_host = None
|
||||||
|
|
|
@ -47,7 +47,7 @@ class TypingNotificationHandler(BaseHandler):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def started_typing(self, target_user, auth_user, room_id, timeout):
|
def started_typing(self, target_user, auth_user, room_id, timeout):
|
||||||
if not target_user.is_mine:
|
if not self.hs.is_mine(target_user):
|
||||||
raise SynapseError(400, "User is not hosted on this Home Server")
|
raise SynapseError(400, "User is not hosted on this Home Server")
|
||||||
|
|
||||||
if target_user != auth_user:
|
if target_user != auth_user:
|
||||||
|
@ -72,7 +72,7 @@ class TypingNotificationHandler(BaseHandler):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def stopped_typing(self, target_user, auth_user, room_id):
|
def stopped_typing(self, target_user, auth_user, room_id):
|
||||||
if not target_user.is_mine:
|
if not self.hs.is_mine(target_user):
|
||||||
raise SynapseError(400, "User is not hosted on this Home Server")
|
raise SynapseError(400, "User is not hosted on this Home Server")
|
||||||
|
|
||||||
if target_user != auth_user:
|
if target_user != auth_user:
|
||||||
|
|
|
@ -35,7 +35,7 @@ class WhoisRestServlet(RestServlet):
|
||||||
if not is_admin and target_user != auth_user:
|
if not is_admin and target_user != auth_user:
|
||||||
raise AuthError(403, "You are not a server admin")
|
raise AuthError(403, "You are not a server admin")
|
||||||
|
|
||||||
if not target_user.is_mine:
|
if not self.hs.is_mine(target_user):
|
||||||
raise SynapseError(400, "Can only whois a local user")
|
raise SynapseError(400, "Can only whois a local user")
|
||||||
|
|
||||||
ret = yield self.handlers.admin_handler.get_whois(target_user)
|
ret = yield self.handlers.admin_handler.get_whois(target_user)
|
||||||
|
|
|
@ -47,8 +47,8 @@ class LoginRestServlet(RestServlet):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def do_password_login(self, login_submission):
|
def do_password_login(self, login_submission):
|
||||||
if not login_submission["user"].startswith('@'):
|
if not login_submission["user"].startswith('@'):
|
||||||
login_submission["user"] = UserID.create_local(
|
login_submission["user"] = UserID.create(
|
||||||
login_submission["user"], self.hs).to_string()
|
login_submission["user"], self.hs.hostname).to_string()
|
||||||
|
|
||||||
handler = self.handlers.login_handler
|
handler = self.handlers.login_handler
|
||||||
token = yield handler.login(
|
token = yield handler.login(
|
||||||
|
|
|
@ -83,7 +83,7 @@ class PresenceListRestServlet(RestServlet):
|
||||||
user_id = urllib.unquote(user_id)
|
user_id = urllib.unquote(user_id)
|
||||||
user = self.hs.parse_userid(user_id)
|
user = self.hs.parse_userid(user_id)
|
||||||
|
|
||||||
if not user.is_mine:
|
if not self.hs.is_mine(user):
|
||||||
raise SynapseError(400, "User not hosted on this Home Server")
|
raise SynapseError(400, "User not hosted on this Home Server")
|
||||||
|
|
||||||
if auth_user != user:
|
if auth_user != user:
|
||||||
|
@ -104,7 +104,7 @@ class PresenceListRestServlet(RestServlet):
|
||||||
user_id = urllib.unquote(user_id)
|
user_id = urllib.unquote(user_id)
|
||||||
user = self.hs.parse_userid(user_id)
|
user = self.hs.parse_userid(user_id)
|
||||||
|
|
||||||
if not user.is_mine:
|
if not self.hs.is_mine(user):
|
||||||
raise SynapseError(400, "User not hosted on this Home Server")
|
raise SynapseError(400, "User not hosted on this Home Server")
|
||||||
|
|
||||||
if auth_user != user:
|
if auth_user != user:
|
||||||
|
|
|
@ -133,22 +133,22 @@ class BaseHomeServer(object):
|
||||||
def parse_userid(self, s):
|
def parse_userid(self, s):
|
||||||
"""Parse the string given by 's' as a User ID and return a UserID
|
"""Parse the string given by 's' as a User ID and return a UserID
|
||||||
object."""
|
object."""
|
||||||
return UserID.from_string(s, hs=self)
|
return UserID.from_string(s)
|
||||||
|
|
||||||
def parse_roomalias(self, s):
|
def parse_roomalias(self, s):
|
||||||
"""Parse the string given by 's' as a Room Alias and return a RoomAlias
|
"""Parse the string given by 's' as a Room Alias and return a RoomAlias
|
||||||
object."""
|
object."""
|
||||||
return RoomAlias.from_string(s, hs=self)
|
return RoomAlias.from_string(s)
|
||||||
|
|
||||||
def parse_roomid(self, s):
|
def parse_roomid(self, s):
|
||||||
"""Parse the string given by 's' as a Room ID and return a RoomID
|
"""Parse the string given by 's' as a Room ID and return a RoomID
|
||||||
object."""
|
object."""
|
||||||
return RoomID.from_string(s, hs=self)
|
return RoomID.from_string(s)
|
||||||
|
|
||||||
def parse_eventid(self, s):
|
def parse_eventid(self, s):
|
||||||
"""Parse the string given by 's' as a Event ID and return a EventID
|
"""Parse the string given by 's' as a Event ID and return a EventID
|
||||||
object."""
|
object."""
|
||||||
return EventID.from_string(s, hs=self)
|
return EventID.from_string(s)
|
||||||
|
|
||||||
def serialize_event(self, e):
|
def serialize_event(self, e):
|
||||||
return serialize_event(self, e)
|
return serialize_event(self, e)
|
||||||
|
@ -165,6 +165,9 @@ class BaseHomeServer(object):
|
||||||
|
|
||||||
return ip_addr
|
return ip_addr
|
||||||
|
|
||||||
|
def is_mine(self, domain_specific_string):
|
||||||
|
return domain_specific_string.domain == self.hostname
|
||||||
|
|
||||||
# Build magic accessors for every dependency
|
# Build magic accessors for every dependency
|
||||||
for depname in BaseHomeServer.DEPENDENCIES:
|
for depname in BaseHomeServer.DEPENDENCIES:
|
||||||
BaseHomeServer._make_dependency_method(depname)
|
BaseHomeServer._make_dependency_method(depname)
|
||||||
|
|
|
@ -19,7 +19,7 @@ from collections import namedtuple
|
||||||
|
|
||||||
|
|
||||||
class DomainSpecificString(
|
class DomainSpecificString(
|
||||||
namedtuple("DomainSpecificString", ("localpart", "domain", "is_mine"))
|
namedtuple("DomainSpecificString", ("localpart", "domain"))
|
||||||
):
|
):
|
||||||
"""Common base class among ID/name strings that have a local part and a
|
"""Common base class among ID/name strings that have a local part and a
|
||||||
domain name, prefixed with a sigil.
|
domain name, prefixed with a sigil.
|
||||||
|
@ -28,15 +28,13 @@ class DomainSpecificString(
|
||||||
|
|
||||||
'localpart' : The local part of the name (without the leading sigil)
|
'localpart' : The local part of the name (without the leading sigil)
|
||||||
'domain' : The domain part of the name
|
'domain' : The domain part of the name
|
||||||
'is_mine' : Boolean indicating if the domain name is recognised by the
|
|
||||||
HomeServer as being its own
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Deny iteration because it will bite you if you try to create a singleton
|
# Deny iteration because it will bite you if you try to create a singleton
|
||||||
# set by:
|
# set by:
|
||||||
# users = set(user)
|
# users = set(user)
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
raise ValueError("Attempted to iterate a %s" % (type(self).__name__))
|
raise ValueError("Attempted to iterate a %s" % (type(self).__name__,))
|
||||||
|
|
||||||
# Because this class is a namedtuple of strings and booleans, it is deeply
|
# Because this class is a namedtuple of strings and booleans, it is deeply
|
||||||
# immutable.
|
# immutable.
|
||||||
|
@ -47,7 +45,7 @@ class DomainSpecificString(
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_string(cls, s, hs):
|
def from_string(cls, s):
|
||||||
"""Parse the string given by 's' into a structure object."""
|
"""Parse the string given by 's' into a structure object."""
|
||||||
if s[0] != cls.SIGIL:
|
if s[0] != cls.SIGIL:
|
||||||
raise SynapseError(400, "Expected %s string to start with '%s'" % (
|
raise SynapseError(400, "Expected %s string to start with '%s'" % (
|
||||||
|
@ -66,22 +64,15 @@ class DomainSpecificString(
|
||||||
|
|
||||||
# This code will need changing if we want to support multiple domain
|
# This code will need changing if we want to support multiple domain
|
||||||
# names on one HS
|
# names on one HS
|
||||||
is_mine = domain == hs.hostname
|
return cls(localpart=parts[0], domain=domain)
|
||||||
return cls(localpart=parts[0], domain=domain, is_mine=is_mine)
|
|
||||||
|
|
||||||
def to_string(self):
|
def to_string(self):
|
||||||
"""Return a string encoding the fields of the structure object."""
|
"""Return a string encoding the fields of the structure object."""
|
||||||
return "%s%s:%s" % (self.SIGIL, self.localpart, self.domain)
|
return "%s%s:%s" % (self.SIGIL, self.localpart, self.domain)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_local(cls, localpart, hs):
|
def create(cls, localpart, domain,):
|
||||||
"""Create a structure on the local domain"""
|
return cls(localpart=localpart, domain=domain)
|
||||||
return cls(localpart=localpart, domain=hs.hostname, is_mine=True)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def create(cls, localpart, domain, hs):
|
|
||||||
is_mine = domain == hs.hostname
|
|
||||||
return cls(localpart=localpart, domain=domain, is_mine=is_mine)
|
|
||||||
|
|
||||||
|
|
||||||
class UserID(DomainSpecificString):
|
class UserID(DomainSpecificString):
|
||||||
|
|
Loading…
Reference in a new issue