view_privilege.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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) + ' : ' + role.name)
  23. logger.debug("roles found : " + str(roles_string))
  24. def get_privileges_from_user(user_id : int) :
  25. for user in privileges_users :
  26. if user.id == user_id :
  27. return user
  28. raise Exception("user privileges not found with id " + str(user_id))
  29. #TODO flask blueprint for privilege management here