|
@@ -1,25 +1,16 @@
|
|
from array import array
|
|
from array import array
|
|
-from msilib.schema import Class
|
|
|
|
-from re import I
|
|
|
|
import threading
|
|
import threading
|
|
-from tkinter.ttk import Separator
|
|
|
|
-from typing import Type
|
|
|
|
-from xmlrpc.client import boolean
|
|
|
|
from flask import session,Flask,request, jsonify
|
|
from flask import session,Flask,request, jsonify
|
|
-from flask_restful import Resource, Api
|
|
|
|
-import flask_restful
|
|
|
|
-from itsdangerous import json
|
|
|
|
-from sqlalchemy import delete
|
|
|
|
|
|
+import flask
|
|
from utility.app_logging import logger_name
|
|
from utility.app_logging import logger_name
|
|
import logging
|
|
import logging
|
|
import persistence
|
|
import persistence
|
|
import Model.isp_model as isp_model
|
|
import Model.isp_model as isp_model
|
|
import Model.model_manager as model_manager
|
|
import Model.model_manager as model_manager
|
|
from werkzeug.security import check_password_hash
|
|
from werkzeug.security import check_password_hash
|
|
-import anytree
|
|
|
|
import View.view_privilege as privileges
|
|
import View.view_privilege as privileges
|
|
|
|
+import Modules.Inventory.inventory_view as inventory_view
|
|
from datetime import timedelta
|
|
from datetime import timedelta
|
|
-from flask_session import Session
|
|
|
|
import View.view_error_management as view_error_management
|
|
import View.view_error_management as view_error_management
|
|
logger = logging.getLogger(logger_name + ".VIEW")
|
|
logger = logging.getLogger(logger_name + ".VIEW")
|
|
|
|
|
|
@@ -28,13 +19,9 @@ logger = logging.getLogger(logger_name + ".VIEW")
|
|
__app__ = Flask("OpenIsp")
|
|
__app__ = Flask("OpenIsp")
|
|
__app__.secret_key = "aseqzdwxc"
|
|
__app__.secret_key = "aseqzdwxc"
|
|
__app__.permanent_session_lifetime = timedelta(minutes=2)
|
|
__app__.permanent_session_lifetime = timedelta(minutes=2)
|
|
-__app__.config["SESSION_PERMANENT"] = False
|
|
|
|
-__app__.config["SESSION_TYPE"] = "filesystem"
|
|
|
|
|
|
|
|
|
|
|
|
__resource_array__ : array
|
|
__resource_array__ : array
|
|
-
|
|
|
|
-
|
|
|
|
__id_counter__ : int = 1
|
|
__id_counter__ : int = 1
|
|
|
|
|
|
|
|
|
|
@@ -87,13 +74,13 @@ def init() :
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ privileges.init()
|
|
|
|
|
|
|
|
+ view_error_management.define_error_management(__app__)
|
|
from flask.logging import default_handler
|
|
from flask.logging import default_handler
|
|
__app__.logger.removeHandler(default_handler)
|
|
__app__.logger.removeHandler(default_handler)
|
|
-
|
|
|
|
-
|
|
|
|
- privileges.init()
|
|
|
|
- view_error_management.define_error_management(__app__)
|
|
|
|
|
|
+ for hand in logger.handlers :
|
|
|
|
+ __app__.logger.addHandler(hand)
|
|
|
|
|
|
@__app__.route('/api/login',methods = ['POST'])
|
|
@__app__.route('/api/login',methods = ['POST'])
|
|
def login():
|
|
def login():
|
|
@@ -121,7 +108,7 @@ def login():
|
|
|
|
|
|
session["username"] = _username
|
|
session["username"] = _username
|
|
session["account_data"] = model_manager.ModelObjectToJsonString(Item)
|
|
session["account_data"] = model_manager.ModelObjectToJsonString(Item)
|
|
- session["roles_ids"] = [privileges.inventory_read_only_role.id]
|
|
|
|
|
|
+ session["roles_ids"] = [inventory_view.inventory_read_only_role.id]
|
|
logger.info("account " + _username + " logged IN successfully with id : " + session["client_id"])
|
|
logger.info("account " + _username + " logged IN successfully with id : " + session["client_id"])
|
|
resp = jsonify({'message' : 'login successful'})
|
|
resp = jsonify({'message' : 'login successful'})
|
|
resp.status_code = 200
|
|
resp.status_code = 200
|
|
@@ -136,13 +123,15 @@ def logout():
|
|
|
|
|
|
|
|
|
|
@__app__.route('/routes',methods = ['GET'])
|
|
@__app__.route('/routes',methods = ['GET'])
|
|
-@privileges.manager.require_authorization(required_role=privileges.inventory_admin_role,ids_getter=get_roles_ids)
|
|
|
|
|
|
+@privileges.manager.require_authorization(required_role=inventory_view.inventory_admin_role,ids_getter=get_roles_ids)
|
|
def routes():
|
|
def routes():
|
|
routes = []
|
|
routes = []
|
|
for route in __app__.url_map.iter_rules():
|
|
for route in __app__.url_map.iter_rules():
|
|
routes.append('%s' % route)
|
|
routes.append('%s' % route)
|
|
return jsonify(routes)
|
|
return jsonify(routes)
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
def run() :
|
|
def run() :
|
|
global __server_process__
|
|
global __server_process__
|
|
__server_process__ = ServerThread(__app__,"0.0.0.0",8000)
|
|
__server_process__ = ServerThread(__app__,"0.0.0.0",8000)
|
|
@@ -157,69 +146,12 @@ def stop() :
|
|
logger.info('View server stopped')
|
|
logger.info('View server stopped')
|
|
|
|
|
|
|
|
|
|
|
|
+def add_blueprint(blueprint : flask.Blueprint) :
|
|
|
|
+ __app__.register_blueprint(blueprint)
|
|
|
|
|
|
-class ResourceNode(anytree.NodeMixin) :
|
|
|
|
- def __init__(self, url_key : str, resource = None, parent=None, children=None):
|
|
|
|
- super(ResourceNode, self).__init__()
|
|
|
|
- self.url_key = url_key
|
|
|
|
- self.parent = parent
|
|
|
|
- if children:
|
|
|
|
- self.children = children
|
|
|
|
-
|
|
|
|
- if resource :
|
|
|
|
- self.resource = resource
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- # we check if the resource class has an http API method
|
|
|
|
- get = getattr(self, "get", None)
|
|
|
|
- post = getattr(self, "post", None)
|
|
|
|
- delete = getattr(self, "delete", None)
|
|
|
|
- update = getattr(self, "update", None)
|
|
|
|
- patch = getattr(self, "patch", None)
|
|
|
|
-
|
|
|
|
- if not callable(get) and not callable(post) \
|
|
|
|
- and not callable(delete) and not callable(update) \
|
|
|
|
- and not callable(patch) :
|
|
|
|
- raise BaseException("class does have an api class")
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- url_slice = None
|
|
|
|
- resource = None
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-def add_resource_tree(node : ResourceNode) :
|
|
|
|
-
|
|
|
|
- if not node.is_root() :
|
|
|
|
- raise BaseException("node is not a root node")
|
|
|
|
-
|
|
|
|
- logger.debug("adding resource tree for API")
|
|
|
|
- logger.debug(anytree.RenderTree(node, style=anytree.AsciiStyle()).by_attr("url_slice"))
|
|
|
|
-
|
|
|
|
- for node in anytree.PreOrderIter(node) :
|
|
|
|
- logger.debug("iterating though node " + node.url_key)
|
|
|
|
-
|
|
|
|
- if node.resource is not None :
|
|
|
|
- logger.debug("resource found")
|
|
|
|
-
|
|
|
|
- url = ""
|
|
|
|
- parent : ResourceNode
|
|
|
|
- for parent in node.ancestors :
|
|
|
|
- url = url + node.separator + parent.url_key
|
|
|
|
-
|
|
|
|
- print("url built for the node : " + url)
|
|
|
|
-
|
|
|
|
- __api__.add_resource(node.resource, url)
|
|
|
|
- __resource_array__.append(node)
|
|
|
|
-
|
|
|
|
-#node.ancestors ( all parent )
|
|
|
|
-
|
|
|
|
-def delete_resource_tree(node : ResourceNode, cascade : boolean = True) :
|
|
|
|
-
|
|
|
|
- if not cascade and not node.is_leaf() :
|
|
|
|
- raise BaseException("cannot delete only a node when it's not a leaf !")
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- raise BaseException("Not implemented yet") #TODO
|
|
|
|
-
|
|
|
|
|
|
+@privileges.manager.require_authorization(required_role=inventory_view.inventory_read_only_role,ids_getter=get_roles_ids)
|
|
|
|
+def tab():
|
|
|
|
+ return jsonify([2,5,7])
|
|
|
|
|
|
|
|
|
|
|
|
+__app__.add_url_rule("/tab","/tab",tab)
|