mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 13:39:19 -06:00
a14621fff6
* Chore: Add user service method SetUsingOrg * Chore: Add user service method GetSignedInUserWithCacheCtx * Use method GetSignedInUserWithCacheCtx from user service * Fix lint after rebase * Fix lint * Fix lint error * roll back some changes * Roll back changes in api and middleware * Add xorm tags to SignedInUser ID fields
63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package sqlstore
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/permissions"
|
|
"github.com/grafana/grafana/pkg/services/user"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
)
|
|
|
|
func NewSqlBuilder(cfg *setting.Cfg) SQLBuilder {
|
|
return SQLBuilder{cfg: cfg}
|
|
}
|
|
|
|
type SQLBuilder struct {
|
|
cfg *setting.Cfg
|
|
sql bytes.Buffer
|
|
params []interface{}
|
|
}
|
|
|
|
func (sb *SQLBuilder) Write(sql string, params ...interface{}) {
|
|
sb.sql.WriteString(sql)
|
|
|
|
if len(params) > 0 {
|
|
sb.params = append(sb.params, params...)
|
|
}
|
|
}
|
|
|
|
func (sb *SQLBuilder) GetSQLString() string {
|
|
return sb.sql.String()
|
|
}
|
|
|
|
func (sb *SQLBuilder) GetParams() []interface{} {
|
|
return sb.params
|
|
}
|
|
|
|
func (sb *SQLBuilder) AddParams(params ...interface{}) {
|
|
sb.params = append(sb.params, params...)
|
|
}
|
|
|
|
func (sb *SQLBuilder) WriteDashboardPermissionFilter(user *user.SignedInUser, permission models.PermissionType) {
|
|
var (
|
|
sql string
|
|
params []interface{}
|
|
)
|
|
if !ac.IsDisabled(sb.cfg) {
|
|
sql, params = permissions.NewAccessControlDashboardPermissionFilter(user, permission, "").Where()
|
|
} else {
|
|
sql, params = permissions.DashboardPermissionFilter{
|
|
OrgRole: user.OrgRole,
|
|
Dialect: dialect,
|
|
UserId: user.UserID,
|
|
OrgId: user.OrgID,
|
|
PermissionLevel: permission,
|
|
}.Where()
|
|
}
|
|
|
|
sb.sql.WriteString(" AND " + sql)
|
|
sb.params = append(sb.params, params...)
|
|
}
|