From 5678d9a7e74b437cac00f3eff4d95a8cb73ab08a Mon Sep 17 00:00:00 2001 From: Garfield Dai Date: Wed, 13 Nov 2024 18:07:06 +0800 Subject: [PATCH 1/2] feat: if license is invalid, logout. --- api/controllers/console/workspace/error.py | 6 +++--- api/controllers/console/wraps.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/api/controllers/console/workspace/error.py b/api/controllers/console/workspace/error.py index 5fbefd0cc5..07a47e5e3b 100644 --- a/api/controllers/console/workspace/error.py +++ b/api/controllers/console/workspace/error.py @@ -37,7 +37,7 @@ class AccountNotInitializedError(BaseHTTPException): code = 400 -class EnterpriseLicenseUnauthorized(BaseHTTPException): - error_code = "unauthorized" - description = "Your license is invalid. Please contact your administrator." +class UnauthorizedAndForceLogout(BaseHTTPException): + error_code = "unauthorized_and_force_logout" + description = "Unauthorized and force logout." code = 401 diff --git a/api/controllers/console/wraps.py b/api/controllers/console/wraps.py index 55e46681b0..9f8904deeb 100644 --- a/api/controllers/console/wraps.py +++ b/api/controllers/console/wraps.py @@ -6,7 +6,7 @@ from flask import abort, request from flask_login import current_user from configs import dify_config -from controllers.console.workspace.error import AccountNotInitializedError, EnterpriseLicenseUnauthorized +from controllers.console.workspace.error import AccountNotInitializedError, UnauthorizedAndForceLogout from models.model import DifySetup from services.feature_service import FeatureService, LicenseStatus from services.operation_service import OperationService @@ -149,7 +149,7 @@ def enterprise_license_required(view): def decorated(*args, **kwargs): settings = FeatureService.get_system_features() if settings.license.status in [LicenseStatus.INACTIVE, LicenseStatus.EXPIRED, LicenseStatus.LOST]: - raise EnterpriseLicenseUnauthorized() + raise UnauthorizedAndForceLogout("Your license is invalid. Please contact your administrator.") return view(*args, **kwargs) From 0ef37def9f8d424359315450095b198c814859ec Mon Sep 17 00:00:00 2001 From: Garfield Dai Date: Wed, 13 Nov 2024 18:11:36 +0800 Subject: [PATCH 2/2] feat: if license is invalid, logout. --- api/controllers/console/app/app.py | 2 ++ api/controllers/console/workspace/account.py | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/api/controllers/console/app/app.py b/api/controllers/console/app/app.py index 36338cbd8a..e8678c461a 100644 --- a/api/controllers/console/app/app.py +++ b/api/controllers/console/app/app.py @@ -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""" diff --git a/api/controllers/console/workspace/account.py b/api/controllers/console/workspace/account.py index 823341ec42..aabc417759 100644 --- a/api/controllers/console/workspace/account.py +++ b/api/controllers/console/workspace/account.py @@ -14,7 +14,7 @@ from controllers.console.workspace.error import ( InvalidInvitationCodeError, RepeatPasswordNotMatchError, ) -from controllers.console.wraps import account_initialization_required, enterprise_license_required, setup_required +from controllers.console.wraps import account_initialization_required, setup_required from extensions.ext_database import db from fields.member_fields import account_fields from libs.helper import TimestampField, timezone @@ -78,7 +78,6 @@ class AccountProfileApi(Resource): @setup_required @login_required @account_initialization_required - @enterprise_license_required @marshal_with(account_fields) def get(self): return current_user