Guest User

Untitled

a guest
Jun 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. # define some decorators here, to be used by modules for access control
  2. def access(*a, **kw):
  3. def check_access(f, *args, **kwargs):
  4. def new_f(*args, **kwargs):
  5. session = Session()
  6. try:
  7. # query the database to check to see if the user is a master or owner
  8. query = session.query(User).filter(User.name == args[1]['source']['nick'])
  9. user = query.first()
  10. except Exception, e:
  11. print e
  12. # check to see if we receive a result from the database and that
  13. # their access level is at least master status
  14. if user and user.access >= Access.__getattribute__(a[0]).index:
  15. return f(*args, **kwargs)
  16. new_f.func_name = f.func_name
  17. return new_f
  18. return check_access
  19.  
  20. def master(f):
  21. return access('master')(f)
Add Comment
Please, Sign In to add comment