← Back to team overview

launchpad-dev team mailing list archive

Re: check_permission removed from security.py

 

On Tuesday 19 April 2011 14:06:26 Gavin Panella wrote:
> On 19 April 2011 12:39, Julian Edwards <julian.edwards@xxxxxxxxxxxxx> wrote:
> > Another pattern that can be used is to construct the appropriate adapter
> > directly and run its checkAuthenticated() method, which is what many of
> > the existing adapters already do.  I think I prefer this to introducing
> > the extra level of indirection in forwardCheckAuthenticated() but YMMV
> > :)
> 
> By skipping the adapter lookup there is a small (very small?) risk
> that the code may one day not use the configured security policy for
> the given object. In essence it short-circuits the configuration of
> security policy, and is probably a violation of DRY, though it's
> hardly an egregious one. I think forwardCheckAuthenticated() should be
> preferred, if only by a slight margin.

I must confess I'm not really sure what you mean.  Surely the context adapter 
knows what it's doing by using a secondary adapter directly, because it *is* 
the security policy?

For example, the one I recently wrote does this:

{{{
class EditDistroSeriesParent(AuthorizationBase):
    """DistroSeriesParent can be edited by the same people who can edit
    the derived_distroseries."""
    permission = "launchpad.Edit"
    usedfor = IDistroSeriesParent

    def checkAuthenticated(self, user):
        auth = EditDistroSeriesByReleaseManagerOrDistroOwnersOrAdmins(
            self.obj.derived_series)
        return auth.checkAuthenticated(user)
}}}

Editing the DistroSeriesParent is identical to editing DistroSeries so that 
policy is re-used directly.

Did I misunderstand or is this short-circuiting the security policy in a way 
I'm not thinking of?

Cheers
J


Follow ups

References