Esempio n. 1
0
    def make_stream(
            self,
            stream_name: str,
            realm: Optional[Realm] = None,
            invite_only: Optional[bool] = False,
            history_public_to_subscribers: Optional[bool] = None) -> Stream:
        if realm is None:
            realm = get_realm('zulip')

        history_public_to_subscribers = get_default_value_for_history_public_to_subscribers(
            realm, invite_only, history_public_to_subscribers)

        try:
            stream = Stream.objects.create(
                realm=realm,
                name=stream_name,
                invite_only=invite_only,
                history_public_to_subscribers=history_public_to_subscribers,
            )
        except IntegrityError:  # nocoverage -- this is for bugs in the tests
            raise Exception('''
                %s already exists

                Please call make_stream with a stream name
                that is not already in use.''' % (stream_name, ))

        recipient = Recipient.objects.create(type_id=stream.id,
                                             type=Recipient.STREAM)
        stream.recipient = recipient
        stream.save(update_fields=["recipient"])
        return stream
Esempio n. 2
0
    def make_stream(self, stream_name: str, realm: Optional[Realm]=None,
                    invite_only: Optional[bool]=False,
                    history_public_to_subscribers: Optional[bool]=None) -> Stream:
        if realm is None:
            realm = self.DEFAULT_REALM

        history_public_to_subscribers = get_default_value_for_history_public_to_subscribers(
            realm, invite_only, history_public_to_subscribers)

        try:
            stream = Stream.objects.create(
                realm=realm,
                name=stream_name,
                invite_only=invite_only,
                history_public_to_subscribers=history_public_to_subscribers,
            )
        except IntegrityError:  # nocoverage -- this is for bugs in the tests
            raise Exception('''
                %s already exists

                Please call make_stream with a stream name
                that is not already in use.''' % (stream_name,))

        Recipient.objects.create(type_id=stream.id, type=Recipient.STREAM)
        return stream