mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-13 22:15:10 +00:00
Let people name accounts and use the names to tell accounts apart
Connections get an account_name (migration 0039) that the owner sets with PATCH /api/connections/<id>; the account label stays the account's identity, so signing in again still finds it. When someone has more than one account of a service, its tools are listed as "Telegram · <account>" and the model sees each account's actions under the account's name (telegram_send_message_alerts_bot) with the account in the description, instead of _1 and _2. Actions shared by different services are named after the service. Tools a user renamed keep their name.
This commit is contained in:
1 parent
607c2296e3
commit
bdcb88866a
11 files changed
+371
-7
No files matched your search
@@ -161,6 +161,21 @@ class ConnectionDetail(Resource):
|
||||
return make_response(jsonify({"success": False, "error": "Failed to load connection"}), 500)
|
||||
return make_response(jsonify({"success": True, "connection": detail}), 200)
|
||||
|
||||
@api.doc(description="Name an account: {name}. An empty name clears it. Owner only.")
|
||||
def patch(self, connection_id: str):
|
||||
user_id = _user_id()
|
||||
if not user_id:
|
||||
return _unauthorized()
|
||||
name = _json_body().get("name")
|
||||
if not isinstance(name, str) or len(name.strip()) > service.ACCOUNT_NAME_MAX:
|
||||
return _error(f"name must be text of at most {service.ACCOUNT_NAME_MAX} characters", 400)
|
||||
with db_session() as conn:
|
||||
row = _owned(conn, connection_id, user_id)
|
||||
if row is None:
|
||||
return _not_found()
|
||||
connection = service.rename_connection(conn, row, name)
|
||||
return make_response(jsonify({"success": True, "connection": connection}), 200)
|
||||
|
||||
@api.doc(
|
||||
description=(
|
||||
"Remove a connection: {sources: keep | delete, tools: delete | keep}. "
|
||||
|
||||
@@ -23,6 +23,7 @@ from docsgpt.api.pat.rules import filter_listing
|
||||
from docsgpt.api.user.artifacts.authz import Principal, authorize_artifact
|
||||
from docsgpt.api.user.team_sharing import effective_write_owner, visible_with_access
|
||||
from docsgpt.connectors.catalog import definition_for_tool
|
||||
from docsgpt.connectors.service import account_tool_names
|
||||
from docsgpt.core.settings import settings
|
||||
from docsgpt.core.url_validation import SSRFError, validate_url
|
||||
from docsgpt.security.encryption import CredentialDecryptionError, decrypt_credentials, encrypt_credentials
|
||||
@@ -290,6 +291,8 @@ class GetTools(Resource):
|
||||
team_shared = visible_with_access(conn, user, "tool")
|
||||
shared_ids = [tid for tid in team_shared if tid not in owned_ids]
|
||||
shared_rows = tools_repo.list_by_ids(shared_ids)
|
||||
# "Telegram · Alerts bot" when the owner has several bots.
|
||||
account_names = account_tool_names(conn, [*rows, *shared_rows])
|
||||
user_tools = []
|
||||
|
||||
def _shape_tool(row, *, ownership="user", force_strip_secret=False):
|
||||
@@ -313,6 +316,8 @@ class GetTools(Resource):
|
||||
# ask for it again.
|
||||
tool_copy.setdefault("config", {})["has_encrypted_credentials"] = True
|
||||
tool_copy["ownership"] = ownership
|
||||
if str(row["id"]) in account_names:
|
||||
tool_copy["customName"] = tool_copy["displayName"] = account_names[str(row["id"])]
|
||||
return tool_copy
|
||||
|
||||
for row in rows:
|
||||
|
||||
Reference in new issue
Block a user