Commit 67ec9edc by Carl Bergquist Committed by GitHub

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

parent f2f2722b
package dtos
import m "github.com/grafana/grafana/pkg/models"
import "github.com/grafana/grafana/pkg/models"
type AddInviteForm struct {
LoginOrEmail string `json:"loginOrEmail" binding:"Required"`
Name string `json:"name"`
Role m.RoleType `json:"role" binding:"Required"`
SendEmail bool `json:"sendEmail"`
LoginOrEmail string `json:"loginOrEmail" binding:"Required"`
Name string `json:"name"`
Role models.RoleType `json:"role" binding:"Required"`
SendEmail bool `json:"sendEmail"`
}
type InviteInfo struct {
......
......@@ -7,7 +7,7 @@ import (
"github.com/grafana/grafana/pkg/bus"
"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"
)
......@@ -19,7 +19,7 @@ type ImportDashboardCommand struct {
FolderId int64
OrgId int64
User *m.SignedInUser
User *models.SignedInUser
PluginId string
Result *PluginDashboardInfoDTO
}
......@@ -44,7 +44,7 @@ func init() {
}
func ImportDashboard(cmd *ImportDashboardCommand) error {
var dashboard *m.Dashboard
var dashboard *models.Dashboard
var err error
if cmd.PluginId != "" {
......@@ -52,7 +52,7 @@ func ImportDashboard(cmd *ImportDashboardCommand) error {
return err
}
} else {
dashboard = m.NewDashboardFromJson(cmd.Dashboard)
dashboard = models.NewDashboardFromJson(cmd.Dashboard)
}
evaluator := &DashTemplateEvaluator{
......@@ -65,7 +65,7 @@ func ImportDashboard(cmd *ImportDashboardCommand) error {
return err
}
saveCmd := m.SaveDashboardCommand{
saveCmd := models.SaveDashboardCommand{
Dashboard: generatedDash,
OrgId: cmd.OrgId,
UserId: cmd.User.UserId,
......
......@@ -5,7 +5,7 @@ import (
"testing"
"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/setting"
. "github.com/smartystreets/goconvey/convey"
......@@ -22,7 +22,7 @@ func TestDashboardImport(t *testing.T) {
PluginId: "test-app",
Path: "dashboards/connections.json",
OrgId: 1,
User: &m.SignedInUser{UserId: 1, OrgRole: m.ROLE_ADMIN},
User: &models.SignedInUser{UserId: 1, OrgRole: models.ROLE_ADMIN},
Inputs: []ImportDashboardInput{
{Name: "*", Type: "datasource", Value: "graphite"},
},
......
......@@ -6,7 +6,7 @@ import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/components/simplejson"
m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/models"
)
type PluginDashboardInfoDTO struct {
......@@ -35,7 +35,7 @@ func GetPluginDashboards(orgId int64, pluginId string) ([]*PluginDashboardInfoDT
result := make([]*PluginDashboardInfoDTO, 0)
// load current dashboards
query := m.GetDashboardsByPluginIdQuery{OrgId: orgId, PluginId: pluginId}
query := models.GetDashboardsByPluginIdQuery{OrgId: orgId, PluginId: pluginId}
if err := bus.Dispatch(&query); err != nil {
return nil, err
}
......@@ -48,7 +48,7 @@ func GetPluginDashboards(orgId int64, pluginId string) ([]*PluginDashboardInfoDT
}
res := &PluginDashboardInfoDTO{}
var dashboard *m.Dashboard
var dashboard *models.Dashboard
var err error
if dashboard, err = loadPluginDashboard(plugin.Id, include.Path); err != nil {
......@@ -89,7 +89,7 @@ func GetPluginDashboards(orgId int64, pluginId string) ([]*PluginDashboardInfoDT
return result, nil
}
func loadPluginDashboard(pluginId, path string) (*m.Dashboard, error) {
func loadPluginDashboard(pluginId, path string) (*models.Dashboard, error) {
plugin, exists := Plugins[pluginId]
if !exists {
......@@ -109,5 +109,5 @@ func loadPluginDashboard(pluginId, path string) (*m.Dashboard, error) {
return nil, err
}
return m.NewDashboardFromJson(data), nil
return models.NewDashboardFromJson(data), nil
}
......@@ -5,7 +5,7 @@ import (
"github.com/grafana/grafana/pkg/bus"
"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/smartystreets/goconvey/convey"
"gopkg.in/ini.v1"
......@@ -22,23 +22,23 @@ func TestPluginDashboards(t *testing.T) {
err = pm.Init()
So(err, ShouldBeNil)
bus.AddHandler("test", func(query *m.GetDashboardQuery) error {
bus.AddHandler("test", func(query *models.GetDashboardQuery) error {
if query.Slug == "nginx-connections" {
dash := m.NewDashboard("Nginx Connections")
dash := models.NewDashboard("Nginx Connections")
dash.Data.Set("revision", "1.1")
query.Result = dash
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()
data.Set("title", "Nginx Connections")
data.Set("revision", 22)
query.Result = []*m.Dashboard{
query.Result = []*models.Dashboard{
{Slug: "nginx-connections", Data: data},
}
return nil
......
......@@ -2,7 +2,7 @@ package plugins
import (
"github.com/grafana/grafana/pkg/bus"
m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/models"
)
func init() {
......@@ -12,7 +12,7 @@ func init() {
func (pm *PluginManager) updateAppDashboards() {
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 {
plog.Error("Failed to get all plugin settings", "error", err)
......@@ -44,7 +44,7 @@ func autoUpdateAppDashboard(pluginDashInfo *PluginDashboardInfoDTO, orgId int64)
PluginId: pluginDashInfo.PluginId,
Overwrite: true,
Dashboard: dash.Data,
User: &m.SignedInUser{UserId: 0, OrgRole: m.ROLE_ADMIN},
User: &models.SignedInUser{UserId: 0, OrgRole: models.ROLE_ADMIN},
Path: pluginDashInfo.Path,
}
......@@ -68,7 +68,7 @@ func syncPluginDashboards(pluginDef *PluginBase, orgId int64) {
if dash.Removed {
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 {
plog.Error("Failed to auto update app dashboard", "pluginId", pluginDef.Id, "error", err)
return
......@@ -87,14 +87,14 @@ func syncPluginDashboards(pluginDef *PluginBase, orgId int64) {
}
// 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 {
plog.Error("Failed to read plugin setting by id", "error", err)
return
}
appSetting := query.Result
cmd := m.UpdatePluginSettingVersionCmd{
cmd := models.UpdatePluginSettingVersionCmd{
OrgId: appSetting.OrgId,
PluginId: appSetting.PluginId,
PluginVersion: pluginDef.Info.Version,
......@@ -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)
if event.Enabled {
syncPluginDashboards(Plugins[event.PluginId], event.OrgId)
} 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 {
return err
}
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)
......
......@@ -5,7 +5,7 @@ import (
"fmt"
"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/setting"
)
......@@ -78,7 +78,7 @@ func (pb *PluginBase) registerPlugin(pluginDir string) error {
for _, include := range pb.Includes {
if include.Role == "" {
include.Role = m.ROLE_VIEWER
include.Role = models.ROLE_VIEWER
}
}
......@@ -93,14 +93,14 @@ type PluginDependencies struct {
}
type PluginInclude struct {
Name string `json:"name"`
Path string `json:"path"`
Type string `json:"type"`
Component string `json:"component"`
Role m.RoleType `json:"role"`
AddToNav bool `json:"addToNav"`
DefaultNav bool `json:"defaultNav"`
Slug string `json:"slug"`
Name string `json:"name"`
Path string `json:"path"`
Type string `json:"type"`
Component string `json:"component"`
Role models.RoleType `json:"role"`
AddToNav bool `json:"addToNav"`
DefaultNav bool `json:"defaultNav"`
Slug string `json:"slug"`
Id string `json:"-"`
}
......
......@@ -2,17 +2,17 @@ package plugins
import (
"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) {
query := m.GetPluginSettingsQuery{OrgId: orgId}
func GetPluginSettings(orgId int64) (map[string]*models.PluginSettingInfoDTO, error) {
query := models.GetPluginSettingsQuery{OrgId: orgId}
if err := bus.Dispatch(&query); err != nil {
return nil, err
}
pluginMap := make(map[string]*m.PluginSettingInfoDTO)
pluginMap := make(map[string]*models.PluginSettingInfoDTO)
for _, plug := range query.Result {
pluginMap[plug.PluginId] = plug
}
......@@ -24,7 +24,7 @@ func GetPluginSettings(orgId int64) (map[string]*m.PluginSettingInfoDTO, error)
}
// default to enabled true
opt := &m.PluginSettingInfoDTO{
opt := &models.PluginSettingInfoDTO{
PluginId: pluginDef.Id,
OrgId: orgId,
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