mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
Merge branch 'license-verify-status' into license-testing
This commit is contained in:
commit
1c97bbcaba
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = ""
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user