refactor.

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.
This commit is contained in:
woodsaj
2015-12-17 23:53:58 +08:00
parent 0697274695
commit c35b51a268
15 changed files with 215 additions and 181 deletions

View File

@@ -8,25 +8,25 @@ import (
)
func init() {
bus.AddHandler("sql", GetPluginBundles)
bus.AddHandler("sql", UpdatePluginBundle)
bus.AddHandler("sql", GetAppPlugins)
bus.AddHandler("sql", UpdateAppPlugin)
}
func GetPluginBundles(query *m.GetPluginBundlesQuery) error {
func GetAppPlugins(query *m.GetAppPluginsQuery) error {
sess := x.Where("org_id=?", query.OrgId)
query.Result = make([]*m.PluginBundle, 0)
query.Result = make([]*m.AppPlugin, 0)
return sess.Find(&query.Result)
}
func UpdatePluginBundle(cmd *m.UpdatePluginBundleCmd) error {
func UpdateAppPlugin(cmd *m.UpdateAppPluginCmd) error {
return inTransaction2(func(sess *session) error {
var bundle m.PluginBundle
var app m.AppPlugin
exists, err := sess.Where("org_id=? and type=?", cmd.OrgId, cmd.Type).Get(&bundle)
exists, err := sess.Where("org_id=? and type=?", cmd.OrgId, cmd.Type).Get(&app)
sess.UseBool("enabled")
if !exists {
bundle = m.PluginBundle{
app = m.AppPlugin{
Type: cmd.Type,
OrgId: cmd.OrgId,
Enabled: cmd.Enabled,
@@ -34,12 +34,12 @@ func UpdatePluginBundle(cmd *m.UpdatePluginBundleCmd) error {
Created: time.Now(),
Updated: time.Now(),
}
_, err = sess.Insert(&bundle)
_, err = sess.Insert(&app)
return err
} else {
bundle.Enabled = cmd.Enabled
bundle.JsonData = cmd.JsonData
_, err = sess.Id(bundle.Id).Update(&bundle)
app.Enabled = cmd.Enabled
app.JsonData = cmd.JsonData
_, err = sess.Id(app.Id).Update(&app)
return err
}
})

View File

@@ -2,10 +2,10 @@ package migrations
import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
func addPluginBundleMigration(mg *Migrator) {
func addAppPluginMigration(mg *Migrator) {
var pluginBundleV1 = Table{
Name: "plugin_bundle",
var appPluginV1 = Table{
Name: "app_plugin",
Columns: []*Column{
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
{Name: "org_id", Type: DB_BigInt, Nullable: true},
@@ -19,8 +19,8 @@ func addPluginBundleMigration(mg *Migrator) {
{Cols: []string{"org_id", "type"}, Type: UniqueIndex},
},
}
mg.AddMigration("create plugin_bundle table v1", NewAddTableMigration(pluginBundleV1))
mg.AddMigration("create app_plugin table v1", NewAddTableMigration(appPluginV1))
//------- indexes ------------------
addTableIndicesMigrations(mg, "v1", pluginBundleV1)
addTableIndicesMigrations(mg, "v1", appPluginV1)
}

View File

@@ -18,7 +18,7 @@ func AddMigrations(mg *Migrator) {
addApiKeyMigrations(mg)
addDashboardSnapshotMigrations(mg)
addQuotaMigration(mg)
addPluginBundleMigration(mg)
addAppPluginMigration(mg)
}
func addMigrationLogMigrations(mg *Migrator) {