Merge branch 'feat/new-login' into test/new-login-testing

* feat/new-login:
  feat: update control
  chore: update MAX_VARIABLE_SIZE
  chore: update MAX_VARIABLE_SIZE
This commit is contained in:
Joe 2024-10-17 18:23:14 +08:00
commit 1690a7cad8
6 changed files with 22 additions and 19 deletions

View File

@ -364,8 +364,8 @@ class WorkflowConfig(BaseSettings):
) )
MAX_VARIABLE_SIZE: PositiveInt = Field( MAX_VARIABLE_SIZE: PositiveInt = Field(
description="Maximum size in bytes for a single variable in workflows. Default to 200 KB.", description="Maximum size in bytes for a single variable in workflows. Default to 5KB.",
default=200 * 1024, default=5 * 1024,
) )

View File

@ -4,7 +4,6 @@ import secrets
from flask import request from flask import request
from flask_restful import Resource, reqparse from flask_restful import Resource, reqparse
from configs import dify_config
from constants.languages import languages from constants.languages import languages
from controllers.console import api from controllers.console import api
from controllers.console.auth.error import ( from controllers.console.auth.error import (
@ -22,6 +21,7 @@ from libs.password import hash_password, valid_password
from models.account import Account from models.account import Account
from services.account_service import AccountService, TenantService from services.account_service import AccountService, TenantService
from services.errors.workspace import WorkSpaceNotAllowedCreateError from services.errors.workspace import WorkSpaceNotAllowedCreateError
from services.feature_service import SystemFeatureModel
class ForgotPasswordSendEmailApi(Resource): class ForgotPasswordSendEmailApi(Resource):
@ -44,7 +44,7 @@ class ForgotPasswordSendEmailApi(Resource):
account = Account.query.filter_by(email=args["email"]).first() account = Account.query.filter_by(email=args["email"]).first()
token = None token = None
if account is None: if account is None:
if dify_config.ALLOW_REGISTER: if SystemFeatureModel.is_allow_register:
token = AccountService.send_reset_password_email(email=args["email"], language=language) token = AccountService.send_reset_password_email(email=args["email"], language=language)
else: else:
raise NotAllowedRegister() raise NotAllowedRegister()
@ -114,7 +114,7 @@ class ForgotPasswordResetApi(Resource):
db.session.commit() db.session.commit()
tenant = TenantService.get_join_tenants(account) tenant = TenantService.get_join_tenants(account)
if not tenant: if not tenant:
if not dify_config.ALLOW_CREATE_WORKSPACE: if not SystemFeatureModel.is_allow_create_workspace:
raise NotAllowedCreateWorkspace() raise NotAllowedCreateWorkspace()
else: else:
tenant = TenantService.create_tenant(f"{account.name}'s Workspace") tenant = TenantService.create_tenant(f"{account.name}'s Workspace")

View File

@ -28,6 +28,7 @@ from libs.password import valid_password
from models.account import Account from models.account import Account
from services.account_service import AccountService, RegisterService, TenantService from services.account_service import AccountService, RegisterService, TenantService
from services.errors.workspace import WorkSpaceNotAllowedCreateError from services.errors.workspace import WorkSpaceNotAllowedCreateError
from services.feature_service import SystemFeatureModel
class LoginApi(Resource): class LoginApi(Resource):
@ -72,7 +73,7 @@ class LoginApi(Resource):
AccountService.add_login_error_rate_limit(args["email"]) AccountService.add_login_error_rate_limit(args["email"])
raise EmailOrPasswordMismatchError() raise EmailOrPasswordMismatchError()
except services.errors.account.AccountNotFoundError: except services.errors.account.AccountNotFoundError:
if not dify_config.ALLOW_REGISTER: if not SystemFeatureModel.is_allow_register:
raise NotAllowedRegister() raise NotAllowedRegister()
token = AccountService.send_reset_password_email(email=args["email"], language=language) token = AccountService.send_reset_password_email(email=args["email"], language=language)
@ -116,7 +117,7 @@ class ResetPasswordSendEmailApi(Resource):
account = AccountService.get_user_through_email(args["email"]) account = AccountService.get_user_through_email(args["email"])
if account is None: if account is None:
if dify_config.ALLOW_REGISTER: if SystemFeatureModel.is_allow_register:
token = AccountService.send_reset_password_email(email=args["email"], language=language) token = AccountService.send_reset_password_email(email=args["email"], language=language)
else: else:
raise NotAllowedRegister() raise NotAllowedRegister()
@ -145,7 +146,7 @@ class EmailCodeLoginSendEmailApi(Resource):
account = AccountService.get_user_through_email(args["email"]) account = AccountService.get_user_through_email(args["email"])
if account is None: if account is None:
if dify_config.ALLOW_REGISTER: if SystemFeatureModel.is_allow_register:
token = AccountService.send_email_code_login_email(email=args["email"], language=language) token = AccountService.send_email_code_login_email(email=args["email"], language=language)
else: else:
raise NotAllowedRegister() raise NotAllowedRegister()
@ -181,7 +182,7 @@ class EmailCodeLoginApi(Resource):
if account: if account:
tenant = TenantService.get_join_tenants(account) tenant = TenantService.get_join_tenants(account)
if not tenant: if not tenant:
if not dify_config.ALLOW_CREATE_WORKSPACE: if not SystemFeatureModel.is_allow_create_workspace:
raise NotAllowedCreateWorkspace() raise NotAllowedCreateWorkspace()
else: else:
tenant = TenantService.create_tenant(f"{account.name}'s Workspace") tenant = TenantService.create_tenant(f"{account.name}'s Workspace")

View File

@ -17,6 +17,7 @@ from models.account import Account, AccountStatus
from services.account_service import AccountService, RegisterService, TenantService from services.account_service import AccountService, RegisterService, TenantService
from services.errors.account import AccountNotFoundError from services.errors.account import AccountNotFoundError
from services.errors.workspace import WorkSpaceNotAllowedCreateError, WorkSpaceNotFoundError from services.errors.workspace import WorkSpaceNotAllowedCreateError, WorkSpaceNotFoundError
from services.feature_service import SystemFeatureModel
from .. import api from .. import api
@ -145,7 +146,7 @@ def _generate_account(provider: str, user_info: OAuthUserInfo):
if account: if account:
tenant = TenantService.get_join_tenants(account) tenant = TenantService.get_join_tenants(account)
if not tenant: if not tenant:
if not dify_config.ALLOW_CREATE_WORKSPACE: if not SystemFeatureModel.is_allow_create_workspace:
raise WorkSpaceNotAllowedCreateError() raise WorkSpaceNotAllowedCreateError()
else: else:
tenant = TenantService.create_tenant(f"{account.name}'s Workspace") tenant = TenantService.create_tenant(f"{account.name}'s Workspace")
@ -154,7 +155,7 @@ def _generate_account(provider: str, user_info: OAuthUserInfo):
tenant_was_created.send(tenant) tenant_was_created.send(tenant)
if not account: if not account:
if not dify_config.ALLOW_REGISTER: if not SystemFeatureModel.is_allow_register:
raise AccountNotFoundError() raise AccountNotFoundError()
account_name = user_info.name or "Dify" account_name = user_info.name or "Dify"
account = RegisterService.register( account = RegisterService.register(

View File

@ -49,6 +49,7 @@ from services.errors.account import (
TenantNotFoundError, TenantNotFoundError,
) )
from services.errors.workspace import WorkSpaceNotAllowedCreateError from services.errors.workspace import WorkSpaceNotAllowedCreateError
from services.feature_service import SystemFeatureModel
from tasks.mail_email_code_login import send_email_code_login_mail_task from tasks.mail_email_code_login import send_email_code_login_mail_task
from tasks.mail_invite_member_task import send_invite_member_mail_task from tasks.mail_invite_member_task import send_invite_member_mail_task
from tasks.mail_reset_password_task import send_reset_password_mail_task from tasks.mail_reset_password_task import send_reset_password_mail_task
@ -196,7 +197,7 @@ class AccountService:
is_setup: Optional[bool] = False, is_setup: Optional[bool] = False,
) -> Account: ) -> Account:
"""create account""" """create account"""
if not dify_config.ALLOW_REGISTER and not is_setup: if not SystemFeatureModel.is_allow_register and not is_setup:
from controllers.console.error import NotAllowedRegister from controllers.console.error import NotAllowedRegister
raise NotAllowedRegister() raise NotAllowedRegister()
@ -487,7 +488,7 @@ class TenantService:
@staticmethod @staticmethod
def create_tenant(name: str, is_setup: Optional[bool] = False) -> Tenant: def create_tenant(name: str, is_setup: Optional[bool] = False) -> Tenant:
"""Create tenant""" """Create tenant"""
if not dify_config.ALLOW_CREATE_WORKSPACE and not is_setup: if not SystemFeatureModel.is_allow_create_workspace and not is_setup:
from controllers.console.error import NotAllowedCreateWorkspace from controllers.console.error import NotAllowedCreateWorkspace
raise NotAllowedCreateWorkspace() raise NotAllowedCreateWorkspace()
@ -505,7 +506,7 @@ class TenantService:
account: Account, name: Optional[str] = None, is_setup: Optional[bool] = False account: Account, name: Optional[str] = None, is_setup: Optional[bool] = False
): ):
"""Create owner tenant if not exist""" """Create owner tenant if not exist"""
if not dify_config.ALLOW_CREATE_WORKSPACE and not is_setup: if not SystemFeatureModel.is_allow_create_workspace and not is_setup:
raise WorkSpaceNotAllowedCreateError() raise WorkSpaceNotAllowedCreateError()
available_ta = ( available_ta = (
TenantAccountJoin.query.filter_by(account_id=account.id).order_by(TenantAccountJoin.id.asc()).first() TenantAccountJoin.query.filter_by(account_id=account.id).order_by(TenantAccountJoin.id.asc()).first()
@ -803,7 +804,7 @@ class RegisterService:
if open_id is not None or provider is not None: if open_id is not None or provider is not None:
AccountService.link_account_integrate(provider, open_id, account) AccountService.link_account_integrate(provider, open_id, account)
if dify_config.ALLOW_CREATE_WORKSPACE: if SystemFeatureModel.is_allow_create_workspace:
tenant = TenantService.create_tenant(f"{account.name}'s Workspace") tenant = TenantService.create_tenant(f"{account.name}'s Workspace")
TenantService.create_tenant_member(tenant, account, role="owner") TenantService.create_tenant_member(tenant, account, role="owner")
account.current_tenant = tenant account.current_tenant = tenant
@ -952,4 +953,4 @@ class RegisterService:
def _generate_refresh_token(length: int = 64): def _generate_refresh_token(length: int = 64):
token = secrets.token_hex(length) token = secrets.token_hex(length)
return token return token

View File

@ -45,8 +45,8 @@ class SystemFeatureModel(BaseModel):
enable_email_code_login: bool = False enable_email_code_login: bool = False
enable_email_password_login: bool = True enable_email_password_login: bool = True
enable_social_oauth_login: bool = False enable_social_oauth_login: bool = False
is_allow_register: bool = True is_allow_register: bool = False
is_allow_create_workspace: bool = True is_allow_create_workspace: bool = False
class FeatureService: class FeatureService:
@ -74,7 +74,7 @@ class FeatureService:
return system_features return system_features
@classmethod @classmethod
def __fulfill_login_params_from_env(cls, features: FeatureModel): def _fulfill_login_params_from_env(cls, features: FeatureModel):
features.enable_email_code_login = dify_config.ENABLE_EMAIL_CODE_LOGIN features.enable_email_code_login = dify_config.ENABLE_EMAIL_CODE_LOGIN
features.enable_email_password_login = dify_config.ENABLE_EMAIL_PASSWORD_LOGIN features.enable_email_password_login = dify_config.ENABLE_EMAIL_PASSWORD_LOGIN
features.enable_social_oauth_login = dify_config.ENABLE_SOCIAL_OAUTH_LOGIN features.enable_social_oauth_login = dify_config.ENABLE_SOCIAL_OAUTH_LOGIN