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
Allow ThirdPartyEventRules modules to manipulate public room state #8292
Merged
anoadragon453
merged 23 commits into
develop
from
anoa/third_party_event_rules_public_rooms
Oct 5, 2020
Merged
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
68391e4
Add a store method for checking whether a room is in the public dir
anoadragon453 0503eee
Allow ThirdPartyEventRules modules to block publishing a room
anoadragon453 9eae87d
Query ThirdPartyEventRules about public rooms during room creation
anoadragon453 833883e
Query ThirdPartyEventRules while trying to add to the public room dir
anoadragon453 8690c86
Add tests
anoadragon453 6eae2c1
Changelog
anoadragon453 431e3e3
Replace verbose type with StateMap
anoadragon453 529863a
Remove get_room_is_public and use get_room instead
anoadragon453 699fa5b
Address review comments
anoadragon453 f5b6246
Axe the PublicRoomsManager and switch to passing the ModuleApi
anoadragon453 e768fae
Move PublicRoomsManager tests to ModuleApi
anoadragon453 04ab21c
Create a PublicRoomListManager as part of ModuleApi
anoadragon453 06deecf
Backwards incompatibility warning for ThirdPartyEventRules in UPGRADE…
anoadragon453 6ed082d
Some minor fixes
anoadragon453 83a20a2
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/thi…
anoadragon453 0f4c1bb
Update unit tests
anoadragon453 3bde820
Fix call to old method name
anoadragon453 8d9b166
Update UPGRADE.rst, remove extra entry, convert to rst
anoadragon453 1ff7df9
Move PublicRoomListManager below ModuleApi
anoadragon453 e5b2d20
Remove hs param from the PublicRoomListManager docstring
anoadragon453 5730d17
Expose http_client and public_room_list_manager as properties
anoadragon453 d46396d
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/thi…
anoadragon453 49e71a8
Move upgrade notes comment from v1.21.0 to v1.22.0
anoadragon453 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
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 @@ | ||
Allow `ThirdPartyEventRules` modules to query and manipulate whether a room is in the public rooms directory. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,18 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import logging | ||
from typing import TYPE_CHECKING | ||
|
||
from twisted.internet import defer | ||
|
||
from synapse.http.client import SimpleHttpClient | ||
from synapse.http.site import SynapseRequest | ||
from synapse.logging.context import make_deferred_yieldable, run_in_background | ||
from synapse.types import UserID | ||
|
||
if TYPE_CHECKING: | ||
from synapse.server import HomeServer | ||
|
||
""" | ||
This package defines the 'stable' API which can be used by extension modules which | ||
are loaded into Synapse. | ||
|
@@ -31,6 +36,50 @@ | |
logger = logging.getLogger(__name__) | ||
|
||
|
||
class PublicRoomListManager: | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Contains methods for adding to, removing from and querying whether a room | ||
is in the public room list. | ||
|
||
Args: | ||
hs: The Homeserver object | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
|
||
def __init__(self, hs: "HomeServer"): | ||
self._store = hs.get_datastore() | ||
|
||
async def room_is_in_public_room_list(self, room_id: str) -> bool: | ||
"""Checks whether a room is in the public room list. | ||
|
||
Args: | ||
room_id: The ID of the room. | ||
|
||
Returns: | ||
Whether the room is in the public room list. Returns False if the room does | ||
not exist. | ||
""" | ||
room = await self._store.get_room(room_id) | ||
if not room: | ||
return False | ||
|
||
return room.get("is_public", False) | ||
|
||
async def add_room_to_public_room_list(self, room_id: str) -> None: | ||
"""Publishes a room to the public room list. | ||
|
||
Args: | ||
room_id: The ID of the room. | ||
""" | ||
await self._store.set_room_is_public(room_id, True) | ||
|
||
async def remove_room_from_public_room_list(self, room_id: str) -> None: | ||
"""Removes a room from the public room list. | ||
|
||
Args: | ||
room_id: The ID of the room. | ||
""" | ||
await self._store.set_room_is_public(room_id, False) | ||
|
||
|
||
class ModuleApi: | ||
"""A proxy object that gets passed to various plugin modules so they | ||
can register new users etc if necessary. | ||
|
@@ -43,6 +92,9 @@ def __init__(self, hs, auth_handler): | |
self._auth = hs.get_auth() | ||
self._auth_handler = auth_handler | ||
|
||
self.http_client = hs.get_simple_http_client() # type: SimpleHttpClient | ||
self.public_room_list_manager = PublicRoomListManager(hs) | ||
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. I would recommend exposing these as 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. I have done so in 5730d17, though I'm not sure if the contents of the docstrings were entirely what you were looking for. 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. they look good to me |
||
|
||
def get_user_by_req(self, req, allow_guest=False): | ||
"""Check the access_token provided for a request | ||
|
||
|
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
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.