feat: add workspace not found

This commit is contained in:
Joe 2024-09-10 10:58:55 +08:00
parent 3f954e2b9f
commit 57a2534c47
2 changed files with 12 additions and 1 deletions

View File

@ -15,7 +15,7 @@ from libs.oauth import GitHubOAuth, GoogleOAuth, OAuthUserInfo
from models.account import Account, AccountStatus
from services.account_service import AccountService, RegisterService, TenantService
from services.errors.account import AccountNotFound
from services.errors.workspace import WorkSpaceNotAllowedCreateError
from services.errors.workspace import WorkSpaceNotAllowedCreateError, WorkSpaceNotFound
from .. import api
@ -91,6 +91,8 @@ class OAuthCallback(Resource):
account = _generate_account(provider, user_info)
except AccountNotFound:
return redirect(f"{dify_config.CONSOLE_WEB_URL}/signin?message=AccountNotFound")
except WorkSpaceNotFound:
return redirect(f"{dify_config.CONSOLE_WEB_URL}/signin?message=WorkspaceNotFound")
except WorkSpaceNotAllowedCreateError:
return redirect(
f"{dify_config.CONSOLE_WEB_URL}/signin?message=Workspace not found, please contact system admin to invite you to join in a workspace."
@ -128,6 +130,11 @@ def _generate_account(provider: str, user_info: OAuthUserInfo):
# Get account by openid or email.
account = _get_account_by_openid_or_email(provider, user_info)
if account:
tenant = TenantService.get_join_tenants(account)
if not tenant:
raise WorkSpaceNotFound()
if not account:
if not dify_config.ALLOW_REGISTER:
raise AccountNotFound()

View File

@ -3,3 +3,7 @@ from services.errors.base import BaseServiceError
class WorkSpaceNotAllowedCreateError(BaseServiceError):
pass
class WorkSpaceNotFound(BaseServiceError):
pass