This repository was 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
Pass the requester during event serialization #15174
Merged
clokep
merged 9 commits into
matrix-org:develop
from
sandhose:quenting/txnid-propagation
Mar 6, 2023
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d96e3eb
Pass the requester during event serialization
sandhose e01a87d
Apply suggestions from code review
sandhose 8172477
Update the changelog
sandhose 3ba7aa1
Rename the newsfile
sandhose 7ee6051
Merge remote-tracking branch 'upstream/develop' into quenting/txnid-p…
sandhose 431d037
Style fixes post merge
sandhose 1700db3
Apply suggestions from code review
sandhose 71f8d63
Revert "Apply suggestions from code review"
sandhose 3903bc3
Merge branch 'develop' into quenting/txnid-propagation
sandhose 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 hidden or 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 @@ | ||
Pass the requester when serializing events. | ||
This file contains hidden or 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 |
---|---|---|
|
@@ -38,7 +38,7 @@ | |
) | ||
from synapse.api.errors import Codes, SynapseError | ||
from synapse.api.room_versions import RoomVersion | ||
from synapse.types import JsonDict | ||
from synapse.types import JsonDict, Requester | ||
from synapse.util.frozenutils import unfreeze | ||
|
||
from . import EventBase | ||
|
@@ -317,8 +317,9 @@ class SerializeEventConfig: | |
as_client_event: bool = True | ||
# Function to convert from federation format to client format | ||
event_format: Callable[[JsonDict], JsonDict] = format_event_for_client_v1 | ||
# ID of the user's auth token - used for namespacing of transaction IDs | ||
token_id: Optional[int] = None | ||
# The entity that requested the event. This is used to determine whether to include | ||
# the transaction_id in the unsigned section of the event. | ||
requester: Optional[Requester] = None | ||
# List of event fields to include. If empty, all fields will be returned. | ||
only_event_fields: Optional[List[str]] = None | ||
# Some events can have stripped room state stored in the `unsigned` field. | ||
|
@@ -368,11 +369,26 @@ def serialize_event( | |
e.unsigned["redacted_because"], time_now_ms, config=config | ||
) | ||
|
||
if config.token_id is not None: | ||
if config.token_id == getattr(e.internal_metadata, "token_id", None): | ||
txn_id = getattr(e.internal_metadata, "txn_id", None) | ||
if txn_id is not None: | ||
d["unsigned"]["transaction_id"] = txn_id | ||
# If we have a txn_id saved in the internal_metadata, we should include it in the | ||
# unsigned section of the event if it was sent by the same session as the one | ||
# requesting the event. | ||
# There is a special case for guests, because they only have one access token | ||
# without associated access_token_id, so we always include the txn_id for events | ||
# they sent. | ||
txn_id = getattr(e.internal_metadata, "txn_id", None) | ||
sandhose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if txn_id is not None and config.requester is not None: | ||
sandhose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
requester: Requester = config.requester | ||
clokep marked this conversation as resolved.
Show resolved
Hide resolved
|
||
event_token_id = getattr(e.internal_metadata, "token_id", None) | ||
sandhose marked this conversation as resolved.
Show resolved
Hide resolved
sandhose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
event_user_id = getattr(e, "user_id", None) | ||
clokep marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if requester.user.to_string() == event_user_id and ( | ||
( | ||
event_token_id is not None | ||
and requester.access_token_id is not None | ||
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. When is the 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. Mainly, yes, as well as some other places where we're manually creating a requester for some operations |
||
and event_token_id == requester.access_token_id | ||
) | ||
or config.requester.is_guest | ||
): | ||
d["unsigned"]["transaction_id"] = txn_id | ||
|
||
# invite_room_state and knock_room_state are a list of stripped room state events | ||
# that are meant to provide metadata about a room to an invitee/knocker. They are | ||
|
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.