コード例 #1
0
def remove_attachment(user_profile: UserProfile,
                      attachment: Attachment) -> None:
    try:
        delete_message_image(attachment.path_id)
    except Exception:
        raise JsonableError(
            _("An error occurred while deleting the attachment. Please try again later."
              ))
    attachment.delete()
コード例 #2
0
def build_attachment(
    realm_id: int,
    message_ids: Set[int],
    user_id: int,
    fileinfo: ZerverFieldsT,
    s3_path: str,
    zerver_attachment: List[ZerverFieldsT],
) -> None:
    """
    This function should be passed a 'fileinfo' dictionary, which contains
    information about 'size', 'created' (created time) and ['name'] (filename).
    """
    attachment_id = NEXT_ID("attachment")

    attachment = Attachment(
        id=attachment_id,
        size=fileinfo["size"],
        create_time=fileinfo["created"],
        is_realm_public=True,
        path_id=s3_path,
        file_name=fileinfo["name"],
    )

    attachment_dict = model_to_dict(attachment, exclude=["owner", "messages", "realm"])
    attachment_dict["owner"] = user_id
    attachment_dict["messages"] = list(message_ids)
    attachment_dict["realm"] = realm_id

    zerver_attachment.append(attachment_dict)
コード例 #3
0
ファイル: import_util.py プロジェクト: wayhome25/zulip
def build_attachment(realm_id: int, message_id: int, attachment_id: int,
                     user_id: int, fileinfo: ZerverFieldsT, s3_path: str,
                     zerver_attachment: List[ZerverFieldsT]) -> None:
    """
    This function should be passed a 'fileinfo' dictionary, which contains
    information about 'size', 'created' (created time) and ['name'] (filename).
    """
    attachment = Attachment(id=attachment_id,
                            size=fileinfo['size'],
                            create_time=fileinfo['created'],
                            is_realm_public=True,
                            path_id=s3_path,
                            file_name=fileinfo['name'])

    attachment_dict = model_to_dict(attachment,
                                    exclude=['owner', 'messages', 'realm'])
    attachment_dict['owner'] = user_id
    attachment_dict['messages'] = [message_id]
    attachment_dict['realm'] = realm_id

    zerver_attachment.append(attachment_dict)
コード例 #4
0
ファイル: attachments.py プロジェクト: 284928489/zulip
def remove_attachment(user_profile: UserProfile, attachment: Attachment) -> None:
    try:
        delete_message_image(attachment.path_id)
    except Exception:
        raise JsonableError(_("An error occurred while deleting the attachment. Please try again later."))
    attachment.delete()