mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 21:19:28 -06:00
e85d0e8d6b
See, $ gometalinter --vendor --disable-all --enable=megacheck --disable=gotype --deadline 6m ./... | grep ID alert.go:193:15⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck) alert.go:252:18⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck) annotation.go:113:12⚠️ sess.Table("annotation").Id is deprecated: use ID instead (SA1019) (megacheck) org.go:136:24⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck) org.go:169:16⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck) org_users.go:24:21⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck) org_users.go:88:12⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck) org_users.go:141:21⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck) plugin_setting.go:103:12⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck) preferences.go:97:12⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck) quota.go:119:17⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck) quota.go:221:17⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck) team.go:77:24⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck) user.go:243:16⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck) user.go:267:13⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck) user.go:282:13⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck) user.go:313:12⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck) user.go:475:3⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck) user.go:479:13⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck) user.go:493:13⚠️ sess.Id is deprecated: use ID instead (SA1019) (megacheck)
116 lines
3.1 KiB
Go
116 lines
3.1 KiB
Go
package sqlstore
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
"github.com/grafana/grafana/pkg/util"
|
|
)
|
|
|
|
func init() {
|
|
bus.AddHandler("sql", GetPluginSettings)
|
|
bus.AddHandler("sql", GetPluginSettingById)
|
|
bus.AddHandler("sql", UpdatePluginSetting)
|
|
bus.AddHandler("sql", UpdatePluginSettingVersion)
|
|
}
|
|
|
|
func GetPluginSettings(query *m.GetPluginSettingsQuery) error {
|
|
sql := `SELECT org_id, plugin_id, enabled, pinned, plugin_version
|
|
FROM plugin_setting `
|
|
params := make([]interface{}, 0)
|
|
|
|
if query.OrgId != 0 {
|
|
sql += "WHERE org_id=?"
|
|
params = append(params, query.OrgId)
|
|
}
|
|
|
|
sess := x.SQL(sql, params...)
|
|
query.Result = make([]*m.PluginSettingInfoDTO, 0)
|
|
return sess.Find(&query.Result)
|
|
}
|
|
|
|
func GetPluginSettingById(query *m.GetPluginSettingByIdQuery) error {
|
|
pluginSetting := m.PluginSetting{OrgId: query.OrgId, PluginId: query.PluginId}
|
|
has, err := x.Get(&pluginSetting)
|
|
if err != nil {
|
|
return err
|
|
} else if !has {
|
|
return m.ErrPluginSettingNotFound
|
|
}
|
|
query.Result = &pluginSetting
|
|
return nil
|
|
}
|
|
|
|
func UpdatePluginSetting(cmd *m.UpdatePluginSettingCmd) error {
|
|
return inTransaction(func(sess *DBSession) error {
|
|
var pluginSetting m.PluginSetting
|
|
|
|
exists, err := sess.Where("org_id=? and plugin_id=?", cmd.OrgId, cmd.PluginId).Get(&pluginSetting)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
sess.UseBool("enabled")
|
|
sess.UseBool("pinned")
|
|
if !exists {
|
|
pluginSetting = m.PluginSetting{
|
|
PluginId: cmd.PluginId,
|
|
OrgId: cmd.OrgId,
|
|
Enabled: cmd.Enabled,
|
|
Pinned: cmd.Pinned,
|
|
JsonData: cmd.JsonData,
|
|
PluginVersion: cmd.PluginVersion,
|
|
SecureJsonData: cmd.GetEncryptedJsonData(),
|
|
Created: time.Now(),
|
|
Updated: time.Now(),
|
|
}
|
|
|
|
// add state change event on commit success
|
|
sess.events = append(sess.events, &m.PluginStateChangedEvent{
|
|
PluginId: cmd.PluginId,
|
|
OrgId: cmd.OrgId,
|
|
Enabled: cmd.Enabled,
|
|
})
|
|
|
|
_, err = sess.Insert(&pluginSetting)
|
|
return err
|
|
}
|
|
for key, data := range cmd.SecureJsonData {
|
|
encryptedData, err := util.Encrypt([]byte(data), setting.SecretKey)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
pluginSetting.SecureJsonData[key] = encryptedData
|
|
}
|
|
|
|
// add state change event on commit success
|
|
if pluginSetting.Enabled != cmd.Enabled {
|
|
sess.events = append(sess.events, &m.PluginStateChangedEvent{
|
|
PluginId: cmd.PluginId,
|
|
OrgId: cmd.OrgId,
|
|
Enabled: cmd.Enabled,
|
|
})
|
|
}
|
|
|
|
pluginSetting.Updated = time.Now()
|
|
pluginSetting.Enabled = cmd.Enabled
|
|
pluginSetting.JsonData = cmd.JsonData
|
|
pluginSetting.Pinned = cmd.Pinned
|
|
pluginSetting.PluginVersion = cmd.PluginVersion
|
|
|
|
_, err = sess.ID(pluginSetting.Id).Update(&pluginSetting)
|
|
return err
|
|
})
|
|
}
|
|
|
|
func UpdatePluginSettingVersion(cmd *m.UpdatePluginSettingVersionCmd) error {
|
|
return inTransaction(func(sess *DBSession) error {
|
|
|
|
_, err := sess.Exec("UPDATE plugin_setting SET plugin_version=? WHERE org_id=? AND plugin_id=?", cmd.PluginVersion, cmd.OrgId, cmd.PluginId)
|
|
return err
|
|
|
|
})
|
|
}
|