publicdashboards: split create/update api paths (#57940)
This PR splits the create and update paths for public dashboards and includes assorted refactors toward a proper REST API. Additionally, we removed the concept of a "public dashboard config" in favor of "public dashboard" Co-authored-by: juanicabanas <juan.cabanas@grafana.com> Co-authored-by: Ezequiel Victorero <ezequiel.victorero@grafana.com>
This commit is contained in:
co-authored by
juanicabanas
Ezequiel Victorero
parent
0367f61bb3
commit
6fcc5b42c0
+16
-5
@@ -28,6 +28,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
pref "github.com/grafana/grafana/pkg/services/preference"
|
||||
publicdashboardModels "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||
"github.com/grafana/grafana/pkg/services/star"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
@@ -100,14 +101,23 @@ func (hs *HTTPServer) GetDashboard(c *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
var (
|
||||
hasPublicDashboard bool
|
||||
err error
|
||||
hasPublicDashboard = false
|
||||
publicDashboardEnabled = false
|
||||
err error
|
||||
)
|
||||
|
||||
// If public dashboards is enabled and we have a public dashboard, update meta
|
||||
// values
|
||||
if hs.Features.IsEnabled(featuremgmt.FlagPublicDashboards) {
|
||||
hasPublicDashboard, err = hs.PublicDashboardsApi.PublicDashboardService.ExistsEnabledByDashboardUid(c.Req.Context(), dash.Uid)
|
||||
if err != nil {
|
||||
publicDashboard, err := hs.PublicDashboardsApi.PublicDashboardService.FindByDashboardUid(c.Req.Context(), c.OrgID, dash.Uid)
|
||||
if err != nil && !errors.Is(err, publicdashboardModels.ErrPublicDashboardNotFound) {
|
||||
return response.Error(500, "Error while retrieving public dashboards", err)
|
||||
}
|
||||
|
||||
if publicDashboard != nil {
|
||||
hasPublicDashboard = true
|
||||
publicDashboardEnabled = publicDashboard.IsEnabled
|
||||
}
|
||||
}
|
||||
|
||||
// When dash contains only keys id, uid that means dashboard data is not valid and json decode failed.
|
||||
@@ -172,7 +182,8 @@ func (hs *HTTPServer) GetDashboard(c *models.ReqContext) response.Response {
|
||||
Url: dash.GetUrl(),
|
||||
FolderTitle: "General",
|
||||
AnnotationsPermissions: annotationPermissions,
|
||||
PublicDashboardEnabled: hasPublicDashboard,
|
||||
PublicDashboardEnabled: publicDashboardEnabled,
|
||||
HasPublicDashboard: hasPublicDashboard,
|
||||
}
|
||||
|
||||
// lookup folder title
|
||||
|
||||
@@ -32,6 +32,7 @@ type DashboardMeta struct {
|
||||
Provisioned bool `json:"provisioned"`
|
||||
ProvisionedExternalId string `json:"provisionedExternalId"`
|
||||
AnnotationsPermissions *AnnotationPermission `json:"annotationsPermissions"`
|
||||
HasPublicDashboard bool `json:"hasPublicDashboard"`
|
||||
PublicDashboardAccessToken string `json:"publicDashboardAccessToken"`
|
||||
PublicDashboardUID string `json:"publicDashboardUid"`
|
||||
PublicDashboardEnabled bool `json:"publicDashboardEnabled"`
|
||||
|
||||
Reference in New Issue
Block a user