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

Commit 5884cb5

Browse files
committed
Documentation
1 parent 357542c commit 5884cb5

File tree

3 files changed

+56
-9
lines changed

3 files changed

+56
-9
lines changed

changelog.d/12028.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add third party event rules functions `check_can_shutdown_room` and `check_can_deactivate_user`.

docs/modules/third_party_rules_callbacks.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,50 @@ deny an incoming event, see [`check_event_for_spam`](spam_checker_callbacks.md#c
148148

149149
If multiple modules implement this callback, Synapse runs them all in order.
150150

151+
### `check_can_shutdown_room`
152+
153+
_First introduced in Synapse v1.5X.0_
154+
155+
```python
156+
async def check_can_shutdown_room(
157+
user_id: str
158+
room_id: str,
159+
) -> bool:
160+
```
161+
162+
Called when a user requests the shutdown of a room. The module must return a
163+
boolean indicating whether the shutdown can go through. If the callback returns `False`,
164+
the shutdown will not proceed and the caller will see a `M_FOBIDDEN` error.
165+
166+
If multiple modules implement this callback, they will be considered in order. If a
167+
callback returns `True`, Synapse falls through to the next one. The value of the first
168+
callback that does not return `True` will be used. If this happens, Synapse will not call
169+
any of the subsequent implementations of this callback.
170+
171+
### `check_can_deactivate_user`
172+
173+
_First introduced in Synapse v1.5X.0_
174+
175+
```python
176+
async def check_can_deactivate_user(
177+
requester: "synapse.types.Requester",
178+
user_id: str,
179+
) -> bool:
180+
```
181+
182+
Called when a user requests the deactivation of a user. User deactivation may be
183+
performed by an admin or the user themselves, so developers are encouraged to check the
184+
requester when implementing this callback. The module must return a
185+
boolean indicating whether the deactivation can go through. If the callback returns `False`,
186+
the deactivation will not proceed and the caller will see a `M_FOBIDDEN` error.
187+
188+
If multiple modules implement this callback, they will be considered in order. If a
189+
callback returns `True`, Synapse falls through to the next one. The value of the first
190+
callback that does not return `True` will be used. If this happens, Synapse will not call
191+
any of the subsequent implementations of this callback.
192+
193+
194+
151195
## Example
152196

153197
The example below is a module that implements the third-party rules callback

synapse/events/third_party_rules.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def __init__(self, hs: "HomeServer"):
156156
CHECK_VISIBILITY_CAN_BE_MODIFIED_CALLBACK
157157
] = []
158158
self._on_new_event_callbacks: List[ON_NEW_EVENT_CALLBACK] = []
159-
self._check_can_delete_room: List[CHECK_CAN_SHUTDOWN_ROOM_CALLBACK] = []
159+
self._check_can_shutdown_room: List[CHECK_CAN_SHUTDOWN_ROOM_CALLBACK] = []
160160
self._check_can_deactivate_user: List[CHECK_CAN_DEACTIVATE_USER_CALLBACK] = []
161161

162162
def register_third_party_rules_callbacks(
@@ -194,7 +194,7 @@ def register_third_party_rules_callbacks(
194194
self._on_new_event_callbacks.append(on_new_event)
195195

196196
if check_can_shutdown_room is not None:
197-
self._check_can_delete_room.append(check_can_shutdown_room)
197+
self._check_can_shutdown_room.append(check_can_shutdown_room)
198198

199199
if check_can_deactivate_user is not None:
200200
self._check_can_deactivate_user.append(check_can_deactivate_user)
@@ -365,19 +365,20 @@ async def on_new_event(self, event_id: str) -> None:
365365
"Failed to run module API callback %s: %s", callback, e
366366
)
367367

368-
async def check_can_shutdown_room(self, requester: Requester, room_id: str) -> None:
369-
"""Intercept requests to delete room to maybe deny it by returning False.
368+
async def check_can_shutdown_room(self, user_id: str, room_id: str) -> bool:
369+
"""Intercept requests to shutdown a room. If `False` is returned, the
370+
room should not be shut down.
370371
371372
Args:
372-
requester
373+
requester: The ID of the user requesting the shutdown.
373374
room_id: The ID of the room.
374375
375376
Raises:
376377
ModuleFailureError if a callback raised any exception.
377378
"""
378-
for callback in self._check_can_delete_room:
379+
for callback in self._check_can_shutdown_room:
379380
try:
380-
if await callback(requester, room_id) is False:
381+
if await callback(user_id, room_id) is False:
381382
return False
382383
except Exception as e:
383384
logger.exception(
@@ -387,8 +388,9 @@ async def check_can_shutdown_room(self, requester: Requester, room_id: str) -> N
387388

388389
async def check_can_deactivate_user(
389390
self, requester: Requester, user_id: str
390-
) -> None:
391-
"""Intercept requests to deactivate a user to maybe deny it by returning False.
391+
) -> bool:
392+
"""Intercept requests to deactivate a user. If `False` is returned, the
393+
user should not be deactivated.
392394
393395
Args:
394396
requester

0 commit comments

Comments
 (0)