def run_with_login(login_id, function, *args, **kwargs): """Run 'function' logged in with 'login_id'. The first argument passed to 'function' will be the Launchpad `Person` object corresponding to 'login_id'. The exception is when the requesting login ID is `LAUNCHPAD_SERVICES`. In that case, we'll pass through the `LAUNCHPAD_SERVICES` variable and the method will do whatever security proxy hackery is required to provide read privileges to the Launchpad services. """ if login_id == LAUNCHPAD_SERVICES or login_id == LAUNCHPAD_ANONYMOUS: # Don't pass in an actual user. Instead pass in LAUNCHPAD_SERVICES # and expect `function` to use `removeSecurityProxy` or similar. return function(login_id, *args, **kwargs) if isinstance(login_id, basestring): requester = getUtility(IPersonSet).getByName(login_id) else: requester = getUtility(IPersonSet).get(login_id) if requester is None: raise NotFoundError("No person with id %s." % login_id) setupInteractionForPerson(requester) try: return function(requester, *args, **kwargs) finally: endInteraction()
def login_person(person, participation=None): """Login the person with their preferred email.""" if person is not None: # The login will fail even without this check, but this gives us a # nice error message, which can save time when debugging. if getattr(person, 'is_team', None): raise ValueError("Got team, expected person: %r" % (person, )) participation = _test_login_impl(participation) setupInteractionForPerson(person, participation) return person
def login_person(person, participation=None): """Login the person with their preferred email.""" if person is not None: # The login will fail even without this check, but this gives us a # nice error message, which can save time when debugging. if getattr(person, 'is_team', None): raise ValueError("Got team, expected person: %r" % (person,)) participation = _test_login_impl(participation) setupInteractionForPerson(person, participation) return person