mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
Merge branch 'license-testing' of github.com:langgenius/dify into license-testing
This commit is contained in:
commit
96f6c321a3
|
@ -9,6 +9,7 @@ from controllers.console.app.wraps import get_app_model
|
|||
from controllers.console.wraps import (
|
||||
account_initialization_required,
|
||||
cloud_edition_billing_resource_check,
|
||||
enterprise_license_required,
|
||||
setup_required,
|
||||
)
|
||||
from core.ops.ops_trace_manager import OpsTraceManager
|
||||
|
@ -28,6 +29,7 @@ class AppListApi(Resource):
|
|||
@setup_required
|
||||
@login_required
|
||||
@account_initialization_required
|
||||
@enterprise_license_required
|
||||
def get(self):
|
||||
"""Get app list"""
|
||||
|
||||
|
|
|
@ -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 UnauthorizedAndForceLogout(BaseHTTPException):
|
||||
error_code = "unauthorized_and_force_logout"
|
||||
description = "Unauthorized and force logout."
|
||||
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, UnauthorizedAndForceLogout
|
||||
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 UnauthorizedAndForceLogout("Your license is invalid. Please contact your administrator.")
|
||||
|
||||
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 = ""
|
||||
|
||||
|
||||
|
@ -164,4 +175,4 @@ class FeatureService:
|
|||
features.license.status = enterprise_info["license"]["status"]
|
||||
|
||||
if "expired_at" in enterprise_info["license"]:
|
||||
features.license.expired_at = enterprise_info["license"]["expired_at"]
|
||||
features.license.expired_at = enterprise_info["license"]["expired_at"]
|
||||
|
|
Loading…
Reference in New Issue
Block a user