Skip to content

Commit 46cae74

Browse files
committed
Minor org setup tweaks
1 parent 841b6ec commit 46cae74

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

db-connector.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4023,7 +4023,11 @@ func GetOrgByCreatorId(ctx context.Context, id string) (*Org, error) {
40234023
// Handles org grabbing and user / org migrations
40244024
func GetOrg(ctx context.Context, id string) (*Org, error) {
40254025
if id == "public" {
4026-
return &Org{}, errors.New("'public' org is used for Singul action without being logged in. Not relevant.")
4026+
//return &Org{}, errors.New("'public' org is used for Singul action without being logged in. Not relevant.")
4027+
return &Org{
4028+
Id: "public",
4029+
Name: "Public",
4030+
}, nil
40274031
}
40284032

40294033
nameKey := "Organizations"

shared.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ func HandleCors(resp http.ResponseWriter, request *http.Request) bool {
116116
"https://br.shuffler.io",
117117
"https://in.shuffler.io",
118118

119+
"https://*.singul.io",
119120
"https://singul.io",
120121
"http://localhost:3002",
122+
"http://localhost:3000",
121123
}
122124

123125
if len(origin) > 0 {

stats.go

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -659,34 +659,42 @@ func HandleGetStatistics(resp http.ResponseWriter, request *http.Request) {
659659
orgId = user.ActiveOrg.Id
660660
}
661661

662+
org := &Org{}
662663
ctx := GetContext(request)
663-
org, err := GetOrg(ctx, orgId)
664-
if err != nil {
665-
resp.WriteHeader(403)
666-
resp.Write([]byte(`{"success": false, "reason": "Failed getting org stats"}`))
667-
return
668-
}
664+
if orgId == "public" {
665+
if user.SupportAccess {
666+
log.Printf("[AUDIT] User %s (%s) is getting org stats for PUBLIC org %s with support access", user.Username, user.Id, orgId)
667+
}
669668

670-
userFound := false
671-
for _, inneruser := range org.Users {
672-
if inneruser.Id == user.Id {
673-
userFound = true
669+
} else {
670+
org, err = GetOrg(ctx, orgId)
671+
if err != nil {
672+
resp.WriteHeader(403)
673+
resp.Write([]byte(`{"success": false, "reason": "Failed getting org stats"}`))
674+
return
675+
}
674676

675-
break
677+
userFound := false
678+
for _, inneruser := range org.Users {
679+
if inneruser.Id == user.Id {
680+
userFound = true
681+
682+
break
683+
}
676684
}
677-
}
678685

679-
if user.SupportAccess {
680-
log.Printf("[AUDIT] User %s (%s) is getting org stats for %s (%s) with support access", user.Username, user.Id, org.Name, orgId)
681-
userFound = true
682-
}
686+
if user.SupportAccess {
687+
log.Printf("[AUDIT] User %s (%s) is getting org stats for %s (%s) with support access", user.Username, user.Id, org.Name, orgId)
688+
userFound = true
689+
}
683690

684-
if !userFound {
685-
log.Printf("[WARNING] User %s isn't a part of org %s (get)", user.Id, org.Id)
686-
resp.WriteHeader(403)
687-
resp.Write([]byte(`{"success": false, "reason": "User doesn't have access to org"}`))
688-
return
691+
if !userFound {
692+
log.Printf("[WARNING] User %s isn't a part of org %s (get)", user.Id, org.Id)
693+
resp.WriteHeader(403)
694+
resp.Write([]byte(`{"success": false, "reason": "User doesn't have access to org"}`))
695+
return
689696

697+
}
690698
}
691699

692700
// FIXME: Removed the current stats grabber as it made no sense

0 commit comments

Comments
 (0)