From 2e540654f124af37e64910d97594ca7bad0da2e4 Mon Sep 17 00:00:00 2001 From: "wangke.2002" Date: Wed, 22 Jul 2026 11:24:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8DIM=E9=97=AE=E7=AD=94?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=AF=BB=E5=8F=96session=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/application/service/session.go | 4 ++- .../service/session_user_scope_test.go | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/internal/application/service/session.go b/internal/application/service/session.go index ea9bd303..c38c7b01 100644 --- a/internal/application/service/session.go +++ b/internal/application/service/session.go @@ -34,11 +34,13 @@ func loadSessionForRead( ownerID, sessionID string, ) (*types.Session, error) { isAdmin := types.TenantRoleFromContext(ctx).HasPermission(types.TenantRoleAdmin) + principal, hasPrincipal := types.PrincipalFromContext(ctx) + isIMRuntime := hasPrincipal && principal.Type == types.PrincipalIMUser session, err := repo.Get(ctx, tenantID, ownerID, sessionID) if err == nil { imPlatform, _ := repo.GetIMPlatform(ctx, tenantID, sessionID) - if types.SessionRequiresAdminConsoleRead(session, imPlatform) && !isAdmin { + if types.SessionRequiresAdminConsoleRead(session, imPlatform) && !isAdmin && !isIMRuntime { return nil, apperrors.ErrSessionNotFound } if imPlatform != "" { diff --git a/internal/application/service/session_user_scope_test.go b/internal/application/service/session_user_scope_test.go index 343e3efa..0f93203d 100644 --- a/internal/application/service/session_user_scope_test.go +++ b/internal/application/service/session_user_scope_test.go @@ -292,6 +292,33 @@ func TestGetSessionDeniesViewerOnIMSession(t *testing.T) { require.Equal(t, "feishu", got.IMPlatform) } +func TestGetSessionAllowsIMRuntimeToReadIMSession(t *testing.T) { + svc, db := newTestSessionService(t) + require.NoError(t, db.AutoMigrate(&testListSessionsIMChannelSession{})) + + imSession := &types.Session{TenantID: 1, Title: "feishu chat"} + require.NoError(t, db.Create(imSession).Error) + require.NoError(t, db.Create(&testListSessionsIMChannelSession{ + SessionID: imSession.ID, + Platform: "feishu", + }).Error) + + ctx := context.WithValue( + testSessionScopeContext(1, "system-1"), + types.TenantRoleContextKey, + types.TenantRoleViewer, + ) + ctx = types.WithPrincipal(ctx, types.Principal{ + Type: types.PrincipalIMUser, + ID: "1:channel-1:feishu:open-id-1", + }) + + got, err := svc.GetSession(ctx, imSession.ID) + require.NoError(t, err) + require.Equal(t, imSession.ID, got.ID) + require.Equal(t, "feishu", got.IMPlatform) +} + // testListSessionsIMChannelSession lets QueryPaged's LEFT JOIN resolve against a // real table in the in-memory SQLite database. type testListSessionsIMChannelSession struct {