|
@@ -2,10 +2,13 @@
|
|
import logging
|
|
import logging
|
|
|
|
|
|
from flask import request
|
|
from flask import request
|
|
-from flask_login import login_required, current_user
|
|
|
|
-from flask_restful import Resource, fields, marshal_with, reqparse, marshal
|
|
|
|
|
|
+from flask_login import current_user
|
|
|
|
+from core.login.login import login_required
|
|
|
|
+from flask_restful import Resource, fields, marshal_with, reqparse, marshal, inputs
|
|
|
|
+from flask_restful.inputs import int_range
|
|
|
|
|
|
from controllers.console import api
|
|
from controllers.console import api
|
|
|
|
+from controllers.console.admin import admin_required
|
|
from controllers.console.setup import setup_required
|
|
from controllers.console.setup import setup_required
|
|
from controllers.console.error import AccountNotLinkTenantError
|
|
from controllers.console.error import AccountNotLinkTenantError
|
|
from controllers.console.wraps import account_initialization_required
|
|
from controllers.console.wraps import account_initialization_required
|
|
@@ -43,6 +46,13 @@ tenants_fields = {
|
|
'current': fields.Boolean
|
|
'current': fields.Boolean
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+workspace_fields = {
|
|
|
|
+ 'id': fields.String,
|
|
|
|
+ 'name': fields.String,
|
|
|
|
+ 'status': fields.String,
|
|
|
|
+ 'created_at': TimestampField
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
class TenantListApi(Resource):
|
|
class TenantListApi(Resource):
|
|
@setup_required
|
|
@setup_required
|
|
@@ -57,6 +67,38 @@ class TenantListApi(Resource):
|
|
return {'workspaces': marshal(tenants, tenants_fields)}, 200
|
|
return {'workspaces': marshal(tenants, tenants_fields)}, 200
|
|
|
|
|
|
|
|
|
|
|
|
+class WorkspaceListApi(Resource):
|
|
|
|
+ @setup_required
|
|
|
|
+ @admin_required
|
|
|
|
+ def get(self):
|
|
|
|
+ parser = reqparse.RequestParser()
|
|
|
|
+ parser.add_argument('page', type=inputs.int_range(1, 99999), required=False, default=1, location='args')
|
|
|
|
+ parser.add_argument('limit', type=inputs.int_range(1, 100), required=False, default=20, location='args')
|
|
|
|
+ args = parser.parse_args()
|
|
|
|
+
|
|
|
|
+ tenants = db.session.query(Tenant).order_by(Tenant.created_at.desc())\
|
|
|
|
+ .paginate(page=args['page'], per_page=args['limit'])
|
|
|
|
+
|
|
|
|
+ has_more = False
|
|
|
|
+ if len(tenants.items) == args['limit']:
|
|
|
|
+ current_page_first_tenant = tenants[-1]
|
|
|
|
+ rest_count = db.session.query(Tenant).filter(
|
|
|
|
+ Tenant.created_at < current_page_first_tenant.created_at,
|
|
|
|
+ Tenant.id != current_page_first_tenant.id
|
|
|
|
+ ).count()
|
|
|
|
+
|
|
|
|
+ if rest_count > 0:
|
|
|
|
+ has_more = True
|
|
|
|
+ total = db.session.query(Tenant).count()
|
|
|
|
+ return {
|
|
|
|
+ 'data': marshal(tenants.items, workspace_fields),
|
|
|
|
+ 'has_more': has_more,
|
|
|
|
+ 'limit': args['limit'],
|
|
|
|
+ 'page': args['page'],
|
|
|
|
+ 'total': total
|
|
|
|
+ }, 200
|
|
|
|
+
|
|
|
|
+
|
|
class TenantApi(Resource):
|
|
class TenantApi(Resource):
|
|
@setup_required
|
|
@setup_required
|
|
@login_required
|
|
@login_required
|
|
@@ -92,6 +134,7 @@ class SwitchWorkspaceApi(Resource):
|
|
|
|
|
|
|
|
|
|
api.add_resource(TenantListApi, '/workspaces') # GET for getting all tenants
|
|
api.add_resource(TenantListApi, '/workspaces') # GET for getting all tenants
|
|
|
|
+api.add_resource(WorkspaceListApi, '/all-workspaces') # GET for getting all tenants
|
|
api.add_resource(TenantApi, '/workspaces/current', endpoint='workspaces_current') # GET for getting current tenant info
|
|
api.add_resource(TenantApi, '/workspaces/current', endpoint='workspaces_current') # GET for getting current tenant info
|
|
api.add_resource(TenantApi, '/info', endpoint='info') # Deprecated
|
|
api.add_resource(TenantApi, '/info', endpoint='info') # Deprecated
|
|
api.add_resource(SwitchWorkspaceApi, '/workspaces/switch') # POST for switching tenant
|
|
api.add_resource(SwitchWorkspaceApi, '/workspaces/switch') # POST for switching tenant
|