mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 01:41:50 +08:00

Rename externalPlugin to apiPlugin Rename bundle to app Move js, css, menuItem and staticRoot to be properties os App Add "app" field to panel, datasource and api plugin models. If populated then the plugin is only enabled if the specific app is enabled for the Org. If app is "", then the plugin is enabled for all orgs and can't be disabled.
47 lines
1006 B
Go
47 lines
1006 B
Go
package sqlstore
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
)
|
|
|
|
func init() {
|
|
bus.AddHandler("sql", GetAppPlugins)
|
|
bus.AddHandler("sql", UpdateAppPlugin)
|
|
}
|
|
|
|
func GetAppPlugins(query *m.GetAppPluginsQuery) error {
|
|
sess := x.Where("org_id=?", query.OrgId)
|
|
|
|
query.Result = make([]*m.AppPlugin, 0)
|
|
return sess.Find(&query.Result)
|
|
}
|
|
|
|
func UpdateAppPlugin(cmd *m.UpdateAppPluginCmd) error {
|
|
return inTransaction2(func(sess *session) error {
|
|
var app m.AppPlugin
|
|
|
|
exists, err := sess.Where("org_id=? and type=?", cmd.OrgId, cmd.Type).Get(&app)
|
|
sess.UseBool("enabled")
|
|
if !exists {
|
|
app = m.AppPlugin{
|
|
Type: cmd.Type,
|
|
OrgId: cmd.OrgId,
|
|
Enabled: cmd.Enabled,
|
|
JsonData: cmd.JsonData,
|
|
Created: time.Now(),
|
|
Updated: time.Now(),
|
|
}
|
|
_, err = sess.Insert(&app)
|
|
return err
|
|
} else {
|
|
app.Enabled = cmd.Enabled
|
|
app.JsonData = cmd.JsonData
|
|
_, err = sess.Id(app.Id).Update(&app)
|
|
return err
|
|
}
|
|
})
|
|
}
|