mirror of https://github.com/zulip/zulip.git
import: Move 'build_stream' to import_util.
This commit is contained in:
parent
c4f8abbd30
commit
a5bc701181
|
@ -17,7 +17,7 @@ from zerver.models import Realm, UserProfile, Recipient, Message
|
|||
from zerver.lib.export import MESSAGE_BATCH_CHUNK_SIZE
|
||||
from zerver.data_import.import_util import ZerverFieldsT, build_zerver_realm, \
|
||||
build_avatar, build_subscription, build_recipient, build_usermessages, \
|
||||
build_defaultstream, process_avatars, build_realm
|
||||
build_defaultstream, process_avatars, build_realm, build_stream
|
||||
|
||||
# stubs
|
||||
GitterDataT = List[Dict[str, Any]]
|
||||
|
@ -39,7 +39,7 @@ def gitter_workspace_to_realm(domain_name: str, gitter_data: GitterDataT,
|
|||
realm = build_realm(zerver_realm, realm_id, domain_name)
|
||||
|
||||
zerver_userprofile, avatars, user_map = build_userprofile(int(NOW), domain_name, gitter_data)
|
||||
zerver_stream, zerver_defaultstream = build_stream(int(NOW))
|
||||
zerver_stream, zerver_defaultstream = build_stream_and_defaultstream(int(NOW))
|
||||
zerver_recipient, zerver_subscription = build_recipient_and_subscription(
|
||||
zerver_userprofile, zerver_stream)
|
||||
|
||||
|
@ -101,20 +101,18 @@ def get_user_email(user_data: ZerverFieldsT, domain_name: str) -> str:
|
|||
email = ("%s@users.noreply.github.com" % user_data['username'])
|
||||
return email
|
||||
|
||||
def build_stream(timestamp: Any) -> Tuple[List[ZerverFieldsT],
|
||||
List[ZerverFieldsT]]:
|
||||
def build_stream_and_defaultstream(timestamp: Any) -> Tuple[List[ZerverFieldsT],
|
||||
List[ZerverFieldsT]]:
|
||||
logging.info('######### IMPORTING STREAM STARTED #########\n')
|
||||
# We have only one stream for gitter export
|
||||
stream = dict(
|
||||
realm=realm_id,
|
||||
name="from gitter",
|
||||
deactivated=False,
|
||||
description="Imported from gitter",
|
||||
invite_only=False,
|
||||
date_created=timestamp,
|
||||
id=0)
|
||||
stream_name = 'from gitter'
|
||||
stream_description = "Imported from gitter"
|
||||
stream_id = 0
|
||||
stream = build_stream(timestamp, realm_id, stream_name, stream_description,
|
||||
stream_id)
|
||||
|
||||
defaultstream = build_defaultstream(realm_id=realm_id, stream_id=0, defaultstream_id=0)
|
||||
defaultstream = build_defaultstream(realm_id=realm_id, stream_id=stream_id,
|
||||
defaultstream_id=0)
|
||||
logging.info('######### IMPORTING STREAMS FINISHED #########\n')
|
||||
return [stream], [defaultstream]
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ from typing import List, Dict, Any
|
|||
from django.forms.models import model_to_dict
|
||||
|
||||
from zerver.models import Realm, RealmEmoji, Subscription, Recipient, \
|
||||
Attachment
|
||||
Attachment, Stream
|
||||
from zerver.lib.actions import STREAM_ASSIGNMENT_COLORS as stream_colors
|
||||
from zerver.lib.avatar_hash import user_avatar_path_from_ids
|
||||
from zerver.lib.parallel import run_parallel
|
||||
|
@ -106,6 +106,21 @@ def build_defaultstream(realm_id: int, stream_id: int,
|
|||
id=defaultstream_id)
|
||||
return defaultstream
|
||||
|
||||
def build_stream(date_created: Any, realm_id: int, name: str,
|
||||
description: str, stream_id: int, deactivated: bool=False,
|
||||
invite_only: bool=False) -> ZerverFieldsT:
|
||||
stream = Stream(
|
||||
name=name,
|
||||
deactivated=deactivated,
|
||||
description=description,
|
||||
date_created=date_created,
|
||||
invite_only=invite_only,
|
||||
id=stream_id)
|
||||
stream_dict = model_to_dict(stream,
|
||||
exclude=['realm'])
|
||||
stream_dict['realm'] = realm_id
|
||||
return stream_dict
|
||||
|
||||
def build_attachment(realm_id: int, message_id: int, attachment_id: int,
|
||||
user_id: int, fileinfo: ZerverFieldsT, s3_path: str,
|
||||
zerver_attachment: List[ZerverFieldsT]) -> None:
|
||||
|
|
|
@ -24,7 +24,7 @@ from zerver.data_import.slack_message_conversion import convert_to_zulip_markdow
|
|||
from zerver.data_import.import_util import ZerverFieldsT, build_zerver_realm, \
|
||||
build_avatar, build_subscription, build_recipient, build_usermessages, \
|
||||
build_defaultstream, build_attachment, process_avatars, process_uploads, \
|
||||
process_emojis, build_realm
|
||||
process_emojis, build_realm, build_stream
|
||||
from zerver.lib.parallel import run_parallel
|
||||
from zerver.lib.upload import random_name, sanitize_name
|
||||
from zerver.lib.export import MESSAGE_BATCH_CHUNK_SIZE
|
||||
|
@ -349,16 +349,9 @@ def channels_to_zerver_stream(slack_data_dir: str, realm_id: int, added_users: A
|
|||
recipient_id = recipient_id_count
|
||||
|
||||
# construct the stream object and append it to zerver_stream
|
||||
stream = dict(
|
||||
realm=realm_id,
|
||||
name=channel["name"],
|
||||
deactivated=channel["is_archived"],
|
||||
description=description,
|
||||
invite_only=False, # TODO: private channels are not
|
||||
# exported with Slack's standard plan;
|
||||
# so this field is always false
|
||||
date_created=float(channel["created"]),
|
||||
id=stream_id)
|
||||
stream = build_stream(float(channel["created"]), realm_id, channel["name"],
|
||||
description, stream_id, channel["is_archived"])
|
||||
zerver_stream.append(stream)
|
||||
|
||||
# construct defaultstream object
|
||||
# slack has the default channel 'general' and 'random'
|
||||
|
@ -370,7 +363,6 @@ def channels_to_zerver_stream(slack_data_dir: str, realm_id: int, added_users: A
|
|||
zerver_defaultstream.append(defaultstream)
|
||||
defaultstream_id += 1
|
||||
|
||||
zerver_stream.append(stream)
|
||||
added_channels[stream['name']] = (channel['id'], stream_id)
|
||||
|
||||
recipient = build_recipient(stream_id, recipient_id, Recipient.STREAM)
|
||||
|
|
Loading…
Reference in New Issue