diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.py index d6db317cb2..8ca6d53409 100755 --- a/zerver/data_import/slack.py +++ b/zerver/data_import/slack.py @@ -993,6 +993,8 @@ def do_convert_data(slack_zip_file: str, output_dir: str, token: str, threads: i realm_id = 0 domain_name = settings.EXTERNAL_HOST + log_token_warning(token) + slack_data_dir = slack_zip_file.replace('.zip', '') if not os.path.exists(slack_data_dir): os.makedirs(slack_data_dir) @@ -1055,15 +1057,16 @@ def get_data_file(path: str) -> Any: data = ujson.load(fp) return data +def log_token_warning(token: str) -> None: + if not token.startswith("xoxp-"): + logging.info('Not a Slack legacy token.\n' + ' This token might not have all the needed scopes. We need the following scopes:\n' + ' - emoji:read\n - users:read\n - users:read.email\n - team:read') + + def get_slack_api_data(slack_api_url: str, get_param: str, **kwargs: Any) -> Any: if not kwargs.get("token"): raise AssertionError("Slack token missing in kwargs") - token = kwargs["token"] - if not token.startswith("xoxp-"): - raise Exception('Invalid Slack legacy token.\n' - ' You must pass a Slack "legacy token" starting with "xoxp-".\n' - ' Create one at https://api.slack.com/custom-integrations/legacy-tokens') - data = requests.get("{}?{}".format(slack_api_url, urlencode(kwargs))) if data.status_code == requests.codes.ok: diff --git a/zerver/tests/test_slack_importer.py b/zerver/tests/test_slack_importer.py index 59b829a7a5..801b65fa05 100644 --- a/zerver/tests/test_slack_importer.py +++ b/zerver/tests/test_slack_importer.py @@ -94,11 +94,6 @@ class SlackImporter(ZulipTestCase): get_slack_api_data(slack_user_list_url, "members", token=token) self.assertEqual(invalid.exception.args, ('Error accessing Slack API: invalid_auth',),) - token = 'xoxe-invalid-token' - with self.assertRaises(Exception) as invalid: - get_slack_api_data(slack_user_list_url, "members", token=token) - self.assertTrue(invalid.exception.args[0].startswith("Invalid Slack legacy token.\n")) - with self.assertRaises(Exception) as invalid: get_slack_api_data(slack_user_list_url, "members") self.assertEqual(invalid.exception.args, ('Slack token missing in kwargs',),)