123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- 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/<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))
|