Exemplo n.º 1
0
def do_remove_streams_from_default_stream_group(realm: Realm,
                                                group: DefaultStreamGroup,
                                                streams: List[Stream]) -> None:
    for stream in streams:
        if stream not in group.streams.all():
            raise JsonableError(
                _(
                    "Stream '{stream_name}' is not present in default stream group '{group_name}'",
                ).format(stream_name=stream.name, group_name=group.name))
        group.streams.remove(stream)

    group.save()
    notify_default_stream_groups(realm)
Exemplo n.º 2
0
def do_change_default_stream_group_name(
    realm: Realm, group: DefaultStreamGroup, new_group_name: str
) -> None:
    if group.name == new_group_name:
        raise JsonableError(
            _("This default stream group is already named '{}'").format(new_group_name)
        )

    if DefaultStreamGroup.objects.filter(name=new_group_name, realm=realm).exists():
        raise JsonableError(_("Default stream group '{}' already exists").format(new_group_name))

    group.name = new_group_name
    group.save()
    notify_default_stream_groups(realm)
Exemplo n.º 3
0
def do_add_streams_to_default_stream_group(realm: Realm,
                                           group: DefaultStreamGroup,
                                           streams: List[Stream]) -> None:
    default_streams = get_default_streams_for_realm(realm.id)
    for stream in streams:
        if stream in default_streams:
            raise JsonableError(
                _(
                    "'{stream_name}' is a default stream and cannot be added to '{group_name}'",
                ).format(stream_name=stream.name, group_name=group.name))
        if stream in group.streams.all():
            raise JsonableError(
                _(
                    "Stream '{stream_name}' is already present in default stream group '{group_name}'",
                ).format(stream_name=stream.name, group_name=group.name))
        group.streams.add(stream)

    group.save()
    notify_default_stream_groups(realm)
Exemplo n.º 4
0
def do_remove_default_stream_group(realm: Realm, group: DefaultStreamGroup) -> None:
    group.delete()
    notify_default_stream_groups(realm)
Exemplo n.º 5
0
def do_change_default_stream_group_description(
    realm: Realm, group: DefaultStreamGroup, new_description: str
) -> None:
    group.description = new_description
    group.save()
    notify_default_stream_groups(realm)