Coverage for slidge/space/nodes.py: 100%
25 statements
« prev ^ index » next coverage.py v7.17.0, created at 2026-12-01 19:36 +0000
« prev ^ index » next coverage.py v7.17.0, created at 2026-12-01 19:36 +0000
1from typing import ClassVar, Unpack
3import sqlalchemy as sa
4import sqlalchemy.orm
6from ..core.collection import BaseByLegacyID
7from ..db.models import Space
8from ..util.types import AnySession
9from ..util.util import derive_wired_class
10from .space import LegacySpace, _SpaceProps
13class LegacySpaceNodes[SpaceT: LegacySpace = LegacySpace](
14 BaseByLegacyID[Space, SpaceT]
15):
16 """
17 A class to manage :xep:`0503` spaces.
19 It is accessible through the ``.spaces`` attribute of the
20 :class:`.slidge.BaseSession` of a given :term:`user <User>`.
21 """
23 _space_cls: ClassVar[type[LegacySpace]] = LegacySpace # type:ignore[type-abstract]
25 def __init_subclass__(cls, **kwargs: object) -> None:
26 super().__init_subclass__(**kwargs)
27 derive_wired_class(cls, LegacySpaceNodes, "_space_cls")
29 def __init__(self, session: AnySession) -> None:
30 super().__init__(
31 session=session,
32 model=Space,
33 child_cls=self._space_cls, # type:ignore[arg-type]
34 store=session.xmpp.store.spaces,
35 )
36 self.log = session.log
38 def legacy_id_to_node(self, legacy_id: str) -> str:
39 return legacy_id
41 def node_to_legacy_id(self, node: str) -> str:
42 return node
44 def _create(self, legacy_id: str, **kwargs: Unpack[_SpaceProps]) -> SpaceT: # type:ignore[override]
45 return super()._create(legacy_id, **kwargs)
47 def _batch_load(self) -> sa.Select[Space]:
48 return super()._batch_load().options(sa.orm.joinedload(self._model.banner))
50 async def on_creation_request(
51 self, name: str | None, description: str | None, pubsub_node: str | None
52 ) -> str:
53 """
54 Called when the :term:`user <User>` requests the creation of a space,
55 i.e., request a pubsub (:xep:`0060`) node creation with the appropriate
56 ``pubsub#type``.
58 This should return the legacy ID of the created space on success, and
59 raise a meaningful :class:`slixmpp.exceptions.XMPPError` otherwise.
61 :param name: User-friendly name of the new space
62 :param description: Description of the new space
63 :param pubsub_node: XMPP clients might request a "node name" when
64 creating a pubsub node. This is not particularly supposed to be
65 user-facing, but if you can control the legacy ID of the created
66 node, you might want to use that. It is fine to ignore otherwise.
67 """
68 raise NotImplementedError