mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 22:12:34 +08:00
add isPublic to dashboard (#48012)
adds toggle to make a dashboard public * config struct for public dashboard config * api endpoints for public dashboard configuration * ui for toggling public dashboard on and off * load public dashboard config on share modal Co-authored-by: Owen Smallwood <owen.smallwood@grafana.com> Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
This commit is contained in:
56
pkg/api/dashboard_public_config.go
Normal file
56
pkg/api/dashboard_public_config.go
Normal file
@ -0,0 +1,56 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
// Sets sharing configuration for dashboard
|
||||
func (hs *HTTPServer) GetPublicDashboard(c *models.ReqContext) response.Response {
|
||||
pdc, err := hs.dashboardService.GetPublicDashboardConfig(c.Req.Context(), c.OrgId, web.Params(c.Req)[":uid"])
|
||||
|
||||
if errors.Is(err, models.ErrDashboardNotFound) {
|
||||
return response.Error(http.StatusNotFound, "dashboard not found", err)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "error retrieving public dashboard config", err)
|
||||
}
|
||||
|
||||
return response.JSON(http.StatusOK, pdc)
|
||||
}
|
||||
|
||||
// Sets sharing configuration for dashboard
|
||||
func (hs *HTTPServer) SavePublicDashboard(c *models.ReqContext) response.Response {
|
||||
pdc := &models.PublicDashboardConfig{}
|
||||
|
||||
if err := web.Bind(c.Req, pdc); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
}
|
||||
|
||||
dto := dashboards.SavePublicDashboardConfigDTO{
|
||||
OrgId: c.OrgId,
|
||||
Uid: web.Params(c.Req)[":uid"],
|
||||
PublicDashboardConfig: *pdc,
|
||||
}
|
||||
|
||||
pdc, err := hs.dashboardService.SavePublicDashboardConfig(c.Req.Context(), &dto)
|
||||
|
||||
fmt.Println("err:", err)
|
||||
|
||||
if errors.Is(err, models.ErrDashboardNotFound) {
|
||||
return response.Error(http.StatusNotFound, "dashboard not found", err)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "error updating public dashboard config", err)
|
||||
}
|
||||
|
||||
return response.JSON(http.StatusOK, pdc)
|
||||
}
|
Reference in New Issue
Block a user