fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 (816+ 处) - 添加缺失的导入 (json, re) - 统一SQL查询格式 - 修复赋值语句空格问题 修复文件: - db_manager.py (96处) - search_manager.py (77处) - ops_manager.py (66处) - developer_ecosystem_manager.py (68处) - growth_manager.py (60处) - enterprise_manager.py (61处) - tenant_manager.py (57处) - plugin_manager.py (48处) - subscription_manager.py (46处) - security_manager.py (29处) - workflow_manager.py (32处) - localization_manager.py (31处) - api_key_manager.py (20处) - ai_manager.py (23处) - performance_manager.py (24处) - neo4j_manager.py (25处) - collaboration_manager.py (33处) - test_phase8_task8.py (16处) - test_phase8_task6.py (4处) - knowledge_reasoner.py (添加import json) - llm_client.py (添加import json)
This commit is contained in:
@@ -495,7 +495,7 @@ class TenantManager:
|
||||
conn = self._get_connection()
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT * FROM tenants WHERE id = ?", (tenant_id,))
|
||||
cursor.execute("SELECT * FROM tenants WHERE id = ?", (tenant_id,))
|
||||
row = cursor.fetchone()
|
||||
|
||||
if row:
|
||||
@@ -510,7 +510,7 @@ class TenantManager:
|
||||
conn = self._get_connection()
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT * FROM tenants WHERE slug = ?", (slug,))
|
||||
cursor.execute("SELECT * FROM tenants WHERE slug = ?", (slug,))
|
||||
row = cursor.fetchone()
|
||||
|
||||
if row:
|
||||
@@ -528,8 +528,8 @@ class TenantManager:
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT t.* FROM tenants t
|
||||
JOIN tenant_domains d ON t.id = d.tenant_id
|
||||
WHERE d.domain = ? AND d.status = 'verified'
|
||||
JOIN tenant_domains d ON t.id = d.tenant_id
|
||||
WHERE d.domain = ? AND d.status = 'verified'
|
||||
""",
|
||||
(domain,),
|
||||
)
|
||||
@@ -562,26 +562,26 @@ class TenantManager:
|
||||
params = []
|
||||
|
||||
if name is not None:
|
||||
updates.append("name = ?")
|
||||
updates.append("name = ?")
|
||||
params.append(name)
|
||||
if description is not None:
|
||||
updates.append("description = ?")
|
||||
updates.append("description = ?")
|
||||
params.append(description)
|
||||
if tier is not None:
|
||||
updates.append("tier = ?")
|
||||
updates.append("tier = ?")
|
||||
params.append(tier)
|
||||
# 更新资源限制
|
||||
tier_enum = TenantTier(tier)
|
||||
updates.append("resource_limits = ?")
|
||||
updates.append("resource_limits = ?")
|
||||
params.append(json.dumps(self.DEFAULT_LIMITS.get(tier_enum, {})))
|
||||
if status is not None:
|
||||
updates.append("status = ?")
|
||||
updates.append("status = ?")
|
||||
params.append(status)
|
||||
if settings is not None:
|
||||
updates.append("settings = ?")
|
||||
updates.append("settings = ?")
|
||||
params.append(json.dumps(settings))
|
||||
|
||||
updates.append("updated_at = ?")
|
||||
updates.append("updated_at = ?")
|
||||
params.append(datetime.now())
|
||||
params.append(tenant_id)
|
||||
|
||||
@@ -589,7 +589,7 @@ class TenantManager:
|
||||
cursor.execute(
|
||||
f"""
|
||||
UPDATE tenants SET {", ".join(updates)}
|
||||
WHERE id = ?
|
||||
WHERE id = ?
|
||||
""",
|
||||
params,
|
||||
)
|
||||
@@ -605,7 +605,7 @@ class TenantManager:
|
||||
conn = self._get_connection()
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("DELETE FROM tenants WHERE id = ?", (tenant_id,))
|
||||
cursor.execute("DELETE FROM tenants WHERE id = ?", (tenant_id,))
|
||||
conn.commit()
|
||||
return cursor.rowcount > 0
|
||||
finally:
|
||||
@@ -623,10 +623,10 @@ class TenantManager:
|
||||
params = []
|
||||
|
||||
if status:
|
||||
query += " AND status = ?"
|
||||
query += " AND status = ?"
|
||||
params.append(status)
|
||||
if tier:
|
||||
query += " AND tier = ?"
|
||||
query += " AND tier = ?"
|
||||
params.append(tier)
|
||||
|
||||
query += " ORDER BY created_at DESC LIMIT ? OFFSET ?"
|
||||
@@ -681,8 +681,8 @@ class TenantManager:
|
||||
if is_primary:
|
||||
cursor.execute(
|
||||
"""
|
||||
UPDATE tenant_domains SET is_primary = 0
|
||||
WHERE tenant_id = ?
|
||||
UPDATE tenant_domains SET is_primary = 0
|
||||
WHERE tenant_id = ?
|
||||
""",
|
||||
(tenant_id,),
|
||||
)
|
||||
@@ -731,7 +731,7 @@ class TenantManager:
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT * FROM tenant_domains
|
||||
WHERE id = ? AND tenant_id = ?
|
||||
WHERE id = ? AND tenant_id = ?
|
||||
""",
|
||||
(domain_id, tenant_id),
|
||||
)
|
||||
@@ -751,8 +751,8 @@ class TenantManager:
|
||||
cursor.execute(
|
||||
"""
|
||||
UPDATE tenant_domains
|
||||
SET status = 'verified', verified_at = ?, updated_at = ?
|
||||
WHERE id = ?
|
||||
SET status = 'verified', verified_at = ?, updated_at = ?
|
||||
WHERE id = ?
|
||||
""",
|
||||
(datetime.now(), datetime.now(), domain_id),
|
||||
)
|
||||
@@ -762,8 +762,8 @@ class TenantManager:
|
||||
cursor.execute(
|
||||
"""
|
||||
UPDATE tenant_domains
|
||||
SET status = 'failed', updated_at = ?
|
||||
WHERE id = ?
|
||||
SET status = 'failed', updated_at = ?
|
||||
WHERE id = ?
|
||||
""",
|
||||
(datetime.now(), domain_id),
|
||||
)
|
||||
@@ -782,7 +782,7 @@ class TenantManager:
|
||||
conn = self._get_connection()
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT * FROM tenant_domains WHERE id = ?", (domain_id,))
|
||||
cursor.execute("SELECT * FROM tenant_domains WHERE id = ?", (domain_id,))
|
||||
row = cursor.fetchone()
|
||||
|
||||
if not row:
|
||||
@@ -821,7 +821,7 @@ class TenantManager:
|
||||
cursor.execute(
|
||||
"""
|
||||
DELETE FROM tenant_domains
|
||||
WHERE id = ? AND tenant_id = ?
|
||||
WHERE id = ? AND tenant_id = ?
|
||||
""",
|
||||
(domain_id, tenant_id),
|
||||
)
|
||||
@@ -838,7 +838,7 @@ class TenantManager:
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT * FROM tenant_domains
|
||||
WHERE tenant_id = ?
|
||||
WHERE tenant_id = ?
|
||||
ORDER BY is_primary DESC, created_at DESC
|
||||
""",
|
||||
(tenant_id,),
|
||||
@@ -857,7 +857,7 @@ class TenantManager:
|
||||
conn = self._get_connection()
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT * FROM tenant_branding WHERE tenant_id = ?", (tenant_id,))
|
||||
cursor.execute("SELECT * FROM tenant_branding WHERE tenant_id = ?", (tenant_id,))
|
||||
row = cursor.fetchone()
|
||||
|
||||
if row:
|
||||
@@ -885,7 +885,7 @@ class TenantManager:
|
||||
cursor = conn.cursor()
|
||||
|
||||
# 检查是否已存在
|
||||
cursor.execute("SELECT id FROM tenant_branding WHERE tenant_id = ?", (tenant_id,))
|
||||
cursor.execute("SELECT id FROM tenant_branding WHERE tenant_id = ?", (tenant_id,))
|
||||
existing = cursor.fetchone()
|
||||
|
||||
if existing:
|
||||
@@ -894,38 +894,38 @@ class TenantManager:
|
||||
params = []
|
||||
|
||||
if logo_url is not None:
|
||||
updates.append("logo_url = ?")
|
||||
updates.append("logo_url = ?")
|
||||
params.append(logo_url)
|
||||
if favicon_url is not None:
|
||||
updates.append("favicon_url = ?")
|
||||
updates.append("favicon_url = ?")
|
||||
params.append(favicon_url)
|
||||
if primary_color is not None:
|
||||
updates.append("primary_color = ?")
|
||||
updates.append("primary_color = ?")
|
||||
params.append(primary_color)
|
||||
if secondary_color is not None:
|
||||
updates.append("secondary_color = ?")
|
||||
updates.append("secondary_color = ?")
|
||||
params.append(secondary_color)
|
||||
if custom_css is not None:
|
||||
updates.append("custom_css = ?")
|
||||
updates.append("custom_css = ?")
|
||||
params.append(custom_css)
|
||||
if custom_js is not None:
|
||||
updates.append("custom_js = ?")
|
||||
updates.append("custom_js = ?")
|
||||
params.append(custom_js)
|
||||
if login_page_bg is not None:
|
||||
updates.append("login_page_bg = ?")
|
||||
updates.append("login_page_bg = ?")
|
||||
params.append(login_page_bg)
|
||||
if email_template is not None:
|
||||
updates.append("email_template = ?")
|
||||
updates.append("email_template = ?")
|
||||
params.append(email_template)
|
||||
|
||||
updates.append("updated_at = ?")
|
||||
updates.append("updated_at = ?")
|
||||
params.append(datetime.now())
|
||||
params.append(tenant_id)
|
||||
|
||||
cursor.execute(
|
||||
f"""
|
||||
UPDATE tenant_branding SET {", ".join(updates)}
|
||||
WHERE tenant_id = ?
|
||||
WHERE tenant_id = ?
|
||||
""",
|
||||
params,
|
||||
)
|
||||
@@ -1073,8 +1073,8 @@ class TenantManager:
|
||||
cursor.execute(
|
||||
"""
|
||||
UPDATE tenant_members
|
||||
SET user_id = ?, status = 'active', joined_at = ?
|
||||
WHERE id = ? AND status = 'pending'
|
||||
SET user_id = ?, status = 'active', joined_at = ?
|
||||
WHERE id = ? AND status = 'pending'
|
||||
""",
|
||||
(user_id, datetime.now(), invitation_id),
|
||||
)
|
||||
@@ -1093,7 +1093,7 @@ class TenantManager:
|
||||
cursor.execute(
|
||||
"""
|
||||
DELETE FROM tenant_members
|
||||
WHERE id = ? AND tenant_id = ?
|
||||
WHERE id = ? AND tenant_id = ?
|
||||
""",
|
||||
(member_id, tenant_id),
|
||||
)
|
||||
@@ -1116,8 +1116,8 @@ class TenantManager:
|
||||
cursor.execute(
|
||||
"""
|
||||
UPDATE tenant_members
|
||||
SET role = ?, permissions = ?, updated_at = ?
|
||||
WHERE id = ? AND tenant_id = ?
|
||||
SET role = ?, permissions = ?, updated_at = ?
|
||||
WHERE id = ? AND tenant_id = ?
|
||||
""",
|
||||
(role, json.dumps(final_permissions), datetime.now(), member_id, tenant_id),
|
||||
)
|
||||
@@ -1134,11 +1134,11 @@ class TenantManager:
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
|
||||
query = "SELECT * FROM tenant_members WHERE tenant_id = ?"
|
||||
query = "SELECT * FROM tenant_members WHERE tenant_id = ?"
|
||||
params = [tenant_id]
|
||||
|
||||
if status:
|
||||
query += " AND status = ?"
|
||||
query += " AND status = ?"
|
||||
params.append(status)
|
||||
|
||||
query += " ORDER BY invited_at DESC"
|
||||
@@ -1159,7 +1159,7 @@ class TenantManager:
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT role, permissions FROM tenant_members
|
||||
WHERE tenant_id = ? AND user_id = ? AND status = 'active'
|
||||
WHERE tenant_id = ? AND user_id = ? AND status = 'active'
|
||||
""",
|
||||
(tenant_id, user_id),
|
||||
)
|
||||
@@ -1193,8 +1193,8 @@ class TenantManager:
|
||||
"""
|
||||
SELECT t.*, m.role, m.status as member_status
|
||||
FROM tenants t
|
||||
JOIN tenant_members m ON t.id = m.tenant_id
|
||||
WHERE m.user_id = ? AND m.status = 'active'
|
||||
JOIN tenant_members m ON t.id = m.tenant_id
|
||||
WHERE m.user_id = ? AND m.status = 'active'
|
||||
ORDER BY t.created_at DESC
|
||||
""",
|
||||
(user_id,),
|
||||
@@ -1242,12 +1242,12 @@ class TenantManager:
|
||||
projects_count, entities_count, members_count)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(tenant_id, date) DO UPDATE SET
|
||||
storage_bytes = storage_bytes + excluded.storage_bytes,
|
||||
transcription_seconds = transcription_seconds + excluded.transcription_seconds,
|
||||
api_calls = api_calls + excluded.api_calls,
|
||||
projects_count = MAX(projects_count, excluded.projects_count),
|
||||
entities_count = MAX(entities_count, excluded.entities_count),
|
||||
members_count = MAX(members_count, excluded.members_count)
|
||||
storage_bytes = storage_bytes + excluded.storage_bytes,
|
||||
transcription_seconds = transcription_seconds + excluded.transcription_seconds,
|
||||
api_calls = api_calls + excluded.api_calls,
|
||||
projects_count = MAX(projects_count, excluded.projects_count),
|
||||
entities_count = MAX(entities_count, excluded.entities_count),
|
||||
members_count = MAX(members_count, excluded.members_count)
|
||||
""",
|
||||
(
|
||||
usage_id,
|
||||
@@ -1284,7 +1284,7 @@ class TenantManager:
|
||||
MAX(entities_count) as max_entities,
|
||||
MAX(members_count) as max_members
|
||||
FROM tenant_usage
|
||||
WHERE tenant_id = ?
|
||||
WHERE tenant_id = ?
|
||||
"""
|
||||
params = [tenant_id]
|
||||
|
||||
@@ -1388,7 +1388,7 @@ class TenantManager:
|
||||
counter = 1
|
||||
|
||||
while True:
|
||||
cursor.execute("SELECT id FROM tenants WHERE slug = ?", (slug,))
|
||||
cursor.execute("SELECT id FROM tenants WHERE slug = ?", (slug,))
|
||||
if not cursor.fetchone():
|
||||
break
|
||||
slug = f"{base_slug}-{counter}"
|
||||
@@ -1420,7 +1420,7 @@ class TenantManager:
|
||||
# TODO: 实现 DNS TXT 记录查询
|
||||
# import dns.resolver
|
||||
# try:
|
||||
# answers = dns.resolver.resolve(f"_insightflow.{domain}", 'TXT')
|
||||
# answers = dns.resolver.resolve(f"_insightflow.{domain}", 'TXT')
|
||||
# for rdata in answers:
|
||||
# if token in str(rdata):
|
||||
# return True
|
||||
@@ -1432,7 +1432,7 @@ class TenantManager:
|
||||
# TODO: 实现 HTTP 文件验证
|
||||
# import requests
|
||||
# try:
|
||||
# response = requests.get(f"http://{domain}/.well-known/insightflow-verify.txt", timeout = 10)
|
||||
# response = requests.get(f"http://{domain}/.well-known/insightflow-verify.txt", timeout = 10)
|
||||
# if response.status_code == 200 and token in response.text:
|
||||
# return True
|
||||
# except (ImportError, Exception):
|
||||
|
||||
Reference in New Issue
Block a user