Make checks for celebrity persons and roles easier

Bug #503454 reported by Henning Eggers
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Launchpad itself
Fix Released
Low
Henning Eggers

Bug Description

A lot of celebrities are IPerson objects and they are used to check if a certain person is (or is inTeam of) that celbrity person. This involves a lot of boilerplate for each such check, like this:

  admins = getUtility(ILaunchpadCelebrities).admin
  result = user.inTeam(admins)

It would be much nicer to be able to do:

  result = user.is_admin

or at least

  result = IPersonRole(user).is_admin

An adapter that provides this would make a lot of code much more readable. Some of this was attempted with the file lib/lp/services/permission_helpers.py but the approach proposed here seems much cleaner.

Another sevice that this adapter should provide is to check for certain roles regarding an object, like this:

  result = IPersonRole(user).isOwner(obj)

although this not really shorter than
  result = user.inTeam(obj.owner)

It gets better with a method that checks multiple attributes, like this:

  result = IPersonRule(user).isOneOf(obj, ['owner', 'driver', 'approver', 'drafter'])

Obviously, checks like this are mostly done in security.py and so it would be really convenient for AuthenticationBase.checkAuthenticated to recieve an IPersonRole instead of an IPerson as the 'user' parameter to get rid of the cast.

Related branches

Curtis Hovey (sinzui)
tags: added: tech-debt
Changed in launchpad-foundations:
status: New → Triaged
importance: Undecided → Low
Changed in launchpad-foundations:
status: Triaged → Fix Committed
assignee: nobody → Henning Eggers (henninge)
milestone: none → 10.01
tags: added: qa-ok
Curtis Hovey (sinzui)
Changed in launchpad-foundations:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.