|
@@ -1,9 +1,7 @@
|
|
|
-import profile
|
|
|
-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 Model.model_manager as model_manager
|
|
|
import json
|
|
|
import flask
|
|
@@ -61,16 +59,48 @@ inventory/group/<contact_id> - DELETE group by id
|
|
|
|
|
|
def declare_route() :
|
|
|
|
|
|
+
|
|
|
+#############################################
|
|
|
+######## items ########
|
|
|
+#############################################
|
|
|
+
|
|
|
#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))
|
|
|
+ ret.append(item)
|
|
|
+
|
|
|
+ return json.dumps(ret, cls=model_manager.ComplexEncoder)
|
|
|
+
|
|
|
+ @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('/item/<int:itemID>',methods = ['UPDATE','DELETE'])
|
|
|
+ @view_privilege.manager.require_authorization(required_role=inventory_admin_role,get_privilege_func=view.get_user_privilege)
|
|
|
+ def update_or_delete_item(itemID : int) :
|
|
|
+ if flask.request.method == 'UPDATE':
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.inventory_item_update(itemID,json.dumps(flask.request.json)))
|
|
|
+
|
|
|
+ if flask.request.method == 'DELETE':
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.inventory_item_delete(itemID))
|
|
|
|
|
|
- return flask.jsonify(ret)
|
|
|
|
|
|
+ @inventory_blueprint.route('/item',methods = ['POST'])
|
|
|
+ @view_privilege.manager.require_authorization(required_role=inventory_admin_role,get_privilege_func=view.get_user_privilege)
|
|
|
+ def create_item() :
|
|
|
+
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.inventory_item_create(json.dumps(flask.request.json)))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+#############################################
|
|
|
+######## sites ########
|
|
|
+#############################################
|
|
|
|
|
|
@inventory_blueprint.route('/sites',methods = ['GET'])
|
|
|
@view_privilege.manager.require_authorization(required_role=inventory_read_only_role,get_privilege_func=view.get_user_privilege)
|
|
@@ -81,6 +111,29 @@ def declare_route() :
|
|
|
|
|
|
return flask.jsonify(ret)
|
|
|
|
|
|
+ @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('/site/<int:siteID>',methods = ['UPDATE','DELETE'])
|
|
|
+ @view_privilege.manager.require_authorization(required_role=inventory_admin_role,get_privilege_func=view.get_user_privilege)
|
|
|
+ def update_or_delete_site(siteID : int) :
|
|
|
+ if flask.request.method == 'UPDATE':
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.inventory_site_update(siteID,json.dumps(flask.request.json)))
|
|
|
+
|
|
|
+ if flask.request.method == 'DELETE':
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.inventory_site_delete(siteID))
|
|
|
+
|
|
|
+ @inventory_blueprint.route('/site',methods = ['POST'])
|
|
|
+ @view_privilege.manager.require_authorization(required_role=inventory_admin_role,get_privilege_func=view.get_user_privilege)
|
|
|
+ def create_site() :
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.inventory_site_create(json.dumps(flask.request.json)))
|
|
|
+
|
|
|
+#############################################
|
|
|
+######## contacts ########
|
|
|
+#############################################
|
|
|
|
|
|
@inventory_blueprint.route('/contacts',methods = ['GET'])
|
|
|
@view_privilege.manager.require_authorization(required_role=inventory_read_only_role,get_privilege_func=view.get_user_privilege)
|
|
@@ -92,6 +145,30 @@ def declare_route() :
|
|
|
return flask.jsonify(ret)
|
|
|
|
|
|
|
|
|
+ @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('/contact/<int:contactID>',methods = ['UPDATE','DELETE'])
|
|
|
+ @view_privilege.manager.require_authorization(required_role=inventory_admin_role,get_privilege_func=view.get_user_privilege)
|
|
|
+ def update_or_delete_contact(contactID : int) :
|
|
|
+ if flask.request.method == 'UPDATE':
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.inventory_contact_update(contactID,json.dumps(flask.request.json)))
|
|
|
+
|
|
|
+ if flask.request.method == 'DELETE':
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.inventory_contact_delete(contactID))
|
|
|
+
|
|
|
+
|
|
|
+ @inventory_blueprint.route('/contact',methods = ['POST'])
|
|
|
+ @view_privilege.manager.require_authorization(required_role=inventory_admin_role,get_privilege_func=view.get_user_privilege)
|
|
|
+ def create_contact() :
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.inventory_contact_create(json.dumps(flask.request.json)))
|
|
|
+
|
|
|
+#############################################
|
|
|
+######## groups ########
|
|
|
+#############################################
|
|
|
+
|
|
|
@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() :
|
|
@@ -101,29 +178,35 @@ def declare_route() :
|
|
|
|
|
|
return flask.jsonify(ret)
|
|
|
|
|
|
-
|
|
|
- @inventory_blueprint.route('/item/<int:itemID>',methods = ['GET'])
|
|
|
+ @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_item(itemID : int) :
|
|
|
- return model_manager.ModelObjectToJsonString(inventory.get_inventory_item(itemID))
|
|
|
+ def get_group(groupID : int) :
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.get_inventory_group(groupID))
|
|
|
|
|
|
+ @inventory_blueprint.route('/group/<int:groupID>',methods = ['UPDATE','DELETE'])
|
|
|
+ @view_privilege.manager.require_authorization(required_role=inventory_admin_role,get_privilege_func=view.get_user_privilege)
|
|
|
+ def update_or_delete_group(groupID : int) :
|
|
|
+ if flask.request.method == 'UPDATE':
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.inventory_group_update(groupID,json.dumps(flask.request.json)))
|
|
|
|
|
|
- @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))
|
|
|
+ if flask.request.method == 'DELETE':
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.inventory_group_delete(groupID))
|
|
|
|
|
|
+ @inventory_blueprint.route('/group',methods = ['POST'])
|
|
|
+ @view_privilege.manager.require_authorization(required_role=inventory_admin_role,get_privilege_func=view.get_user_privilege)
|
|
|
+ def create_group() :
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.inventory_group_create(json.dumps(flask.request.json)))
|
|
|
|
|
|
|
|
|
- @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>/item/<int:itemID>',methods = ['POST','DELETE'])
|
|
|
+ @view_privilege.manager.require_authorization(required_role=inventory_admin_role,get_privilege_func=view.get_user_privilege)
|
|
|
+ def manage_group_members(groupID : int,itemID : int) :
|
|
|
+ if flask.request.method == 'POST':
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.inventory_group_add_item(groupID,itemID))
|
|
|
+ if flask.request.method == 'DELETE':
|
|
|
+ return model_manager.ModelObjectToJsonString(inventory.inventory_group_delete_item(groupID,itemID))
|
|
|
+
|
|
|
|
|
|
|
|
|
- @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))
|
|
|
|
|
|
|