Skip to content

Commit

Permalink
more user management fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danenania committed Mar 27, 2024
1 parent 507215f commit 204e9bd
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions app/server/db/org_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"strings"

"github.com/davecgh/go-spew/spew"
"github.com/lib/pq"
"github.com/plandex/plandex/shared"
)
Expand All @@ -21,15 +22,20 @@ func GetAccessibleOrgsForUser(user *User) ([]*Org, error) {
return nil, fmt.Errorf("error getting orgs for user: %v", err)
}

orgIds := make([]string, len(orgUsers))
for i, ou := range orgUsers {
orgIds[i] = ou.OrgId
orgIds := []string{}
for _, ou := range orgUsers {
orgIds = append(orgIds, ou.OrgId)
}

err = Conn.Select(&orgs, "SELECT * FROM orgs WHERE id = ANY($1)", pq.Array(orgIds))
if len(orgIds) > 0 {
err = Conn.Select(&orgs, "SELECT * FROM orgs WHERE id = ANY($1)", pq.Array(orgIds))

if err != nil {
return nil, fmt.Errorf("error getting orgs for user: %v", err)
if err != nil {
return nil, fmt.Errorf("error getting orgs for user: %v", err)
}
} else {
log.Println("No orgs found for user")
return orgs, nil
}

// access via invitation
Expand All @@ -39,11 +45,13 @@ func GetAccessibleOrgsForUser(user *User) ([]*Org, error) {
return nil, fmt.Errorf("error getting invites for user: %v", err)
}

orgIds = make([]string, len(invites))
orgIds = []string{}
for _, invite := range invites {
orgIds = append(orgIds, invite.OrgId)
}

log.Println(spew.Sdump(orgIds))

if len(orgIds) > 0 {
var orgsFromInvites []*Org
err = Conn.Select(&orgsFromInvites, "SELECT * FROM orgs WHERE id = ANY($1)", pq.Array(orgIds))
Expand Down

0 comments on commit 204e9bd

Please sign in to comment.