如何传输 url 参数以重新配置自定义谓词检查器

发布于 2024-09-05 22:48:34 字数 475 浏览 14 评论 0原文

我想创建一个 repoze 自定义谓词检查器,它能够访问 url 参数并验证某些内容。但我想使用allow_only 在所有控制器的范围内设置此权限检查器。类似于:

class MyController(BaseController):

    allow_only = All(not_anonymous(msg=l_(u'You must be logged on')),
                     my_custom_predicate(msg=l_(u'something wrong')))

    def index(self, **kw):
        return dict()

然后,my_custom_predicate 应该检查每个 MyController 方法中每个请求的 url 参数,并执行它所做的任何操作。 问题在于:如何允许 my_custom_predicate 检查 url 参数,以我上面写的方式使用它。

I would like to create a repoze custom predicate checker that is capable to access url parameters and validate something. But I would like to use allow_only to set this permission checker in all the controller's scope. Something like:

class MyController(BaseController):

    allow_only = All(not_anonymous(msg=l_(u'You must be logged on')),
                     my_custom_predicate(msg=l_(u'something wrong')))

    def index(self, **kw):
        return dict()

then, my_custom_predicate should check the url paramters for every request in every MyController method, and do whatever it do.
The problem is just that: how to allow my_custom_predicate to check the url parameters, using it in that way I wrote above.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟柳画桥 2024-09-12 22:48:34

可能您需要使用 ControllerProtector

from repoze.what.plugins.pylonshq import ControllerProtector

allow_only = All(not_anonymous(msg=l_(u'You must be logged on')),
                     my_custom_predicate(msg=l_(u'something wrong')))

@ControllerProtector(allow_only)
class MyController(BaseController):

    def index(self, **kw):
        return dict()

请参阅 http 上的文档://code.gustavonarea.net/repoze.what-pylons/API.html

May be you need to use ControllerProtector

from repoze.what.plugins.pylonshq import ControllerProtector

allow_only = All(not_anonymous(msg=l_(u'You must be logged on')),
                     my_custom_predicate(msg=l_(u'something wrong')))

@ControllerProtector(allow_only)
class MyController(BaseController):

    def index(self, **kw):
        return dict()

See docs at http://code.gustavonarea.net/repoze.what-pylons/API.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文