Support Spanner's UNION syntax, which needs to be UNION DISTINCT or UNION ALL. (#101768)
* Support Spanner's UNION syntax, which needs to be UNION DISTINCT or UNION ALL.
This commit is contained in:
@@ -6,9 +6,10 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"go.opentelemetry.io/otel"
|
||||
)
|
||||
|
||||
var tracer = otel.Tracer("github.com/grafana/grafana/pkg/services/accesscontrol/database")
|
||||
@@ -58,7 +59,7 @@ func (s *AccessControlStore) GetUserPermissions(ctx context.Context, query acces
|
||||
return nil
|
||||
}
|
||||
|
||||
filter, params := accesscontrol.UserRolesFilter(query.OrgID, query.UserID, query.TeamIDs, query.Roles)
|
||||
filter, params := accesscontrol.UserRolesFilter(query.OrgID, query.UserID, query.TeamIDs, query.Roles, s.sql.GetDialect())
|
||||
|
||||
q := `
|
||||
SELECT
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
)
|
||||
|
||||
var sqlIDAcceptList = map[string]struct{}{
|
||||
@@ -127,7 +128,7 @@ func SetAcceptListForTest(list map[string]struct{}) func() {
|
||||
}
|
||||
}
|
||||
|
||||
func UserRolesFilter(orgID, userID int64, teamIDs []int64, roles []string) (string, []any) {
|
||||
func UserRolesFilter(orgID, userID int64, teamIDs []int64, roles []string, dialect migrator.Dialect) (string, []any) {
|
||||
var params []any
|
||||
builder := strings.Builder{}
|
||||
|
||||
@@ -145,7 +146,7 @@ func UserRolesFilter(orgID, userID int64, teamIDs []int64, roles []string) (stri
|
||||
|
||||
if len(teamIDs) > 0 {
|
||||
if builder.Len() > 0 {
|
||||
builder.WriteString("UNION")
|
||||
builder.WriteString(dialect.UnionDistinct())
|
||||
}
|
||||
builder.WriteString(`
|
||||
SELECT tr.role_id FROM team_role as tr
|
||||
@@ -160,7 +161,7 @@ func UserRolesFilter(orgID, userID int64, teamIDs []int64, roles []string) (stri
|
||||
|
||||
if len(roles) != 0 {
|
||||
if builder.Len() > 0 {
|
||||
builder.WriteString("UNION")
|
||||
builder.WriteString(dialect.UnionDistinct())
|
||||
}
|
||||
|
||||
builder.WriteString(`
|
||||
|
||||
Reference in New Issue
Block a user