Skip to content

Commit

Permalink
Merge pull request #1398 from kaytu-io/fix-steampipe-upgrade
Browse files Browse the repository at this point in the history
fix: fix workspace check query
  • Loading branch information
artaasadi authored Aug 1, 2024
2 parents 990e4b4 + 08fb883 commit 85c5cdc
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions pkg/auth/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package db

import (
"errors"
"fmt"
"github.com/jackc/pgtype"
"github.com/kaytu-io/kaytu-util/pkg/api"
"gorm.io/gorm"
Expand Down Expand Up @@ -264,8 +265,8 @@ func (db Database) GetUsersByEmail(email string) ([]User, error) {

func (db Database) GetUsersByWorkspace(ws string) ([]User, error) {
var users []User
query := `SELECT * FROM users WHERE app_metadata->'workspaceAccess' \? ?`
err := db.Orm.Raw(query, ws).Scan(&users).Error
query := fmt.Sprintf("SELECT * FROM users WHERE app_metadata->'workspaceAccess' ? '%s'", ws)
err := db.Orm.Raw(query).Scan(&users).Error
if err != nil {
return nil, err
}
Expand All @@ -274,21 +275,17 @@ func (db Database) GetUsersByWorkspace(ws string) ([]User, error) {

func (db Database) SearchUsers(ws string, email *string, emailVerified *bool) ([]User, error) {
var users []User
query := `SELECT * FROM users WHERE app_metadata->'workspaceAccess' \? ?`

params := []interface{}{ws}
query := fmt.Sprintf("SELECT * FROM users WHERE app_metadata->'workspaceAccess' ? '%s'", ws)

if email != nil {
query += ` AND email = ?`
params = append(params, *email)
query += fmt.Sprintf(" AND email = %s", *email)
}

if emailVerified != nil {
query += ` AND email_verified = ?`
params = append(params, *emailVerified)
query += fmt.Sprintf(" AND email_verified = %v", *emailVerified)
}

err := db.Orm.Raw(query, params...).Scan(&users).Error
err := db.Orm.Raw(query).Scan(&users).Error
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 85c5cdc

Please sign in to comment.