Commit 67ec9edc by Carl Bergquist Committed by GitHub

chore: avoid alias for models in plugins (#22483)

parent f2f2722b
package dtos package dtos
import m "github.com/grafana/grafana/pkg/models" import "github.com/grafana/grafana/pkg/models"
type AddInviteForm struct { type AddInviteForm struct {
LoginOrEmail string `json:"loginOrEmail" binding:"Required"` LoginOrEmail string `json:"loginOrEmail" binding:"Required"`
Name string `json:"name"` Name string `json:"name"`
Role m.RoleType `json:"role" binding:"Required"` Role models.RoleType `json:"role" binding:"Required"`
SendEmail bool `json:"sendEmail"` SendEmail bool `json:"sendEmail"`
} }
type InviteInfo struct { type InviteInfo struct {
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
m "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards"
) )
...@@ -19,7 +19,7 @@ type ImportDashboardCommand struct { ...@@ -19,7 +19,7 @@ type ImportDashboardCommand struct {
FolderId int64 FolderId int64
OrgId int64 OrgId int64
User *m.SignedInUser User *models.SignedInUser
PluginId string PluginId string
Result *PluginDashboardInfoDTO Result *PluginDashboardInfoDTO
} }
...@@ -44,7 +44,7 @@ func init() { ...@@ -44,7 +44,7 @@ func init() {
} }
func ImportDashboard(cmd *ImportDashboardCommand) error { func ImportDashboard(cmd *ImportDashboardCommand) error {
var dashboard *m.Dashboard var dashboard *models.Dashboard
var err error var err error
if cmd.PluginId != "" { if cmd.PluginId != "" {
...@@ -52,7 +52,7 @@ func ImportDashboard(cmd *ImportDashboardCommand) error { ...@@ -52,7 +52,7 @@ func ImportDashboard(cmd *ImportDashboardCommand) error {
return err return err
} }
} else { } else {
dashboard = m.NewDashboardFromJson(cmd.Dashboard) dashboard = models.NewDashboardFromJson(cmd.Dashboard)
} }
evaluator := &DashTemplateEvaluator{ evaluator := &DashTemplateEvaluator{
...@@ -65,7 +65,7 @@ func ImportDashboard(cmd *ImportDashboardCommand) error { ...@@ -65,7 +65,7 @@ func ImportDashboard(cmd *ImportDashboardCommand) error {
return err return err
} }
saveCmd := m.SaveDashboardCommand{ saveCmd := models.SaveDashboardCommand{
Dashboard: generatedDash, Dashboard: generatedDash,
OrgId: cmd.OrgId, OrgId: cmd.OrgId,
UserId: cmd.User.UserId, UserId: cmd.User.UserId,
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"testing" "testing"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
m "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
...@@ -22,7 +22,7 @@ func TestDashboardImport(t *testing.T) { ...@@ -22,7 +22,7 @@ func TestDashboardImport(t *testing.T) {
PluginId: "test-app", PluginId: "test-app",
Path: "dashboards/connections.json", Path: "dashboards/connections.json",
OrgId: 1, OrgId: 1,
User: &m.SignedInUser{UserId: 1, OrgRole: m.ROLE_ADMIN}, User: &models.SignedInUser{UserId: 1, OrgRole: models.ROLE_ADMIN},
Inputs: []ImportDashboardInput{ Inputs: []ImportDashboardInput{
{Name: "*", Type: "datasource", Value: "graphite"}, {Name: "*", Type: "datasource", Value: "graphite"},
}, },
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
m "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
) )
type PluginDashboardInfoDTO struct { type PluginDashboardInfoDTO struct {
...@@ -35,7 +35,7 @@ func GetPluginDashboards(orgId int64, pluginId string) ([]*PluginDashboardInfoDT ...@@ -35,7 +35,7 @@ func GetPluginDashboards(orgId int64, pluginId string) ([]*PluginDashboardInfoDT
result := make([]*PluginDashboardInfoDTO, 0) result := make([]*PluginDashboardInfoDTO, 0)
// load current dashboards // load current dashboards
query := m.GetDashboardsByPluginIdQuery{OrgId: orgId, PluginId: pluginId} query := models.GetDashboardsByPluginIdQuery{OrgId: orgId, PluginId: pluginId}
if err := bus.Dispatch(&query); err != nil { if err := bus.Dispatch(&query); err != nil {
return nil, err return nil, err
} }
...@@ -48,7 +48,7 @@ func GetPluginDashboards(orgId int64, pluginId string) ([]*PluginDashboardInfoDT ...@@ -48,7 +48,7 @@ func GetPluginDashboards(orgId int64, pluginId string) ([]*PluginDashboardInfoDT
} }
res := &PluginDashboardInfoDTO{} res := &PluginDashboardInfoDTO{}
var dashboard *m.Dashboard var dashboard *models.Dashboard
var err error var err error
if dashboard, err = loadPluginDashboard(plugin.Id, include.Path); err != nil { if dashboard, err = loadPluginDashboard(plugin.Id, include.Path); err != nil {
...@@ -89,7 +89,7 @@ func GetPluginDashboards(orgId int64, pluginId string) ([]*PluginDashboardInfoDT ...@@ -89,7 +89,7 @@ func GetPluginDashboards(orgId int64, pluginId string) ([]*PluginDashboardInfoDT
return result, nil return result, nil
} }
func loadPluginDashboard(pluginId, path string) (*m.Dashboard, error) { func loadPluginDashboard(pluginId, path string) (*models.Dashboard, error) {
plugin, exists := Plugins[pluginId] plugin, exists := Plugins[pluginId]
if !exists { if !exists {
...@@ -109,5 +109,5 @@ func loadPluginDashboard(pluginId, path string) (*m.Dashboard, error) { ...@@ -109,5 +109,5 @@ func loadPluginDashboard(pluginId, path string) (*m.Dashboard, error) {
return nil, err return nil, err
} }
return m.NewDashboardFromJson(data), nil return models.NewDashboardFromJson(data), nil
} }
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
m "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"gopkg.in/ini.v1" "gopkg.in/ini.v1"
...@@ -22,23 +22,23 @@ func TestPluginDashboards(t *testing.T) { ...@@ -22,23 +22,23 @@ func TestPluginDashboards(t *testing.T) {
err = pm.Init() err = pm.Init()
So(err, ShouldBeNil) So(err, ShouldBeNil)
bus.AddHandler("test", func(query *m.GetDashboardQuery) error { bus.AddHandler("test", func(query *models.GetDashboardQuery) error {
if query.Slug == "nginx-connections" { if query.Slug == "nginx-connections" {
dash := m.NewDashboard("Nginx Connections") dash := models.NewDashboard("Nginx Connections")
dash.Data.Set("revision", "1.1") dash.Data.Set("revision", "1.1")
query.Result = dash query.Result = dash
return nil return nil
} }
return m.ErrDashboardNotFound return models.ErrDashboardNotFound
}) })
bus.AddHandler("test", func(query *m.GetDashboardsByPluginIdQuery) error { bus.AddHandler("test", func(query *models.GetDashboardsByPluginIdQuery) error {
var data = simplejson.New() var data = simplejson.New()
data.Set("title", "Nginx Connections") data.Set("title", "Nginx Connections")
data.Set("revision", 22) data.Set("revision", 22)
query.Result = []*m.Dashboard{ query.Result = []*models.Dashboard{
{Slug: "nginx-connections", Data: data}, {Slug: "nginx-connections", Data: data},
} }
return nil return nil
......
...@@ -2,7 +2,7 @@ package plugins ...@@ -2,7 +2,7 @@ package plugins
import ( import (
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
m "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
) )
func init() { func init() {
...@@ -12,7 +12,7 @@ func init() { ...@@ -12,7 +12,7 @@ func init() {
func (pm *PluginManager) updateAppDashboards() { func (pm *PluginManager) updateAppDashboards() {
pm.log.Debug("Looking for App Dashboard Updates") pm.log.Debug("Looking for App Dashboard Updates")
query := m.GetPluginSettingsQuery{OrgId: 0} query := models.GetPluginSettingsQuery{OrgId: 0}
if err := bus.Dispatch(&query); err != nil { if err := bus.Dispatch(&query); err != nil {
plog.Error("Failed to get all plugin settings", "error", err) plog.Error("Failed to get all plugin settings", "error", err)
...@@ -44,7 +44,7 @@ func autoUpdateAppDashboard(pluginDashInfo *PluginDashboardInfoDTO, orgId int64) ...@@ -44,7 +44,7 @@ func autoUpdateAppDashboard(pluginDashInfo *PluginDashboardInfoDTO, orgId int64)
PluginId: pluginDashInfo.PluginId, PluginId: pluginDashInfo.PluginId,
Overwrite: true, Overwrite: true,
Dashboard: dash.Data, Dashboard: dash.Data,
User: &m.SignedInUser{UserId: 0, OrgRole: m.ROLE_ADMIN}, User: &models.SignedInUser{UserId: 0, OrgRole: models.ROLE_ADMIN},
Path: pluginDashInfo.Path, Path: pluginDashInfo.Path,
} }
...@@ -68,7 +68,7 @@ func syncPluginDashboards(pluginDef *PluginBase, orgId int64) { ...@@ -68,7 +68,7 @@ func syncPluginDashboards(pluginDef *PluginBase, orgId int64) {
if dash.Removed { if dash.Removed {
plog.Info("Deleting plugin dashboard", "pluginId", pluginDef.Id, "dashboard", dash.Slug) plog.Info("Deleting plugin dashboard", "pluginId", pluginDef.Id, "dashboard", dash.Slug)
deleteCmd := m.DeleteDashboardCommand{OrgId: orgId, Id: dash.DashboardId} deleteCmd := models.DeleteDashboardCommand{OrgId: orgId, Id: dash.DashboardId}
if err := bus.Dispatch(&deleteCmd); err != nil { if err := bus.Dispatch(&deleteCmd); err != nil {
plog.Error("Failed to auto update app dashboard", "pluginId", pluginDef.Id, "error", err) plog.Error("Failed to auto update app dashboard", "pluginId", pluginDef.Id, "error", err)
return return
...@@ -87,14 +87,14 @@ func syncPluginDashboards(pluginDef *PluginBase, orgId int64) { ...@@ -87,14 +87,14 @@ func syncPluginDashboards(pluginDef *PluginBase, orgId int64) {
} }
// update version in plugin_setting table to mark that we have processed the update // update version in plugin_setting table to mark that we have processed the update
query := m.GetPluginSettingByIdQuery{PluginId: pluginDef.Id, OrgId: orgId} query := models.GetPluginSettingByIdQuery{PluginId: pluginDef.Id, OrgId: orgId}
if err := bus.Dispatch(&query); err != nil { if err := bus.Dispatch(&query); err != nil {
plog.Error("Failed to read plugin setting by id", "error", err) plog.Error("Failed to read plugin setting by id", "error", err)
return return
} }
appSetting := query.Result appSetting := query.Result
cmd := m.UpdatePluginSettingVersionCmd{ cmd := models.UpdatePluginSettingVersionCmd{
OrgId: appSetting.OrgId, OrgId: appSetting.OrgId,
PluginId: appSetting.PluginId, PluginId: appSetting.PluginId,
PluginVersion: pluginDef.Info.Version, PluginVersion: pluginDef.Info.Version,
...@@ -105,19 +105,19 @@ func syncPluginDashboards(pluginDef *PluginBase, orgId int64) { ...@@ -105,19 +105,19 @@ func syncPluginDashboards(pluginDef *PluginBase, orgId int64) {
} }
} }
func handlePluginStateChanged(event *m.PluginStateChangedEvent) error { func handlePluginStateChanged(event *models.PluginStateChangedEvent) error {
plog.Info("Plugin state changed", "pluginId", event.PluginId, "enabled", event.Enabled) plog.Info("Plugin state changed", "pluginId", event.PluginId, "enabled", event.Enabled)
if event.Enabled { if event.Enabled {
syncPluginDashboards(Plugins[event.PluginId], event.OrgId) syncPluginDashboards(Plugins[event.PluginId], event.OrgId)
} else { } else {
query := m.GetDashboardsByPluginIdQuery{PluginId: event.PluginId, OrgId: event.OrgId} query := models.GetDashboardsByPluginIdQuery{PluginId: event.PluginId, OrgId: event.OrgId}
if err := bus.Dispatch(&query); err != nil { if err := bus.Dispatch(&query); err != nil {
return err return err
} }
for _, dash := range query.Result { for _, dash := range query.Result {
deleteCmd := m.DeleteDashboardCommand{OrgId: dash.OrgId, Id: dash.Id} deleteCmd := models.DeleteDashboardCommand{OrgId: dash.OrgId, Id: dash.Id}
plog.Info("Deleting plugin dashboard", "pluginId", event.PluginId, "dashboard", dash.Slug) plog.Info("Deleting plugin dashboard", "pluginId", event.PluginId, "dashboard", dash.Slug)
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"strings" "strings"
m "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/plugins/backendplugin" "github.com/grafana/grafana/pkg/plugins/backendplugin"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
...@@ -78,7 +78,7 @@ func (pb *PluginBase) registerPlugin(pluginDir string) error { ...@@ -78,7 +78,7 @@ func (pb *PluginBase) registerPlugin(pluginDir string) error {
for _, include := range pb.Includes { for _, include := range pb.Includes {
if include.Role == "" { if include.Role == "" {
include.Role = m.ROLE_VIEWER include.Role = models.ROLE_VIEWER
} }
} }
...@@ -93,14 +93,14 @@ type PluginDependencies struct { ...@@ -93,14 +93,14 @@ type PluginDependencies struct {
} }
type PluginInclude struct { type PluginInclude struct {
Name string `json:"name"` Name string `json:"name"`
Path string `json:"path"` Path string `json:"path"`
Type string `json:"type"` Type string `json:"type"`
Component string `json:"component"` Component string `json:"component"`
Role m.RoleType `json:"role"` Role models.RoleType `json:"role"`
AddToNav bool `json:"addToNav"` AddToNav bool `json:"addToNav"`
DefaultNav bool `json:"defaultNav"` DefaultNav bool `json:"defaultNav"`
Slug string `json:"slug"` Slug string `json:"slug"`
Id string `json:"-"` Id string `json:"-"`
} }
......
...@@ -2,17 +2,17 @@ package plugins ...@@ -2,17 +2,17 @@ package plugins
import ( import (
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
m "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
) )
func GetPluginSettings(orgId int64) (map[string]*m.PluginSettingInfoDTO, error) { func GetPluginSettings(orgId int64) (map[string]*models.PluginSettingInfoDTO, error) {
query := m.GetPluginSettingsQuery{OrgId: orgId} query := models.GetPluginSettingsQuery{OrgId: orgId}
if err := bus.Dispatch(&query); err != nil { if err := bus.Dispatch(&query); err != nil {
return nil, err return nil, err
} }
pluginMap := make(map[string]*m.PluginSettingInfoDTO) pluginMap := make(map[string]*models.PluginSettingInfoDTO)
for _, plug := range query.Result { for _, plug := range query.Result {
pluginMap[plug.PluginId] = plug pluginMap[plug.PluginId] = plug
} }
...@@ -24,7 +24,7 @@ func GetPluginSettings(orgId int64) (map[string]*m.PluginSettingInfoDTO, error) ...@@ -24,7 +24,7 @@ func GetPluginSettings(orgId int64) (map[string]*m.PluginSettingInfoDTO, error)
} }
// default to enabled true // default to enabled true
opt := &m.PluginSettingInfoDTO{ opt := &models.PluginSettingInfoDTO{
PluginId: pluginDef.Id, PluginId: pluginDef.Id,
OrgId: orgId, OrgId: orgId,
Enabled: true, Enabled: true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment