From f3429953f38031e2243b8305b5f3597a26dabe73 Mon Sep 17 00:00:00 2001 From: Joe <1264204425@qq.com> Date: Mon, 2 Sep 2024 16:03:44 +0800 Subject: [PATCH] feat: remove extra judgement --- api/controllers/console/auth/oauth.py | 10 +++++++--- api/services/account_service.py | 3 --- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/api/controllers/console/auth/oauth.py b/api/controllers/console/auth/oauth.py index fe64b322d0..10308943fd 100644 --- a/api/controllers/console/auth/oauth.py +++ b/api/controllers/console/auth/oauth.py @@ -5,8 +5,8 @@ from typing import Optional import requests from flask import current_app, redirect, request from flask_restful import Resource +from werkzeug.exceptions import Unauthorized -import services from configs import dify_config from constants.languages import languages from extensions.ext_database import db @@ -81,8 +81,9 @@ class OAuthCallback(Resource): try: account = _generate_account(provider, user_info) - except services.errors.account.AccountNotFound as e: + except Unauthorized: return redirect(f"{dify_config.CONSOLE_WEB_URL}/signin?message=AccountNotFound") + # Check account status if account.status == AccountStatus.BANNED.value or account.status == AccountStatus.CLOSED.value: return {"error": "Account is banned or closed."}, 403 @@ -92,7 +93,10 @@ class OAuthCallback(Resource): account.initialized_at = datetime.now(timezone.utc).replace(tzinfo=None) db.session.commit() - TenantService.create_owner_tenant_if_not_exist(account) + try: + TenantService.create_owner_tenant_if_not_exist(account) + except Unauthorized: + return redirect(f"{dify_config.CONSOLE_WEB_URL}/signin?message=WorkspaceNotFound") token = AccountService.login(account, ip_address=get_remote_ip(request)) diff --git a/api/services/account_service.py b/api/services/account_service.py index ca80f057ba..2abc2d33a5 100644 --- a/api/services/account_service.py +++ b/api/services/account_service.py @@ -329,9 +329,6 @@ class TenantService: @staticmethod def create_owner_tenant_if_not_exist(account: Account): """Create owner tenant if not exist""" - if not dify_config.ALLOW_CREATE_WORKSPACE: - raise Unauthorized("Create workspace is not allowed.") - available_ta = ( TenantAccountJoin.query.filter_by(account_id=account.id).order_by(TenantAccountJoin.id.asc()).first() )