Skip to content

Commit afda283

Browse files
committed
Added org id pivot made easier
1 parent c4d0e12 commit afda283

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

ai.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ END VALIDATION RULES
747747
CONSTRAINTS
748748
749749
- Do NOT invent values
750+
- Do NOT add irrelevant headers or body fields
750751
- MUST use keys present in original JSON
751752
- Make sure all "Required data" values are in the output.
752753
- Do not focus on authentication unless necessary

db-connector.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5436,8 +5436,10 @@ func FindUser(ctx context.Context, username string) ([]User, error) {
54365436
query := map[string]interface{}{
54375437
"size": 1000,
54385438
"query": map[string]interface{}{
5439-
"match": map[string]interface{}{
5440-
"username": username,
5439+
"must": map[string]interface{}{
5440+
"match": map[string]interface{}{
5441+
"username": username,
5442+
},
54415443
},
54425444
},
54435445
}

shared.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11502,6 +11502,42 @@ func HandleChangeUserOrg(resp http.ResponseWriter, request *http.Request) {
1150211502
return
1150311503
}
1150411504

11505+
// Support access pivot
11506+
if strings.Contains(fileId, "@") && strings.Contains(fileId, ".") && user.SupportAccess && user.Active && user.Verified && project.Environment == "cloud" {
11507+
foundUsers, err := FindUser(ctx, fileId)
11508+
if err != nil || len(foundUsers) == 0 {
11509+
log.Printf("[ERROR] Failed finding user %s for support access: %s", user.Username, err)
11510+
resp.WriteHeader(400)
11511+
resp.Write([]byte(`{"success": false, "reason": "Failed finding user for support access"}`))
11512+
return
11513+
}
11514+
11515+
if len(foundUsers) > 1 {
11516+
log.Printf("[ERROR] Found multiple users for support access user %s", user.Username)
11517+
}
11518+
11519+
newUsers := []User{}
11520+
for _, loopUser := range foundUsers {
11521+
if strings.ToLower(strings.TrimSpace(loopUser.Username)) != fileId {
11522+
continue
11523+
}
11524+
11525+
newUsers = append(newUsers, loopUser)
11526+
}
11527+
11528+
if len(newUsers) == 0 {
11529+
log.Printf("[WARNING] No user found with username '%s' for support access user %s", fileId, user.Username)
11530+
resp.WriteHeader(400)
11531+
resp.Write([]byte(`{"success": false, "reason": "No user found with that username"}`))
11532+
return
11533+
}
11534+
11535+
foundUsers = newUsers
11536+
log.Printf("[AUDIT] Support access user %s is trying to swap to org for user %s (%s). Found ID: %s", user.Username, fileId, foundUsers[0].Id, foundUsers[0].ActiveOrg.Id)
11537+
tmpData.OrgId = foundUsers[0].ActiveOrg.Id
11538+
fileId = foundUsers[0].ActiveOrg.Id
11539+
}
11540+
1150511541
// Add instantswap of backend
1150611542
// This could in theory be built out open source as well
1150711543
regionUrl := ""
@@ -11658,7 +11694,7 @@ func HandleChangeUserOrg(resp http.ResponseWriter, request *http.Request) {
1165811694

1165911695
log.Printf("[INFO] User %s (%s) successfully changed org to '%s' (%s)", user.Username, user.Id, org.Name, org.Id)
1166011696
resp.WriteHeader(200)
11661-
resp.Write([]byte(fmt.Sprintf(`{"success": true, "reason": "Changed Organization", "region_url": "%s"}`, regionUrl)))
11697+
resp.Write([]byte(fmt.Sprintf(`{"success": true, "reason": "Changed Organization", "region_url": "%s", "org_id": "%s"}`, regionUrl, org.Id)))
1166211698

1166311699
}
1166411700

0 commit comments

Comments
 (0)