fix(session): 项目上下文 per-session 隔离——切换项目写 pipeline_session_settings,读项目优先 per-session,前端请求带 session_id
This commit is contained in:
parent
32a8377a4c
commit
107990bb0a
@ -7,21 +7,17 @@ action = (params_kw or {}).get('action', 'agent_status')
|
||||
dbname = get_module_dbname('pipeline-sdlc')
|
||||
uid = await get_user()
|
||||
org_id = await get_userorgid() or '0'
|
||||
session_id = (params_kw or {}).get('session_id', '')
|
||||
|
||||
|
||||
async def _get_context(sor, uid):
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT current_project_id, current_iteration_id FROM pipeline_agent_settings WHERE user_id=${uid}$",
|
||||
{"uid": uid})
|
||||
if recs:
|
||||
return {'project_id': getattr(recs[0], 'current_project_id', '') or '',
|
||||
'iteration_id': getattr(recs[0], 'current_iteration_id', '') or ''}
|
||||
return {'project_id': '', 'iteration_id': ''}
|
||||
async def _get_context(sor, uid, session_id=''):
|
||||
pid, iid = await get_session_context(sor, uid, session_id)
|
||||
return {'project_id': pid, 'iteration_id': iid}
|
||||
|
||||
|
||||
if action == 'start_agent':
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
ctx = await _get_context(sor, uid)
|
||||
ctx = await _get_context(sor, uid, session_id)
|
||||
pid = ctx['project_id']
|
||||
if not pid:
|
||||
return json.dumps({"success": False, "error": "请先选择项目"}, ensure_ascii=False)
|
||||
@ -53,7 +49,7 @@ if action == 'start_agent':
|
||||
|
||||
elif action == 'agent_status':
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
ctx = await _get_context(sor, uid)
|
||||
ctx = await _get_context(sor, uid, session_id)
|
||||
pid = ctx['project_id']
|
||||
|
||||
agents = []
|
||||
@ -81,7 +77,7 @@ elif action == 'agent_status':
|
||||
|
||||
elif action == 'list_deliverables':
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
ctx = await _get_context(sor, uid)
|
||||
ctx = await _get_context(sor, uid, session_id)
|
||||
pid = ctx['project_id']
|
||||
if not pid:
|
||||
return json.dumps([], ensure_ascii=False)
|
||||
|
||||
@ -84,13 +84,10 @@ if action == 'send_message':
|
||||
uid = 'user-01' # 测试兼容
|
||||
|
||||
# ── 加载上下文 ──
|
||||
session_id = (params_kw or {}).get('session_id', '')
|
||||
ctx = {'pid': '', 'name': '', 'pipeline_id': ''}
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${u}$",
|
||||
{"u": uid})
|
||||
if recs:
|
||||
ctx['pid'] = getattr(recs[0], 'current_project_id', '') or ''
|
||||
ctx['pid'], _ = await get_session_context(sor, uid, session_id)
|
||||
if ctx['pid']:
|
||||
proj_recs = await sor.sqlExe(
|
||||
"SELECT name, pipeline_id FROM sd_projects WHERE id=${p}$", {"p": ctx['pid']})
|
||||
|
||||
@ -2,16 +2,10 @@
|
||||
|
||||
import json
|
||||
uid = await get_user()
|
||||
session_id = (params_kw or {}).get('session_id', '')
|
||||
dbname = get_module_dbname('pipeline-sdlc')
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT current_project_id, current_iteration_id FROM pipeline_agent_settings WHERE user_id=${uid}$",
|
||||
{"uid": uid})
|
||||
pid = ''
|
||||
iid = ''
|
||||
if recs and len(recs) > 0:
|
||||
pid = getattr(recs[0], 'current_project_id', '') or ''
|
||||
iid = getattr(recs[0], 'current_iteration_id', '') or ''
|
||||
pid, iid = await get_session_context(sor, uid, session_id)
|
||||
|
||||
# 拿到项目名和迭代名
|
||||
pname = ''
|
||||
|
||||
@ -10,6 +10,7 @@ if not uid:
|
||||
|
||||
pid = (params_kw or {}).get('project_id', '')
|
||||
iid = (params_kw or {}).get('iteration_id', '')
|
||||
session_id = (params_kw or {}).get('session_id', '')
|
||||
|
||||
if not pid and not iid:
|
||||
return json.dumps({"success": False, "error": "请提供 project_id 或 iteration_id"}, ensure_ascii=False)
|
||||
@ -45,6 +46,24 @@ async with DBPools().sqlorContext(dbname) as sor:
|
||||
'current_iteration_id': new_iid,
|
||||
})
|
||||
|
||||
# 会话级项目上下文(多 tab 隔离):写 pipeline_session_settings
|
||||
if session_id:
|
||||
try:
|
||||
await sor.sqlExe(
|
||||
"UPDATE pipeline_session_settings SET current_project_id=${pid}$, current_iteration_id=${iid}$ "
|
||||
"WHERE user_id=${uid}$ AND session_id=${sid}$",
|
||||
{"pid": new_pid, "iid": new_iid, "uid": uid, "sid": session_id})
|
||||
sexists = await sor.sqlExe(
|
||||
"SELECT 1 FROM pipeline_session_settings WHERE user_id=${uid}$ AND session_id=${sid}$",
|
||||
{"uid": uid, "sid": session_id})
|
||||
if not sexists:
|
||||
await sor.C('pipeline_session_settings', {
|
||||
'id': getID(), 'user_id': uid, 'session_id': session_id,
|
||||
'current_project_id': new_pid, 'current_iteration_id': new_iid,
|
||||
})
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Look up names
|
||||
pname = ''
|
||||
iname = ''
|
||||
|
||||
@ -10,11 +10,10 @@ if not uid:
|
||||
dbname = get_module_dbname('pipeline-sdlc')
|
||||
|
||||
# Get current project and tasks in one session
|
||||
session_id = (params_kw or {}).get('session_id', '')
|
||||
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${uid}$",
|
||||
{"uid": uid})
|
||||
pid = getattr(recs[0], 'current_project_id', '') if recs else ''
|
||||
pid, _ = await get_session_context(sor, uid, session_id)
|
||||
|
||||
if not pid:
|
||||
return json.dumps({"tasks": [], "error": "没有当前项目"}, ensure_ascii=False)
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user