【问题标题】:Using Authorization methods on a nested Resource在嵌套资源上使用授权方法
【发布时间】:2018-04-10 21:12:55
【问题描述】:

tastepie 是否可以理解我希望它使用相同的授权方法从嵌套资源中过滤掉对象?

class ProjectResource(ModelResource):
    def authorized_read_list(self, object_list, bundle):
        return object_list.filter(user=bundle.request.user) # return projects only the user created

class ProjectGroupResource(ModelResource):
    projects = ToManyField(
        ProjectResource,
        attribute='projects',
        null=True,
        blank=True
    )

访问ProjectGroupResource 时不会触发authorized_read_list 方法,因此我得到了所有项目,包括非用户创建的项目。我的假设是,由于我传递了一个 ProjectResource ref,它会尝试模拟一个 get_object_list,这应该会触发包中的 authorized_read_list。

【问题讨论】:

    标签: tastypie


    【解决方案1】:

    自从我使用 Tastypie 已经有一段时间了,但我认为 authorized_* 方法仅在直接使用时适用于该资源,而不是在使用资源序列化相关属性时。

    您的 authorized_read_list 方法似乎缺少返回 statement

    【讨论】:

    • 编辑添加return语句
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多