mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Remove dashboards from models pkg (#61578)
* Copy dashboard models to dashboard pkg * Use some models from current pkg instead of models * Adjust api pkg * Adjust pkg services * Fix lint * Chore: Remove dashboards models * Remove dashboards from models pkg * Fix lint in tests * Fix lint in tests 2 * Fix for import in auth * Remove newline * Revert unused fix
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/alerting"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/notifier/channels_config"
|
||||
@@ -147,7 +148,7 @@ func (hs *HTTPServer) GetAlerts(c *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
for _, alert := range query.Result {
|
||||
alert.Url = models.GetDashboardUrl(alert.DashboardUid, alert.DashboardSlug)
|
||||
alert.Url = dashboards.GetDashboardURL(alert.DashboardUid, alert.DashboardSlug)
|
||||
}
|
||||
|
||||
return response.JSON(http.StatusOK, query.Result)
|
||||
|
||||
@@ -64,7 +64,7 @@ func dashboardGuardianResponse(err error) response.Response {
|
||||
// 401: unauthorisedError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) TrimDashboard(c *models.ReqContext) response.Response {
|
||||
cmd := models.TrimDashboardCommand{}
|
||||
cmd := dashboards.TrimDashboardCommand{}
|
||||
if err := web.Bind(c.Req, &cmd); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
}
|
||||
@@ -169,7 +169,7 @@ func (hs *HTTPServer) GetDashboard(c *models.ReqContext) response.Response {
|
||||
meta := dtos.DashboardMeta{
|
||||
IsStarred: isStarred,
|
||||
Slug: dash.Slug,
|
||||
Type: models.DashTypeDB,
|
||||
Type: dashboards.DashTypeDB,
|
||||
CanStar: c.IsSignedIn,
|
||||
CanSave: canSave,
|
||||
CanEdit: canEdit,
|
||||
@@ -217,7 +217,7 @@ func (hs *HTTPServer) GetDashboard(c *models.ReqContext) response.Response {
|
||||
|
||||
meta.ProvisionedExternalId, err = filepath.Rel(
|
||||
hs.ProvisioningService.GetDashboardProvisionerResolvedPath(provisioningData.Name),
|
||||
provisioningData.ExternalId,
|
||||
provisioningData.ExternalID,
|
||||
)
|
||||
if err != nil {
|
||||
// Not sure when this could happen so not sure how to better handle this. Right now ProvisionedExternalId
|
||||
@@ -429,7 +429,7 @@ func (hs *HTTPServer) postDashboard(c *models.ReqContext, cmd dashboards.SaveDas
|
||||
}
|
||||
}
|
||||
|
||||
var provisioningData *models.DashboardProvisioning
|
||||
var provisioningData *dashboards.DashboardProvisioning
|
||||
if dash.ID != 0 {
|
||||
data, err := hs.dashboardProvisioningService.GetProvisionedDashboardDataByDashboardID(c.Req.Context(), dash.ID)
|
||||
if err != nil {
|
||||
@@ -536,7 +536,7 @@ func (hs *HTTPServer) GetHomeDashboard(c *models.ReqContext) response.Response {
|
||||
slugQuery := dashboards.GetDashboardRefByIDQuery{ID: preference.HomeDashboardID}
|
||||
err := hs.DashboardService.GetDashboardUIDByID(c.Req.Context(), &slugQuery)
|
||||
if err == nil {
|
||||
url := models.GetDashboardUrl(slugQuery.Result.UID, slugQuery.Result.Slug)
|
||||
url := dashboards.GetDashboardURL(slugQuery.Result.UID, slugQuery.Result.Slug)
|
||||
dashRedirect := dtos.DashboardRedirect{RedirectUri: url}
|
||||
return response.JSON(http.StatusOK, &dashRedirect)
|
||||
}
|
||||
@@ -786,7 +786,7 @@ func (hs *HTTPServer) GetDashboardVersion(c *models.ReqContext) response.Respons
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) ValidateDashboard(c *models.ReqContext) response.Response {
|
||||
cmd := models.ValidateDashboardCommand{}
|
||||
cmd := dashboards.ValidateDashboardCommand{}
|
||||
|
||||
if err := web.Bind(c.Req, &cmd); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
@@ -1018,7 +1018,7 @@ func (hs *HTTPServer) RestoreDashboardVersion(c *models.ReqContext) response.Res
|
||||
// 401: unauthorisedError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) GetDashboardTags(c *models.ReqContext) {
|
||||
query := models.GetDashboardTagsQuery{OrgId: c.OrgID}
|
||||
query := dashboards.GetDashboardTagsQuery{OrgID: c.OrgID}
|
||||
err := hs.DashboardService.GetDashboardTags(c.Req.Context(), &query)
|
||||
if err != nil {
|
||||
c.JsonApiErr(500, "Failed to get tags from database", err)
|
||||
@@ -1137,7 +1137,7 @@ type DeleteDashboardByUIDParams struct {
|
||||
type PostDashboardParams struct {
|
||||
// in:body
|
||||
// required:true
|
||||
Body models.SaveDashboardCommand
|
||||
Body dashboards.SaveDashboardCommand
|
||||
}
|
||||
|
||||
// swagger:parameters calculateDashboardDiff
|
||||
@@ -1160,7 +1160,7 @@ type CalcDashboardDiffParams struct {
|
||||
type TrimDashboardParams struct {
|
||||
// in:body
|
||||
// required:true
|
||||
Body models.TrimDashboardCommand
|
||||
Body dashboards.TrimDashboardCommand
|
||||
}
|
||||
|
||||
// swagger:response dashboardResponse
|
||||
@@ -1249,7 +1249,7 @@ type GetHomeDashboardResponse struct {
|
||||
// swagger:response getDashboardsTagsResponse
|
||||
type DashboardsTagsResponse struct {
|
||||
// in: body
|
||||
Body []*models.DashboardTagCloudItem `json:"body"`
|
||||
Body []*dashboards.DashboardTagCloudItem `json:"body"`
|
||||
}
|
||||
|
||||
// Get home dashboard response.
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
@@ -82,7 +83,7 @@ func (hs *HTTPServer) GetDashboardPermissionList(c *models.ReqContext) response.
|
||||
perm.TeamAvatarUrl = dtos.GetGravatarUrlWithDefault(perm.TeamEmail, perm.Team)
|
||||
}
|
||||
if perm.Slug != "" {
|
||||
perm.Url = models.GetDashboardFolderUrl(perm.IsFolder, perm.Uid, perm.Slug)
|
||||
perm.Url = dashboards.GetDashboardFolderURL(perm.IsFolder, perm.Uid, perm.Slug)
|
||||
}
|
||||
|
||||
filteredACLs = append(filteredACLs, perm)
|
||||
|
||||
@@ -216,7 +216,7 @@ func (hs *HTTPServer) GetDashboardSnapshot(c *models.ReqContext) response.Respon
|
||||
dto := dtos.DashboardFullWithMeta{
|
||||
Dashboard: snapshot.Dashboard,
|
||||
Meta: dtos.DashboardMeta{
|
||||
Type: models.DashTypeSnapshot,
|
||||
Type: dashboards.DashTypeSnapshot,
|
||||
IsSnapshot: true,
|
||||
Created: snapshot.Created,
|
||||
Expires: snapshot.Expires,
|
||||
|
||||
@@ -578,14 +578,14 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Given two dashboards with the same title in different folders", func(t *testing.T) {
|
||||
dashOne := models.NewDashboard("dash")
|
||||
dashOne.Id = 2
|
||||
dashOne.FolderId = 1
|
||||
dashOne := dashboards.NewDashboard("dash")
|
||||
dashOne.ID = 2
|
||||
dashOne.FolderID = 1
|
||||
dashOne.HasACL = false
|
||||
|
||||
dashTwo := models.NewDashboard("dash")
|
||||
dashTwo.Id = 4
|
||||
dashTwo.FolderId = 3
|
||||
dashTwo := dashboards.NewDashboard("dash")
|
||||
dashTwo.ID = 4
|
||||
dashTwo.FolderID = 3
|
||||
dashTwo.HasACL = false
|
||||
})
|
||||
|
||||
@@ -597,14 +597,14 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
const folderID int64 = 3
|
||||
const dashID int64 = 2
|
||||
|
||||
cmd := models.SaveDashboardCommand{
|
||||
OrgId: 1,
|
||||
UserId: 5,
|
||||
cmd := dashboards.SaveDashboardCommand{
|
||||
OrgID: 1,
|
||||
UserID: 5,
|
||||
Dashboard: simplejson.NewFromAny(map[string]interface{}{
|
||||
"title": "Dash",
|
||||
}),
|
||||
Overwrite: true,
|
||||
FolderId: folderID,
|
||||
FolderID: folderID,
|
||||
IsFolder: false,
|
||||
Message: "msg",
|
||||
}
|
||||
@@ -629,14 +629,14 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
const folderUid string = "folderUID"
|
||||
const dashID int64 = 2
|
||||
|
||||
cmd := models.SaveDashboardCommand{
|
||||
OrgId: 1,
|
||||
UserId: 5,
|
||||
cmd := dashboards.SaveDashboardCommand{
|
||||
OrgID: 1,
|
||||
UserID: 5,
|
||||
Dashboard: simplejson.NewFromAny(map[string]interface{}{
|
||||
"title": "Dash",
|
||||
}),
|
||||
Overwrite: true,
|
||||
FolderUid: folderUid,
|
||||
FolderUID: folderUid,
|
||||
IsFolder: false,
|
||||
Message: "msg",
|
||||
}
|
||||
@@ -662,14 +662,14 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Given a request with incorrect folder uid for creating a dashboard with", func(t *testing.T) {
|
||||
cmd := models.SaveDashboardCommand{
|
||||
OrgId: 1,
|
||||
UserId: 5,
|
||||
cmd := dashboards.SaveDashboardCommand{
|
||||
OrgID: 1,
|
||||
UserID: 5,
|
||||
Dashboard: simplejson.NewFromAny(map[string]interface{}{
|
||||
"title": "Dash",
|
||||
}),
|
||||
Overwrite: true,
|
||||
FolderUid: "folderUID",
|
||||
FolderUID: "folderUID",
|
||||
IsFolder: false,
|
||||
Message: "msg",
|
||||
}
|
||||
@@ -712,8 +712,8 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
{SaveError: dashboards.UpdatePluginDashboardError{PluginId: "plug"}, ExpectedStatusCode: 412},
|
||||
}
|
||||
|
||||
cmd := models.SaveDashboardCommand{
|
||||
OrgId: 1,
|
||||
cmd := dashboards.SaveDashboardCommand{
|
||||
OrgID: 1,
|
||||
Dashboard: simplejson.NewFromAny(map[string]interface{}{
|
||||
"title": "",
|
||||
}),
|
||||
@@ -736,7 +736,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
sqlmock := mockstore.SQLStoreMock{}
|
||||
|
||||
t.Run("When an invalid dashboard json is posted", func(t *testing.T) {
|
||||
cmd := models.ValidateDashboardCommand{
|
||||
cmd := dashboards.ValidateDashboardCommand{
|
||||
Dashboard: "{\"hello\": \"world\"}",
|
||||
}
|
||||
|
||||
@@ -752,7 +752,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("When a dashboard with a too-low schema version is posted", func(t *testing.T) {
|
||||
cmd := models.ValidateDashboardCommand{
|
||||
cmd := dashboards.ValidateDashboardCommand{
|
||||
Dashboard: "{\"schemaVersion\": 1}",
|
||||
}
|
||||
|
||||
@@ -771,7 +771,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
devenvDashboard, readErr := os.ReadFile("../../devenv/dev-dashboards/home.json")
|
||||
assert.Empty(t, readErr)
|
||||
|
||||
cmd := models.ValidateDashboardCommand{
|
||||
cmd := dashboards.ValidateDashboardCommand{
|
||||
Dashboard: string(devenvDashboard),
|
||||
}
|
||||
|
||||
@@ -930,7 +930,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
t.Run("Given provisioned dashboard", func(t *testing.T) {
|
||||
mockSQLStore := mockstore.NewSQLStoreMock()
|
||||
dashboardStore := dashboards.NewFakeDashboardStore(t)
|
||||
dashboardStore.On("GetProvisionedDataByDashboardID", mock.Anything, mock.AnythingOfType("int64")).Return(&models.DashboardProvisioning{ExternalId: "/dashboard1.json"}, nil).Once()
|
||||
dashboardStore.On("GetProvisionedDataByDashboardID", mock.Anything, mock.AnythingOfType("int64")).Return(&dashboards.DashboardProvisioning{ExternalID: "/dashboard1.json"}, nil).Once()
|
||||
|
||||
teamService := &teamtest.FakeService{}
|
||||
dashboardService := dashboards.NewFakeDashboardService(t)
|
||||
@@ -1086,7 +1086,7 @@ func callPostDashboardShouldReturnSuccess(sc *scenarioContext) {
|
||||
assert.Equal(sc.t, 200, sc.resp.Code)
|
||||
}
|
||||
|
||||
func postDashboardScenario(t *testing.T, desc string, url string, routePattern string, cmd models.SaveDashboardCommand, dashboardService dashboards.DashboardService, folderService folder.Service, fn scenarioFunc) {
|
||||
func postDashboardScenario(t *testing.T, desc string, url string, routePattern string, cmd dashboards.SaveDashboardCommand, dashboardService dashboards.DashboardService, folderService folder.Service, fn scenarioFunc) {
|
||||
t.Run(fmt.Sprintf("%s %s", desc, url), func(t *testing.T) {
|
||||
cfg := setting.NewCfg()
|
||||
hs := HTTPServer{
|
||||
@@ -1109,7 +1109,7 @@ func postDashboardScenario(t *testing.T, desc string, url string, routePattern s
|
||||
c.Req.Body = mockRequestBody(cmd)
|
||||
c.Req.Header.Add("Content-Type", "application/json")
|
||||
sc.context = c
|
||||
sc.context.SignedInUser = &user.SignedInUser{OrgID: cmd.OrgId, UserID: cmd.UserId}
|
||||
sc.context.SignedInUser = &user.SignedInUser{OrgID: cmd.OrgID, UserID: cmd.UserID}
|
||||
|
||||
return hs.PostDashboard(c)
|
||||
})
|
||||
@@ -1120,7 +1120,7 @@ func postDashboardScenario(t *testing.T, desc string, url string, routePattern s
|
||||
})
|
||||
}
|
||||
|
||||
func postValidateScenario(t *testing.T, desc string, url string, routePattern string, cmd models.ValidateDashboardCommand,
|
||||
func postValidateScenario(t *testing.T, desc string, url string, routePattern string, cmd dashboards.ValidateDashboardCommand,
|
||||
role org.RoleType, fn scenarioFunc, sqlmock db.DB) {
|
||||
t.Run(fmt.Sprintf("%s %s", desc, url), func(t *testing.T) {
|
||||
cfg := setting.NewCfg()
|
||||
@@ -1250,7 +1250,7 @@ type mockDashboardProvisioningService struct {
|
||||
}
|
||||
|
||||
func (s mockDashboardProvisioningService) GetProvisionedDashboardDataByDashboardID(ctx context.Context, dashboardID int64) (
|
||||
*models.DashboardProvisioning, error) {
|
||||
*dashboards.DashboardProvisioning, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ func (hs *HTTPServer) GetFolderPermissionList(c *models.ReqContext) response.Res
|
||||
}
|
||||
|
||||
if perm.Slug != "" {
|
||||
perm.Url = models.GetDashboardFolderUrl(perm.IsFolder, perm.Uid, perm.Slug)
|
||||
perm.Url = dashboards.GetDashboardFolderURL(perm.IsFolder, perm.Uid, perm.Slug)
|
||||
}
|
||||
|
||||
filteredACLs = append(filteredACLs, perm)
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
_ "github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/playlist"
|
||||
"github.com/grafana/grafana/pkg/services/search"
|
||||
@@ -30,7 +29,7 @@ func (hs *HTTPServer) populateDashboardsByID(ctx context.Context, dashboardByIDs
|
||||
Slug: item.Slug,
|
||||
Title: item.Title,
|
||||
Uri: "db/" + item.Slug,
|
||||
Url: models.GetDashboardUrl(item.UID, item.Slug),
|
||||
Url: dashboards.GetDashboardURL(item.UID, item.Slug),
|
||||
Order: dashboardIDOrder[item.ID],
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user