Skip to content

Commit

Permalink
slack_import: Support importing private slack channels.
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerkid authored and timabbott committed Jun 28, 2019
1 parent 196388c commit 443439d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions templates/zerver/help/import-from-slack.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ root domain. Replace the last line above with the following, after replacing
[Slack's documentation](https://get.slack.help/hc/en-us/articles/204897248-Guide-to-Slack-import-and-export-tools)
for more details.

- (Slack Plus import) Private channels and direct messages are currently
not imported. We expect to address this in a future revision.
- (Slack Plus import) Direct messages are currently not imported. We
expect to address this in a future revision.

- (Slack Plus import) Message edit history is currently not imported.

Expand Down
14 changes: 10 additions & 4 deletions zerver/data_import/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def channels_to_zerver_stream(slack_data_dir: str, realm_id: int, added_users: A

stream_id_count = subscription_id_count = recipient_id_count = defaultstream_id = 0

def process_channels(channels: List[Dict[str, Any]]) -> None:
def process_channels(channels: List[Dict[str, Any]], invite_only: bool=False) -> None:
nonlocal stream_id_count
nonlocal recipient_id_count
nonlocal defaultstream_id
Expand All @@ -365,7 +365,7 @@ def process_channels(channels: List[Dict[str, Any]]) -> None:

# construct the stream object and append it to zerver_stream
stream = build_stream(float(channel["created"]), realm_id, channel["name"],
description, stream_id, channel["is_archived"])
description, stream_id, channel["is_archived"], invite_only)
zerver_stream.append(stream)

# construct defaultstream object
Expand Down Expand Up @@ -411,8 +411,14 @@ def process_channels(channels: List[Dict[str, Any]]) -> None:
# }
# ],

channels = get_data_file(slack_data_dir + '/channels.json')
process_channels(channels)
public_channels = get_data_file(slack_data_dir + '/channels.json')
process_channels(public_channels)

try:
private_channels = get_data_file(slack_data_dir + '/groups.json')
except FileNotFoundError:
private_channels = []
process_channels(private_channels, True)

for user in zerver_userprofile:
# this maps the recipients and subscriptions
Expand Down
2 changes: 1 addition & 1 deletion zerver/tests/test_slack_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def test_channels_to_zerver_stream(self, mock_get_data_file: mock.Mock) -> None:
{'id': "C061A0HJG", 'name': 'feedback', 'created': '1433558359',
'is_general': False, 'members': ['U061A3E0G'], 'is_archived': False,
'topic': {'value': ''}, 'purpose': {'value': ''}}]
mock_get_data_file.return_value = channel_data
mock_get_data_file.side_effect = [channel_data, []]

channel_to_zerver_stream_output = channels_to_zerver_stream('./random_path', realm_id, added_users,
zerver_userprofile)
Expand Down

0 comments on commit 443439d

Please sign in to comment.