from functools import wraps def changeUserOnPlugin(apiFunc): """ Changes to a given user when the authenticated user is an plugin When the user which called the apifunc is an plugin this function goes through the following steps: - searches the user it should change to - checks if this user allowed the plugin to "speak for him" - change the request so it looks like the user called himself - add an plugin_user entry containing the previous request user This decorator is intended to be used with django piston, so on error it will return the appropriate rc.* values. """ @wraps(apiFunc) def wrapper(self, request, *args, **kwargs): return self.apiFunc(request, *args, **kwargs) return wrapper