English 中文(简体)
无国界记者协会
原标题:Pyramid ACL without traversal

我实际上对《欧洲常规武装力量条约》如何发挥作用没有什么想法。 我知道它非常冷却,可以拯救我很多时间和痛苦。 但是,目前损失了两倍。 所有金字塔的例子都使用透镜。 我只使用URL 发送机。 我不敢理解我如何能够建立资源树结构。

这里是一部法典样本:

class QuestionFactory(object):

    def __init__(self, request):
        self.__acl__ = default[:]
        self.uid = authenticated_userid(request)

        self.qid = request.matchdict.get( id )
        if self.qid:
            self.question = request.db.questions.find_one({ _id : ObjectId(self.qid)})
            if str(self.question.get( owner )) == self.uid:
                self.__acl__.append((Allow, userid,  view ))     

事情是,它行之有效。 但是,我确实需要为每一种类型的资源确定一个新的工厂。 我不怀疑我为什么要知道哪些是利用Im资源试图进入高强度的URL 解体和工厂。 我看到这样的情况。

/accounts/{account}   //Owners only but viewable by anyone 
/messages/{message}   //Owners only
/configs/{config}     //Admin only
/pages/{page}         //Admins only but viewable by anyone

That said here I d have such structure

  Root -
         +-- account
         +-- message
         +-- config
         +-- page

每个工厂都有自己的特殊产品。 另一个问题是,账户是主页。 它没有任何东西。 此外,账户/新账户也是一个特殊案例。 它不是一种骗局,而是想制造一个新项目。

I m 采用符合GET/PUT/DELETE/POST要求的全身风格。 我不敢肯定我为什么要自动地将ur与资源相匹配,并自动与右.相匹配。 如果我从根源上说,像上面这样专门工厂就不存在问题。

<><>>>

I did got it to work with the exception of some things. I finally think I understand what is the purpose of traverse. For example with we have that url: 页: 1/9494f0eda/new, 页: 1/{comment}/new

我们可能不得不放弃我们的资源树或甚至3个 no子。

根基将首先检查,然后根据我们的方言检查。 它将获得关于根基的评述,然后是“评论工厂”和“新”评论或目标本身。

I don t use Factory as dict as in the example of Michael

这似乎非常相似:

class RessourceFactory(object):
    def __init__(self, parent, name):

        self.__acl__ = []
        self.__name__ = name
        self.__parent__ = parent

        self.uid = parent.uid
        self.locale = parent.locale
        self.db = parent.db
        self.req = parent.req

这是我的基调资源目标。 在每一个步骤上,委员会都向新子女提供父母提供的资料。 我当然可以放弃我的属性。

为什么我不使用字词。 我补充说,它同我们合作。

页: 1

出于某些原因,它的确产生了我的评论,但却没有回去,因为不需要钥匙。

因此,我的根工厂非常喜欢这样做:

class RootFactory(object):

    def __init__(self, request):
        self.__acl__ = default[:]

        self.req = request
        self.db = request.db

        self.uid = authenticated_userid(request)
        self.locale = request.params.get( locale ,  en )

    def __getitem__(self, key):

        if key ==  questions :
            return QuestionFactory(self,  questions )
        elif key ==  pages :
            return PageFactory(self,  pages )
        elif key ==  configs :
            return ConfigFactory(self,  configs )
        elif key ==  accounts :
            return AccountFactory(self,  accounts )

        return self

如果找不到任何物品,则根基实际上返回自己,则返回新的工厂。 自2006年以来 我的法典以迈克尔的法典为基础,工厂建筑商有第二个参数。 我一定要把它当作一个问题工具来对待“问题”,因此没有必要在此指定工厂。 它应当知道它的名字。

class QuestionFactory(RessourceFactory):
    def __init__(self, parent, name):
        RessourceFactory.__init__(self, parent, name)
        self.__acl__.append((Allow,  g:admin ,  view ))
        self.__acl__.append((Allow,  g:admin ,  edit ))
        self.__acl__.append((Allow,  g:admin ,  create ))
        self.__acl__.append((Allow,  g:admin ,  delete ))
        self.__acl__.append((Allow, Everyone,  create ))

    def __getitem__(self, key):

        if key== read :
            return self

        self.qid = key
        self.question = self.db.questions.find_one({ _id : ObjectId(self.qid)})

        if str(self.question.get( owner )) == self.uid:
            log.info( Allowd user %s  % self.uid)
            self.__acl__.append((Allow, self.uid,  view ))
            self.__acl__.append((Allow, self.uid,  edit ))
            self.__acl__.append((Allow, self.uid,  delete ))

        return self

因此,几乎所有逻辑都会发生。 在<<><>init/strong> 我的一组内容将用来处理/询问它将为处理/询问/调查/调查而开展的工作。

Since I return itself, any getitem past this RessourceFactory will point to itself unless I return a new Factory for some special case. The reason why doing so is that my context isn t just an object in database or an object.

我的背景是处理多种问题,如用户id、当地等,等等。 ......当cl子做成时,我有一个新的环境物体,愿意使用。 它删除了意见中的大部分逻辑。

我也许会安排一些事件,以问当地情况,但确实如此。 如果我需要任何新东西,我就不得不将我的根基和RessourceFactory复制到儿童工厂。

这样,如果必须改变所有观点,就根本不存在重叠。

最佳回答

它希望你对一些目标/增长一级的安全特征重新感兴趣,以便只有账户的所有人能够查看其数据。 我将提及我先前关于这个专题的SO回答,以及辅导员I ve正在根据这一回答在URL 派遣地工作。 具体来说,您不妨研究2.object_security。 在相关联的哥廷布项目中以及在我网站上解释资源树木作为已建成的html的一部分的docs。

https://stackoverflow.com/questions/5761617/pyramid-authorization-for-stored-items/5761901#5761901”>Pyramid 批准储存项目

https://github.com/mmerickel/pyramid_auth_demo

如果你有任何问题理解这些资源,我很高兴在此进一步阐述。

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签