feat: add billing switch. (#1789)
Co-authored-by: StyleZhang <jasonapring2015@outlook.com>
This commit is contained in:
@@ -6,7 +6,7 @@ bp = Blueprint('console', __name__, url_prefix='/console/api')
|
||||
api = ExternalApi(bp)
|
||||
|
||||
# Import other controllers
|
||||
from . import extension, setup, version, apikey, admin
|
||||
from . import extension, setup, version, apikey, admin, feature
|
||||
|
||||
# Import app controllers
|
||||
from .app import advanced_prompt_template, app, site, completion, model_config, statistic, conversation, message, generator, audio, annotation
|
||||
|
@@ -1,6 +1,5 @@
|
||||
from flask_restful import Resource, reqparse
|
||||
from flask_login import current_user
|
||||
from flask import current_app
|
||||
|
||||
from controllers.console import api
|
||||
from controllers.console.setup import setup_required
|
||||
@@ -10,20 +9,6 @@ from libs.login import login_required
|
||||
from services.billing_service import BillingService
|
||||
|
||||
|
||||
class BillingInfo(Resource):
|
||||
|
||||
@setup_required
|
||||
@login_required
|
||||
@account_initialization_required
|
||||
def get(self):
|
||||
|
||||
edition = current_app.config['EDITION']
|
||||
if edition != 'CLOUD':
|
||||
return {"enabled": False}
|
||||
|
||||
return BillingService.get_info(current_user.current_tenant_id)
|
||||
|
||||
|
||||
class Subscription(Resource):
|
||||
|
||||
@setup_required
|
||||
@@ -56,6 +41,5 @@ class Invoices(Resource):
|
||||
return BillingService.get_invoices(current_user.email)
|
||||
|
||||
|
||||
api.add_resource(BillingInfo, '/billing/info')
|
||||
api.add_resource(Subscription, '/billing/subscription')
|
||||
api.add_resource(Invoices, '/billing/invoices')
|
||||
|
14
api/controllers/console/feature.py
Normal file
14
api/controllers/console/feature.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from flask_restful import Resource
|
||||
from flask_login import current_user
|
||||
|
||||
from . import api
|
||||
from services.feature_service import FeatureService
|
||||
|
||||
|
||||
class FeatureApi(Resource):
|
||||
|
||||
def get(self):
|
||||
return FeatureService.get_features(current_user.current_tenant_id).dict()
|
||||
|
||||
|
||||
api.add_resource(FeatureApi, '/features')
|
@@ -5,7 +5,7 @@ from flask import current_app, abort
|
||||
from flask_login import current_user
|
||||
|
||||
from controllers.console.workspace.error import AccountNotInitializedError
|
||||
from services.billing_service import BillingService
|
||||
from services.feature_service import FeatureService
|
||||
|
||||
|
||||
def account_initialization_required(view):
|
||||
@@ -49,23 +49,23 @@ def cloud_edition_billing_resource_check(resource: str,
|
||||
def interceptor(view):
|
||||
@wraps(view)
|
||||
def decorated(*args, **kwargs):
|
||||
if current_app.config['EDITION'] == 'CLOUD':
|
||||
tenant_id = current_user.current_tenant_id
|
||||
billing_info = BillingService.get_info(tenant_id)
|
||||
members = billing_info['members']
|
||||
apps = billing_info['apps']
|
||||
vector_space = billing_info['vector_space']
|
||||
annotation_quota_limit = billing_info['annotation_quota_limit']
|
||||
features = FeatureService.get_features(current_user.current_tenant_id)
|
||||
|
||||
if resource == 'members' and 0 < members['limit'] <= members['size']:
|
||||
if features.billing.enabled:
|
||||
members = features.members
|
||||
apps = features.apps
|
||||
vector_space = features.vector_space
|
||||
annotation_quota_limit = features.annotation_quota_limit
|
||||
|
||||
if resource == 'members' and 0 < members.limit <= members.size:
|
||||
abort(403, error_msg)
|
||||
elif resource == 'apps' and 0 < apps['limit'] <= apps['size']:
|
||||
elif resource == 'apps' and 0 < apps.limit <= apps.size:
|
||||
abort(403, error_msg)
|
||||
elif resource == 'vector_space' and 0 < vector_space['limit'] <= vector_space['size']:
|
||||
elif resource == 'vector_space' and 0 < vector_space.limit <= vector_space.size:
|
||||
abort(403, error_msg)
|
||||
elif resource == 'workspace_custom' and not billing_info['can_replace_logo']:
|
||||
elif resource == 'workspace_custom' and not features.can_replace_logo:
|
||||
abort(403, error_msg)
|
||||
elif resource == 'annotation' and 0 < annotation_quota_limit['limit'] < annotation_quota_limit['size']:
|
||||
elif resource == 'annotation' and 0 < annotation_quota_limit.limit < annotation_quota_limit.size:
|
||||
abort(403, error_msg)
|
||||
else:
|
||||
return view(*args, **kwargs)
|
||||
|
Reference in New Issue
Block a user