Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Handle rejections of invites from local users locally #615

Merged
merged 10 commits into from Mar 4, 2016

Conversation

Projects
None yet
3 participants
Member

richvdh commented Mar 1, 2016

Slightly hacky fix to SYN-642, which avoids the federation codepath when trying
to reject invites from local users.

richvdh added some commits Mar 1, 2016

Handle rejections of invites from local users locally
Slightly hacky fix to SYN-642, which avoids the federation codepath when trying
to reject invites from local users.
Member

richvdh commented Mar 1, 2016

See matrix-org/sytest#198 for test

@erikjohnston erikjohnston and 2 others commented on an outdated diff Mar 2, 2016

synapse/handlers/_base.py
@@ -208,7 +207,18 @@ def _create_new_client_event(self, builder):
prev_member_event = yield self.store.get_room_member(
builder.sender, builder.room_id
)
- if prev_member_event:
+
+ # if we have the prev_member_event in context, we didn't receive
+ # the invite over federation. (More likely is that the inviting
+ # user, and all other local users, have left, making
+ # is_host_in_room return false).
+ #
+ context_events = (e.event_id for e in context.current_state.values())
@erikjohnston

erikjohnston Mar 2, 2016

Owner

I'm a bit confused about this. The canonical check for if we received the invite over federation is if inviter.domain != self.server_name?

@richvdh

richvdh Mar 2, 2016

Member

True, but I guess here we're actually less interested in whether the event arrived over federation, and more in whether we already have it in context.current_state. If the event is in context.current_state despite being received over federation, there's no point dropping the context.

@richvdh

richvdh Mar 2, 2016

Member

I guess the comment is unclear. If you're happy otherwise I could update the comment.

@erikjohnston

erikjohnston Mar 2, 2016

Owner

Aha, right, yes, it was mainly the comment that confused me.

@illicitonion

illicitonion Mar 2, 2016

Contributor

Call this context_event_ids

@richvdh

richvdh Mar 2, 2016

Member

done, and comment rewritten.

Member

richvdh commented Mar 2, 2016

maybe @illicitonion should also take a look at this since he's been in the area recently.

Owner

erikjohnston commented Mar 2, 2016

Looks ok to me, though I think @illicitonion should have a quick peek since I don't really know how any of this works anymore :)

@illicitonion illicitonion and 1 other commented on an outdated diff Mar 2, 2016

synapse/handlers/room.py
if not is_host_in_room:
- action = "remote_reject"
+ # perhaps we've been invited
+ inviter = self.get_inviter(target_user.to_string(), context.current_state)
+ if not inviter:
+ raise SynapseError(404, "Not a known room")
+
+ if inviter.domain == self.server_name:
@illicitonion

illicitonion Mar 2, 2016

Contributor

self.hs.is_mine(inviter)?

@richvdh

richvdh Mar 2, 2016

Member

I just lifted the code from do_remotely_reject_invite. I guess your way is better

if anybody had bothered to document what self.hs actually is, this would have been somewhat easier to figure out.

@illicitonion illicitonion and 1 other commented on an outdated diff Mar 2, 2016

synapse/handlers/room.py
- action = "remote_reject"
+ # perhaps we've been invited
+ inviter = self.get_inviter(target_user.to_string(), context.current_state)
+ if not inviter:
+ raise SynapseError(404, "Not a known room")
+
+ if inviter.domain == self.server_name:
+ # the inviter was on our server, but has now left. Carry on
+ # with the normal rejection codepath.
+ #
+ # This is a bit of a hack, because the room might still be
+ # active on other servers.
+ pass
+ else:
+ # send the rejection to the inviter's HS.
+ remote_room_hosts = [inviter.domain]
@illicitonion

illicitonion Mar 2, 2016

Contributor

Being really picky, I could argue that this should probably be an append not an overwrite, because the caller may have specified some useful hints.

I know that none of the callers currently do, but...

@richvdh

richvdh Mar 2, 2016

Member

agreed; thanks.

Contributor

illicitonion commented Mar 2, 2016

LGTM, small handful of comments

Member

richvdh commented Mar 2, 2016

I generally favour this being the very first line of a function, so that it's obvious what's going on (because it's really compensating for the fact that default params are mutably stateful across invocations), and so that it doesn't matter what codepath you try to access/modify from

Contributor

illicitonion commented Mar 2, 2016

LGTM, one minor comment

Move arg default to the start of the function
Also don't overwrite the list that gets passed in.

@richvdh richvdh assigned richvdh and unassigned illicitonion Mar 2, 2016

Member

richvdh commented Mar 2, 2016

retest this please

Member

richvdh commented Mar 2, 2016

retest this please

Member

richvdh commented Mar 3, 2016

retest this please

pleeeease

Member

richvdh commented Mar 3, 2016

retest this please

Owner

erikjohnston commented Mar 3, 2016

retest this please

richvdh added some commits Mar 3, 2016

Member

richvdh commented Mar 3, 2016

retest this please

richvdh added a commit that referenced this pull request Mar 4, 2016

Merge pull request #615 from matrix-org/rav/SYN-642
Handle rejections of invites from local users locally

@richvdh richvdh merged commit fa6d6bb into develop Mar 4, 2016

7 of 8 checks passed

Sytest Postgres (Merged PR) Build finished.
Details
Flake8 + Packaging (Commit) Build #45 origin/rav/SYN-642 succeeded in 25 sec
Details
Flake8 + Packaging (Merged PR) Build finished.
Details
Sytest Postgres (Commit) Build #45 origin/rav/SYN-642 succeeded in 4 min 53 sec
Details
Sytest SQLite (Commit) Build #45 origin/rav/SYN-642 succeeded in 3 min 40 sec
Details
Sytest SQLite (Merged PR) Build finished.
Details
Unit Tests (Commit) Build #90 origin/rav/SYN-642 succeeded in 1 min 1 sec
Details
Unit Tests (Merged PR) Build finished.
Details

@richvdh richvdh deleted the rav/SYN-642 branch Mar 4, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment