This commit is contained in:
erikjohnston 2022-05-31 13:48:55 +00:00
parent 1fec7f5214
commit 25eebe534e
5 changed files with 40 additions and 44 deletions

View File

@ -153,28 +153,26 @@ Synapse instances. Spam checker callbacks can be registered using the module API
<h2 id="callbacks"><a class="header" href="#callbacks">Callbacks</a></h2> <h2 id="callbacks"><a class="header" href="#callbacks">Callbacks</a></h2>
<p>The available spam checker callbacks are:</p> <p>The available spam checker callbacks are:</p>
<h3 id="check_event_for_spam"><a class="header" href="#check_event_for_spam"><code>check_event_for_spam</code></a></h3> <h3 id="check_event_for_spam"><a class="header" href="#check_event_for_spam"><code>check_event_for_spam</code></a></h3>
<p><em>First introduced in Synapse v1.37.0</em> <p><em>First introduced in Synapse v1.37.0</em></p>
<em>Signature extended to support Allow and Code in Synapse v1.60.0</em> <p><em>Changed in Synapse v1.60.0: <code>synapse.module_api.NOT_SPAM</code> and <code>synapse.module_api.errors.Codes</code> can be returned by this callback. Returning a boolean or a string is now deprecated.</em> </p>
<em>Boolean and string return value types deprecated in Synapse v1.60.0</em></p> <pre><code class="language-python">async def check_event_for_spam(event: &quot;synapse.module_api.EventBase&quot;) -&gt; Union[&quot;synapse.module_api.NOT_SPAM&quot;, &quot;synapse.module_api.errors.Codes&quot;, str, bool]
<pre><code class="language-python">async def check_event_for_spam(event: &quot;synapse.module_api.EventBase&quot;) -&gt; Union[&quot;synapse.module_api.ALLOW&quot;, &quot;synapse.module_api.error.Codes&quot;, str, bool]
</code></pre> </code></pre>
<p>Called when receiving an event from a client or via federation. The callback must return either:</p> <p>Called when receiving an event from a client or via federation. The callback must return one of:</p>
<ul> <ul>
<li><code>synapse.module_api.ALLOW</code>, to allow the operation. Other callbacks <li><code>synapse.module_api.NOT_SPAM</code>, to allow the operation. Other callbacks may still
may still decide to reject it.</li> decide to reject it.</li>
<li><code>synapse.api.Codes</code> to reject the operation with an error code. In case <li><code>synapse.module_api.errors.Codes</code> to reject the operation with an error code. In case
of doubt, <code>synapse.api.error.Codes.FORBIDDEN</code> is a good error code.</li> of doubt, <code>synapse.module_api.errors.Codes.FORBIDDEN</code> is a good error code.</li>
<li>(deprecated) a <code>str</code> to reject the operation and specify an error message. Note that clients <li>(deprecated) a non-<code>Codes</code> <code>str</code> to reject the operation and specify an error message. Note that clients
typically will not localize the error message to the user's preferred locale.</li> typically will not localize the error message to the user's preferred locale.</li>
<li>(deprecated) on <code>False</code>, behave as <code>ALLOW</code>. Deprecated as confusing, as some <li>(deprecated) <code>False</code>, which is the same as returning <code>synapse.module_api.NOT_SPAM</code>.</li>
callbacks in expect <code>True</code> to allow and others <code>True</code> to reject.</li> <li>(deprecated) <code>True</code>, which is the same as returning <code>synapse.module_api.errors.Codes.FORBIDDEN</code>.</li>
<li>(deprecated) on <code>True</code>, behave as <code>synapse.api.error.Codes.FORBIDDEN</code>. Deprecated as confusing, as
some callbacks in expect <code>True</code> to allow and others <code>True</code> to reject.</li>
</ul> </ul>
<p>If multiple modules implement this callback, they will be considered in order. If a <p>If multiple modules implement this callback, they will be considered in order. If a
callback returns <code>synapse.module_api.ALLOW</code>, Synapse falls through to the next one. The value of the callback returns <code>synapse.module_api.NOT_SPAM</code>, Synapse falls through to the next one.
first callback that does not return <code>synapse.module_api.ALLOW</code> will be used. If this happens, Synapse The value of the first callback that does not return <code>synapse.module_api.NOT_SPAM</code> will
will not call any of the subsequent implementations of this callback.</p> be used. If this happens, Synapse will not call any of the subsequent implementations of
this callback.</p>
<h3 id="user_may_join_room"><a class="header" href="#user_may_join_room"><code>user_may_join_room</code></a></h3> <h3 id="user_may_join_room"><a class="header" href="#user_may_join_room"><code>user_may_join_room</code></a></h3>
<p><em>First introduced in Synapse v1.37.0</em></p> <p><em>First introduced in Synapse v1.37.0</em></p>
<pre><code class="language-python">async def user_may_join_room(user: str, room: str, is_invited: bool) -&gt; bool <pre><code class="language-python">async def user_may_join_room(user: str, room: str, is_invited: bool) -&gt; bool

View File

@ -1694,9 +1694,9 @@ COMMIT;
<p><a href="https://github.com/matrix-org/synapse/issues/11779#issuecomment-1131545970">This comment on issue 11779</a> <p><a href="https://github.com/matrix-org/synapse/issues/11779#issuecomment-1131545970">This comment on issue 11779</a>
has queries that can be used to check a database for this problem in advance.</p> has queries that can be used to check a database for this problem in advance.</p>
</details> </details>
<h2 id="spamchecker-apis-check_event_for_spam-has-a-new-signature"><a class="header" href="#spamchecker-apis-check_event_for_spam-has-a-new-signature">SpamChecker API's <code>check_event_for_spam</code> has a new signature.</a></h2> <h2 id="new-signature-for-the-spam-checker-callback-check_event_for_spam"><a class="header" href="#new-signature-for-the-spam-checker-callback-check_event_for_spam">New signature for the spam checker callback <code>check_event_for_spam</code></a></h2>
<p>The previous signature has been deprecated.</p> <p>The previous signature has been deprecated.</p>
<p>Whereas <code>check_event_for_spam</code> callbacks used to return <code>Union[str, bool]</code>, they should now return <code>Union[&quot;synapse.module_api.Allow&quot;, &quot;synapse.module_api.errors.Codes&quot;]</code>.</p> <p>Whereas <code>check_event_for_spam</code> callbacks used to return <code>Union[str, bool]</code>, they should now return <code>Union[&quot;synapse.module_api.NOT_SPAM&quot;, &quot;synapse.module_api.errors.Codes&quot;]</code>.</p>
<p>This is part of an ongoing refactoring of the SpamChecker API to make it less ambiguous and more powerful.</p> <p>This is part of an ongoing refactoring of the SpamChecker API to make it less ambiguous and more powerful.</p>
<p>If your module implements <code>check_event_for_spam</code> as follows:</p> <p>If your module implements <code>check_event_for_spam</code> as follows:</p>
<pre><code class="language-python">async def check_event_for_spam(event): <pre><code class="language-python">async def check_event_for_spam(event):
@ -1712,8 +1712,8 @@ has queries that can be used to check a database for this problem in advance.</p
# Event is spam, mark it as forbidden (you may use some more precise error # Event is spam, mark it as forbidden (you may use some more precise error
# code if it is useful). # code if it is useful).
return synapse.module_api.errors.Codes.FORBIDDEN return synapse.module_api.errors.Codes.FORBIDDEN
# Event is not spam, mark it as `ALLOW`. # Event is not spam, mark it as such.
return synapse.module_api.ALLOW return synapse.module_api.NOT_SPAM
</code></pre> </code></pre>
<h1 id="upgrading-to-v1590"><a class="header" href="#upgrading-to-v1590">Upgrading to v1.59.0</a></h1> <h1 id="upgrading-to-v1590"><a class="header" href="#upgrading-to-v1590">Upgrading to v1.59.0</a></h1>
<h2 id="device-name-lookup-over-federation-has-been-disabled-by-default"><a class="header" href="#device-name-lookup-over-federation-has-been-disabled-by-default">Device name lookup over federation has been disabled by default</a></h2> <h2 id="device-name-lookup-over-federation-has-been-disabled-by-default"><a class="header" href="#device-name-lookup-over-federation-has-been-disabled-by-default">Device name lookup over federation has been disabled by default</a></h2>
@ -11213,28 +11213,26 @@ Synapse instances. Spam checker callbacks can be registered using the module API
<h2 id="callbacks"><a class="header" href="#callbacks">Callbacks</a></h2> <h2 id="callbacks"><a class="header" href="#callbacks">Callbacks</a></h2>
<p>The available spam checker callbacks are:</p> <p>The available spam checker callbacks are:</p>
<h3 id="check_event_for_spam"><a class="header" href="#check_event_for_spam"><code>check_event_for_spam</code></a></h3> <h3 id="check_event_for_spam"><a class="header" href="#check_event_for_spam"><code>check_event_for_spam</code></a></h3>
<p><em>First introduced in Synapse v1.37.0</em> <p><em>First introduced in Synapse v1.37.0</em></p>
<em>Signature extended to support Allow and Code in Synapse v1.60.0</em> <p><em>Changed in Synapse v1.60.0: <code>synapse.module_api.NOT_SPAM</code> and <code>synapse.module_api.errors.Codes</code> can be returned by this callback. Returning a boolean or a string is now deprecated.</em> </p>
<em>Boolean and string return value types deprecated in Synapse v1.60.0</em></p> <pre><code class="language-python">async def check_event_for_spam(event: &quot;synapse.module_api.EventBase&quot;) -&gt; Union[&quot;synapse.module_api.NOT_SPAM&quot;, &quot;synapse.module_api.errors.Codes&quot;, str, bool]
<pre><code class="language-python">async def check_event_for_spam(event: &quot;synapse.module_api.EventBase&quot;) -&gt; Union[&quot;synapse.module_api.ALLOW&quot;, &quot;synapse.module_api.error.Codes&quot;, str, bool]
</code></pre> </code></pre>
<p>Called when receiving an event from a client or via federation. The callback must return either:</p> <p>Called when receiving an event from a client or via federation. The callback must return one of:</p>
<ul> <ul>
<li><code>synapse.module_api.ALLOW</code>, to allow the operation. Other callbacks <li><code>synapse.module_api.NOT_SPAM</code>, to allow the operation. Other callbacks may still
may still decide to reject it.</li> decide to reject it.</li>
<li><code>synapse.api.Codes</code> to reject the operation with an error code. In case <li><code>synapse.module_api.errors.Codes</code> to reject the operation with an error code. In case
of doubt, <code>synapse.api.error.Codes.FORBIDDEN</code> is a good error code.</li> of doubt, <code>synapse.module_api.errors.Codes.FORBIDDEN</code> is a good error code.</li>
<li>(deprecated) a <code>str</code> to reject the operation and specify an error message. Note that clients <li>(deprecated) a non-<code>Codes</code> <code>str</code> to reject the operation and specify an error message. Note that clients
typically will not localize the error message to the user's preferred locale.</li> typically will not localize the error message to the user's preferred locale.</li>
<li>(deprecated) on <code>False</code>, behave as <code>ALLOW</code>. Deprecated as confusing, as some <li>(deprecated) <code>False</code>, which is the same as returning <code>synapse.module_api.NOT_SPAM</code>.</li>
callbacks in expect <code>True</code> to allow and others <code>True</code> to reject.</li> <li>(deprecated) <code>True</code>, which is the same as returning <code>synapse.module_api.errors.Codes.FORBIDDEN</code>.</li>
<li>(deprecated) on <code>True</code>, behave as <code>synapse.api.error.Codes.FORBIDDEN</code>. Deprecated as confusing, as
some callbacks in expect <code>True</code> to allow and others <code>True</code> to reject.</li>
</ul> </ul>
<p>If multiple modules implement this callback, they will be considered in order. If a <p>If multiple modules implement this callback, they will be considered in order. If a
callback returns <code>synapse.module_api.ALLOW</code>, Synapse falls through to the next one. The value of the callback returns <code>synapse.module_api.NOT_SPAM</code>, Synapse falls through to the next one.
first callback that does not return <code>synapse.module_api.ALLOW</code> will be used. If this happens, Synapse The value of the first callback that does not return <code>synapse.module_api.NOT_SPAM</code> will
will not call any of the subsequent implementations of this callback.</p> be used. If this happens, Synapse will not call any of the subsequent implementations of
this callback.</p>
<h3 id="user_may_join_room"><a class="header" href="#user_may_join_room"><code>user_may_join_room</code></a></h3> <h3 id="user_may_join_room"><a class="header" href="#user_may_join_room"><code>user_may_join_room</code></a></h3>
<p><em>First introduced in Synapse v1.37.0</em></p> <p><em>First introduced in Synapse v1.37.0</em></p>
<pre><code class="language-python">async def user_may_join_room(user: str, room: str, is_invited: bool) -&gt; bool <pre><code class="language-python">async def user_may_join_room(user: str, room: str, is_invited: bool) -&gt; bool

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -295,9 +295,9 @@ COMMIT;
<p><a href="https://github.com/matrix-org/synapse/issues/11779#issuecomment-1131545970">This comment on issue 11779</a> <p><a href="https://github.com/matrix-org/synapse/issues/11779#issuecomment-1131545970">This comment on issue 11779</a>
has queries that can be used to check a database for this problem in advance.</p> has queries that can be used to check a database for this problem in advance.</p>
</details> </details>
<h2 id="spamchecker-apis-check_event_for_spam-has-a-new-signature"><a class="header" href="#spamchecker-apis-check_event_for_spam-has-a-new-signature">SpamChecker API's <code>check_event_for_spam</code> has a new signature.</a></h2> <h2 id="new-signature-for-the-spam-checker-callback-check_event_for_spam"><a class="header" href="#new-signature-for-the-spam-checker-callback-check_event_for_spam">New signature for the spam checker callback <code>check_event_for_spam</code></a></h2>
<p>The previous signature has been deprecated.</p> <p>The previous signature has been deprecated.</p>
<p>Whereas <code>check_event_for_spam</code> callbacks used to return <code>Union[str, bool]</code>, they should now return <code>Union[&quot;synapse.module_api.Allow&quot;, &quot;synapse.module_api.errors.Codes&quot;]</code>.</p> <p>Whereas <code>check_event_for_spam</code> callbacks used to return <code>Union[str, bool]</code>, they should now return <code>Union[&quot;synapse.module_api.NOT_SPAM&quot;, &quot;synapse.module_api.errors.Codes&quot;]</code>.</p>
<p>This is part of an ongoing refactoring of the SpamChecker API to make it less ambiguous and more powerful.</p> <p>This is part of an ongoing refactoring of the SpamChecker API to make it less ambiguous and more powerful.</p>
<p>If your module implements <code>check_event_for_spam</code> as follows:</p> <p>If your module implements <code>check_event_for_spam</code> as follows:</p>
<pre><code class="language-python">async def check_event_for_spam(event): <pre><code class="language-python">async def check_event_for_spam(event):
@ -313,8 +313,8 @@ has queries that can be used to check a database for this problem in advance.</p
# Event is spam, mark it as forbidden (you may use some more precise error # Event is spam, mark it as forbidden (you may use some more precise error
# code if it is useful). # code if it is useful).
return synapse.module_api.errors.Codes.FORBIDDEN return synapse.module_api.errors.Codes.FORBIDDEN
# Event is not spam, mark it as `ALLOW`. # Event is not spam, mark it as such.
return synapse.module_api.ALLOW return synapse.module_api.NOT_SPAM
</code></pre> </code></pre>
<h1 id="upgrading-to-v1590"><a class="header" href="#upgrading-to-v1590">Upgrading to v1.59.0</a></h1> <h1 id="upgrading-to-v1590"><a class="header" href="#upgrading-to-v1590">Upgrading to v1.59.0</a></h1>
<h2 id="device-name-lookup-over-federation-has-been-disabled-by-default"><a class="header" href="#device-name-lookup-over-federation-has-been-disabled-by-default">Device name lookup over federation has been disabled by default</a></h2> <h2 id="device-name-lookup-over-federation-has-been-disabled-by-default"><a class="header" href="#device-name-lookup-over-federation-has-been-disabled-by-default">Device name lookup over federation has been disabled by default</a></h2>