feat(kbshare): enhance sharing functionality with soft-delete handling and shared access

- Updated ListByOrganization and ListSharedKBsForUser methods to exclude soft-deleted knowledge bases and organizations, improving data integrity.
- Modified knowledge fetching methods to include documents from shared knowledge bases the user has access to, enhancing user experience.
- Improved comments for clarity on functionality and permission checks in UpdateSharePermission method.

This update strengthens the sharing capabilities and ensures users only see relevant knowledge bases, enhancing overall application usability.
This commit is contained in:
wizardchen
2026-02-02 17:28:48 +08:00
committed by lyingbug
parent 342e56735f
commit b3d743a0a9
5 changed files with 24 additions and 14 deletions
+7 -3
View File
@@ -119,7 +119,8 @@ func (s *kbShareService) ShareKnowledgeBase(ctx context.Context, kbID string, or
return share, nil
}
// UpdateSharePermission updates the permission of a share
// UpdateSharePermission updates the permission of a share.
// Allowed if: (1) current user is the sharer, or (2) current user is admin of the target organization.
func (s *kbShareService) UpdateSharePermission(ctx context.Context, shareID string, permission types.OrgMemberRole, userID string) error {
share, err := s.shareRepo.GetByID(ctx, shareID)
if err != nil {
@@ -129,9 +130,12 @@ func (s *kbShareService) UpdateSharePermission(ctx context.Context, shareID stri
return err
}
// Only the user who shared can update
// Sharer can always update; org admin can also update (e.g. when sharer left)
if share.SharedByUserID != userID {
return ErrSharePermissionDenied
member, err := s.orgRepo.GetMember(ctx, share.OrganizationID, userID)
if err != nil || member.Role != types.OrgRoleAdmin {
return ErrSharePermissionDenied
}
}
if !permission.IsValid() {