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

Allow rejecting invites #317

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion synapse/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,11 @@ def is_membership_change_allowed(self, event, auth_events):
)

if Membership.JOIN != membership:
# JOIN is the only action you can perform if you're not in the room
if (caller_invited
and Membership.LEAVE == membership
and target_user_id == event.user_id):
return True

if not caller_in_room: # caller isn't joined
raise AuthError(
403,
Expand Down
39 changes: 33 additions & 6 deletions synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def get_event_auth(self, destination, room_id, event_id):
defer.returnValue(signed_auth)

@defer.inlineCallbacks
def make_join(self, destinations, room_id, user_id, content):
def make_membership_event(self, destinations, room_id, user_id, membership, content):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Docstring?
  • Can we assert that membership in [Membership.Join, Membership.Leave]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

for destination in destinations:
if destination == self.server_name:
continue
Expand All @@ -368,13 +368,13 @@ def make_join(self, destinations, room_id, user_id, content):
content["third_party_invite"]
)
try:
ret = yield self.transport_layer.make_join(
destination, room_id, user_id, args
ret = yield self.transport_layer.make_membership_event(
destination, room_id, user_id, membership, args
)

pdu_dict = ret["event"]

logger.debug("Got response to make_join: %s", pdu_dict)
logger.debug("Got response to make_%s: %s", membership, pdu_dict)

defer.returnValue(
(destination, self.event_from_pdu_json(pdu_dict))
Expand All @@ -384,8 +384,8 @@ def make_join(self, destinations, room_id, user_id, content):
raise
except Exception as e:
logger.warn(
"Failed to make_join via %s: %s",
destination, e.message
"Failed to make_%s via %s: %s",
membership, destination, e.message
)

raise RuntimeError("Failed to send to any server.")
Expand Down Expand Up @@ -491,6 +491,33 @@ def send_invite(self, destination, room_id, event_id, pdu):

defer.returnValue(pdu)

@defer.inlineCallbacks
def send_leave(self, destinations, pdu):
for destination in destinations:
if destination == self.server_name:
continue

try:
time_now = self._clock.time_msec()
_, content = yield self.transport_layer.send_leave(
destination=destination,
room_id=pdu.room_id,
event_id=pdu.event_id,
content=pdu.get_pdu_json(time_now),
)

logger.debug("Got content: %s", content)
defer.returnValue(None)
except CodeMessageException:
raise
except Exception as e:
logger.exception(
"Failed to send_leave via %s: %s",
destination, e.message
)

raise RuntimeError("Failed to send to any server.")

@defer.inlineCallbacks
def query_auth(self, destination, room_id, event_id, local_auth):
"""
Expand Down
14 changes: 14 additions & 0 deletions synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,20 @@ def on_send_join_request(self, origin, content):
],
}))

@defer.inlineCallbacks
def on_make_leave_request(self, room_id, user_id):
pdu = yield self.handler.on_make_leave_request(room_id, user_id)
time_now = self._clock.time_msec()
defer.returnValue({"event": pdu.get_pdu_json(time_now)})

@defer.inlineCallbacks
def on_send_leave_request(self, origin, content):
logger.debug("on_send_leave_request: content: %s", content)
pdu = self.event_from_pdu_json(content)
logger.debug("on_send_leave_request: pdu sigs: %s", pdu.signatures)
yield self.handler.on_send_leave_request(origin, pdu)
defer.returnValue((200, {}))

@defer.inlineCallbacks
def on_event_auth(self, origin, room_id, event_id):
time_now = self._clock.time_msec()
Expand Down
17 changes: 15 additions & 2 deletions synapse/federation/transport/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ def make_query(self, destination, query_type, args, retry_on_dns_fail):

@defer.inlineCallbacks
@log_function
def make_join(self, destination, room_id, user_id, args={}):
path = PREFIX + "/make_join/%s/%s" % (room_id, user_id)
def make_membership_event(self, destination, room_id, user_id, membership, args={}):
path = PREFIX + "/make_%s/%s/%s" % (membership, room_id, user_id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we assert that membership in [Membership.Join, Membership.Leave]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


content = yield self.client.get_json(
destination=destination,
Expand All @@ -185,6 +185,19 @@ def send_join(self, destination, room_id, event_id, content):

defer.returnValue(response)

@defer.inlineCallbacks
@log_function
def send_leave(self, destination, room_id, event_id, content):
path = PREFIX + "/send_leave/%s/%s" % (room_id, event_id)

response = yield self.client.put_json(
destination=destination,
path=path,
data=content,
)

defer.returnValue(response)

@defer.inlineCallbacks
@log_function
def send_invite(self, destination, room_id, event_id, content):
Expand Down
20 changes: 20 additions & 0 deletions synapse/federation/transport/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,24 @@ def on_GET(self, origin, content, query, context, user_id):
defer.returnValue((200, content))


class FederationMakeLeaveServlet(BaseFederationServlet):
PATH = "/make_leave/([^/]*)/([^/]*)"

@defer.inlineCallbacks
def on_GET(self, origin, content, query, context, user_id):
content = yield self.handler.on_make_leave_request(context, user_id)
defer.returnValue((200, content))


class FederationSendLeaveServlet(BaseFederationServlet):
PATH = "/send_leave/([^/]*)/([^/]*)"

@defer.inlineCallbacks
def on_PUT(self, origin, content, query, room_id, txid):
content = yield self.handler.on_send_leave_request(origin, content)
defer.returnValue((200, content))


class FederationEventAuthServlet(BaseFederationServlet):
PATH = "/event_auth/([^/]*)/([^/]*)"

Expand Down Expand Up @@ -385,8 +403,10 @@ def on_POST(self, origin, content, query, room_id):
FederationBackfillServlet,
FederationQueryServlet,
FederationMakeJoinServlet,
FederationMakeLeaveServlet,
FederationEventServlet,
FederationSendJoinServlet,
FederationSendLeaveServlet,
FederationInviteServlet,
FederationQueryAuthServlet,
FederationGetMissingEventsServlet,
Expand Down
Loading