0

在 plone 4.3 中,我在 plone4.3 at_download 中编写了一些代码。当人们访问包含“at_download”的 url 时,他们将被阻止。但是当点击 url 不包含“at_download”时,他们也可以下载文件。

谢谢。

我使用文档查看器来显示 .doc .pdf .ppt,我只想让他们使用文档查看器查看文件。但无法从 url 下载文件。

4

2 回答 2

1

不确定这是否可行,但您也可以尝试更改read_permission内容上的“文件”字段。

但可能这也会隐藏文件预览(或破坏模板,在这种情况下你必须修复它)。

于 2013-10-25T10:18:16.837 回答
0

为了确保没有人可以获取您的文件,我想最好的方法是创建自己的 FileField 并修改index_html方法

  1. 您必须创建自己的基于 ATFile 的内容类型 如果要使用此类型而不是默认的 plone 文件,请使用相同的 portal_type

  2. file用你自己的覆盖字段CustomFileField

您的 FileField 可能看起来像...

from plone.app.blob import field


class CustomFileField(field.FileField):

    def index_html(self, instance, REQUEST=None, RESPONSE=None,
                   no_output=False, disposition=None):
        """Docstring"""

        if self.has_permission_to_download():
            # Default behaviour
            super(CustomFileField, self).index_html(
                instance,
                REQUEST=None,
                RESPONSE=None,
                no_output=False,
                disposition=None)
        else:
            # Your code if the user does not have the permission
            raise WhatEverYouWant


       def has_permission_to_download(self):
           """Do your permission check"""

           return bool()

捷径是猴子补丁,但我不建议这样做。

于 2013-10-25T08:08:51.597 回答