Skip to content

Commit 3dcb55b

Browse files
committed
Fixed problems with user and org invites, along with lingering orgs and bad org user info access
1 parent 49488a0 commit 3dcb55b

File tree

2 files changed

+75
-9
lines changed

2 files changed

+75
-9
lines changed

db-connector.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4089,7 +4089,6 @@ func GetOrg(ctx context.Context, id string) (*Org, error) {
40894089
log.Printf("[WARNING] Error in org loading (4), but returning without warning: %s", err)
40904090
err = nil
40914091
} else {
4092-
log.Printf("[ERROR] Problem in org loading (2) for %s: %s", key, err)
40934092
if strings.Contains(err.Error(), `no such entity`) && project.CacheDb {
40944093
neworg, err := json.Marshal(curOrg)
40954094
if err != nil {
@@ -4101,7 +4100,10 @@ func GetOrg(ctx context.Context, id string) (*Org, error) {
41014100
if err != nil {
41024101
log.Printf("[ERROR] Failed updating org cache (3): %s", err)
41034102
}
4103+
} else {
4104+
log.Printf("[ERROR] Problem in org loading (2) for %s: %s", key, err)
41044105
}
4106+
41054107
//orgErr = err
41064108
return &Org{}, err
41074109
}
@@ -6216,7 +6218,10 @@ func fixUserOrg(ctx context.Context, user *User) *User {
62166218
go func(orgId string) {
62176219
org, err := GetOrg(ctx, orgId)
62186220
if err != nil {
6219-
log.Printf("[WARNING] Error getting org %s in fixUserOrg: %s", orgId, err)
6221+
if !strings.Contains(err.Error(), "doesn't exist") {
6222+
log.Printf("[WARNING] Error getting org %s in fixUserOrg: %s", orgId, err)
6223+
}
6224+
62206225
return
62216226
}
62226227

shared.go

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5440,7 +5440,9 @@ func HandleUpdateUser(resp http.ResponseWriter, request *http.Request) {
54405440
}
54415441
*/
54425442

5443-
log.Printf("[DEBUG] Found github username '%s'. User ID to look for: %s", foundUser.PublicProfile.GithubUsername, t.UserId)
5443+
if len(foundUser.PublicProfile.GithubUsername) > 0 {
5444+
log.Printf("[DEBUG] Found github username '%s'. User ID to look for: %s", foundUser.PublicProfile.GithubUsername, t.UserId)
5445+
}
54445446

54455447
username := foundUser.PublicProfile.GithubUsername
54465448
creator, err := HandleAlgoliaCreatorSearch(ctx, username)
@@ -5515,6 +5517,10 @@ func HandleUpdateUser(resp http.ResponseWriter, request *http.Request) {
55155517
// 3. Make sure it's ONLY changing orgs based on parent org
55165518

55175519
// Check which ones the current user has access to
5520+
if debug {
5521+
log.Printf("[DEBUG] PRE PRE orgs for %s (%s) is len(%d). Input length: %d", foundUser.Username, foundUser.Id, len(foundUser.Orgs), len(t.Suborgs))
5522+
}
5523+
55185524
parentOrgId := userInfo.ActiveOrg.Id
55195525
newSuborgs := []string{}
55205526
for _, suborg := range t.Suborgs {
@@ -5530,6 +5536,10 @@ func HandleUpdateUser(resp http.ResponseWriter, request *http.Request) {
55305536
}
55315537

55325538
if org.CreatorOrg != parentOrgId {
5539+
if debug {
5540+
log.Printf("[ERROR] Skipping org %s as it is not a suborg of parent org %s for user %s (%s).", suborg, parentOrgId, userInfo.Username, userInfo.Id)
5541+
}
5542+
55335543
continue
55345544
}
55355545

@@ -5540,8 +5550,16 @@ func HandleUpdateUser(resp http.ResponseWriter, request *http.Request) {
55405550
}
55415551
}
55425552

5553+
if userInfo.SupportAccess && strings.HasSuffix(userInfo.Username, "@shuffler.io") {
5554+
found = true
5555+
}
5556+
55435557
if found {
55445558
newSuborgs = append(newSuborgs, suborg)
5559+
} else {
5560+
if debug {
5561+
log.Printf("[ERROR] Skipping adding to org %s as user %s (%s) can't edit this one.", suborg, userInfo.Username, userInfo.Id)
5562+
}
55455563
}
55465564
}
55475565

@@ -5554,18 +5572,20 @@ func HandleUpdateUser(resp http.ResponseWriter, request *http.Request) {
55545572
}
55555573

55565574
if ArrayContains(foundUser.Orgs, suborg) {
5557-
log.Printf("[DEBUG] Skipping %s as it already exists", suborg)
55585575
continue
55595576
}
55605577

5561-
if !ArrayContains(userInfo.Orgs, suborg) {
5578+
if !ArrayContains(userInfo.Orgs, suborg) && !userInfo.SupportAccess {
55625579
log.Printf("[ERROR] Skipping org %s as user %s (%s) can't edit this one. Should never happen unless direct API usage.", suborg, userInfo.Username, userInfo.Id)
55635580
continue
55645581
}
55655582

55665583
foundOrg, err := GetOrg(ctx, suborg)
55675584
if err != nil {
5568-
log.Printf("[WARNING] Failed to get suborg in user edit for %s (%s): %s", foundUser.Username, foundUser.Id, err)
5585+
if !strings.Contains(err.Error(), "no such entity") {
5586+
log.Printf("[WARNING] Failed to get suborg in user edit for %s (%s): %s", foundUser.Username, foundUser.Id, err)
5587+
}
5588+
55695589
continue
55705590
}
55715591

@@ -5589,6 +5609,10 @@ func HandleUpdateUser(resp http.ResponseWriter, request *http.Request) {
55895609
//log.Printf("[DEBUG] Orgs to be added: %s. Existing: %s.", addedOrgs, foundUser.Orgs)
55905610

55915611
// Removed for now due to multi-org chain deleting you from other org chains
5612+
if debug {
5613+
log.Printf("[DEBUG] Pre orgs for %s (%s) is len(%d)", foundUser.Username, foundUser.Id, len(foundUser.Orgs))
5614+
}
5615+
55925616
newUserOrgs := []string{}
55935617
for _, suborg := range foundUser.Orgs {
55945618
if suborg == userInfo.ActiveOrg.Id {
@@ -5598,7 +5622,10 @@ func HandleUpdateUser(resp http.ResponseWriter, request *http.Request) {
55985622

55995623
foundOrg, err := GetOrg(ctx, suborg)
56005624
if err != nil {
5601-
log.Printf("[WARNING] Failed to get suborg in user edit (2) for %s (%s): %s", foundUser.Username, foundUser.Id, err)
5625+
if !strings.Contains(err.Error(), "no such entity") && !strings.Contains(err.Error(), "Org doesn't exist") {
5626+
log.Printf("[WARNING] Failed to get suborg in user edit (2) for %s (%s): %s", foundUser.Username, foundUser.Id, err)
5627+
}
5628+
56025629
newUserOrgs = append(newUserOrgs, suborg)
56035630
continue
56045631
}
@@ -5612,9 +5639,10 @@ func HandleUpdateUser(resp http.ResponseWriter, request *http.Request) {
56125639
for _, item := range foundOrg.ChildOrgs {
56135640
orgRelevancies = append(orgRelevancies, item.Id)
56145641
}
5642+
56155643
if !ArrayContains(orgRelevancies, userInfo.ActiveOrg.Id) {
56165644
newUserOrgs = append(newUserOrgs, suborg)
5617-
log.Printf("[DEBUG] Org %s (%s) is not relevant to parent org %s (%s). Skipping.", foundOrg.Name, foundOrg.Id, userInfo.ActiveOrg.Name, userInfo.ActiveOrg.Id)
5645+
log.Printf("[DEBUG] Org '%s' (%s) is not relevant to parent org %s (%s). Skipping.", foundOrg.Name, foundOrg.Id, userInfo.ActiveOrg.Name, userInfo.ActiveOrg.Id)
56185646
continue
56195647
}
56205648

@@ -5630,7 +5658,7 @@ func HandleUpdateUser(resp http.ResponseWriter, request *http.Request) {
56305658
//log.Printf("[DEBUG] Reappending org %s", suborg)
56315659
newUserOrgs = append(newUserOrgs, suborg)
56325660
} else {
5633-
log.Printf("[DEBUG] Skipping org %s", suborg)
5661+
log.Printf("[DEBUG] Skipping org '%s'", suborg)
56345662
}
56355663

56365664
continue
@@ -9220,6 +9248,18 @@ func CleanCreds(user *User) *User {
92209248
user.VerificationToken = ""
92219249
user.ValidatedSessionOrgs = []string{}
92229250
//user.Orgs = []string{}
9251+
handledOrgs := []string{}
9252+
9253+
// Quick deduplication.
9254+
for _, org := range user.Orgs {
9255+
if ArrayContains(handledOrgs, org) {
9256+
continue
9257+
}
9258+
9259+
handledOrgs = append(handledOrgs, org)
9260+
}
9261+
user.Orgs = handledOrgs
9262+
92239263
user.Authentication = []UserAuth{}
92249264
user.PrivateApps = []WorkflowApp{}
92259265

@@ -9340,8 +9380,14 @@ func HandleGetUsers(resp http.ResponseWriter, request *http.Request) {
93409380
} else {
93419381
// Only add IF the admin querying it has access, meaning only show what you yourself have access toMFAInfo
93429382
allOrgs := []string{}
9383+
handledOrgs := []string{}
93439384
for _, orgname := range foundUser.Orgs {
93449385
found := false
9386+
if ArrayContains(handledOrgs, orgname) {
9387+
continue
9388+
}
9389+
9390+
handledOrgs = append(handledOrgs, orgname)
93459391

93469392
for _, userOrg := range user.Orgs {
93479393
if userOrg == orgname {
@@ -9367,6 +9413,9 @@ func HandleGetUsers(resp http.ResponseWriter, request *http.Request) {
93679413
item.Orgs = append(item.Orgs, user.ActiveOrg.Id)
93689414
}
93699415

9416+
if user.SupportAccess {
9417+
item.Orgs = foundUser.Orgs
9418+
}
93709419
newUsers = append(newUsers, item)
93719420
}
93729421

@@ -9421,9 +9470,16 @@ func HandleGetUsers(resp http.ResponseWriter, request *http.Request) {
94219470
foundUser, err := GetUser(ctx, orgUser.Id)
94229471
if err == nil {
94239472
allOrgs := []string{}
9473+
handledOrgs := []string{}
94249474
for _, orgname := range foundUser.Orgs {
94259475
found := false
94269476

9477+
if ArrayContains(handledOrgs, orgname) {
9478+
continue
9479+
}
9480+
9481+
handledOrgs = append(handledOrgs, orgname)
9482+
94279483
for _, userOrg := range user.Orgs {
94289484
if userOrg == orgname {
94299485
found = true
@@ -9443,12 +9499,17 @@ func HandleGetUsers(resp http.ResponseWriter, request *http.Request) {
94439499
orgUser.Active = foundUser.Active
94449500
orgUser.Orgs = allOrgs
94459501
}
9502+
9503+
if user.SupportAccess {
9504+
orgUser.Orgs = foundUser.Orgs
9505+
}
94469506
}
94479507

94489508
if len(orgUser.Orgs) == 0 {
94499509
orgUser.Orgs = append(orgUser.Orgs, user.ActiveOrg.Id)
94509510
}
94519511

9512+
94529513
newUsers = append(newUsers, orgUser)
94539514
}
94549515
}

0 commit comments

Comments
 (0)