Working on a little project where I need to start a transaction on a database, and up until now I have just used named queries to run SQL commands. Starting a transaction is not possible using named queries and the
startTransaction function requires client permissions to be enabled.
My question is, instead of allowing all user roles legacy database access (I am aware that the client roles can be restricted), is there a way to run a function (any function really) using another users credentials without switching user?
I thought about making a decorator, just can’t figure out how to run the function with different credentials.
def runAsUser(username, password): """ Description: Decorator for running a function using an alternative set of client permissions e.g. @runAsUser('Username', 'Password') e.g.2. runAsUser('Username', 'Password')(IRequireSpecialCredentialsFunction)(*args, **kwargs) """ def decorator(function): def wrapper(*args, **kwargs): print "Has legacy database access: %s" % ('LegacyDatabaseAcces' in system.security.getUserRoles(username, password)) # return RUN_WITH_CREDENTIALS(username, password, function(*args, **kwargs)) return wrapper return decorator
Thanks in advance