Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
feat: add create tenant command (#4974)
takatost3579fd1b0945
diff --git a/api/commands.py b/api/commands.pyindex 86cc9e204f5..186b97c3fa6 100644--- a/api/commands.py+++ b/api/commands.py@@ -1,11 +1,13 @@import base64import jsonimport secrets+from typing import Optionalimport clickfrom flask import current_appfrom werkzeug.exceptions import NotFound+from constants.languages import languagesfrom core.rag.datasource.vdb.vector_factory import Vectorfrom core.rag.models.document import Documentfrom extensions.ext_database import db@@ -17,6 +19,7 @@ from models.dataset import Dataset, DatasetCollectionBinding, DocumentSegmentfrom models.dataset import Document as DatasetDocumentfrom models.model import Account, App, AppAnnotationSetting, AppMode, Conversation, MessageAnnotationfrom models.provider import Provider, ProviderModel+from services.account_service import RegisterService, TenantService@click.command('reset-password', help='Reset the account password.')@@ -57,7 +60,7 @@ def reset_password(email, new_password, password_confirm):account.password = base64_password_hashedaccount.password_salt = base64_saltdb.session.commit()- click.echo(click.style('Congratulations!, password has been reset.', fg='green'))+ click.echo(click.style('Congratulations! Password has been reset.', fg='green'))@click.command('reset-email', help='Reset the account email.')@@ -501,6 +504,46 @@ def add_qdrant_doc_id_index(field: str):fg='green'))[email protected]('create-tenant', help='Create account and tenant.')[email protected]('--email', prompt=True, help='The email address of the tenant account.')[email protected]('--language', prompt=True, help='Account language, default: en-US.')+def create_tenant(email: str, language: Optional[str] = None):+ """+ Create tenant account+ """+ if not email:+ click.echo(click.style('Sorry, email is required.', fg='red'))+ return++ # Create account+ email = email.strip()++ if '@' not in email:+ click.echo(click.style('Sorry, invalid email address.', fg='red'))+ return++ account_name = email.split('@')[0]++ if language not in languages:+ language = 'en-US'++ # generate random password+ new_password = secrets.token_urlsafe(16)++ # register account+ account = RegisterService.register(+ email=email,+ name=account_name,+ password=new_password,+ language=language+ )++ TenantService.create_owner_tenant_if_not_exist(account)++ click.echo(click.style('Congratulations! Account and tenant created.\n'+ 'Account: {}\nPassword: {}'.format(email, new_password), fg='green'))++def register_commands(app):app.cli.add_command(reset_password)app.cli.add_command(reset_email)@@ -508,4 +551,5 @@ def register_commands(app):app.cli.add_command(vdb_migrate)app.cli.add_command(convert_to_agent_apps)app.cli.add_command(add_qdrant_doc_id_index)+ app.cli.add_command(create_tenant)diff --git a/api/pyproject.toml b/api/pyproject.tomlindex f65795b4f65..a8920139c64 100644--- a/api/pyproject.toml+++ b/api/pyproject.toml@@ -7,7 +7,6 @@ exclude = [line-length = 120[tool.ruff.lint]-ignore-init-module-imports = trueselect = ["B", # flake8-bugbear rules"F", # pyflakes rules@@ -38,6 +37,7 @@ ignore = ["B006", # mutable-argument-default"B007", # unused-loop-control-variable"B026", # star-arg-unpacking-after-keyword-arg+ "B901", # return-in-generator"B904", # raise-without-from-inside-except"B905", # zip-without-explicit-strict]