ash 2 gadi atpakaļ
vecāks
revīzija
33462876a5

+ 3 - 3
Backend/Sources/Model/model_manager.py

@@ -9,7 +9,7 @@ from werkzeug.security import generate_password_hash
 from utility.app_logging import logger_name
 import logging
 
-logger = logging.getLogger(logger_name)
+logger = logging.getLogger(logger_name + ".MODEL")
 
 def declare_model():
     # insert here all model that need to be declared
@@ -31,9 +31,9 @@ def init() :
             Item = Model.isp_model.user_account(id = 1, nickname = "admin",description = "admin account", is_super_admin = True,password = generate_password_hash("aseqzdwxc"))
             sess.add(Item)
             sess.commit()
-            logger.debug("admin account created")
+            logger.debug("Admin account created")
         else :
-            logger.debug("admin account already created")
+            logger.debug("Admin account already created")
 
 
 # from https://stackoverflow.com/questions/5022066/how-to-serialize-sqlalchemy-result-to-json

+ 6 - 4
Backend/Sources/Modules/Inventory/inventory_view.py

@@ -1,6 +1,9 @@
+from Model.isp_model import user_account
 import View.view_privilege as view_privilege
 from utility.privilege_manager import *
-
+import persistence
+import Model.isp_model
+import json
 
 inventory_read_only_role  = Privilege_Role(name="read_only")
 inventory_admin_role      = Privilege_Role(name="admin")
@@ -8,11 +11,10 @@ inventory_admin_role      = Privilege_Role(name="admin")
 
 
 def init():
-
-
-
     inventory_privilege_domain = Privilege_Domain("inventory",description="privilege domain for inventory")
     view_privilege.manager.register_domain(inventory_privilege_domain)
     inventory_privilege_domain.add_role(inventory_read_only_role)
     inventory_privilege_domain.add_role(inventory_admin_role)
     inventory_privilege_domain.include_role(inventory_admin_role,inventory_read_only_role)
+
+

+ 12 - 7
Backend/Sources/View/view_manager.py

@@ -14,14 +14,15 @@ from datetime import timedelta
 import View.view_error_management as view_error_management
 from flask_limiter import Limiter
 from flask_limiter.util import get_remote_address
-logger = logging.getLogger(logger_name + ".VIEW")
-
+from flask_cors import CORS
 
+logger = logging.getLogger(logger_name + ".VIEW")
 
 __app__ = Flask("OpenIsp")
 __app__.secret_key = "aseqzdwxc"
 __app__.permanent_session_lifetime = timedelta(minutes=2)
-
+__app__.logger = logger
+#CORS(__app__)
 
 __resource_array__ : array
 __id_counter__ : int = 1
@@ -88,10 +89,6 @@ def init() :
     privileges.init()
 
     view_error_management.define_error_management(__app__)
-    from flask.logging import default_handler
-    __app__.logger.removeHandler(default_handler)
-    for hand in logger.handlers :
-        __app__.logger.addHandler(hand)
 
 @__app__.route('/api/login',methods = ['POST'])
 def login():
@@ -141,6 +138,14 @@ def routes():
     return jsonify(routes)
 
 
+@__app__.after_request
+def after_request(response):
+    header = response.headers
+    header['Access-Control-Allow-Origin'] = '*'
+    header['Access-Control-Allow-Methods'] = 'GET,HEAD,OPTIONS,POST,PUT'
+    header['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
+    return response
+
 
 def run() :
     global __server_process__

+ 1 - 1
Backend/Sources/View/view_privilege.py

@@ -28,7 +28,7 @@ def load_privilege_data() :
             logger.debug("user privilege for account : " + user.nickname + " with id " + str(user.id) + " parsed")
             roles_string : list[str] = list()
             for role in privileges.get_roles() :
-                roles_string.append(manager.get_role_domain(role) + ' : ' + role.name)
+                roles_string.append(manager.get_role_domain(role).name + ' : ' + role.name)
             logger.debug("roles found : " + str(roles_string))
 
 

+ 2 - 2
Backend/Sources/utility/privilege_manager.py

@@ -176,7 +176,7 @@ class Privilege_Manager :
             self.roles : set[Privilege_Role] = set()
 
             if privileges_data_str :
-                privileges_data : dict = json.load(privileges_data_str)
+                privileges_data = json.loads(privileges_data_str)
 
 
                 for key in privileges_data.keys() :
@@ -193,7 +193,7 @@ class Privilege_Manager :
 
                 ret_dict[domain.name] = role.name
 
-            return json.dump(json.load(ret_dict))
+            return json.dumps(ret_dict)
 
         @property
         def id(self):