view_privilege.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from utility.privilege_manager import *
  2. import Modules.Inventory.inventory_view as inventory_view
  3. import persistence
  4. from Model.isp_model import user_account
  5. manager = Privilege_Manager()
  6. privileges_users : set[Privilege_Manager.Privilege_User] = set()
  7. def init() :
  8. inventory_view.init()
  9. load_privilege_data()
  10. def save_privilege_data() :
  11. None
  12. def load_privilege_data() :
  13. with persistence.get_Session_Instance() as sess :
  14. users = sess.query(user_account)
  15. user : user_account
  16. for user in users :
  17. privileges = Privilege_Manager.Privilege_User(manager,user.privileges_data,user.is_super_admin,user.id)
  18. privileges_users.add(privileges)
  19. logger.debug("user privilege for account : " + user.nickname + " with id " + str(user.id) + " parsed")
  20. roles_string : list[str] = list()
  21. for role in privileges.get_roles() :
  22. roles_string.append(manager.get_role_domain(role).name + ' : ' + role.name)
  23. logger.debug("roles found : " + str(roles_string))
  24. if privileges.is_super_admin :
  25. logger.debug("user is Super Admin !")
  26. def get_privileges_from_user(user_id : int) :
  27. for user in privileges_users :
  28. if user.id == user_id :
  29. return user
  30. raise Exception("user privileges not found with id " + str(user_id))
  31. #TODO flask blueprint for privilege management here