mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 00:57:04 +08:00
feat: add setup only
This commit is contained in:
parent
067955c2b1
commit
7e4d105e8b
@ -146,10 +146,15 @@ class AccountService:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_account(
|
def create_account(
|
||||||
email: str, name: str, interface_language: str, password: Optional[str] = None, interface_theme: str = "light"
|
email: str,
|
||||||
|
name: str,
|
||||||
|
interface_language: str,
|
||||||
|
password: Optional[str] = None,
|
||||||
|
interface_theme: str = "light",
|
||||||
|
is_setup: Optional[bool] = False,
|
||||||
) -> Account:
|
) -> Account:
|
||||||
"""create account"""
|
"""create account"""
|
||||||
if not dify_config.ALLOW_REGISTER:
|
if not dify_config.ALLOW_REGISTER and not is_setup:
|
||||||
from controllers.console.error import NotAllowedRegister
|
from controllers.console.error import NotAllowedRegister
|
||||||
|
|
||||||
raise NotAllowedRegister()
|
raise NotAllowedRegister()
|
||||||
@ -371,9 +376,9 @@ def _get_login_cache_key(*, account_id: str, token: str):
|
|||||||
|
|
||||||
class TenantService:
|
class TenantService:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_tenant(name: str) -> Tenant:
|
def create_tenant(name: str, is_setup: Optional[bool] = False) -> Tenant:
|
||||||
"""Create tenant"""
|
"""Create tenant"""
|
||||||
if not dify_config.ALLOW_CREATE_WORKSPACE:
|
if not dify_config.ALLOW_CREATE_WORKSPACE and not is_setup:
|
||||||
from controllers.console.error import NotAllowedCreateWorkspace
|
from controllers.console.error import NotAllowedCreateWorkspace
|
||||||
|
|
||||||
raise NotAllowedCreateWorkspace()
|
raise NotAllowedCreateWorkspace()
|
||||||
@ -387,9 +392,11 @@ class TenantService:
|
|||||||
return tenant
|
return tenant
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_owner_tenant_if_not_exist(account: Account, name: Optional[str] = None):
|
def create_owner_tenant_if_not_exist(
|
||||||
|
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:
|
if not dify_config.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()
|
||||||
@ -399,9 +406,9 @@ class TenantService:
|
|||||||
return
|
return
|
||||||
|
|
||||||
if name:
|
if name:
|
||||||
tenant = TenantService.create_tenant(name)
|
tenant = TenantService.create_tenant(name=name, is_setup=is_setup)
|
||||||
else:
|
else:
|
||||||
tenant = TenantService.create_tenant(f"{account.name}'s Workspace")
|
tenant = TenantService.create_tenant(name=f"{account.name}'s Workspace", is_setup=is_setup)
|
||||||
TenantService.create_tenant_member(tenant, account, role="owner")
|
TenantService.create_tenant_member(tenant, account, role="owner")
|
||||||
account.current_tenant = tenant
|
account.current_tenant = tenant
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
@ -633,12 +640,13 @@ class RegisterService:
|
|||||||
name=name,
|
name=name,
|
||||||
interface_language=languages[0],
|
interface_language=languages[0],
|
||||||
password=password,
|
password=password,
|
||||||
|
is_setup=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
account.last_login_ip = ip_address
|
account.last_login_ip = ip_address
|
||||||
account.initialized_at = datetime.now(timezone.utc).replace(tzinfo=None)
|
account.initialized_at = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||||
|
|
||||||
TenantService.create_owner_tenant_if_not_exist(account)
|
TenantService.create_owner_tenant_if_not_exist(account=account, is_setup=True)
|
||||||
|
|
||||||
dify_setup = DifySetup(version=dify_config.CURRENT_VERSION)
|
dify_setup = DifySetup(version=dify_config.CURRENT_VERSION)
|
||||||
db.session.add(dify_setup)
|
db.session.add(dify_setup)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user