Skip to content

Commit

Permalink
Merge branch 'license-testing' of github.com:langgenius/dify into lic…
Browse files Browse the repository at this point in the history
…ense-testing
  • Loading branch information
douxc committed Nov 14, 2024
2 parents cb810a7 + b2570c2 commit 96f6c32
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
2 changes: 2 additions & 0 deletions api/controllers/console/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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
Expand All @@ -28,6 +29,7 @@ class AppListApi(Resource):
@setup_required
@login_required
@account_initialization_required
@enterprise_license_required
def get(self):
"""Get app list"""

Expand Down
6 changes: 6 additions & 0 deletions api/controllers/console/workspace/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 14 additions & 2 deletions api/controllers/console/wraps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
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
Expand Down Expand Up @@ -142,3 +142,15 @@ def decorated(*args, **kwargs):
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
15 changes: 13 additions & 2 deletions api/services/feature_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from enum import Enum

from pydantic import BaseModel, ConfigDict

from configs import dify_config
Expand All @@ -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 = ""


Expand Down Expand Up @@ -164,4 +175,4 @@ def _fulfill_params_from_enterprise(cls, features):
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"]

0 comments on commit 96f6c32

Please sign in to comment.