@@ -1015,10 +1015,21 @@ func HandleGetOrg(resp http.ResponseWriter, request *http.Request) {
10151015 }
10161016
10171017 if !userFound && !sanitizeOrg {
1018- log.Printf("[ERROR] User '%s' (%s) isn't a part of org %s (get)", user.Username, user.Id, org.Id)
1019- resp.WriteHeader(401)
1020- resp.Write([]byte(`{"success": false, "reason": "User doesn't have access to org"}`))
1021- return
1018+ found := false
1019+ for _, orgId := range user.Orgs {
1020+ if orgId == org.Id {
1021+ found = true
1022+ admin = false
1023+ break
1024+ }
1025+ }
1026+
1027+ if !found {
1028+ log.Printf("[ERROR] User '%s' (%s) isn't a part of org %s (get)", user.Username, user.Id, org.Id)
1029+ resp.WriteHeader(401)
1030+ resp.Write([]byte(`{"success": false, "reason": "User doesn't have access to org"}`))
1031+ return
1032+ }
10221033
10231034 }
10241035 }
@@ -1182,7 +1193,6 @@ func HandleGetOrg(resp http.ResponseWriter, request *http.Request) {
11821193 }
11831194 }
11841195
1185- org.Users = []User{}
11861196 org.SyncConfig.Apikey = ""
11871197 org.SyncConfig.Source = ""
11881198
@@ -1215,6 +1225,8 @@ func HandleGetOrg(resp http.ResponseWriter, request *http.Request) {
12151225 }
12161226 }
12171227 }
1228+ } else {
1229+ org.Users = []User{}
12181230 }
12191231
12201232 // This is for sending branding information
@@ -9292,6 +9304,32 @@ func HandleGetUsers(resp http.ResponseWriter, request *http.Request) {
92929304 newUsers = append(newUsers, item)
92939305 }
92949306
9307+ if project.Environment == "cloud" {
9308+ orgUsers, err := GetUsersByOrg(ctx, user.ActiveOrg.Id)
9309+ if err != nil {
9310+ log.Printf("[WARNING] Failed getting org users for support access: %s", err)
9311+ } else {
9312+ for _, orgUser := range orgUsers {
9313+ found := false
9314+ for _, existingUser := range newUsers {
9315+ if existingUser.Id == orgUser.Id {
9316+ found = true
9317+ break
9318+ }
9319+ }
9320+
9321+ if found {
9322+ continue
9323+ }
9324+
9325+ //orgUser.Deleted = true
9326+ orgUser.LoginType = "DELETED"
9327+ orgUser.Role = "user"
9328+ newUsers = append(newUsers, orgUser)
9329+ }
9330+ }
9331+ }
9332+
92959333 deduplicatedUsers := []User{}
92969334 for _, item := range newUsers {
92979335 found := false
@@ -10703,7 +10741,7 @@ func DeleteUser(resp http.ResponseWriter, request *http.Request) {
1070310741 resp.Write([]byte(`{"success": true}`))
1070410742}
1070510743
10706- func HandleDeleteUsersAccount (resp http.ResponseWriter, request *http.Request) {
10744+ func HandleDeleteUsersAccountPermanent (resp http.ResponseWriter, request *http.Request) {
1070710745
1070810746 cors := HandleCors(resp, request)
1070910747 if cors {
@@ -10758,8 +10796,15 @@ func HandleDeleteUsersAccount(resp http.ResponseWriter, request *http.Request) {
1075810796 return
1075910797 }
1076010798
10761- if !userInfo.SupportAccess && userInfo.Id != foundUser.Id {
10762- log.Printf("Unauthorized user (%s) attempted to delete an account. Must be a user or have support access.", userInfo.Username)
10799+ if !userInfo.SupportAccess {
10800+ log.Printf("[INFO] Unauthorized user (%s) attempted to delete an account. Must be a user or have support access.", userInfo.Username)
10801+ resp.WriteHeader(401)
10802+ resp.Write([]byte(`{"success": false, "reason": "Unauthorize User. Must be a regular user or have support access"}`))
10803+ return
10804+ }
10805+
10806+ if userInfo.Id != foundUser.Id {
10807+ log.Printf("[INFO] Unauthorized user (%s) attempted to delete an account. Must be a user or have support access.", userInfo.Username)
1076310808 resp.WriteHeader(401)
1076410809 resp.Write([]byte(`{"success": false, "reason": "Unauthorize User. Must be a regular user or have support access"}`))
1076510810 return
@@ -11646,10 +11691,24 @@ func HandleChangeUserOrg(resp http.ResponseWriter, request *http.Request) {
1164611691 }
1164711692
1164811693 if !userFound && !user.SupportAccess {
11649- log.Printf("[ERROR] User %s (%s) can't change to org %s (%s) (2)", user.Username, user.Id, org.Name, org.Id)
11650- resp.WriteHeader(403)
11651- resp.Write([]byte(`{"success": false, "reason": "No permission to change to this org (2). Please contact
[email protected] if this is unexpected."}`))
11652- return
11694+
11695+ // FIXME: This changes the source of truth from JUST org.Users to user.Orgs
11696+ // May be a problem in worst case scenarios, but only works for orgids
11697+ // you know, so chance of causing an issue is **VERY** low.
11698+ found := false
11699+ for _, orgId := range user.Orgs {
11700+ if orgId == org.Id {
11701+ found = true
11702+ break
11703+ }
11704+ }
11705+
11706+ if !found {
11707+ log.Printf("[ERROR] User %s (%s) can't change to org %s (%s) (2)", user.Username, user.Id, org.Name, org.Id)
11708+ resp.WriteHeader(403)
11709+ resp.Write([]byte(`{"success": false, "reason": "No permission to change to this org (2). Please contact
[email protected] if this is unexpected."}`))
11710+ return
11711+ }
1165311712 }
1165411713
1165511714 if user.SupportAccess {
0 commit comments