I am attempting to integrate a very old system and a newer system at work. The best I can do - without major IT changes and the work that entails of rounding up project resources, management, etc - is to utilize an RSS firehouse type feed the system utilizes. The goal, is to use this RSS feed to make the other system perform certain actions when certain people do things.
My idea is to wrap a decorator around certain functions to check if the user (a user ID provided in the RSS feed) has permissions in the new system.
My current solution has a lot of functions that look like this, which are called based on an action
field in the feed:
actions_dict = {
...
'action1': function1
}
actions_dict[RSSFEED['action_taken']](RSSFEED['user_id'])
def function1(user_id):
if has_permissions(user_id):
# Do this function
I want to create a has_permissions
decorator that takes the user_id
so that I can remove this redundant code in each of my functions.
@has_permissions(user_id)
def function1():
# Do this function
Unfortunately, I am not sure how to write such a decorator. All the tutorials I see have the @has_permissions()
line with a hardcoded value, but in my case it needs to be passed at runtime and will be different each time the function is called.
How do I do this?
Aucun commentaire:
Enregistrer un commentaire