feat: remove extra judgement

This commit is contained in:
Joe 2024-09-02 16:03:44 +08:00
parent 0da352ae84
commit f3429953f3
2 changed files with 7 additions and 6 deletions

View File

@ -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))

View File

@ -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()
)