This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add auth events as per spec. #6556
Merged
+35
−67
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix a cause of state resets in v5. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
# limitations under the License. | ||
|
||
import logging | ||
from typing import Dict, List, Tuple | ||
|
||
from six import itervalues | ||
|
||
|
@@ -25,13 +26,7 @@ | |
import synapse.logging.opentracing as opentracing | ||
import synapse.types | ||
from synapse import event_auth | ||
from synapse.api.constants import ( | ||
EventTypes, | ||
JoinRules, | ||
LimitBlockingTypes, | ||
Membership, | ||
UserTypes, | ||
) | ||
from synapse.api.constants import EventTypes, LimitBlockingTypes, Membership, UserTypes | ||
from synapse.api.errors import ( | ||
AuthError, | ||
Codes, | ||
|
@@ -513,69 +508,38 @@ def is_server_admin(self, user): | |
""" | ||
return self.store.is_server_admin(user) | ||
|
||
@defer.inlineCallbacks | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. turning this from a deferred-returning function to an immediate one without updating the call sites feels like it might bite us later? Better to Not that bothered though. We'll probably catch it when we update the call sites... |
||
def compute_auth_events(self, event, current_state_ids, for_verification=False): | ||
def compute_auth_events( | ||
self, | ||
event, | ||
current_state_ids: Dict[Tuple[str, str], str], | ||
for_verification: bool = False, | ||
) -> List[str]: | ||
"""Given an event and current state return the list of event IDs used | ||
to auth an event. | ||
|
||
If `for_verification` is False then only return auth events that | ||
should be added to the event's `auth_events`. | ||
""" | ||
|
||
if event.type == EventTypes.Create: | ||
return [] | ||
|
||
auth_ids = [] | ||
|
||
key = (EventTypes.PowerLevels, "") | ||
power_level_event_id = current_state_ids.get(key) | ||
|
||
if power_level_event_id: | ||
auth_ids.append(power_level_event_id) | ||
|
||
key = (EventTypes.JoinRules, "") | ||
join_rule_event_id = current_state_ids.get(key) | ||
# Currently we ignore the `for_verification` flag even though there are | ||
# some situations where we can drop particular auth events when adding | ||
# to the event's `auth_events` (e.g. joins pointing to previous joins | ||
# when room is publically joinable). Dropping event IDs has the | ||
# advantage that the auth chain for the room grows slower, but we use | ||
# the auth chain in state resolution v2 to order events, which means | ||
# care must be taken if dropping events to ensure that it doesn't | ||
# introduce undesirable "state reset" behaviour. | ||
# | ||
# All of which sounds a bit tricky so we don't bother for now. | ||
|
||
key = (EventTypes.Member, event.sender) | ||
member_event_id = current_state_ids.get(key) | ||
|
||
key = (EventTypes.Create, "") | ||
create_event_id = current_state_ids.get(key) | ||
if create_event_id: | ||
auth_ids.append(create_event_id) | ||
|
||
if join_rule_event_id: | ||
join_rule_event = yield self.store.get_event(join_rule_event_id) | ||
join_rule = join_rule_event.content.get("join_rule") | ||
is_public = join_rule == JoinRules.PUBLIC if join_rule else False | ||
else: | ||
is_public = False | ||
|
||
if event.type == EventTypes.Member: | ||
e_type = event.content["membership"] | ||
if e_type in [Membership.JOIN, Membership.INVITE]: | ||
if join_rule_event_id: | ||
auth_ids.append(join_rule_event_id) | ||
|
||
if e_type == Membership.JOIN: | ||
if member_event_id and not is_public: | ||
auth_ids.append(member_event_id) | ||
else: | ||
if member_event_id: | ||
auth_ids.append(member_event_id) | ||
|
||
if for_verification: | ||
key = (EventTypes.Member, event.state_key) | ||
existing_event_id = current_state_ids.get(key) | ||
if existing_event_id: | ||
auth_ids.append(existing_event_id) | ||
|
||
if e_type == Membership.INVITE: | ||
if "third_party_invite" in event.content: | ||
key = ( | ||
EventTypes.ThirdPartyInvite, | ||
event.content["third_party_invite"]["signed"]["token"], | ||
) | ||
third_party_invite_id = current_state_ids.get(key) | ||
if third_party_invite_id: | ||
auth_ids.append(third_party_invite_id) | ||
elif member_event_id: | ||
member_event = yield self.store.get_event(member_event_id) | ||
if member_event.content["membership"] == Membership.JOIN: | ||
auth_ids.append(member_event.event_id) | ||
auth_ids = [] | ||
for etype, state_key in event_auth.auth_types_for_event(event): | ||
auth_ev_id = current_state_ids.get((etype, state_key)) | ||
if auth_ev_id: | ||
auth_ids.append(auth_ev_id) | ||
|
||
return auth_ids | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v5 of what?
Itym room version 2 and onwards.