PublicDashboards: Accept AccessToken for pubdash creation (#74134)
* Add Access token input * add unit tests to access token * if else logic to not call find on empty string * update var naming
This commit is contained in:
@@ -155,6 +155,12 @@ func (api *Api) CreatePublicDashboard(c *contextmodel.ReqContext) response.Respo
|
||||
return response.Err(ErrInvalidUid.Errorf("CreatePublicDashboard: invalid Uid %s", uid))
|
||||
}
|
||||
|
||||
//validate accessToken
|
||||
accessToken := pdDTO.AccessToken
|
||||
if accessToken != "" && !validation.IsValidAccessToken(accessToken) {
|
||||
return response.Err(ErrInvalidAccessToken.Errorf("CreatePublicDashboard: invalid Access Token %s", accessToken))
|
||||
}
|
||||
|
||||
// Always set the orgID and userID from the session
|
||||
dto := &SavePublicDashboardDTO{
|
||||
UserId: c.UserID,
|
||||
|
||||
@@ -448,6 +448,24 @@ func TestApiCreatePublicDashboard(t *testing.T) {
|
||||
ShouldCallService: true,
|
||||
JsonBody: `{ "uid": "123abc", "isEnabled": true}`,
|
||||
},
|
||||
{
|
||||
Name: "returns 400 when access token is invalid",
|
||||
ExpectedHttpResponse: http.StatusBadRequest,
|
||||
publicDashboard: nil,
|
||||
SaveDashboardErr: nil,
|
||||
User: userAdmin,
|
||||
ShouldCallService: false,
|
||||
JsonBody: `{ "AccessToken": "123abc", "isEnabled": true }`,
|
||||
},
|
||||
{
|
||||
Name: "returns 200 when access token is valid",
|
||||
ExpectedHttpResponse: http.StatusOK,
|
||||
publicDashboard: &PublicDashboard{IsEnabled: true},
|
||||
SaveDashboardErr: nil,
|
||||
User: userAdmin,
|
||||
ShouldCallService: true,
|
||||
JsonBody: `{ "accessToken": "d64457c699644079b50230cfefddb211", "isEnabled": true}`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
|
||||
Reference in New Issue
Block a user