def get_guest(user: ZerverFieldsT) -> bool: restricted_user = user.get('is_restricted', False) ultra_restricted_user = user.get('is_ultra_restricted', False) if restricted_user or ultra_restricted_user: return True else: return False
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_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_guest(user: ZerverFieldsT) -> bool: restricted_user = user.get('is_restricted', False) ultra_restricted_user = user.get('is_ultra_restricted', False) # Slack's Single channel and multi channel guests both have # is_restricted set to True. So assuming Slack doesn't change their # data model, it would also be correct to just check whether # is_restricted is set to True. return restricted_user or ultra_restricted_user
def get_message_sending_user(message: ZerverFieldsT) -> Optional[str]: if 'user' in message: return message['user'] if message.get('file'): return message['file'].get('user') return None
def get_user_timezone(user: ZerverFieldsT) -> str: _default_timezone = "America/New_York" timezone = user.get("tz", _default_timezone) if timezone is None or '/' not in timezone: timezone = _default_timezone return timezone
def get_message_sending_user(message: ZerverFieldsT) -> Optional[str]: if 'user' in message: return message['user'] if message.get('file'): return message['file'].get('user') return None
def process_message_files(message: ZerverFieldsT, domain_name: str, realm_id: int, message_id: int, user: str, users: List[ZerverFieldsT], added_users: AddedUsersT, zerver_attachment: List[ZerverFieldsT], uploads_list: List[ZerverFieldsT]) -> Dict[str, Any]: has_attachment = False has_image = False has_link = False files = message.get('files', []) subtype = message.get('subtype') if subtype == 'file_share': # In Slack messages, uploads can either have the subtype as 'file_share' or # have the upload information in 'files' keyword files = [message['file']] markdown_links = [] for fileinfo in files: url = fileinfo['url_private'] if 'files.slack.com' in url: # For attachments with slack download link has_attachment = True has_link = True has_image = True if 'image' in fileinfo['mimetype'] else False file_user = [iterate_user for iterate_user in users if message['user'] == iterate_user['id']] file_user_email = get_user_email(file_user[0], domain_name) s3_path, content_for_link = get_attachment_path_and_content(fileinfo, realm_id) markdown_links.append(content_for_link) # construct attachments build_uploads(added_users[user], realm_id, file_user_email, fileinfo, s3_path, uploads_list) build_attachment(realm_id, {message_id}, added_users[user], fileinfo, s3_path, zerver_attachment) else: # For attachments with link not from slack # Example: Google drive integration has_link = True if 'title' in fileinfo: file_name = fileinfo['title'] else: file_name = fileinfo['name'] markdown_links.append('[%s](%s)' % (file_name, fileinfo['url_private'])) content = '\n'.join(markdown_links) return dict( content=content, has_attachment=has_attachment, has_image=has_image, has_link=has_link, )
def get_user_timezone(user: ZerverFieldsT) -> str: _default_timezone = "America/New_York" timezone = user.get("tz", _default_timezone) if timezone is None or '/' not in timezone: timezone = _default_timezone return timezone
def process_message_files(message: ZerverFieldsT, domain_name: str, realm_id: int, message_id: int, slack_user_id: str, users: List[ZerverFieldsT], slack_user_id_to_zulip_user_id: SlackToZulipUserIDT, zerver_attachment: List[ZerverFieldsT], uploads_list: List[ZerverFieldsT]) -> Dict[str, Any]: has_attachment = False has_image = False has_link = False files = message.get('files', []) subtype = message.get('subtype') if subtype == 'file_share': # In Slack messages, uploads can either have the subtype as 'file_share' or # have the upload information in 'files' keyword files = [message['file']] markdown_links = [] for fileinfo in files: if fileinfo.get('mode', '') in ['tombstone', 'hidden_by_limit']: # Slack sometimes includes tombstone mode files with no # real data on the actual file (presumably in cases where # the file was deleted). hidden_by_limit mode is for files # that are hidden because of 10k cap in free plan. continue url = fileinfo['url_private'] if 'files.slack.com' in url: # For attachments with slack download link has_attachment = True has_link = True has_image = True if 'image' in fileinfo['mimetype'] else False file_user = [ iterate_user for iterate_user in users if message['user'] == iterate_user['id'] ] file_user_email = get_user_email(file_user[0], domain_name) s3_path, content_for_link = get_attachment_path_and_content( fileinfo, realm_id) markdown_links.append(content_for_link) build_uploads(slack_user_id_to_zulip_user_id[slack_user_id], realm_id, file_user_email, fileinfo, s3_path, uploads_list) build_attachment(realm_id, {message_id}, slack_user_id_to_zulip_user_id[slack_user_id], fileinfo, s3_path, zerver_attachment) else: # For attachments with link not from slack # Example: Google drive integration has_link = True if 'title' in fileinfo: file_name = fileinfo['title'] else: file_name = fileinfo['name'] markdown_links.append('[%s](%s)' % (file_name, fileinfo['url_private'])) content = '\n'.join(markdown_links) return dict( content=content, has_attachment=has_attachment, has_image=has_image, has_link=has_link, )
def process_message_files( message: ZerverFieldsT, domain_name: str, realm_id: int, message_id: int, slack_user_id: str, users: List[ZerverFieldsT], slack_user_id_to_zulip_user_id: SlackToZulipUserIDT, zerver_attachment: List[ZerverFieldsT], uploads_list: List[ZerverFieldsT], ) -> Dict[str, Any]: has_attachment = False has_image = False has_link = False files = message.get("files", []) subtype = message.get("subtype") if subtype == "file_share": # In Slack messages, uploads can either have the subtype as 'file_share' or # have the upload information in 'files' keyword files = [message["file"]] markdown_links = [] for fileinfo in files: if fileinfo.get("mode", "") in ["tombstone", "hidden_by_limit"]: # Slack sometimes includes tombstone mode files with no # real data on the actual file (presumably in cases where # the file was deleted). hidden_by_limit mode is for files # that are hidden because of 10k cap in free plan. continue url = fileinfo["url_private"] if "files.slack.com" in url: # For attachments with Slack download link has_attachment = True has_link = True has_image = True if "image" in fileinfo["mimetype"] else False file_user = [ iterate_user for iterate_user in users if message["user"] == iterate_user["id"] ] file_user_email = get_user_email(file_user[0], domain_name) s3_path, content_for_link = get_attachment_path_and_content(fileinfo, realm_id) markdown_links.append(content_for_link) build_uploads( slack_user_id_to_zulip_user_id[slack_user_id], realm_id, file_user_email, fileinfo, s3_path, uploads_list, ) build_attachment( realm_id, {message_id}, slack_user_id_to_zulip_user_id[slack_user_id], fileinfo, s3_path, zerver_attachment, ) else: # For attachments with link not from Slack # Example: Google drive integration has_link = True if "title" in fileinfo: file_name = fileinfo["title"] else: file_name = fileinfo["name"] markdown_links.append("[{}]({})".format(file_name, fileinfo["url_private"])) content = "\n".join(markdown_links) return dict( content=content, has_attachment=has_attachment, has_image=has_image, has_link=has_link, )
def get_admin(user: ZerverFieldsT) -> bool: admin = user.get("is_admin", False) return admin
def get_owner(user: ZerverFieldsT) -> bool: owner = user.get("is_owner", False) primary_owner = user.get("is_primary_owner", False) return primary_owner or owner
def get_message_sending_user(message: ZerverFieldsT) -> Optional[str]: if "user" in message: return message["user"] if message.get("file"): return message["file"].get("user") return None
def process_message_files(message: ZerverFieldsT, domain_name: str, realm_id: int, message_id: int, user: str, users: List[ZerverFieldsT], added_users: AddedUsersT, zerver_attachment: List[ZerverFieldsT], uploads_list: List[ZerverFieldsT]) -> Dict[str, Any]: has_attachment = False has_image = False has_link = False files = message.get('files', []) subtype = message.get('subtype') if subtype == 'file_share': # In Slack messages, uploads can either have the subtype as 'file_share' or # have the upload information in 'files' keyword files = [message['file']] markdown_links = [] for fileinfo in files: url = fileinfo['url_private'] if 'files.slack.com' in url: # For attachments with slack download link has_attachment = True has_link = True has_image = True if 'image' in fileinfo['mimetype'] else False file_user = [iterate_user for iterate_user in users if message['user'] == iterate_user['id']] file_user_email = get_user_email(file_user[0], domain_name) s3_path, content_for_link = get_attachment_path_and_content(fileinfo, realm_id) markdown_links.append(content_for_link) # construct attachments build_uploads(added_users[user], realm_id, file_user_email, fileinfo, s3_path, uploads_list) build_attachment(realm_id, {message_id}, added_users[user], fileinfo, s3_path, zerver_attachment) else: # For attachments with link not from slack # Example: Google drive integration has_link = True if 'title' in fileinfo: file_name = fileinfo['title'] else: file_name = fileinfo['name'] markdown_links.append('[%s](%s)' % (file_name, fileinfo['url_private'])) content = '\n'.join(markdown_links) return dict( content=content, has_attachment=has_attachment, has_image=has_image, has_link=has_link, )