Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
feat(kbshare): enhance knowledge base share listing with tenant ownership
wizardchen4f44c12c4196
diff --git a/internal/application/service/kbshare.go b/internal/application/service/kbshare.goindex 589333b14..68aa4e0f4 100644--- a/internal/application/service/kbshare.go+++ b/internal/application/service/kbshare.go@@ -174,8 +174,15 @@ func (s *kbShareService) RemoveShare(ctx context.Context, shareID string, userIDreturn ErrSharePermissionDenied}-// ListSharesByKnowledgeBase lists all shares for a knowledge base-func (s *kbShareService) ListSharesByKnowledgeBase(ctx context.Context, kbID string) ([]*types.KnowledgeBaseShare, error) {+// ListSharesByKnowledgeBase lists shares for a knowledge base; caller's tenant must own the KB.+func (s *kbShareService) ListSharesByKnowledgeBase(ctx context.Context, kbID string, tenantID uint64) ([]*types.KnowledgeBaseShare, error) {+ kb, err := s.kbRepo.GetKnowledgeBaseByID(ctx, kbID)+ if err != nil {+ return nil, ErrKBNotFound+ }+ if kb.TenantID != tenantID {+ return nil, ErrNotKBOwner+ }return s.shareRepo.ListByKnowledgeBase(ctx, kbID)}diff --git a/internal/handler/organization.go b/internal/handler/organization.goindex 7ecbcd763..d71f69689 100644--- a/internal/handler/organization.go+++ b/internal/handler/organization.go@@ -909,9 +909,22 @@ func (h *OrganizationHandler) ListKBShares(c *gin.Context) {ctx := c.Request.Context()kbID := c.Param("id")+ tenantID, _ := c.Get(types.TenantIDContextKey.String())+ if tenantID == nil {+ c.Error(apperrors.NewUnauthorizedError("Unauthorized"))+ return+ }- shares, err := h.shareService.ListSharesByKnowledgeBase(ctx, kbID)+ shares, err := h.shareService.ListSharesByKnowledgeBase(ctx, kbID, tenantID.(uint64))if err != nil {+ if errors.Is(err, service.ErrKBNotFound) {+ c.Error(apperrors.NewNotFoundError("Knowledge base not found"))+ return+ }+ if errors.Is(err, service.ErrNotKBOwner) {+ c.Error(apperrors.NewForbiddenError("Only the knowledge base owner can list its shares"))+ return+ }logger.Errorf(ctx, "Failed to list shares: %v", err)c.Error(apperrors.NewInternalServerError("Failed to list shares"))returndiff --git a/internal/types/interfaces/organization.go b/internal/types/interfaces/organization.goindex 0df2731d1..822ae4d2b 100644--- a/internal/types/interfaces/organization.go+++ b/internal/types/interfaces/organization.go@@ -86,7 +86,8 @@ type KBShareService interface {RemoveShare(ctx context.Context, shareID string, userID string) error// Query- ListSharesByKnowledgeBase(ctx context.Context, kbID string) ([]*types.KnowledgeBaseShare, error)+ // ListSharesByKnowledgeBase lists shares for a KB; tenantID must own the KB (authz check).+ ListSharesByKnowledgeBase(ctx context.Context, kbID string, tenantID uint64) ([]*types.KnowledgeBaseShare, error)ListSharesByOrganization(ctx context.Context, orgID string) ([]*types.KnowledgeBaseShare, error)ListSharedKnowledgeBases(ctx context.Context, userID string, currentTenantID uint64) ([]*types.SharedKnowledgeBaseInfo, error)GetShare(ctx context.Context, shareID string) (*types.KnowledgeBaseShare, error)