mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
PublicDashboards: Remove non updatable fields from DTO (#70871)
This commit is contained in:
parent
72581a77ac
commit
75a81e5b9f
@ -150,9 +150,9 @@ func (api *Api) CreatePublicDashboard(c *contextmodel.ReqContext) response.Respo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Always set the orgID and userID from the session
|
// Always set the orgID and userID from the session
|
||||||
pdDTO.OrgId = c.OrgID
|
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
UserId: c.UserID,
|
UserId: c.UserID,
|
||||||
|
OrgID: c.OrgID,
|
||||||
DashboardUid: dashboardUid,
|
DashboardUid: dashboardUid,
|
||||||
PublicDashboard: pdDTO,
|
PublicDashboard: pdDTO,
|
||||||
}
|
}
|
||||||
@ -167,7 +167,7 @@ func (api *Api) CreatePublicDashboard(c *contextmodel.ReqContext) response.Respo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdatePublicDashboard Sets public dashboard for dashboard
|
// UpdatePublicDashboard Sets public dashboard for dashboard
|
||||||
// PUT /api/dashboards/uid/:dashboardUid/public-dashboards/:uid
|
// PATCH /api/dashboards/uid/:dashboardUid/public-dashboards/:uid
|
||||||
func (api *Api) UpdatePublicDashboard(c *contextmodel.ReqContext) response.Response {
|
func (api *Api) UpdatePublicDashboard(c *contextmodel.ReqContext) response.Response {
|
||||||
// exit if we don't have a valid dashboardUid
|
// exit if we don't have a valid dashboardUid
|
||||||
dashboardUid := web.Params(c.Req)[":dashboardUid"]
|
dashboardUid := web.Params(c.Req)[":dashboardUid"]
|
||||||
@ -186,10 +186,10 @@ func (api *Api) UpdatePublicDashboard(c *contextmodel.ReqContext) response.Respo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Always set the orgID and userID from the session
|
// Always set the orgID and userID from the session
|
||||||
pdDTO.OrgId = c.OrgID
|
|
||||||
pdDTO.Uid = uid
|
|
||||||
dto := SavePublicDashboardDTO{
|
dto := SavePublicDashboardDTO{
|
||||||
|
Uid: uid,
|
||||||
UserId: c.UserID,
|
UserId: c.UserID,
|
||||||
|
OrgID: c.OrgID,
|
||||||
DashboardUid: dashboardUid,
|
DashboardUid: dashboardUid,
|
||||||
PublicDashboard: pdDTO,
|
PublicDashboard: pdDTO,
|
||||||
}
|
}
|
||||||
|
@ -313,9 +313,9 @@ func TestIntegrationUnauthenticatedUserCanGetPubdashPanelQueryData(t *testing.T)
|
|||||||
isEnabled := true
|
isEnabled := true
|
||||||
savePubDashboardCmd := &SavePublicDashboardDTO{
|
savePubDashboardCmd := &SavePublicDashboardDTO{
|
||||||
DashboardUid: dashboard.UID,
|
DashboardUid: dashboard.UID,
|
||||||
|
OrgID: dashboard.OrgID,
|
||||||
PublicDashboard: &PublicDashboardDTO{
|
PublicDashboard: &PublicDashboardDTO{
|
||||||
IsEnabled: &isEnabled,
|
IsEnabled: &isEnabled,
|
||||||
OrgId: dashboard.OrgID,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,21 +56,11 @@ type PublicDashboard struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PublicDashboardDTO struct {
|
type PublicDashboardDTO struct {
|
||||||
Uid string `json:"uid"`
|
|
||||||
DashboardUid string `json:"dashboardUid"`
|
|
||||||
OrgId int64 `json:"-"` // Don't ever marshal orgId to Json
|
|
||||||
AccessToken string `json:"accessToken"`
|
|
||||||
CreatedBy int64 `json:"createdBy"`
|
|
||||||
UpdatedBy int64 `json:"updatedBy"`
|
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
|
||||||
//config fields
|
|
||||||
TimeSettings *TimeSettings `json:"timeSettings"`
|
TimeSettings *TimeSettings `json:"timeSettings"`
|
||||||
TimeSelectionEnabled *bool `json:"timeSelectionEnabled"`
|
TimeSelectionEnabled *bool `json:"timeSelectionEnabled"`
|
||||||
IsEnabled *bool `json:"isEnabled"`
|
IsEnabled *bool `json:"isEnabled"`
|
||||||
AnnotationsEnabled *bool `json:"annotationsEnabled"`
|
AnnotationsEnabled *bool `json:"annotationsEnabled"`
|
||||||
Share ShareType `json:"share"`
|
Share ShareType `json:"share"`
|
||||||
Recipients []EmailDTO `json:"recipients,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmailDTO struct {
|
type EmailDTO struct {
|
||||||
@ -143,7 +133,9 @@ func (ts *TimeSettings) ToDB() ([]byte, error) {
|
|||||||
|
|
||||||
// DTO for transforming user input in the api
|
// DTO for transforming user input in the api
|
||||||
type SavePublicDashboardDTO struct {
|
type SavePublicDashboardDTO struct {
|
||||||
|
Uid string
|
||||||
DashboardUid string
|
DashboardUid string
|
||||||
|
OrgID int64
|
||||||
UserId int64
|
UserId int64
|
||||||
PublicDashboard *PublicDashboardDTO
|
PublicDashboard *PublicDashboardDTO
|
||||||
}
|
}
|
||||||
|
@ -704,10 +704,9 @@ func TestGetQueryDataResponse(t *testing.T) {
|
|||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
DashboardUid: dashboard.UID,
|
DashboardUid: dashboard.UID,
|
||||||
UserId: 7,
|
UserId: 7,
|
||||||
|
OrgID: dashboard.OrgID,
|
||||||
PublicDashboard: &PublicDashboardDTO{
|
PublicDashboard: &PublicDashboardDTO{
|
||||||
IsEnabled: &isEnabled,
|
IsEnabled: &isEnabled,
|
||||||
DashboardUid: "NOTTHESAME",
|
|
||||||
OrgId: dashboard.OrgID,
|
|
||||||
TimeSettings: timeSettings,
|
TimeSettings: timeSettings,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -1215,10 +1214,9 @@ func TestBuildMetricRequest(t *testing.T) {
|
|||||||
isEnabled := true
|
isEnabled := true
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
DashboardUid: publicDashboard.UID,
|
DashboardUid: publicDashboard.UID,
|
||||||
|
OrgID: 9999999,
|
||||||
PublicDashboard: &PublicDashboardDTO{
|
PublicDashboard: &PublicDashboardDTO{
|
||||||
IsEnabled: &isEnabled,
|
IsEnabled: &isEnabled,
|
||||||
DashboardUid: "NOTTHESAME",
|
|
||||||
OrgId: 9999999,
|
|
||||||
TimeSettings: timeSettings,
|
TimeSettings: timeSettings,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -1229,10 +1227,9 @@ func TestBuildMetricRequest(t *testing.T) {
|
|||||||
isEnabled = false
|
isEnabled = false
|
||||||
nonPublicDto := &SavePublicDashboardDTO{
|
nonPublicDto := &SavePublicDashboardDTO{
|
||||||
DashboardUid: nonPublicDashboard.UID,
|
DashboardUid: nonPublicDashboard.UID,
|
||||||
|
OrgID: 9999999,
|
||||||
PublicDashboard: &PublicDashboardDTO{
|
PublicDashboard: &PublicDashboardDTO{
|
||||||
IsEnabled: &isEnabled,
|
IsEnabled: &isEnabled,
|
||||||
DashboardUid: "NOTTHESAME",
|
|
||||||
OrgId: 9999999,
|
|
||||||
TimeSettings: defaultPubdashTimeSettings,
|
TimeSettings: defaultPubdashTimeSettings,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -208,11 +208,11 @@ func (pd *PublicDashboardServiceImpl) Update(ctx context.Context, u *user.Signed
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get existing public dashboard if exists
|
// get existing public dashboard if exists
|
||||||
existingPubdash, err := pd.store.Find(ctx, dto.PublicDashboard.Uid)
|
existingPubdash, err := pd.store.Find(ctx, dto.Uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrInternalServerError.Errorf("Update: failed to find public dashboard by uid: %s: %w", dto.PublicDashboard.Uid, err)
|
return nil, ErrInternalServerError.Errorf("Update: failed to find public dashboard by uid: %s: %w", dto.Uid, err)
|
||||||
} else if existingPubdash == nil {
|
} else if existingPubdash == nil {
|
||||||
return nil, ErrPublicDashboardNotFound.Errorf("Update: public dashboard not found by uid: %s", dto.PublicDashboard.Uid)
|
return nil, ErrPublicDashboardNotFound.Errorf("Update: public dashboard not found by uid: %s", dto.Uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
publicDashboard := newUpdatePublicDashboard(dto, existingPubdash)
|
publicDashboard := newUpdatePublicDashboard(dto, existingPubdash)
|
||||||
@ -230,7 +230,7 @@ func (pd *PublicDashboardServiceImpl) Update(ctx context.Context, u *user.Signed
|
|||||||
|
|
||||||
// 404 if not found
|
// 404 if not found
|
||||||
if affectedRows == 0 {
|
if affectedRows == 0 {
|
||||||
return nil, ErrPublicDashboardNotFound.Errorf("Update: failed to update public dashboard not found by uid: %s", dto.PublicDashboard.Uid)
|
return nil, ErrPublicDashboardNotFound.Errorf("Update: failed to update public dashboard not found by uid: %s", dto.Uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get latest public dashboard to return
|
// get latest public dashboard to return
|
||||||
@ -418,17 +418,21 @@ func (pd *PublicDashboardServiceImpl) newCreatePublicDashboard(ctx context.Conte
|
|||||||
share = PublicShareType
|
share = PublicShareType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
return &PublicDashboard{
|
return &PublicDashboard{
|
||||||
Uid: uid,
|
Uid: uid,
|
||||||
DashboardUid: dto.DashboardUid,
|
DashboardUid: dto.DashboardUid,
|
||||||
OrgId: dto.PublicDashboard.OrgId,
|
OrgId: dto.OrgID,
|
||||||
IsEnabled: isEnabled,
|
IsEnabled: isEnabled,
|
||||||
AnnotationsEnabled: annotationsEnabled,
|
AnnotationsEnabled: annotationsEnabled,
|
||||||
TimeSelectionEnabled: timeSelectionEnabled,
|
TimeSelectionEnabled: timeSelectionEnabled,
|
||||||
TimeSettings: timeSettings,
|
TimeSettings: timeSettings,
|
||||||
Share: share,
|
Share: share,
|
||||||
CreatedBy: dto.UserId,
|
CreatedBy: dto.UserId,
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: now,
|
||||||
|
UpdatedBy: dto.UserId,
|
||||||
|
UpdatedAt: now,
|
||||||
AccessToken: accessToken,
|
AccessToken: accessToken,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -210,13 +210,12 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
DashboardUid: dashboard.UID,
|
DashboardUid: dashboard.UID,
|
||||||
UserId: 7,
|
UserId: 7,
|
||||||
|
OrgID: dashboard.OrgID,
|
||||||
PublicDashboard: &PublicDashboardDTO{
|
PublicDashboard: &PublicDashboardDTO{
|
||||||
IsEnabled: &isEnabled,
|
IsEnabled: &isEnabled,
|
||||||
AnnotationsEnabled: &annotationsEnabled,
|
AnnotationsEnabled: &annotationsEnabled,
|
||||||
TimeSelectionEnabled: &timeSelectionEnabled,
|
TimeSelectionEnabled: &timeSelectionEnabled,
|
||||||
Share: EmailShareType,
|
Share: EmailShareType,
|
||||||
DashboardUid: "NOTTHESAME",
|
|
||||||
OrgId: dashboard.OrgID,
|
|
||||||
TimeSettings: timeSettings,
|
TimeSettings: timeSettings,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -298,13 +297,12 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
DashboardUid: dashboard.UID,
|
DashboardUid: dashboard.UID,
|
||||||
UserId: 7,
|
UserId: 7,
|
||||||
|
OrgID: dashboard.OrgID,
|
||||||
PublicDashboard: &PublicDashboardDTO{
|
PublicDashboard: &PublicDashboardDTO{
|
||||||
IsEnabled: tt.IsEnabled,
|
IsEnabled: tt.IsEnabled,
|
||||||
TimeSelectionEnabled: tt.TimeSelectionEnabled,
|
TimeSelectionEnabled: tt.TimeSelectionEnabled,
|
||||||
AnnotationsEnabled: tt.AnnotationsEnabled,
|
AnnotationsEnabled: tt.AnnotationsEnabled,
|
||||||
Share: PublicShareType,
|
Share: PublicShareType,
|
||||||
DashboardUid: "NOTTHESAME",
|
|
||||||
OrgId: dashboard.OrgID,
|
|
||||||
TimeSettings: timeSettings,
|
TimeSettings: timeSettings,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -338,11 +336,10 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
isEnabled := true
|
isEnabled := true
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
DashboardUid: dashboard.UID,
|
DashboardUid: dashboard.UID,
|
||||||
|
OrgID: dashboard.OrgID,
|
||||||
UserId: 7,
|
UserId: 7,
|
||||||
PublicDashboard: &PublicDashboardDTO{
|
PublicDashboard: &PublicDashboardDTO{
|
||||||
IsEnabled: &isEnabled,
|
IsEnabled: &isEnabled,
|
||||||
DashboardUid: "NOTTHESAME",
|
|
||||||
OrgId: dashboard.OrgID,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,11 +370,10 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
isEnabled := true
|
isEnabled := true
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
DashboardUid: dashboard.UID,
|
DashboardUid: dashboard.UID,
|
||||||
|
OrgID: dashboard.OrgID,
|
||||||
UserId: 7,
|
UserId: 7,
|
||||||
PublicDashboard: &PublicDashboardDTO{
|
PublicDashboard: &PublicDashboardDTO{
|
||||||
IsEnabled: &isEnabled,
|
IsEnabled: &isEnabled,
|
||||||
DashboardUid: "NOTTHESAME",
|
|
||||||
OrgId: dashboard.OrgID,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,11 +414,10 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
isEnabled := true
|
isEnabled := true
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
DashboardUid: "an-id",
|
DashboardUid: "an-id",
|
||||||
|
OrgID: dashboard.OrgID,
|
||||||
UserId: 7,
|
UserId: 7,
|
||||||
PublicDashboard: &PublicDashboardDTO{
|
PublicDashboard: &PublicDashboardDTO{
|
||||||
IsEnabled: &isEnabled,
|
IsEnabled: &isEnabled,
|
||||||
DashboardUid: "NOTTHESAME",
|
|
||||||
OrgId: dashboard.OrgID,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,11 +482,10 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
isEnabled := true
|
isEnabled := true
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
DashboardUid: dashboard.UID,
|
DashboardUid: dashboard.UID,
|
||||||
|
OrgID: dashboard.OrgID,
|
||||||
UserId: 7,
|
UserId: 7,
|
||||||
PublicDashboard: &PublicDashboardDTO{
|
PublicDashboard: &PublicDashboardDTO{
|
||||||
IsEnabled: &isEnabled,
|
IsEnabled: &isEnabled,
|
||||||
DashboardUid: "NOTTHESAME",
|
|
||||||
OrgId: dashboard.OrgID,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,24 +540,20 @@ func TestUpdatePublicDashboard(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
isEnabled, annotationsEnabled, timeSelectionEnabled = true, true, true
|
isEnabled, annotationsEnabled, timeSelectionEnabled = true, true, true
|
||||||
// attempt to overwrite settings
|
|
||||||
dto = &SavePublicDashboardDTO{
|
dto = &SavePublicDashboardDTO{
|
||||||
|
Uid: savedPubdash.Uid,
|
||||||
DashboardUid: dashboard.UID,
|
DashboardUid: dashboard.UID,
|
||||||
|
OrgID: 9,
|
||||||
UserId: 8,
|
UserId: 8,
|
||||||
PublicDashboard: &PublicDashboardDTO{
|
PublicDashboard: &PublicDashboardDTO{
|
||||||
Uid: savedPubdash.Uid,
|
|
||||||
OrgId: 9,
|
|
||||||
DashboardUid: "abc1234",
|
|
||||||
CreatedBy: 9,
|
|
||||||
CreatedAt: time.Time{},
|
|
||||||
|
|
||||||
IsEnabled: &isEnabled,
|
IsEnabled: &isEnabled,
|
||||||
AnnotationsEnabled: &annotationsEnabled,
|
AnnotationsEnabled: &annotationsEnabled,
|
||||||
TimeSelectionEnabled: &timeSelectionEnabled,
|
TimeSelectionEnabled: &timeSelectionEnabled,
|
||||||
TimeSettings: timeSettings,
|
TimeSettings: timeSettings,
|
||||||
AccessToken: "NOTAREALUUID",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
updatedPubdash, err := service.Update(context.Background(), SignedInUser, dto)
|
updatedPubdash, err := service.Update(context.Background(), SignedInUser, dto)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@ -612,19 +602,14 @@ func TestUpdatePublicDashboard(t *testing.T) {
|
|||||||
savedPubdash, err := service.Create(context.Background(), SignedInUser, dto)
|
savedPubdash, err := service.Create(context.Background(), SignedInUser, dto)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// attempt to overwrite settings
|
|
||||||
dto = &SavePublicDashboardDTO{
|
dto = &SavePublicDashboardDTO{
|
||||||
|
Uid: savedPubdash.Uid,
|
||||||
DashboardUid: dashboard.UID,
|
DashboardUid: dashboard.UID,
|
||||||
|
OrgID: 9,
|
||||||
UserId: 8,
|
UserId: 8,
|
||||||
PublicDashboard: &PublicDashboardDTO{
|
PublicDashboard: &PublicDashboardDTO{
|
||||||
Uid: savedPubdash.Uid,
|
|
||||||
OrgId: 9,
|
|
||||||
DashboardUid: "abc1234",
|
|
||||||
CreatedBy: 9,
|
|
||||||
CreatedAt: time.Time{},
|
|
||||||
IsEnabled: &isEnabled,
|
IsEnabled: &isEnabled,
|
||||||
TimeSettings: &TimeSettings{},
|
TimeSettings: &TimeSettings{},
|
||||||
AccessToken: "NOTAREALUUID",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -714,22 +699,17 @@ func TestUpdatePublicDashboard(t *testing.T) {
|
|||||||
savedPubdash, err := service.Create(context.Background(), SignedInUser, dto)
|
savedPubdash, err := service.Create(context.Background(), SignedInUser, dto)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// attempt to overwrite settings
|
|
||||||
dto = &SavePublicDashboardDTO{
|
dto = &SavePublicDashboardDTO{
|
||||||
|
Uid: savedPubdash.Uid,
|
||||||
DashboardUid: dashboard.UID,
|
DashboardUid: dashboard.UID,
|
||||||
|
OrgID: 9,
|
||||||
UserId: 8,
|
UserId: 8,
|
||||||
PublicDashboard: &PublicDashboardDTO{
|
PublicDashboard: &PublicDashboardDTO{
|
||||||
Uid: savedPubdash.Uid,
|
|
||||||
OrgId: 9,
|
|
||||||
DashboardUid: "abc1234",
|
|
||||||
CreatedBy: 9,
|
|
||||||
CreatedAt: time.Time{},
|
|
||||||
IsEnabled: tt.IsEnabled,
|
IsEnabled: tt.IsEnabled,
|
||||||
AnnotationsEnabled: tt.AnnotationsEnabled,
|
AnnotationsEnabled: tt.AnnotationsEnabled,
|
||||||
TimeSelectionEnabled: tt.TimeSelectionEnabled,
|
TimeSelectionEnabled: tt.TimeSelectionEnabled,
|
||||||
TimeSettings: tt.TimeSettings,
|
TimeSettings: tt.TimeSettings,
|
||||||
Share: tt.ShareType,
|
Share: tt.ShareType,
|
||||||
AccessToken: "NOTAREALUUID",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
updatedPubdash, err := service.Update(context.Background(), SignedInUser, dto)
|
updatedPubdash, err := service.Update(context.Background(), SignedInUser, dto)
|
||||||
|
Loading…
Reference in New Issue
Block a user