slack importer: Change organization admin mappings.

Map 'Primary owner', 'owner' and 'admin' to 'organization admin'.
Added tests for the same.
This commit is contained in:
Rhea Parekh 2018-02-07 01:32:23 +05:30 committed by Tim Abbott
parent b3b6023230
commit 052e3e1540
2 changed files with 24 additions and 1 deletions

View File

@ -133,6 +133,9 @@ def users_to_zerver_userprofile(slack_data_dir: str, realm_id: int, timestamp: A
# email
email = get_user_email(user, domain_name)
# check if user is the admin
realm_admin = get_admin(user)
# avatar
# ref: https://chat.zulip.org/help/change-your-avatar
avatar_source = get_user_avatar_source(profile['image_32'])
@ -154,7 +157,7 @@ def users_to_zerver_userprofile(slack_data_dir: str, realm_id: int, timestamp: A
is_mirror_dummy=False,
pointer=-1,
default_events_register_stream=None,
is_realm_admin=user.get('is_owner', False),
is_realm_admin=realm_admin,
# invites_granted=0, # TODO
enter_sends=True,
bot_type=1 if user.get('is_bot', False) else None,
@ -211,6 +214,15 @@ def get_user_email(user: ZerverFieldsT, domain_name: str) -> str:
email = user['profile']['email']
return email
def get_admin(user: ZerverFieldsT) -> bool:
admin = user.get('is_admin', False)
owner = user.get('is_owner', False)
primary_owner = user.get('is_primary_owner', False)
if admin or owner or primary_owner:
return True
return False
def get_user_avatar_source(image_url: str) -> str:
if 'gravatar.com' in image_url:
# use the avatar from gravatar

View File

@ -6,6 +6,7 @@ from zerver.lib.slack_data_to_zulip_data import (
get_model_id,
build_zerver_realm,
get_user_email,
get_admin,
get_user_avatar_source,
get_user_timezone,
users_to_zerver_userprofile,
@ -57,6 +58,16 @@ class SlackImporter(ZulipTestCase):
self.assertEqual(test_zerver_realm_dict['name'], realm_subdomain)
self.assertEqual(test_zerver_realm_dict['date_created'], time)
def test_get_admin(self) -> None:
user_data = [{'is_admin': True, 'is_owner': False, 'is_primary_owner': False},
{'is_admin': True, 'is_owner': True, 'is_primary_owner': False},
{'is_admin': True, 'is_owner': True, 'is_primary_owner': True},
{'is_admin': False, 'is_owner': False, 'is_primary_owner': False}]
self.assertEqual(get_admin(user_data[0]), True)
self.assertEqual(get_admin(user_data[1]), True)
self.assertEqual(get_admin(user_data[2]), True)
self.assertEqual(get_admin(user_data[3]), False)
def test_get_avatar_source(self) -> None:
gravatar_image_url = "https:\/\/secure.gravatar.com\/avatar\/78dc7b2e1bf423df8c82fb2a62c8917d.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F66f9%2Fimg%2Favatars%2Fava_0016-24.png"
uploaded_avatar_url = "https:\/\/avatars.slack-edge.com\/2015-06-12\/6314338625_3c7c62301a2d61b4a756_24.jpg"