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 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_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) declare_route() view.register_blueprint(inventory_blueprint) """ # INVENTORY inventory/items - GET -> get all items inventory/item - POST create items inventory/item/ - GET get item by id inventory/item/ - UPDATE item by id inventory/item/ - DELETE item by id inventory/sites - GET -> get all site inventory/site - POST create site inventory/site/ - GET get site by id inventory/site/ - UPDATE site by id inventory/site/ - DELETE site by id inventory/contacts - GET -> get all contact inventory/contact - POST create contact inventory/contact/ - GET get contact by id inventory/contact/ - UPDATE contact by id inventory/contact/ - DELETE contact by id inventory/groups - GET -> get all groups with items array id inventory/group - POST create group with items ids inventory/group/ - GET get group by id inventory/group//item/ - POST add item to group inventory/group//item/ - DELETE delete item to group inventory/group/ - 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/',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/',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/',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/',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))