Underground-Digital/Workflow-Engine
0
1from flask_restful import Resource, reqparse2 3from controllers.console.wraps import setup_required4from controllers.inner_api import api5from controllers.inner_api.wraps import inner_api_only6from events.tenant_event import tenant_was_created7from models.account import Account8from services.account_service import TenantService9 10 11class EnterpriseWorkspace(Resource):12 @setup_required13 @inner_api_only14 def post(self):15 parser = reqparse.RequestParser()16 parser.add_argument("name", type=str, required=True, location="json")17 parser.add_argument("owner_email", type=str, required=True, location="json")18 args = parser.parse_args()19 20 account = Account.query.filter_by(email=args["owner_email"]).first()21 if account is None:22 return {"message": "owner account not found."}, 40423 24 tenant = TenantService.create_tenant(args["name"], is_from_dashboard=True)25 TenantService.create_tenant_member(tenant, account, role="owner")26 27 tenant_was_created.send(tenant)28 29 return {"message": "enterprise workspace created."}30 31 32api.add_resource(EnterpriseWorkspace, "/enterprise/workspace")33 