Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions db-connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -4736,6 +4736,7 @@ func SetOrg(ctx context.Context, data Org, id string) error {
}

data.Users = newUsers

if len(data.Tutorials) == 0 {
data = *GetTutorials(ctx, data, false)
}
Expand Down Expand Up @@ -6048,6 +6049,52 @@ func fixUserOrg(ctx context.Context, user *User) *User {
return user
}

// fixUsersForOrg syncs user.Orgs with org.Users
// For each user in org.Users, ensures the org is in user.Orgs
// This is a standalone function to fix data sync issues manually
// Only call this when you need to fix broken org/user relationships
func fixUsersForOrg(ctx context.Context, org *Org) *Org {
// Made it background due to potential timeouts if this is
// used in API calls
ctx = context.Background()

// For each user in org.Users
for _, orgUser := range org.Users {
if len(orgUser.Id) == 0 {
continue
}

go func(userId string, orgId string) {
user, err := GetUser(ctx, userId)
if err != nil {
log.Printf("[WARNING] Error getting user %s in fixUsersForOrg: %s", userId, err)
return
}

found := false
for _, userOrgId := range user.Orgs {
if userOrgId == orgId {
found = true
break
}
}

if !found {
user.Orgs = append(user.Orgs, orgId)

err = SetUser(ctx, user, false) // false to avoid recursive call
if err != nil {
log.Printf("[WARNING] Failed setting user %s in fixUsersForOrg: %s", userId, err)
} else {
log.Printf("[INFO] Added org %s to user %s's Orgs list", orgId, userId)
}
}
}(orgUser.Id, org.Id)
}

return org
}

func GetAllWorkflowAppAuth(ctx context.Context, orgId string) ([]AppAuthenticationStorage, error) {
var allworkflowappAuths []AppAuthenticationStorage
nameKey := "workflowappauth"
Expand Down
Loading