Skip to content

Allow admins to see policy server-flagged events #18585

New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

turt2live
Copy link
Member

@turt2live turt2live commented Jun 20, 2025

Requires #18238 Merged!

Real diff: 881d521...travis/flag-ps-events

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct (run the linters)

@turt2live turt2live changed the title Travis/flag ps events Allow admins to see policy server-flagged events Jun 20, 2025
@github-actions github-actions bot deployed to PR Documentation Preview June 20, 2025 18:42 Active
@github-actions github-actions bot deployed to PR Documentation Preview June 20, 2025 18:46 Active
@turt2live turt2live marked this pull request as ready for review June 20, 2025 18:49
@turt2live turt2live requested a review from a team as a code owner June 20, 2025 18:49
@github-actions github-actions bot deployed to PR Documentation Preview June 20, 2025 19:04 Active
@github-actions github-actions bot deployed to PR Documentation Preview June 20, 2025 19:09 Active
@github-actions github-actions bot deployed to PR Documentation Preview June 20, 2025 19:14 Active
@github-actions github-actions bot deployed to PR Documentation Preview June 20, 2025 19:18 Active
@@ -0,0 +1,51 @@
# Client-Server API Extensions
Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed in the #synapse-dev:matrix.org room

@MadLittleMods MadLittleMods requested a review from a team June 20, 2025 19:26
Copy link
Member

@anoadragon453 anoadragon453 left a comment

Choose a reason for hiding this comment

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

The term "spammy" doesn't feel like a real term to me... Can we just say "marked as spam"?

If you were looking for a short field name, policy_server_spam seems fine.

@turt2live turt2live force-pushed the travis/flag-ps-events branch from e343076 to 32d605f Compare July 14, 2025 23:14
@turt2live
Copy link
Member Author

sorry for the force push: I thought I set this PR up for a clean merge of develop->PR, but forgot all of the important steps.

@github-actions github-actions bot deployed to PR Documentation Preview July 14, 2025 23:15 Active
@turt2live
Copy link
Member Author

"spammy" comes from the detail that the policy server doesn't technically get final say on whether the event is spam or not, despite that being the current implementation. It's also used in other places throughout the codebase, especially around the existing spam checker interfaces.

I'd prefer to keep it as an invented word, but can change it if needed.

@turt2live turt2live requested a review from anoadragon453 July 14, 2025 23:24
@github-actions github-actions bot deployed to PR Documentation Preview July 14, 2025 23:25 Active
Copy link
Member

@anoadragon453 anoadragon453 left a comment

Choose a reason for hiding this comment

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

Some more iteration.

Could you also add some unit tests for this new field please?


if account_data:
self.return_soft_failed_events = account_data.get(
"return_soft_failed_events", False
)
self.return_policy_server_spammy_events = account_data.get(
"return_policy_server_spammy_events", False
Copy link
Member

Choose a reason for hiding this comment

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

To match the docs:

Suggested change
"return_policy_server_spammy_events", False
"return_policy_server_spammy_events", self.return_soft_failed_events

@@ -120,10 +120,26 @@ async def filter_events_for_client(
client_config = await storage.main.get_admin_client_config_for_user(user_id)
if not (
Copy link
Member

Choose a reason for hiding this comment

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

Is this not supposed to be here?

or e.internal_metadata.policy_server_spammy
]
else:
events = [e for e in events if not e.internal_metadata.is_soft_failed()]
Copy link
Member

Choose a reason for hiding this comment

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

The logic here is currently quite difficult (for me) to follow. I'd find this easier to read as:

if (
    filter_send_to_client
    and await storage.main.is_server_admin(UserID.from_string(user_id))
):
    if client_config.return_soft_failed_events:
        # Include events that were soft-failed by any means.
        # `events` does not need to be modified in this case.
    else if (
        not client_config.return_soft_failed_events
        and client_config.return_policy_server_spammy_events
    ):
        # Include events that were only soft-failed by a policy server.
        # Events that were soft-failed by other means are excluded.
        events = [
            e
            for e in events
            # Return non-soft-failed events as well as those explicitly marked
            # as spam by a policy server. This excludes events that were soft
            # failed by other means.
            if not e.internal_metadata.is_soft_failed()
            or e.internal_metadata.policy_server_spammy
        ]
    else if (
        not client_config.return_soft_failed_events
        and not client_config.return_policy_server_spammy_events
    ):
        # Only include non-soft-failed events.
        events = [e for e in events if not e.internal_metadata.is_soft_failed()]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants