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

Third party event rules Update#6781

Merged
anoadragon453 merged 8 commits intomatrix-org:developfrom
PeerD:peer/third-party-event-rules
Feb 6, 2020
Merged

Third party event rules Update#6781
anoadragon453 merged 8 commits intomatrix-org:developfrom
PeerD:peer/third-party-event-rules

Conversation

@PeerD
Copy link
Contributor

@PeerD PeerD commented Jan 25, 2020

Fixes and additions to third party event rules to function correctly and return custom error messages:

This fixes:

  • on_create_room() was not checked and thus ignored

And adds:

  • check_event_allowed(), on_create_room() and check_threepid_can_be_invited() can now return an error message as second return parameter. This is then used instead of the default error message and send to the client.

The tupel option was chosen to guarantee backwards compatibility. Existing forein rules should not break. If the second return value is not given, the default message will be used as it was until now.

Signed-off-by: Peer Diestelhorst <signoff@spy.de>

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.
  • Pull request includes a sign off
  • Code style is correct (run the linters)

@PeerD
Copy link
Contributor Author

PeerD commented Jan 26, 2020

One thing I do not understand: In third_party_rules.py return is used instead of returnValue() in inlineCallbacks decorated functions. According to the twisted documentation this should not work. But somehow it does. Am I missing something? Sorry, I'm quite new to python and just started reading into it for this pr.

@PeerD
Copy link
Contributor Author

PeerD commented Jan 28, 2020

Ok, I saw that the latest version of the twisted documentation allows for this. Nevermind.

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.

Modules are able to import SynapseError (specifically from synapse.module_api.SynapseError) and raise errors themselves. I agree this isn't intuitive though and should probably be added to some documentation or a comment inside of events/third_party_rules.py. This is preferable and more "pythonic" to having modules return error tuples and checking them all over the codebase.

The on_create_room fix is important though, however while dealing with the same functions, a little tangentially related. Could you split that out into a separate PR, while we focus this one on module api error handling?

Copy link
Member

Choose a reason for hiding this comment

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

Changelog entries are read by Synapse maintainers and matrix users, rather than synapse developers, thus we may want to phrase this is a different way. Something along the lines of:

Improve error messages when an action is denied by a third party rule.

perhaps.

@anoadragon453 anoadragon453 self-assigned this Feb 3, 2020
@PeerD
Copy link
Contributor Author

PeerD commented Feb 3, 2020

Thanks for the info about SynapseError. I tested it and it works like a charm. I guess that solution was so obvious I missed it. But I agree that it could be better documented.

I removed all the tuple return value stuff again so all that remains should be the bugfix for the on room create. I also worked in your remarks, I hope I didn't miss anything.

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.

Just a tiny typo.

Now that I think about it though, if modules can raise exceptions, there's not much point in having them return a True or False value. Instead they should just be run, and if no exception is raised, the calling function will continue.

This PR is still useful, but I wonder if the reason on_create_room's return value isn't used is because it was expected to raise an exception on failure.

The docstring doesn't say it's supposed to raise any exceptions though, so 🤷‍♂️

@PeerD
Copy link
Contributor Author

PeerD commented Feb 4, 2020

Is it normal that the tests are failing? But it looks to me like it has nothing to do with my changes?

@anoadragon453
Copy link
Member

It's due to a brief period on the develop branch where CI is failing that you seem to have branched your PR off of.

Just do:

git pull origin develop
git push

to fix it.

PeerD and others added 8 commits February 6, 2020 14:00
Fixes and additions to third party event rules to function correctly and return custom error messages
Fixed typo

Co-Authored-By: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
@PeerD
Copy link
Contributor Author

PeerD commented Feb 6, 2020

Ok, now I screwed something up... I guess its easier to redo those few changes and make a new PR?

@PeerD PeerD force-pushed the peer/third-party-event-rules branch from 915534e to 38b2fde Compare February 6, 2020 13:31
@PeerD
Copy link
Contributor Author

PeerD commented Feb 6, 2020

Ok, nevermind. Some git commandline fu and somehow I got it fixed. Not sure how but it seems to build work now :D

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.

Looking good, thank you!

@anoadragon453 anoadragon453 merged commit 99fcc96 into matrix-org:develop Feb 6, 2020
@PeerD
Copy link
Contributor Author

PeerD commented Feb 6, 2020

Thank you very much for your support!

babolivier pushed a commit that referenced this pull request Sep 1, 2021
* commit '99fcc9628':
  Third party event rules Update (#6781)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants