Merge branch 'license-verify-status' into license-testing

This commit is contained in:
Garfield Dai 2024-11-13 16:59:18 +08:00
commit 1c97bbcaba
4 changed files with 35 additions and 5 deletions

View File

@ -14,7 +14,7 @@ from controllers.console.workspace.error import (
InvalidInvitationCodeError,
RepeatPasswordNotMatchError,
)
from controllers.console.wraps import account_initialization_required, setup_required
from controllers.console.wraps import account_initialization_required, enterprise_license_required, setup_required
from extensions.ext_database import db
from fields.member_fields import account_fields
from libs.helper import TimestampField, timezone
@ -78,6 +78,7 @@ class AccountProfileApi(Resource):
@setup_required
@login_required
@account_initialization_required
@enterprise_license_required
@marshal_with(account_fields)
def get(self):
return current_user

View File

@ -35,3 +35,9 @@ class AccountNotInitializedError(BaseHTTPException):
error_code = "account_not_initialized"
description = "The account has not been initialized yet. Please proceed with the initialization process first."
code = 400
class EnterpriseLicenseUnauthorized(BaseHTTPException):
error_code = "unauthorized"
description = "Your license is invalid. Please contact your administrator."
code = 401

View File

@ -6,9 +6,9 @@ from flask import abort, request
from flask_login import current_user
from configs import dify_config
from controllers.console.workspace.error import AccountNotInitializedError
from controllers.console.workspace.error import AccountNotInitializedError, EnterpriseLicenseUnauthorized
from models.model import DifySetup
from services.feature_service import FeatureService
from services.feature_service import FeatureService, LicenseStatus
from services.operation_service import OperationService
from .error import NotInitValidateError, NotSetupError
@ -142,3 +142,15 @@ def setup_required(view):
return view(*args, **kwargs)
return decorated
def enterprise_license_required(view):
@wraps(view)
def decorated(*args, **kwargs):
settings = FeatureService.get_system_features()
if settings.license.status in [LicenseStatus.INACTIVE, LicenseStatus.EXPIRED, LicenseStatus.LOST]:
raise EnterpriseLicenseUnauthorized()
return view(*args, **kwargs)
return decorated

View File

@ -1,3 +1,5 @@
from enum import Enum
from pydantic import BaseModel, ConfigDict
from configs import dify_config
@ -20,8 +22,17 @@ class LimitationModel(BaseModel):
limit: int = 0
class LicenseStatus(str, Enum):
NONE = "none"
INACTIVE = "inactive"
ACTIVE = "active"
EXPIRING = "expiring"
EXPIRED = "expired"
LOST = "lost"
class LicenseModel(BaseModel):
status: str = "none"
status: LicenseStatus = LicenseStatus.NONE
expired_at: str = ""