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
fix(org): searchable join bypasses invite code expiry
Andy Yang6e6d61d9452b
diff --git a/internal/application/service/organization.go b/internal/application/service/organization.goindex 71c1270b7..386a0938a 100644--- a/internal/application/service/organization.go+++ b/internal/application/service/organization.go@@ -300,11 +300,11 @@ func (s *organizationService) JoinByOrganizationID(ctx context.Context, orgID st}return org, nil}- // Direct join using invite code flow logic (add member)- _, err = s.JoinByInviteCode(ctx, org.InviteCode, userID, tenantID)- if err != nil {+ // Searchable direct join: do not validate invite code or expiry (product copy: no invite code required).+ if err := s.joinAsViewerWithChecks(ctx, org, userID, tenantID); err != nil {return nil, err}+ logger.Infof(ctx, "User %s joined organization %s via searchable join", userID, org.ID)return org, nil}@@ -470,47 +470,26 @@ func (s *organizationService) GenerateInviteCode(ctx context.Context, orgID strireturn inviteCode, nil}-// JoinByInviteCode allows a user to join an organization via invite code-func (s *organizationService) JoinByInviteCode(ctx context.Context, inviteCode string, userID string, tenantID uint64) (*types.Organization, error) {- org, err := s.orgRepo.GetByInviteCode(ctx, inviteCode)- if err != nil {- if errors.Is(err, repository.ErrInviteCodeNotFound) {- return nil, ErrOrgNotFound- }- if errors.Is(err, repository.ErrInviteCodeExpired) {- return nil, ErrInviteCodeExpired- }- return nil, err- }-- // check if the organization need approval- if org.RequireApproval {- logger.Infof(ctx, "Organization %s requires approval", org.ID)- return nil, ErrOrgPermissionDenied- }-- // Check if user is already a member- _, err = s.orgRepo.GetMember(ctx, org.ID, userID)+// joinAsViewerWithChecks adds the user as viewer when not already a member (enforces member limit).+func (s *organizationService) joinAsViewerWithChecks(ctx context.Context, org *types.Organization, userID string, tenantID uint64) error {+ _, err := s.orgRepo.GetMember(ctx, org.ID, userID)if err == nil {- // User is already a member, just return the organization- return org, nil+ return nil}if !errors.Is(err, repository.ErrOrgMemberNotFound) {- return nil, err+ return err}- // Check member limit (0 = unlimited)if org.MemberLimit > 0 {count, errCount := s.orgRepo.CountMembers(ctx, org.ID)if errCount != nil {- return nil, errCount+ return errCount}if count >= int64(org.MemberLimit) {- return nil, ErrOrgMemberLimitReached+ return ErrOrgMemberLimitReached}}- // Add user as viewer by defaultmember := &types.OrganizationMember{ID: uuid.New().String(),OrganizationID: org.ID,@@ -521,7 +500,29 @@ func (s *organizationService) JoinByInviteCode(ctx context.Context, inviteCode sUpdatedAt: time.Now(),}- if err := s.orgRepo.AddMember(ctx, member); err != nil {+ return s.orgRepo.AddMember(ctx, member)+}++// JoinByInviteCode allows a user to join an organization via invite code+func (s *organizationService) JoinByInviteCode(ctx context.Context, inviteCode string, userID string, tenantID uint64) (*types.Organization, error) {+ org, err := s.orgRepo.GetByInviteCode(ctx, inviteCode)+ if err != nil {+ if errors.Is(err, repository.ErrInviteCodeNotFound) {+ return nil, ErrOrgNotFound+ }+ if errors.Is(err, repository.ErrInviteCodeExpired) {+ return nil, ErrInviteCodeExpired+ }+ return nil, err+ }++ // check if the organization need approval+ if org.RequireApproval {+ logger.Infof(ctx, "Organization %s requires approval", org.ID)+ return nil, ErrOrgPermissionDenied+ }++ if err := s.joinAsViewerWithChecks(ctx, org, userID, tenantID); err != nil {return nil, err}