mirror of https://github.com/zulip/zulip.git
types: Create a new TypedDict RealmPlaygroundDict for playground objects.
This commit creates a new TypedDict RealmPlaygroundDict for realm playground objects. Now the list of playgrounds in the events sent to clients and the "added_playground" field of RealmAuditLog entry use RealmPlaygroundDict instead of Dict.
This commit is contained in:
parent
4bbb5f18e4
commit
6f93f07844
|
@ -182,6 +182,7 @@ from zerver.lib.types import (
|
|||
ProfileFieldData,
|
||||
RawStreamDict,
|
||||
RawSubscriptionDict,
|
||||
RealmPlaygroundDict,
|
||||
SubscriptionInfo,
|
||||
SubscriptionStreamDict,
|
||||
UnspecifiedValue,
|
||||
|
@ -8097,9 +8098,7 @@ def do_remove_realm_domain(
|
|||
transaction.on_commit(lambda: send_event(realm, event, active_user_ids(realm.id)))
|
||||
|
||||
|
||||
def notify_realm_playgrounds(
|
||||
realm: Realm, realm_playgrounds: List[Dict[str, Union[int, str]]]
|
||||
) -> None:
|
||||
def notify_realm_playgrounds(realm: Realm, realm_playgrounds: List[RealmPlaygroundDict]) -> None:
|
||||
event = dict(type="realm_playgrounds", realm_playgrounds=realm_playgrounds)
|
||||
transaction.on_commit(lambda: send_event(realm, event, active_user_ids(realm.id)))
|
||||
|
||||
|
@ -8123,12 +8122,12 @@ def do_add_realm_playground(
|
|||
extra_data=orjson.dumps(
|
||||
{
|
||||
"realm_playgrounds": realm_playgrounds,
|
||||
"added_playground": {
|
||||
"id": realm_playground.id,
|
||||
"name": realm_playground.name,
|
||||
"pygments_language": realm_playground.pygments_language,
|
||||
"url_prefix": realm_playground.url_prefix,
|
||||
},
|
||||
"added_playground": RealmPlaygroundDict(
|
||||
id=realm_playground.id,
|
||||
name=realm_playground.name,
|
||||
pygments_language=realm_playground.pygments_language,
|
||||
url_prefix=realm_playground.url_prefix,
|
||||
),
|
||||
}
|
||||
).decode(),
|
||||
)
|
||||
|
|
|
@ -227,3 +227,10 @@ class SubscriptionInfo:
|
|||
subscriptions: List[SubscriptionStreamDict]
|
||||
unsubscribed: List[SubscriptionStreamDict]
|
||||
never_subscribed: List[NeverSubscribedStreamDict]
|
||||
|
||||
|
||||
class RealmPlaygroundDict(TypedDict):
|
||||
id: int
|
||||
name: str
|
||||
pygments_language: str
|
||||
url_prefix: str
|
||||
|
|
|
@ -86,6 +86,7 @@ from zerver.lib.types import (
|
|||
ProfileData,
|
||||
ProfileDataElementBase,
|
||||
ProfileDataElementValue,
|
||||
RealmPlaygroundDict,
|
||||
RealmUserValidator,
|
||||
UnspecifiedValue,
|
||||
UserFieldElement,
|
||||
|
@ -1381,11 +1382,11 @@ class RealmPlayground(models.Model):
|
|||
return f"<RealmPlayground({self.realm.string_id}): {self.pygments_language} {self.name}>"
|
||||
|
||||
|
||||
def get_realm_playgrounds(realm: Realm) -> List[Dict[str, Union[int, str]]]:
|
||||
playgrounds: List[Dict[str, Union[int, str]]] = []
|
||||
def get_realm_playgrounds(realm: Realm) -> List[RealmPlaygroundDict]:
|
||||
playgrounds: List[RealmPlaygroundDict] = []
|
||||
for playground in RealmPlayground.objects.filter(realm=realm).all():
|
||||
playgrounds.append(
|
||||
dict(
|
||||
RealmPlaygroundDict(
|
||||
id=playground.id,
|
||||
name=playground.name,
|
||||
pygments_language=playground.pygments_language,
|
||||
|
|
|
@ -44,6 +44,7 @@ from zerver.lib.message import get_last_message_id
|
|||
from zerver.lib.stream_traffic import get_streams_traffic
|
||||
from zerver.lib.streams import create_stream_if_needed
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
from zerver.lib.types import RealmPlaygroundDict
|
||||
from zerver.models import (
|
||||
Message,
|
||||
Realm,
|
||||
|
@ -745,12 +746,12 @@ class TestRealmAuditLog(ZulipTestCase):
|
|||
pygments_language="Python",
|
||||
url_prefix="https://python.example.com",
|
||||
)
|
||||
added_playground: Dict[str, Union[int, str]] = {
|
||||
"id": playground_id,
|
||||
"name": "Python playground",
|
||||
"pygments_language": "Python",
|
||||
"url_prefix": "https://python.example.com",
|
||||
}
|
||||
added_playground = RealmPlaygroundDict(
|
||||
id=playground_id,
|
||||
name="Python playground",
|
||||
pygments_language="Python",
|
||||
url_prefix="https://python.example.com",
|
||||
)
|
||||
expected_extra_data = {
|
||||
"realm_playgrounds": intial_playgrounds + [added_playground],
|
||||
"added_playground": added_playground,
|
||||
|
|
Loading…
Reference in New Issue