def gitter_workspace_to_realm( domain_name: str, gitter_data: GitterDataT, realm_subdomain: str ) -> Tuple[ZerverFieldsT, List[ZerverFieldsT], Dict[str, int], Dict[str, int]]: """ Returns: 1. realm, converted realm data 2. avatars, which is list to map avatars to Zulip avatar records.json 3. user_map, which is a dictionary to map from Gitter user id to Zulip user id 4. stream_map, which is a dictionary to map from Gitter rooms to Zulip stream id """ NOW = float(timezone_now().timestamp()) zerver_realm: List[ZerverFieldsT] = build_zerver_realm( realm_id, realm_subdomain, NOW, 'Gitter') 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, stream_map = build_stream_map( int(NOW), gitter_data) zerver_recipient, zerver_subscription = build_recipient_and_subscription( zerver_userprofile, zerver_stream) realm['zerver_userprofile'] = zerver_userprofile realm['zerver_stream'] = zerver_stream realm['zerver_defaultstream'] = zerver_defaultstream realm['zerver_recipient'] = zerver_recipient realm['zerver_subscription'] = zerver_subscription return realm, avatars, user_map, stream_map
def gitter_workspace_to_realm(domain_name: str, gitter_data: GitterDataT, realm_subdomain: str) -> Tuple[ZerverFieldsT, List[ZerverFieldsT], Dict[str, int]]: """ Returns: 1. realm, Converted Realm data 2. avatars, which is list to map avatars to zulip avatar records.json 3. user_map, which is a dictionary to map from gitter user id to zulip user id """ NOW = float(timezone_now().timestamp()) zerver_realm = build_zerver_realm(realm_id, realm_subdomain, NOW, 'Gitter') # type: List[ZerverFieldsT] 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_and_defaultstream(int(NOW)) zerver_recipient, zerver_subscription = build_recipient_and_subscription( zerver_userprofile, zerver_stream) realm['zerver_userprofile'] = zerver_userprofile realm['zerver_stream'] = zerver_stream realm['zerver_defaultstream'] = zerver_defaultstream realm['zerver_recipient'] = zerver_recipient realm['zerver_subscription'] = zerver_subscription return realm, avatars, user_map
def gitter_workspace_to_realm( domain_name: str, gitter_data: GitterDataT, realm_subdomain: str ) -> Tuple[ZerverFieldsT, List[ZerverFieldsT], Dict[str, int]]: """ Returns: 1. realm, Converted Realm data 2. avatars, which is list to map avatars to zulip avatar records.json 3. user_map, which is a dictionary to map from gitter user id to zulip user id """ NOW = float(timezone_now().timestamp()) zerver_realm = build_zerver_realm(realm_id, realm_subdomain, NOW, 'Gitter') # type: List[ZerverFieldsT] realm = dict( zerver_client=[{ "name": "populate_db", "id": 1 }, { "name": "website", "id": 2 }, { "name": "API", "id": 3 }], zerver_customprofilefield=[], zerver_customprofilefieldvalue=[], zerver_userpresence= [], # shows last logged in data, which is not available in gitter zerver_userprofile_mirrordummy=[], zerver_realmdomain=[{ "realm": realm_id, "allow_subdomains": False, "domain": domain_name, "id": realm_id }], zerver_useractivity=[], zerver_realm=zerver_realm, zerver_huddle=[], zerver_userprofile_crossrealm=[], zerver_useractivityinterval=[], zerver_reaction=[], zerver_realmemoji=[], zerver_realmfilter=[]) zerver_userprofile, avatars, user_map = build_userprofile( int(NOW), domain_name, gitter_data) zerver_stream, zerver_defaultstream = build_stream(int(NOW)) zerver_recipient, zerver_subscription = build_recipient_and_subscription( zerver_userprofile, zerver_stream) realm['zerver_userprofile'] = zerver_userprofile realm['zerver_stream'] = zerver_stream realm['zerver_defaultstream'] = zerver_defaultstream realm['zerver_recipient'] = zerver_recipient realm['zerver_subscription'] = zerver_subscription return realm, avatars, user_map
def test_build_zerver_realm(self) -> None: realm_id = 2 realm_subdomain = "test-realm" time = float(timezone_now().timestamp()) test_realm = build_zerver_realm(realm_id, realm_subdomain, time, 'Slack') # type: List[Dict[str, Any]] test_zerver_realm_dict = test_realm[0] self.assertEqual(test_zerver_realm_dict['id'], realm_id) self.assertEqual(test_zerver_realm_dict['string_id'], realm_subdomain) self.assertEqual(test_zerver_realm_dict['name'], realm_subdomain) self.assertEqual(test_zerver_realm_dict['date_created'], time)
def make_realm(realm_id: int) -> ZerverFieldsT: NOW = float(timezone_now().timestamp()) domain_name = settings.EXTERNAL_HOST realm_subdomain = "" zerver_realm = build_zerver_realm(realm_id, realm_subdomain, NOW, 'HipChat') realm = build_realm(zerver_realm, realm_id, domain_name) # We may override these later. realm['zerver_defaultstream'] = [] return realm
def test_build_zerver_realm(self) -> None: realm_id = 2 realm_subdomain = "test-realm" time = float(timezone_now().timestamp()) test_realm: List[Dict[str, Any]] = build_zerver_realm( realm_id, realm_subdomain, time, "Slack") test_zerver_realm_dict = test_realm[0] self.assertEqual(test_zerver_realm_dict["id"], realm_id) self.assertEqual(test_zerver_realm_dict["string_id"], realm_subdomain) self.assertEqual(test_zerver_realm_dict["name"], realm_subdomain) self.assertEqual(test_zerver_realm_dict["date_created"], time)
def make_realm(realm_id: int, realm_subdomain: str, domain_name: str, rc_instance: Dict[str, Any]) -> ZerverFieldsT: created_at = float(rc_instance["_createdAt"].timestamp()) zerver_realm = build_zerver_realm(realm_id, realm_subdomain, created_at, "Rocket.Chat") realm = build_realm(zerver_realm, realm_id, domain_name) # We may override these later. realm["zerver_defaultstream"] = [] return realm
def make_realm(realm_id: int, team: Dict[str, Any]) -> ZerverFieldsT: # set correct realm details NOW = float(timezone_now().timestamp()) domain_name = settings.EXTERNAL_HOST realm_subdomain = team["name"] zerver_realm = build_zerver_realm(realm_id, realm_subdomain, NOW, "Mattermost") realm = build_realm(zerver_realm, realm_id, domain_name) # We may override these later. realm["zerver_defaultstream"] = [] return realm
def slack_workspace_to_realm(domain_name: str, realm_id: int, user_list: List[ZerverFieldsT], realm_subdomain: str, slack_data_dir: str, custom_emoji_list: ZerverFieldsT) -> Tuple[ZerverFieldsT, AddedUsersT, AddedRecipientsT, AddedChannelsT, AddedMPIMsT, List[ZerverFieldsT], ZerverFieldsT]: """ Returns: 1. realm, Converted Realm data 2. added_users, which is a dictionary to map from slack user id to zulip user id 3. added_recipient, which is a dictionary to map from channel name to zulip recipient_id 4. added_channels, which is a dictionary to map from channel name to channel id, zulip stream_id 5. added_mpims, which is a dictionary to map from MPIM name to MPIM id, zulip huddle_id 6. avatars, which is list to map avatars to zulip avatar records.json 7. emoji_url_map, which is maps emoji name to its slack url """ NOW = float(timezone_now().timestamp()) zerver_realm = build_zerver_realm(realm_id, realm_subdomain, NOW, 'Slack') # type: List[ZerverFieldsT] realm = build_realm(zerver_realm, realm_id, domain_name) zerver_userprofile, avatars, added_users, zerver_customprofilefield, \ zerver_customprofilefield_value = users_to_zerver_userprofile(slack_data_dir, user_list, realm_id, int(NOW), domain_name) channels_to_zerver_stream_fields = channels_to_zerver_stream(slack_data_dir, realm_id, added_users, zerver_userprofile) zerver_realmemoji, emoji_url_map = build_realmemoji(custom_emoji_list, realm_id) realm['zerver_realmemoji'] = zerver_realmemoji # See https://zulipchat.com/help/set-default-streams-for-new-users # for documentation on zerver_defaultstream realm['zerver_userprofile'] = zerver_userprofile # Custom profile fields realm['zerver_customprofilefield'] = zerver_customprofilefield realm['zerver_customprofilefieldvalue'] = zerver_customprofilefield_value realm['zerver_defaultstream'] = channels_to_zerver_stream_fields[0] realm['zerver_stream'] = channels_to_zerver_stream_fields[1] realm['zerver_huddle'] = channels_to_zerver_stream_fields[2] realm['zerver_subscription'] = channels_to_zerver_stream_fields[5] realm['zerver_recipient'] = channels_to_zerver_stream_fields[6] added_channels = channels_to_zerver_stream_fields[3] added_mpims = channels_to_zerver_stream_fields[4] added_recipient = channels_to_zerver_stream_fields[7] return realm, added_users, added_recipient, added_channels, added_mpims, avatars, emoji_url_map
def slack_workspace_to_realm(domain_name: str, realm_id: int, user_list: List[ZerverFieldsT], realm_subdomain: str, slack_data_dir: str, custom_emoji_list: ZerverFieldsT)-> Tuple[ZerverFieldsT, AddedUsersT, AddedRecipientsT, AddedChannelsT, List[ZerverFieldsT], ZerverFieldsT]: """ Returns: 1. realm, Converted Realm data 2. added_users, which is a dictionary to map from slack user id to zulip user id 3. added_recipient, which is a dictionary to map from channel name to zulip recipient_id 4. added_channels, which is a dictionary to map from channel name to channel id, zulip stream_id 5. avatars, which is list to map avatars to zulip avatar records.json 6. emoji_url_map, which is maps emoji name to its slack url """ NOW = float(timezone_now().timestamp()) zerver_realm = build_zerver_realm(realm_id, realm_subdomain, NOW, 'Slack') # type: List[ZerverFieldsT] realm = build_realm(zerver_realm, realm_id, domain_name) zerver_userprofile, avatars, added_users, zerver_customprofilefield, \ zerver_customprofilefield_value = users_to_zerver_userprofile(slack_data_dir, user_list, realm_id, int(NOW), domain_name) channels_to_zerver_stream_fields = channels_to_zerver_stream(slack_data_dir, realm_id, added_users, zerver_userprofile) zerver_realmemoji, emoji_url_map = build_realmemoji(custom_emoji_list, realm_id) realm['zerver_realmemoji'] = zerver_realmemoji # See https://zulipchat.com/help/set-default-streams-for-new-users # for documentation on zerver_defaultstream realm['zerver_userprofile'] = zerver_userprofile # Custom profile fields realm['zerver_customprofilefield'] = zerver_customprofilefield realm['zerver_customprofilefieldvalue'] = zerver_customprofilefield_value realm['zerver_defaultstream'] = channels_to_zerver_stream_fields[0] realm['zerver_stream'] = channels_to_zerver_stream_fields[1] realm['zerver_subscription'] = channels_to_zerver_stream_fields[3] realm['zerver_recipient'] = channels_to_zerver_stream_fields[4] added_channels = channels_to_zerver_stream_fields[2] added_recipient = channels_to_zerver_stream_fields[5] return realm, added_users, added_recipient, added_channels, avatars, emoji_url_map
def slack_workspace_to_realm(domain_name: str, realm_id: int, user_list: List[ZerverFieldsT], realm_subdomain: str, slack_data_dir: str, custom_emoji_list: ZerverFieldsT) -> Tuple[ZerverFieldsT, SlackToZulipUserIDT, SlackToZulipRecipientT, AddedChannelsT, AddedMPIMsT, DMMembersT, List[ZerverFieldsT], ZerverFieldsT]: """ Returns: 1. realm, Converted Realm data 2. slack_user_id_to_zulip_user_id, which is a dictionary to map from slack user id to zulip user id 3. slack_recipient_name_to_zulip_recipient_id, which is a dictionary to map from slack recipient name(channel names, mpim names, usernames, etc) to zulip recipient id 4. added_channels, which is a dictionary to map from channel name to channel id, zulip stream_id 5. added_mpims, which is a dictionary to map from MPIM name to MPIM id, zulip huddle_id 6. dm_members, which is a dictionary to map from DM id to tuple of DM participants. 7. avatars, which is list to map avatars to zulip avatar records.json 8. emoji_url_map, which is maps emoji name to its slack url """ NOW = float(timezone_now().timestamp()) zerver_realm = build_zerver_realm(realm_id, realm_subdomain, NOW, 'Slack') # type: List[ZerverFieldsT] realm = build_realm(zerver_realm, realm_id, domain_name) zerver_userprofile, avatars, slack_user_id_to_zulip_user_id, zerver_customprofilefield, \ zerver_customprofilefield_value = users_to_zerver_userprofile(slack_data_dir, user_list, realm_id, int(NOW), domain_name) realm, added_channels, added_mpims, dm_members, slack_recipient_name_to_zulip_recipient_id = \ channels_to_zerver_stream(slack_data_dir, realm_id, realm, slack_user_id_to_zulip_user_id, zerver_userprofile) zerver_realmemoji, emoji_url_map = build_realmemoji(custom_emoji_list, realm_id) realm['zerver_realmemoji'] = zerver_realmemoji # See https://zulipchat.com/help/set-default-streams-for-new-users # for documentation on zerver_defaultstream realm['zerver_userprofile'] = zerver_userprofile realm['zerver_customprofilefield'] = zerver_customprofilefield realm['zerver_customprofilefieldvalue'] = zerver_customprofilefield_value return realm, slack_user_id_to_zulip_user_id, slack_recipient_name_to_zulip_recipient_id, \ added_channels, added_mpims, dm_members, avatars, emoji_url_map
def slack_workspace_to_realm( domain_name: str, realm_id: int, user_list: List[ZerverFieldsT], realm_subdomain: str, slack_data_dir: str, custom_emoji_list: ZerverFieldsT ) -> Tuple[ZerverFieldsT, AddedUsersT, AddedRecipientsT, AddedChannelsT, List[ZerverFieldsT], ZerverFieldsT]: """ Returns: 1. realm, Converted Realm data 2. added_users, which is a dictionary to map from slack user id to zulip user id 3. added_recipient, which is a dictionary to map from channel name to zulip recipient_id 4. added_channels, which is a dictionary to map from channel name to channel id, zulip stream_id 5. avatars, which is list to map avatars to zulip avatar records.json 6. emoji_url_map, which is maps emoji name to its slack url """ NOW = float(timezone_now().timestamp()) zerver_realm = build_zerver_realm(realm_id, realm_subdomain, NOW, 'Slack') # type: List[ZerverFieldsT] realm = dict( zerver_client=[{ "name": "populate_db", "id": 1 }, { "name": "website", "id": 2 }, { "name": "API", "id": 3 }], zerver_userpresence= [], # shows last logged in data, which is not available in slack zerver_userprofile_mirrordummy=[], zerver_realmdomain=[{ "realm": realm_id, "allow_subdomains": False, "domain": domain_name, "id": realm_id }], zerver_useractivity=[], zerver_realm=zerver_realm, zerver_huddle=[], zerver_userprofile_crossrealm=[], zerver_useractivityinterval=[], zerver_realmfilter=[]) zerver_userprofile, avatars, added_users, zerver_customprofilefield, \ zerver_customprofilefield_value = users_to_zerver_userprofile(slack_data_dir, user_list, realm_id, int(NOW), domain_name) channels_to_zerver_stream_fields = channels_to_zerver_stream( slack_data_dir, realm_id, added_users, zerver_userprofile) zerver_realmemoji, emoji_url_map = build_realmemoji( custom_emoji_list, realm_id) realm['zerver_realmemoji'] = zerver_realmemoji # See https://zulipchat.com/help/set-default-streams-for-new-users # for documentation on zerver_defaultstream realm['zerver_userprofile'] = zerver_userprofile # Custom profile fields realm['zerver_customprofilefield'] = zerver_customprofilefield realm['zerver_customprofilefieldvalue'] = zerver_customprofilefield_value realm['zerver_defaultstream'] = channels_to_zerver_stream_fields[0] realm['zerver_stream'] = channels_to_zerver_stream_fields[1] realm['zerver_subscription'] = channels_to_zerver_stream_fields[3] realm['zerver_recipient'] = channels_to_zerver_stream_fields[4] added_channels = channels_to_zerver_stream_fields[2] added_recipient = channels_to_zerver_stream_fields[5] return realm, added_users, added_recipient, added_channels, avatars, emoji_url_map