|
@@ -1,15 +1,25 @@
|
|
|
|
+import profile
|
|
from Model.isp_model import user_account
|
|
from Model.isp_model import user_account
|
|
import View.view_privilege as view_privilege
|
|
import View.view_privilege as view_privilege
|
|
from utility.privilege_manager import *
|
|
from utility.privilege_manager import *
|
|
import persistence
|
|
import persistence
|
|
import Model.isp_model
|
|
import Model.isp_model
|
|
|
|
+import Model.model_manager as model_manager
|
|
import json
|
|
import json
|
|
|
|
+import flask
|
|
|
|
+import View.view_manager as view
|
|
|
|
+import Modules.Inventory.inventory as inventory
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+from flask import Blueprint
|
|
|
|
+inventory_blueprint = Blueprint('Inventory', __name__,url_prefix='/inventory')
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
inventory_read_only_role = Privilege_Role(name="read_only")
|
|
inventory_read_only_role = Privilege_Role(name="read_only")
|
|
inventory_admin_role = Privilege_Role(name="admin")
|
|
inventory_admin_role = Privilege_Role(name="admin")
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
def init():
|
|
def init():
|
|
inventory_privilege_domain = Privilege_Domain("inventory",description="privilege domain for inventory")
|
|
inventory_privilege_domain = Privilege_Domain("inventory",description="privilege domain for inventory")
|
|
view_privilege.manager.register_domain(inventory_privilege_domain)
|
|
view_privilege.manager.register_domain(inventory_privilege_domain)
|
|
@@ -18,3 +28,102 @@ def init():
|
|
inventory_privilege_domain.include_role(inventory_admin_role,inventory_read_only_role)
|
|
inventory_privilege_domain.include_role(inventory_admin_role,inventory_read_only_role)
|
|
|
|
|
|
|
|
|
|
|
|
+ declare_route()
|
|
|
|
+ view.register_blueprint(inventory_blueprint)
|
|
|
|
+
|
|
|
|
+"""
|
|
|
|
+# INVENTORY
|
|
|
|
+inventory/items - GET -> get all items
|
|
|
|
+inventory/item - POST create items
|
|
|
|
+inventory/item/<item_id> - GET get item by id
|
|
|
|
+inventory/item/<item_id> - UPDATE item by id
|
|
|
|
+inventory/item/<item_id> - DELETE item by id
|
|
|
|
+
|
|
|
|
+inventory/sites - GET -> get all site
|
|
|
|
+inventory/site - POST create site
|
|
|
|
+inventory/site/<site_id> - GET get site by id
|
|
|
|
+inventory/site/<site_id> - UPDATE site by id
|
|
|
|
+inventory/site/<site_id> - DELETE site by id
|
|
|
|
+
|
|
|
|
+inventory/contacts - GET -> get all contact
|
|
|
|
+inventory/contact - POST create contact
|
|
|
|
+inventory/contact/<contact_id> - GET get contact by id
|
|
|
|
+inventory/contact/<contact_id> - UPDATE contact by id
|
|
|
|
+inventory/contact/<contact_id> - DELETE contact by id
|
|
|
|
+
|
|
|
|
+inventory/groups - GET -> get all groups with items array id
|
|
|
|
+inventory/group - POST create group with items ids
|
|
|
|
+inventory/group/<contact_id> - GET get group by id
|
|
|
|
+inventory/group/<contact_id>/item/<item_id> - POST add item to group
|
|
|
|
+inventory/group/<contact_id>/item/<item_id> - DELETE delete item to group
|
|
|
|
+inventory/group/<contact_id> - DELETE group by id
|
|
|
|
+"""
|
|
|
|
+
|
|
|
|
+def declare_route() :
|
|
|
|
+
|
|
|
|
+ #the order of decorator are important
|
|
|
|
+ @inventory_blueprint.route('/items',methods = ['GET'])
|
|
|
|
+ @view_privilege.manager.require_authorization(required_role=inventory_read_only_role,get_privilege_func=view.get_user_privilege)
|
|
|
|
+ def get_all_items() :
|
|
|
|
+ ret = list()
|
|
|
|
+ for item in inventory.get_all_inventory_items() :
|
|
|
|
+ ret.append(model_manager.ModelObjectToJsonString(item))
|
|
|
|
+
|
|
|
|
+ return flask.jsonify(ret)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @inventory_blueprint.route('/sites',methods = ['GET'])
|
|
|
|
+ @view_privilege.manager.require_authorization(required_role=inventory_read_only_role,get_privilege_func=view.get_user_privilege)
|
|
|
|
+ def get_all_sites() :
|
|
|
|
+ ret = list()
|
|
|
|
+ for item in inventory.get_all_inventory_sites() :
|
|
|
|
+ ret.append(model_manager.ModelObjectToJsonString(item))
|
|
|
|
+
|
|
|
|
+ return flask.jsonify(ret)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @inventory_blueprint.route('/contacts',methods = ['GET'])
|
|
|
|
+ @view_privilege.manager.require_authorization(required_role=inventory_read_only_role,get_privilege_func=view.get_user_privilege)
|
|
|
|
+ def get_all_contacts() :
|
|
|
|
+ ret = list()
|
|
|
|
+ for item in inventory.get_all_inventory_contacts() :
|
|
|
|
+ ret.append(model_manager.ModelObjectToJsonString(item))
|
|
|
|
+
|
|
|
|
+ return flask.jsonify(ret)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @inventory_blueprint.route('/groups',methods = ['GET'])
|
|
|
|
+ @view_privilege.manager.require_authorization(required_role=inventory_read_only_role,get_privilege_func=view.get_user_privilege)
|
|
|
|
+ def get_all_groups() :
|
|
|
|
+ ret = list()
|
|
|
|
+ for item in inventory.get_all_inventory_groups() :
|
|
|
|
+ ret.append(model_manager.ModelObjectToJsonString(item))
|
|
|
|
+
|
|
|
|
+ return flask.jsonify(ret)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @inventory_blueprint.route('/item/<int:itemID>',methods = ['GET'])
|
|
|
|
+ @view_privilege.manager.require_authorization(required_role=inventory_read_only_role,get_privilege_func=view.get_user_privilege)
|
|
|
|
+ def get_item(itemID : int) :
|
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.get_inventory_item(itemID))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @inventory_blueprint.route('/site/<int:siteID>',methods = ['GET'])
|
|
|
|
+ @view_privilege.manager.require_authorization(required_role=inventory_read_only_role,get_privilege_func=view.get_user_privilege)
|
|
|
|
+ def get_site(siteID : int) :
|
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.get_inventory_site(siteID))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @inventory_blueprint.route('/contact/<int:contactID>',methods = ['GET'])
|
|
|
|
+ @view_privilege.manager.require_authorization(required_role=inventory_read_only_role,get_privilege_func=view.get_user_privilege)
|
|
|
|
+ def get_contact(contactID : int) :
|
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.get_inventory_contact(contactID))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @inventory_blueprint.route('/group/<int:groupID>',methods = ['GET'])
|
|
|
|
+ @view_privilege.manager.require_authorization(required_role=inventory_read_only_role,get_privilege_func=view.get_user_privilege)
|
|
|
|
+ def get_group(groupID : int) :
|
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.get_inventory_group(groupID))
|
|
|
|
+
|
|
|
|
+
|