Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
22fffe0d
Unverified
Commit
22fffe0d
authored
Mar 22, 2018
by
Carl Bergquist
Committed by
GitHub
Mar 22, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11337 from digineo/golint
Make golint happier
parents
624dac16
7aab6a88
Show whitespace changes
Inline
Side-by-side
Showing
33 changed files
with
231 additions
and
235 deletions
+231
-235
pkg/api/admin_users.go
+7
-7
pkg/api/alerting.go
+3
-3
pkg/api/annotations.go
+17
-17
pkg/api/api.go
+19
-19
pkg/api/apikey.go
+3
-3
pkg/api/app_routes.go
+2
-2
pkg/api/dashboard.go
+18
-21
pkg/api/dashboard_permission.go
+8
-8
pkg/api/dashboard_snapshot.go
+2
-2
pkg/api/dashboard_test.go
+10
-10
pkg/api/dataproxy.go
+4
-4
pkg/api/datasources.go
+12
-13
pkg/api/folder.go
+2
-2
pkg/api/folder_test.go
+2
-2
pkg/api/http_server.go
+1
-1
pkg/api/index.go
+15
-14
pkg/api/login.go
+3
-3
pkg/api/metrics.go
+3
-3
pkg/api/org.go
+6
-6
pkg/api/org_invite.go
+1
-2
pkg/api/org_users.go
+9
-9
pkg/api/playlist.go
+2
-2
pkg/api/playlist_play.go
+11
-13
pkg/api/plugins.go
+18
-16
pkg/api/preferences.go
+5
-5
pkg/api/search.go
+8
-8
pkg/api/team.go
+2
-2
pkg/api/user.go
+18
-18
pkg/cmd/grafana-server/server.go
+1
-1
pkg/middleware/auth.go
+3
-3
pkg/middleware/dashboard_redirect.go
+1
-1
pkg/middleware/dashboard_redirect_test.go
+9
-9
pkg/middleware/recovery_test.go
+6
-6
No files found.
pkg/api/admin_users.go
View file @
22fffe0d
...
...
@@ -47,14 +47,14 @@ func AdminCreateUser(c *m.ReqContext, form dtos.AdminCreateUserForm) {
}
func
AdminUpdateUserPassword
(
c
*
m
.
ReqContext
,
form
dtos
.
AdminUpdateUserPasswordForm
)
{
userI
d
:=
c
.
ParamsInt64
(
":id"
)
userI
D
:=
c
.
ParamsInt64
(
":id"
)
if
len
(
form
.
Password
)
<
4
{
c
.
JsonApiErr
(
400
,
"New password too short"
,
nil
)
return
}
userQuery
:=
m
.
GetUserByIdQuery
{
Id
:
userI
d
}
userQuery
:=
m
.
GetUserByIdQuery
{
Id
:
userI
D
}
if
err
:=
bus
.
Dispatch
(
&
userQuery
);
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Could not read user from database"
,
err
)
...
...
@@ -64,7 +64,7 @@ func AdminUpdateUserPassword(c *m.ReqContext, form dtos.AdminUpdateUserPasswordF
passwordHashed
:=
util
.
EncodePassword
(
form
.
Password
,
userQuery
.
Result
.
Salt
)
cmd
:=
m
.
ChangeUserPasswordCommand
{
UserId
:
userI
d
,
UserId
:
userI
D
,
NewPassword
:
passwordHashed
,
}
...
...
@@ -77,10 +77,10 @@ func AdminUpdateUserPassword(c *m.ReqContext, form dtos.AdminUpdateUserPasswordF
}
func
AdminUpdateUserPermissions
(
c
*
m
.
ReqContext
,
form
dtos
.
AdminUpdateUserPermissionsForm
)
{
userI
d
:=
c
.
ParamsInt64
(
":id"
)
userI
D
:=
c
.
ParamsInt64
(
":id"
)
cmd
:=
m
.
UpdateUserPermissionsCommand
{
UserId
:
userI
d
,
UserId
:
userI
D
,
IsGrafanaAdmin
:
form
.
IsGrafanaAdmin
,
}
...
...
@@ -93,9 +93,9 @@ func AdminUpdateUserPermissions(c *m.ReqContext, form dtos.AdminUpdateUserPermis
}
func
AdminDeleteUser
(
c
*
m
.
ReqContext
)
{
userI
d
:=
c
.
ParamsInt64
(
":id"
)
userI
D
:=
c
.
ParamsInt64
(
":id"
)
cmd
:=
m
.
DeleteUserCommand
{
UserId
:
userI
d
}
cmd
:=
m
.
DeleteUserCommand
{
UserId
:
userI
D
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to delete user"
,
err
)
...
...
pkg/api/alerting.go
View file @
22fffe0d
...
...
@@ -26,9 +26,9 @@ func ValidateOrgAlert(c *m.ReqContext) {
}
func
GetAlertStatesForDashboard
(
c
*
m
.
ReqContext
)
Response
{
dashboardI
d
:=
c
.
QueryInt64
(
"dashboardId"
)
dashboardI
D
:=
c
.
QueryInt64
(
"dashboardId"
)
if
dashboardI
d
==
0
{
if
dashboardI
D
==
0
{
return
ApiError
(
400
,
"Missing query parameter dashboardId"
,
nil
)
}
...
...
@@ -151,7 +151,7 @@ func GetAlertNotifications(c *m.ReqContext) Response {
return
Json
(
200
,
result
)
}
func
GetAlertNotificationByI
d
(
c
*
m
.
ReqContext
)
Response
{
func
GetAlertNotificationByI
D
(
c
*
m
.
ReqContext
)
Response
{
query
:=
&
m
.
GetAlertNotificationsQuery
{
OrgId
:
c
.
OrgId
,
Id
:
c
.
ParamsInt64
(
"notificationId"
),
...
...
pkg/api/annotations.go
View file @
22fffe0d
...
...
@@ -52,7 +52,7 @@ func (e *CreateAnnotationError) Error() string {
}
func
PostAnnotation
(
c
*
m
.
ReqContext
,
cmd
dtos
.
PostAnnotationsCmd
)
Response
{
if
canSave
,
err
:=
canSaveByDashboardI
d
(
c
,
cmd
.
DashboardId
);
err
!=
nil
||
!
canSave
{
if
canSave
,
err
:=
canSaveByDashboardI
D
(
c
,
cmd
.
DashboardId
);
err
!=
nil
||
!
canSave
{
return
dashboardGuardianResponse
(
err
)
}
...
...
@@ -179,18 +179,18 @@ func PostGraphiteAnnotation(c *m.ReqContext, cmd dtos.PostGraphiteAnnotationsCmd
}
func
UpdateAnnotation
(
c
*
m
.
ReqContext
,
cmd
dtos
.
UpdateAnnotationsCmd
)
Response
{
annotationI
d
:=
c
.
ParamsInt64
(
":annotationId"
)
annotationI
D
:=
c
.
ParamsInt64
(
":annotationId"
)
repo
:=
annotations
.
GetRepository
()
if
resp
:=
canSave
(
c
,
repo
,
annotationI
d
);
resp
!=
nil
{
if
resp
:=
canSave
(
c
,
repo
,
annotationI
D
);
resp
!=
nil
{
return
resp
}
item
:=
annotations
.
Item
{
OrgId
:
c
.
OrgId
,
UserId
:
c
.
UserId
,
Id
:
annotationI
d
,
Id
:
annotationI
D
,
Epoch
:
cmd
.
Time
/
1000
,
Text
:
cmd
.
Text
,
Tags
:
cmd
.
Tags
,
...
...
@@ -254,14 +254,14 @@ func DeleteAnnotationById(c *m.ReqContext) Response {
func
DeleteAnnotationRegion
(
c
*
m
.
ReqContext
)
Response
{
repo
:=
annotations
.
GetRepository
()
regionI
d
:=
c
.
ParamsInt64
(
":regionId"
)
regionI
D
:=
c
.
ParamsInt64
(
":regionId"
)
if
resp
:=
canSave
(
c
,
repo
,
regionI
d
);
resp
!=
nil
{
if
resp
:=
canSave
(
c
,
repo
,
regionI
D
);
resp
!=
nil
{
return
resp
}
err
:=
repo
.
Delete
(
&
annotations
.
DeleteParams
{
RegionId
:
regionI
d
,
RegionId
:
regionI
D
,
})
if
err
!=
nil
{
...
...
@@ -271,13 +271,13 @@ func DeleteAnnotationRegion(c *m.ReqContext) Response {
return
ApiSuccess
(
"Annotation region deleted"
)
}
func
canSaveByDashboardI
d
(
c
*
m
.
ReqContext
,
dashboardId
int64
)
(
bool
,
error
)
{
if
dashboardI
d
==
0
&&
!
c
.
SignedInUser
.
HasRole
(
m
.
ROLE_EDITOR
)
{
func
canSaveByDashboardI
D
(
c
*
m
.
ReqContext
,
dashboardID
int64
)
(
bool
,
error
)
{
if
dashboardI
D
==
0
&&
!
c
.
SignedInUser
.
HasRole
(
m
.
ROLE_EDITOR
)
{
return
false
,
nil
}
if
dashboardI
d
>
0
{
guardian
:=
guardian
.
New
(
dashboardI
d
,
c
.
OrgId
,
c
.
SignedInUser
)
if
dashboardI
D
>
0
{
guardian
:=
guardian
.
New
(
dashboardI
D
,
c
.
OrgId
,
c
.
SignedInUser
)
if
canEdit
,
err
:=
guardian
.
CanEdit
();
err
!=
nil
||
!
canEdit
{
return
false
,
err
}
...
...
@@ -293,25 +293,25 @@ func canSave(c *m.ReqContext, repo annotations.Repository, annotationId int64) R
return
ApiError
(
500
,
"Could not find annotation to update"
,
err
)
}
dashboardI
d
:=
items
[
0
]
.
DashboardId
dashboardI
D
:=
items
[
0
]
.
DashboardId
if
canSave
,
err
:=
canSaveByDashboardI
d
(
c
,
dashboardId
);
err
!=
nil
||
!
canSave
{
if
canSave
,
err
:=
canSaveByDashboardI
D
(
c
,
dashboardID
);
err
!=
nil
||
!
canSave
{
return
dashboardGuardianResponse
(
err
)
}
return
nil
}
func
canSaveByRegionI
d
(
c
*
m
.
ReqContext
,
repo
annotations
.
Repository
,
regionId
int64
)
Response
{
items
,
err
:=
repo
.
Find
(
&
annotations
.
ItemQuery
{
RegionId
:
regionI
d
,
OrgId
:
c
.
OrgId
})
func
canSaveByRegionI
D
(
c
*
m
.
ReqContext
,
repo
annotations
.
Repository
,
regionID
int64
)
Response
{
items
,
err
:=
repo
.
Find
(
&
annotations
.
ItemQuery
{
RegionId
:
regionI
D
,
OrgId
:
c
.
OrgId
})
if
err
!=
nil
||
len
(
items
)
==
0
{
return
ApiError
(
500
,
"Could not find annotation to update"
,
err
)
}
dashboardI
d
:=
items
[
0
]
.
DashboardId
dashboardI
D
:=
items
[
0
]
.
DashboardId
if
canSave
,
err
:=
canSaveByDashboardI
d
(
c
,
dashboardId
);
err
!=
nil
||
!
canSave
{
if
canSave
,
err
:=
canSaveByDashboardI
D
(
c
,
dashboardID
);
err
!=
nil
||
!
canSave
{
return
dashboardGuardianResponse
(
err
)
}
...
...
pkg/api/api.go
View file @
22fffe0d
...
...
@@ -15,7 +15,7 @@ func (hs *HttpServer) registerRoutes() {
reqGrafanaAdmin
:=
middleware
.
Auth
(
&
middleware
.
AuthOptions
{
ReqSignedIn
:
true
,
ReqGrafanaAdmin
:
true
})
reqEditorRole
:=
middleware
.
RoleAuth
(
m
.
ROLE_EDITOR
,
m
.
ROLE_ADMIN
)
reqOrgAdmin
:=
middleware
.
RoleAuth
(
m
.
ROLE_ADMIN
)
redirectFromLegacyDashboardUrl
:=
middleware
.
RedirectFromLegacyDashboardU
rl
()
redirectFromLegacyDashboardUrl
:=
middleware
.
RedirectFromLegacyDashboardU
RL
()
redirectFromLegacyDashboardSoloUrl
:=
middleware
.
RedirectFromLegacyDashboardSoloUrl
()
quota
:=
middleware
.
Quota
bind
:=
binding
.
Bind
...
...
@@ -110,7 +110,7 @@ func (hs *HttpServer) registerRoutes() {
r
.
Get
(
"/api/snapshots-delete/:key"
,
reqEditorRole
,
wrap
(
DeleteDashboardSnapshot
))
// api renew session based on remember cookie
r
.
Get
(
"/api/login/ping"
,
quota
(
"session"
),
LoginA
pi
Ping
)
r
.
Get
(
"/api/login/ping"
,
quota
(
"session"
),
LoginA
PI
Ping
)
// authed api
r
.
Group
(
"/api"
,
func
(
apiRoute
RouteRegister
)
{
...
...
@@ -139,7 +139,7 @@ func (hs *HttpServer) registerRoutes() {
apiRoute
.
Group
(
"/users"
,
func
(
usersRoute
RouteRegister
)
{
usersRoute
.
Get
(
"/"
,
wrap
(
SearchUsers
))
usersRoute
.
Get
(
"/search"
,
wrap
(
SearchUsersWithPaging
))
usersRoute
.
Get
(
"/:id"
,
wrap
(
GetUserByI
d
))
usersRoute
.
Get
(
"/:id"
,
wrap
(
GetUserByI
D
))
usersRoute
.
Get
(
"/:id/orgs"
,
wrap
(
GetUserOrgList
))
// query parameters /users/lookup?loginOrEmail=admin@example.com
usersRoute
.
Get
(
"/lookup"
,
wrap
(
GetUserByLoginOrEmail
))
...
...
@@ -149,11 +149,11 @@ func (hs *HttpServer) registerRoutes() {
// team (admin permission required)
apiRoute
.
Group
(
"/teams"
,
func
(
teamsRoute
RouteRegister
)
{
teamsRoute
.
Get
(
"/:teamId"
,
wrap
(
GetTeamByI
d
))
teamsRoute
.
Get
(
"/:teamId"
,
wrap
(
GetTeamByI
D
))
teamsRoute
.
Get
(
"/search"
,
wrap
(
SearchTeams
))
teamsRoute
.
Post
(
"/"
,
bind
(
m
.
CreateTeamCommand
{}),
wrap
(
CreateTeam
))
teamsRoute
.
Put
(
"/:teamId"
,
bind
(
m
.
UpdateTeamCommand
{}),
wrap
(
UpdateTeam
))
teamsRoute
.
Delete
(
"/:teamId"
,
wrap
(
DeleteTeamByI
d
))
teamsRoute
.
Delete
(
"/:teamId"
,
wrap
(
DeleteTeamByI
D
))
teamsRoute
.
Get
(
"/:teamId/members"
,
wrap
(
GetTeamMembers
))
teamsRoute
.
Post
(
"/:teamId/members"
,
bind
(
m
.
AddTeamMemberCommand
{}),
wrap
(
AddTeamMember
))
teamsRoute
.
Delete
(
"/:teamId/members/:userId"
,
wrap
(
RemoveTeamMember
))
...
...
@@ -192,10 +192,10 @@ func (hs *HttpServer) registerRoutes() {
// orgs (admin routes)
apiRoute
.
Group
(
"/orgs/:orgId"
,
func
(
orgsRoute
RouteRegister
)
{
orgsRoute
.
Get
(
"/"
,
wrap
(
GetOrgByI
d
))
orgsRoute
.
Get
(
"/"
,
wrap
(
GetOrgByI
D
))
orgsRoute
.
Put
(
"/"
,
bind
(
dtos
.
UpdateOrgForm
{}),
wrap
(
UpdateOrg
))
orgsRoute
.
Put
(
"/address"
,
bind
(
dtos
.
UpdateOrgAddressForm
{}),
wrap
(
UpdateOrgAddress
))
orgsRoute
.
Delete
(
"/"
,
wrap
(
DeleteOrgByI
d
))
orgsRoute
.
Delete
(
"/"
,
wrap
(
DeleteOrgByI
D
))
orgsRoute
.
Get
(
"/users"
,
wrap
(
GetOrgUsers
))
orgsRoute
.
Post
(
"/users"
,
bind
(
m
.
AddOrgUserCommand
{}),
wrap
(
AddOrgUser
))
orgsRoute
.
Patch
(
"/users/:userId"
,
bind
(
m
.
UpdateOrgUserCommand
{}),
wrap
(
UpdateOrgUser
))
...
...
@@ -211,9 +211,9 @@ func (hs *HttpServer) registerRoutes() {
// auth api keys
apiRoute
.
Group
(
"/auth/keys"
,
func
(
keysRoute
RouteRegister
)
{
keysRoute
.
Get
(
"/"
,
wrap
(
GetA
pi
Keys
))
keysRoute
.
Post
(
"/"
,
quota
(
"api_key"
),
bind
(
m
.
AddApiKeyCommand
{}),
wrap
(
AddA
pi
Key
))
keysRoute
.
Delete
(
"/:id"
,
wrap
(
DeleteA
pi
Key
))
keysRoute
.
Get
(
"/"
,
wrap
(
GetA
PI
Keys
))
keysRoute
.
Post
(
"/"
,
quota
(
"api_key"
),
bind
(
m
.
AddApiKeyCommand
{}),
wrap
(
AddA
PI
Key
))
keysRoute
.
Delete
(
"/:id"
,
wrap
(
DeleteA
PI
Key
))
},
reqOrgAdmin
)
// Preferences
...
...
@@ -226,16 +226,16 @@ func (hs *HttpServer) registerRoutes() {
datasourceRoute
.
Get
(
"/"
,
wrap
(
GetDataSources
))
datasourceRoute
.
Post
(
"/"
,
quota
(
"data_source"
),
bind
(
m
.
AddDataSourceCommand
{}),
wrap
(
AddDataSource
))
datasourceRoute
.
Put
(
"/:id"
,
bind
(
m
.
UpdateDataSourceCommand
{}),
wrap
(
UpdateDataSource
))
datasourceRoute
.
Delete
(
"/:id"
,
wrap
(
DeleteDataSourceByI
d
))
datasourceRoute
.
Delete
(
"/:id"
,
wrap
(
DeleteDataSourceByI
D
))
datasourceRoute
.
Delete
(
"/name/:name"
,
wrap
(
DeleteDataSourceByName
))
datasourceRoute
.
Get
(
"/:id"
,
wrap
(
GetDataSourceByI
d
))
datasourceRoute
.
Get
(
"/:id"
,
wrap
(
GetDataSourceByI
D
))
datasourceRoute
.
Get
(
"/name/:name"
,
wrap
(
GetDataSourceByName
))
},
reqOrgAdmin
)
apiRoute
.
Get
(
"/datasources/id/:name"
,
wrap
(
GetDataSourceI
d
ByName
),
reqSignedIn
)
apiRoute
.
Get
(
"/datasources/id/:name"
,
wrap
(
GetDataSourceI
D
ByName
),
reqSignedIn
)
apiRoute
.
Get
(
"/plugins"
,
wrap
(
GetPluginList
))
apiRoute
.
Get
(
"/plugins/:pluginId/settings"
,
wrap
(
GetPluginSettingByI
d
))
apiRoute
.
Get
(
"/plugins/:pluginId/settings"
,
wrap
(
GetPluginSettingByI
D
))
apiRoute
.
Get
(
"/plugins/:pluginId/markdown/:name"
,
wrap
(
GetPluginMarkdown
))
apiRoute
.
Group
(
"/plugins"
,
func
(
pluginRoute
RouteRegister
)
{
...
...
@@ -250,11 +250,11 @@ func (hs *HttpServer) registerRoutes() {
// Folders
apiRoute
.
Group
(
"/folders"
,
func
(
folderRoute
RouteRegister
)
{
folderRoute
.
Get
(
"/"
,
wrap
(
GetFolders
))
folderRoute
.
Get
(
"/id/:id"
,
wrap
(
GetFolderByI
d
))
folderRoute
.
Get
(
"/id/:id"
,
wrap
(
GetFolderByI
D
))
folderRoute
.
Post
(
"/"
,
bind
(
m
.
CreateFolderCommand
{}),
wrap
(
CreateFolder
))
folderRoute
.
Group
(
"/:uid"
,
func
(
folderUidRoute
RouteRegister
)
{
folderUidRoute
.
Get
(
"/"
,
wrap
(
GetFolderByU
id
))
folderUidRoute
.
Get
(
"/"
,
wrap
(
GetFolderByU
ID
))
folderUidRoute
.
Put
(
"/"
,
bind
(
m
.
UpdateFolderCommand
{}),
wrap
(
UpdateFolder
))
folderUidRoute
.
Delete
(
"/"
,
wrap
(
DeleteFolder
))
...
...
@@ -268,7 +268,7 @@ func (hs *HttpServer) registerRoutes() {
// Dashboard
apiRoute
.
Group
(
"/dashboards"
,
func
(
dashboardRoute
RouteRegister
)
{
dashboardRoute
.
Get
(
"/uid/:uid"
,
wrap
(
GetDashboard
))
dashboardRoute
.
Delete
(
"/uid/:uid"
,
wrap
(
DeleteDashboardByU
id
))
dashboardRoute
.
Delete
(
"/uid/:uid"
,
wrap
(
DeleteDashboardByU
ID
))
dashboardRoute
.
Get
(
"/db/:slug"
,
wrap
(
GetDashboard
))
dashboardRoute
.
Delete
(
"/db/:slug"
,
wrap
(
DeleteDashboard
))
...
...
@@ -314,7 +314,7 @@ func (hs *HttpServer) registerRoutes() {
// metrics
apiRoute
.
Post
(
"/tsdb/query"
,
bind
(
dtos
.
MetricRequest
{}),
wrap
(
QueryMetrics
))
apiRoute
.
Get
(
"/tsdb/testdata/scenarios"
,
wrap
(
GetTestDataScenarios
))
apiRoute
.
Get
(
"/tsdb/testdata/gensql"
,
reqGrafanaAdmin
,
wrap
(
GenerateS
ql
TestData
))
apiRoute
.
Get
(
"/tsdb/testdata/gensql"
,
reqGrafanaAdmin
,
wrap
(
GenerateS
QL
TestData
))
apiRoute
.
Get
(
"/tsdb/testdata/random-walk"
,
wrap
(
GetTestDataRandomWalk
))
apiRoute
.
Group
(
"/alerts"
,
func
(
alertsRoute
RouteRegister
)
{
...
...
@@ -332,7 +332,7 @@ func (hs *HttpServer) registerRoutes() {
alertNotifications
.
Post
(
"/test"
,
bind
(
dtos
.
NotificationTestCommand
{}),
wrap
(
NotificationTest
))
alertNotifications
.
Post
(
"/"
,
bind
(
m
.
CreateAlertNotificationCommand
{}),
wrap
(
CreateAlertNotification
))
alertNotifications
.
Put
(
"/:notificationId"
,
bind
(
m
.
UpdateAlertNotificationCommand
{}),
wrap
(
UpdateAlertNotification
))
alertNotifications
.
Get
(
"/:notificationId"
,
wrap
(
GetAlertNotificationByI
d
))
alertNotifications
.
Get
(
"/:notificationId"
,
wrap
(
GetAlertNotificationByI
D
))
alertNotifications
.
Delete
(
"/:notificationId"
,
wrap
(
DeleteAlertNotification
))
},
reqEditorRole
)
...
...
pkg/api/apikey.go
View file @
22fffe0d
...
...
@@ -7,7 +7,7 @@ import (
m
"github.com/grafana/grafana/pkg/models"
)
func
GetA
pi
Keys
(
c
*
m
.
ReqContext
)
Response
{
func
GetA
PI
Keys
(
c
*
m
.
ReqContext
)
Response
{
query
:=
m
.
GetApiKeysQuery
{
OrgId
:
c
.
OrgId
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
...
...
@@ -26,7 +26,7 @@ func GetApiKeys(c *m.ReqContext) Response {
return
Json
(
200
,
result
)
}
func
DeleteA
pi
Key
(
c
*
m
.
ReqContext
)
Response
{
func
DeleteA
PI
Key
(
c
*
m
.
ReqContext
)
Response
{
id
:=
c
.
ParamsInt64
(
":id"
)
cmd
:=
&
m
.
DeleteApiKeyCommand
{
Id
:
id
,
OrgId
:
c
.
OrgId
}
...
...
@@ -39,7 +39,7 @@ func DeleteApiKey(c *m.ReqContext) Response {
return
ApiSuccess
(
"API key deleted"
)
}
func
AddA
pi
Key
(
c
*
m
.
ReqContext
,
cmd
m
.
AddApiKeyCommand
)
Response
{
func
AddA
PI
Key
(
c
*
m
.
ReqContext
,
cmd
m
.
AddApiKeyCommand
)
Response
{
if
!
cmd
.
Role
.
IsValid
()
{
return
ApiError
(
400
,
"Invalid role specified"
,
nil
)
}
...
...
pkg/api/app_routes.go
View file @
22fffe0d
...
...
@@ -55,11 +55,11 @@ func InitAppPluginRoutes(r *macaron.Macaron) {
}
}
func
AppPluginRoute
(
route
*
plugins
.
AppPluginRoute
,
appI
d
string
)
macaron
.
Handler
{
func
AppPluginRoute
(
route
*
plugins
.
AppPluginRoute
,
appI
D
string
)
macaron
.
Handler
{
return
func
(
c
*
m
.
ReqContext
)
{
path
:=
c
.
Params
(
"*"
)
proxy
:=
pluginproxy
.
NewApiPluginProxy
(
c
,
path
,
route
,
appI
d
)
proxy
:=
pluginproxy
.
NewApiPluginProxy
(
c
,
path
,
route
,
appI
D
)
proxy
.
Transport
=
pluginProxyTransport
proxy
.
ServeHTTP
(
c
.
Resp
,
c
.
Req
.
Request
)
}
...
...
pkg/api/dashboard.go
View file @
22fffe0d
...
...
@@ -22,12 +22,12 @@ import (
"github.com/grafana/grafana/pkg/util"
)
func
isDashboardStarredByUser
(
c
*
m
.
ReqContext
,
dashI
d
int64
)
(
bool
,
error
)
{
func
isDashboardStarredByUser
(
c
*
m
.
ReqContext
,
dashI
D
int64
)
(
bool
,
error
)
{
if
!
c
.
IsSignedIn
{
return
false
,
nil
}
query
:=
m
.
IsStarredByUserQuery
{
UserId
:
c
.
UserId
,
DashboardId
:
dashI
d
}
query
:=
m
.
IsStarredByUserQuery
{
UserId
:
c
.
UserId
,
DashboardId
:
dashI
D
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
false
,
err
}
...
...
@@ -114,24 +114,22 @@ func GetDashboard(c *m.ReqContext) Response {
return
Json
(
200
,
dto
)
}
func
getUserLogin
(
userI
d
int64
)
string
{
query
:=
m
.
GetUserByIdQuery
{
Id
:
userI
d
}
func
getUserLogin
(
userI
D
int64
)
string
{
query
:=
m
.
GetUserByIdQuery
{
Id
:
userI
D
}
err
:=
bus
.
Dispatch
(
&
query
)
if
err
!=
nil
{
return
"Anonymous"
}
else
{
user
:=
query
.
Result
return
user
.
Login
}
return
query
.
Result
.
Login
}
func
getDashboardHelper
(
orgI
d
int64
,
slug
string
,
id
int64
,
uid
string
)
(
*
m
.
Dashboard
,
Response
)
{
func
getDashboardHelper
(
orgI
D
int64
,
slug
string
,
id
int64
,
uid
string
)
(
*
m
.
Dashboard
,
Response
)
{
var
query
m
.
GetDashboardQuery
if
len
(
uid
)
>
0
{
query
=
m
.
GetDashboardQuery
{
Uid
:
uid
,
Id
:
id
,
OrgId
:
orgI
d
}
query
=
m
.
GetDashboardQuery
{
Uid
:
uid
,
Id
:
id
,
OrgId
:
orgI
D
}
}
else
{
query
=
m
.
GetDashboardQuery
{
Slug
:
slug
,
Id
:
id
,
OrgId
:
orgI
d
}
query
=
m
.
GetDashboardQuery
{
Slug
:
slug
,
Id
:
id
,
OrgId
:
orgI
D
}
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
...
...
@@ -173,7 +171,7 @@ func DeleteDashboard(c *m.ReqContext) Response {
})
}
func
DeleteDashboardByU
id
(
c
*
m
.
ReqContext
)
Response
{
func
DeleteDashboardByU
ID
(
c
*
m
.
ReqContext
)
Response
{
dash
,
rsp
:=
getDashboardHelper
(
c
.
OrgId
,
""
,
0
,
c
.
Params
(
":uid"
))
if
rsp
!=
nil
{
return
rsp
...
...
@@ -291,9 +289,8 @@ func GetHomeDashboard(c *m.ReqContext) Response {
url
:=
m
.
GetDashboardUrl
(
slugQuery
.
Result
.
Uid
,
slugQuery
.
Result
.
Slug
)
dashRedirect
:=
dtos
.
DashboardRedirect
{
RedirectUri
:
url
}
return
Json
(
200
,
&
dashRedirect
)
}
else
{
log
.
Warn
(
"Failed to get slug from database, %s"
,
err
.
Error
())
}
log
.
Warn
(
"Failed to get slug from database, %s"
,
err
.
Error
())
}
filePath
:=
path
.
Join
(
setting
.
StaticRootPath
,
"dashboards/home.json"
)
...
...
@@ -339,22 +336,22 @@ func addGettingStartedPanelToHomeDashboard(dash *simplejson.Json) {
// GetDashboardVersions returns all dashboard versions as JSON
func
GetDashboardVersions
(
c
*
m
.
ReqContext
)
Response
{
dashI
d
:=
c
.
ParamsInt64
(
":dashboardId"
)
dashI
D
:=
c
.
ParamsInt64
(
":dashboardId"
)
guardian
:=
guardian
.
New
(
dashI
d
,
c
.
OrgId
,
c
.
SignedInUser
)
guardian
:=
guardian
.
New
(
dashI
D
,
c
.
OrgId
,
c
.
SignedInUser
)
if
canSave
,
err
:=
guardian
.
CanSave
();
err
!=
nil
||
!
canSave
{
return
dashboardGuardianResponse
(
err
)
}
query
:=
m
.
GetDashboardVersionsQuery
{
OrgId
:
c
.
OrgId
,
DashboardId
:
dashI
d
,
DashboardId
:
dashI
D
,
Limit
:
c
.
QueryInt
(
"limit"
),
Start
:
c
.
QueryInt
(
"start"
),
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
ApiError
(
404
,
fmt
.
Sprintf
(
"No versions found for dashboardId %d"
,
dashI
d
),
err
)
return
ApiError
(
404
,
fmt
.
Sprintf
(
"No versions found for dashboardId %d"
,
dashI
D
),
err
)
}
for
_
,
version
:=
range
query
.
Result
{
...
...
@@ -378,21 +375,21 @@ func GetDashboardVersions(c *m.ReqContext) Response {
// GetDashboardVersion returns the dashboard version with the given ID.
func
GetDashboardVersion
(
c
*
m
.
ReqContext
)
Response
{
dashI
d
:=
c
.
ParamsInt64
(
":dashboardId"
)
dashI
D
:=
c
.
ParamsInt64
(
":dashboardId"
)
guardian
:=
guardian
.
New
(
dashI
d
,
c
.
OrgId
,
c
.
SignedInUser
)
guardian
:=
guardian
.
New
(
dashI
D
,
c
.
OrgId
,
c
.
SignedInUser
)
if
canSave
,
err
:=
guardian
.
CanSave
();
err
!=
nil
||
!
canSave
{
return
dashboardGuardianResponse
(
err
)
}
query
:=
m
.
GetDashboardVersionQuery
{
OrgId
:
c
.
OrgId
,
DashboardId
:
dashI
d
,
DashboardId
:
dashI
D
,
Version
:
c
.
ParamsInt
(
":id"
),
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
ApiError
(
500
,
fmt
.
Sprintf
(
"Dashboard version %d not found for dashboardId %d"
,
query
.
Version
,
dashI
d
),
err
)
return
ApiError
(
500
,
fmt
.
Sprintf
(
"Dashboard version %d not found for dashboardId %d"
,
query
.
Version
,
dashI
D
),
err
)
}
creator
:=
"Anonymous"
...
...
pkg/api/dashboard_permission.go
View file @
22fffe0d
...
...
@@ -10,14 +10,14 @@ import (
)
func
GetDashboardPermissionList
(
c
*
m
.
ReqContext
)
Response
{
dashI
d
:=
c
.
ParamsInt64
(
":dashboardId"
)
dashI
D
:=
c
.
ParamsInt64
(
":dashboardId"
)
_
,
rsp
:=
getDashboardHelper
(
c
.
OrgId
,
""
,
dashI
d
,
""
)
_
,
rsp
:=
getDashboardHelper
(
c
.
OrgId
,
""
,
dashI
D
,
""
)
if
rsp
!=
nil
{
return
rsp
}
g
:=
guardian
.
New
(
dashI
d
,
c
.
OrgId
,
c
.
SignedInUser
)
g
:=
guardian
.
New
(
dashI
D
,
c
.
OrgId
,
c
.
SignedInUser
)
if
canAdmin
,
err
:=
g
.
CanAdmin
();
err
!=
nil
||
!
canAdmin
{
return
dashboardGuardianResponse
(
err
)
...
...
@@ -38,25 +38,25 @@ func GetDashboardPermissionList(c *m.ReqContext) Response {
}
func
UpdateDashboardPermissions
(
c
*
m
.
ReqContext
,
apiCmd
dtos
.
UpdateDashboardAclCommand
)
Response
{
dashI
d
:=
c
.
ParamsInt64
(
":dashboardId"
)
dashI
D
:=
c
.
ParamsInt64
(
":dashboardId"
)
_
,
rsp
:=
getDashboardHelper
(
c
.
OrgId
,
""
,
dashI
d
,
""
)
_
,
rsp
:=
getDashboardHelper
(
c
.
OrgId
,
""
,
dashI
D
,
""
)
if
rsp
!=
nil
{
return
rsp
}
g
:=
guardian
.
New
(
dashI
d
,
c
.
OrgId
,
c
.
SignedInUser
)
g
:=
guardian
.
New
(
dashI
D
,
c
.
OrgId
,
c
.
SignedInUser
)
if
canAdmin
,
err
:=
g
.
CanAdmin
();
err
!=
nil
||
!
canAdmin
{
return
dashboardGuardianResponse
(
err
)
}
cmd
:=
m
.
UpdateDashboardAclCommand
{}
cmd
.
DashboardId
=
dashI
d
cmd
.
DashboardId
=
dashI
D
for
_
,
item
:=
range
apiCmd
.
Items
{
cmd
.
Items
=
append
(
cmd
.
Items
,
&
m
.
DashboardAcl
{
OrgId
:
c
.
OrgId
,
DashboardId
:
dashI
d
,
DashboardId
:
dashI
D
,
UserId
:
item
.
UserId
,
TeamId
:
item
.
TeamId
,
Role
:
item
.
Role
,
...
...
pkg/api/dashboard_snapshot.go
View file @
22fffe0d
...
...
@@ -106,9 +106,9 @@ func DeleteDashboardSnapshot(c *m.ReqContext) Response {
return
ApiError
(
404
,
"Failed to get dashboard snapshot"
,
nil
)
}
dashboard
:=
query
.
Result
.
Dashboard
dashboardI
d
:=
dashboard
.
Get
(
"id"
)
.
MustInt64
()
dashboardI
D
:=
dashboard
.
Get
(
"id"
)
.
MustInt64
()
guardian
:=
guardian
.
New
(
dashboardI
d
,
c
.
OrgId
,
c
.
SignedInUser
)
guardian
:=
guardian
.
New
(
dashboardI
D
,
c
.
OrgId
,
c
.
SignedInUser
)
canEdit
,
err
:=
guardian
.
CanEdit
()
if
err
!=
nil
{
return
ApiError
(
500
,
"Error while checking permissions for snapshot"
,
err
)
...
...
pkg/api/dashboard_test.go
View file @
22fffe0d
...
...
@@ -105,7 +105,7 @@ func TestDashboardApiEndpoint(t *testing.T) {
})
loggedInUserScenarioWithRole
(
"When calling DELETE on"
,
"DELETE"
,
"/api/dashboards/uid/abcdefghi"
,
"/api/dashboards/uid/:uid"
,
role
,
func
(
sc
*
scenarioContext
)
{
CallDeleteDashboardByU
id
(
sc
)
CallDeleteDashboardByU
ID
(
sc
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
403
)
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
...
...
@@ -165,7 +165,7 @@ func TestDashboardApiEndpoint(t *testing.T) {
})
loggedInUserScenarioWithRole
(
"When calling DELETE on"
,
"DELETE"
,
"/api/dashboards/uid/abcdefghi"
,
"/api/dashboards/uid/:uid"
,
role
,
func
(
sc
*
scenarioContext
)
{
CallDeleteDashboardByU
id
(
sc
)
CallDeleteDashboardByU
ID
(
sc
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
200
)
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
...
...
@@ -271,7 +271,7 @@ func TestDashboardApiEndpoint(t *testing.T) {
})
loggedInUserScenarioWithRole
(
"When calling DELETE on"
,
"DELETE"
,
"/api/dashboards/uid/abcdefghi"
,
"/api/dashboards/uid/:uid"
,
role
,
func
(
sc
*
scenarioContext
)
{
CallDeleteDashboardByU
id
(
sc
)
CallDeleteDashboardByU
ID
(
sc
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
403
)
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
...
...
@@ -329,7 +329,7 @@ func TestDashboardApiEndpoint(t *testing.T) {
})
loggedInUserScenarioWithRole
(
"When calling DELETE on"
,
"DELETE"
,
"/api/dashboards/uid/abcdefghi"
,
"/api/dashboards/uid/:uid"
,
role
,
func
(
sc
*
scenarioContext
)
{
CallDeleteDashboardByU
id
(
sc
)
CallDeleteDashboardByU
ID
(
sc
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
403
)
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
...
...
@@ -398,7 +398,7 @@ func TestDashboardApiEndpoint(t *testing.T) {
})
loggedInUserScenarioWithRole
(
"When calling DELETE on"
,
"DELETE"
,
"/api/dashboards/uid/abcdefghi"
,
"/api/dashboards/uid/:uid"
,
role
,
func
(
sc
*
scenarioContext
)
{
CallDeleteDashboardByU
id
(
sc
)
CallDeleteDashboardByU
ID
(
sc
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
200
)
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
...
...
@@ -468,7 +468,7 @@ func TestDashboardApiEndpoint(t *testing.T) {
})
loggedInUserScenarioWithRole
(
"When calling DELETE on"
,
"DELETE"
,
"/api/dashboards/uid/abcdefghi"
,
"/api/dashboards/uid/:uid"
,
role
,
func
(
sc
*
scenarioContext
)
{
CallDeleteDashboardByU
id
(
sc
)
CallDeleteDashboardByU
ID
(
sc
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
403
)
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
...
...
@@ -527,7 +527,7 @@ func TestDashboardApiEndpoint(t *testing.T) {
})
loggedInUserScenarioWithRole
(
"When calling DELETE on"
,
"DELETE"
,
"/api/dashboards/uid/abcdefghi"
,
"/api/dashboards/uid/:uid"
,
role
,
func
(
sc
*
scenarioContext
)
{
CallDeleteDashboardByU
id
(
sc
)
CallDeleteDashboardByU
ID
(
sc
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
200
)
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
...
...
@@ -594,7 +594,7 @@ func TestDashboardApiEndpoint(t *testing.T) {
})
loggedInUserScenarioWithRole
(
"When calling DELETE on"
,
"DELETE"
,
"/api/dashboards/uid/abcdefghi"
,
"/api/dashboards/uid/:uid"
,
role
,
func
(
sc
*
scenarioContext
)
{
CallDeleteDashboardByU
id
(
sc
)
CallDeleteDashboardByU
ID
(
sc
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
403
)
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
...
...
@@ -837,12 +837,12 @@ func CallDeleteDashboard(sc *scenarioContext) {
sc
.
fakeReqWithParams
(
"DELETE"
,
sc
.
url
,
map
[
string
]
string
{})
.
exec
()
}
func
CallDeleteDashboardByU
id
(
sc
*
scenarioContext
)
{
func
CallDeleteDashboardByU
ID
(
sc
*
scenarioContext
)
{
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
DeleteDashboardCommand
)
error
{
return
nil
})
sc
.
handlerFunc
=
DeleteDashboardByU
id
sc
.
handlerFunc
=
DeleteDashboardByU
ID
sc
.
fakeReqWithParams
(
"DELETE"
,
sc
.
url
,
map
[
string
]
string
{})
.
exec
()
}
...
...
pkg/api/dataproxy.go
View file @
22fffe0d
...
...
@@ -13,19 +13,19 @@ import (
const
HeaderNameNoBackendCache
=
"X-Grafana-NoCache"
func
(
hs
*
HttpServer
)
getDatasourceByI
d
(
id
int64
,
orgId
int64
,
nocache
bool
)
(
*
m
.
DataSource
,
error
)
{
func
(
hs
*
HttpServer
)
getDatasourceByI
D
(
id
int64
,
orgID
int64
,
nocache
bool
)
(
*
m
.
DataSource
,
error
)
{
cacheKey
:=
fmt
.
Sprintf
(
"ds-%d"
,
id
)
if
!
nocache
{
if
cached
,
found
:=
hs
.
cache
.
Get
(
cacheKey
);
found
{
ds
:=
cached
.
(
*
m
.
DataSource
)
if
ds
.
OrgId
==
orgI
d
{
if
ds
.
OrgId
==
orgI
D
{
return
ds
,
nil
}
}
}
query
:=
m
.
GetDataSourceByIdQuery
{
Id
:
id
,
OrgId
:
orgI
d
}
query
:=
m
.
GetDataSourceByIdQuery
{
Id
:
id
,
OrgId
:
orgI
D
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -39,7 +39,7 @@ func (hs *HttpServer) ProxyDataSourceRequest(c *m.ReqContext) {
nocache
:=
c
.
Req
.
Header
.
Get
(
HeaderNameNoBackendCache
)
==
"true"
ds
,
err
:=
hs
.
getDatasourceByI
d
(
c
.
ParamsInt64
(
":id"
),
c
.
OrgId
,
nocache
)
ds
,
err
:=
hs
.
getDatasourceByI
D
(
c
.
ParamsInt64
(
":id"
),
c
.
OrgId
,
nocache
)
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Unable to load datasource meta data"
,
err
)
...
...
pkg/api/datasources.go
View file @
22fffe0d
...
...
@@ -49,7 +49,7 @@ func GetDataSources(c *m.ReqContext) Response {
return
Json
(
200
,
&
result
)
}
func
GetDataSourceByI
d
(
c
*
m
.
ReqContext
)
Response
{
func
GetDataSourceByI
D
(
c
*
m
.
ReqContext
)
Response
{
query
:=
m
.
GetDataSourceByIdQuery
{
Id
:
c
.
ParamsInt64
(
":id"
),
OrgId
:
c
.
OrgId
,
...
...
@@ -68,14 +68,14 @@ func GetDataSourceById(c *m.ReqContext) Response {
return
Json
(
200
,
&
dtos
)
}
func
DeleteDataSourceByI
d
(
c
*
m
.
ReqContext
)
Response
{
func
DeleteDataSourceByI
D
(
c
*
m
.
ReqContext
)
Response
{
id
:=
c
.
ParamsInt64
(
":id"
)
if
id
<=
0
{
return
ApiError
(
400
,
"Missing valid datasource id"
,
nil
)
}
ds
,
err
:=
getRawDataSourceByI
d
(
id
,
c
.
OrgId
)
ds
,
err
:=
getRawDataSourceByI
D
(
id
,
c
.
OrgId
)
if
err
!=
nil
{
return
ApiError
(
400
,
"Failed to delete datasource"
,
nil
)
}
...
...
@@ -143,7 +143,7 @@ func UpdateDataSource(c *m.ReqContext, cmd m.UpdateDataSourceCommand) Response {
cmd
.
OrgId
=
c
.
OrgId
cmd
.
Id
=
c
.
ParamsInt64
(
":id"
)
err
:=
fillWithSecureJ
son
Data
(
&
cmd
)
err
:=
fillWithSecureJ
SON
Data
(
&
cmd
)
if
err
!=
nil
{
return
ApiError
(
500
,
"Failed to update datasource"
,
err
)
}
...
...
@@ -152,9 +152,8 @@ func UpdateDataSource(c *m.ReqContext, cmd m.UpdateDataSourceCommand) Response {
if
err
!=
nil
{
if
err
==
m
.
ErrDataSourceUpdatingOldVersion
{
return
ApiError
(
500
,
"Failed to update datasource. Reload new version and try again"
,
err
)
}
else
{
return
ApiError
(
500
,
"Failed to update datasource"
,
err
)
}
return
ApiError
(
500
,
"Failed to update datasource"
,
err
)
}
ds
:=
convertModelToDtos
(
cmd
.
Result
)
return
Json
(
200
,
util
.
DynMap
{
...
...
@@ -165,12 +164,12 @@ func UpdateDataSource(c *m.ReqContext, cmd m.UpdateDataSourceCommand) Response {
})
}
func
fillWithSecureJ
son
Data
(
cmd
*
m
.
UpdateDataSourceCommand
)
error
{
func
fillWithSecureJ
SON
Data
(
cmd
*
m
.
UpdateDataSourceCommand
)
error
{
if
len
(
cmd
.
SecureJsonData
)
==
0
{
return
nil
}
ds
,
err
:=
getRawDataSourceByI
d
(
cmd
.
Id
,
cmd
.
OrgId
)
ds
,
err
:=
getRawDataSourceByI
D
(
cmd
.
Id
,
cmd
.
OrgId
)
if
err
!=
nil
{
return
err
}
...
...
@@ -179,8 +178,8 @@ func fillWithSecureJsonData(cmd *m.UpdateDataSourceCommand) error {
return
m
.
ErrDatasourceIsReadOnly
}
secureJ
son
Data
:=
ds
.
SecureJsonData
.
Decrypt
()
for
k
,
v
:=
range
secureJ
son
Data
{
secureJ
SON
Data
:=
ds
.
SecureJsonData
.
Decrypt
()
for
k
,
v
:=
range
secureJ
SON
Data
{
if
_
,
ok
:=
cmd
.
SecureJsonData
[
k
];
!
ok
{
cmd
.
SecureJsonData
[
k
]
=
v
...
...
@@ -190,10 +189,10 @@ func fillWithSecureJsonData(cmd *m.UpdateDataSourceCommand) error {
return
nil
}
func
getRawDataSourceByI
d
(
id
int64
,
orgId
int64
)
(
*
m
.
DataSource
,
error
)
{
func
getRawDataSourceByI
D
(
id
int64
,
orgID
int64
)
(
*
m
.
DataSource
,
error
)
{
query
:=
m
.
GetDataSourceByIdQuery
{
Id
:
id
,
OrgId
:
orgI
d
,
OrgId
:
orgI
D
,
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
...
...
@@ -220,7 +219,7 @@ func GetDataSourceByName(c *m.ReqContext) Response {
}
// Get /api/datasources/id/:name
func
GetDataSourceI
d
ByName
(
c
*
m
.
ReqContext
)
Response
{
func
GetDataSourceI
D
ByName
(
c
*
m
.
ReqContext
)
Response
{
query
:=
m
.
GetDataSourceByNameQuery
{
Name
:
c
.
Params
(
":name"
),
OrgId
:
c
.
OrgId
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
...
...
pkg/api/folder.go
View file @
22fffe0d
...
...
@@ -31,7 +31,7 @@ func GetFolders(c *m.ReqContext) Response {
return
Json
(
200
,
result
)
}
func
GetFolderByU
id
(
c
*
m
.
ReqContext
)
Response
{
func
GetFolderByU
ID
(
c
*
m
.
ReqContext
)
Response
{
s
:=
dashboards
.
NewFolderService
(
c
.
OrgId
,
c
.
SignedInUser
)
folder
,
err
:=
s
.
GetFolderByUid
(
c
.
Params
(
":uid"
))
...
...
@@ -43,7 +43,7 @@ func GetFolderByUid(c *m.ReqContext) Response {
return
Json
(
200
,
toFolderDto
(
g
,
folder
))
}
func
GetFolderByI
d
(
c
*
m
.
ReqContext
)
Response
{
func
GetFolderByI
D
(
c
*
m
.
ReqContext
)
Response
{
s
:=
dashboards
.
NewFolderService
(
c
.
OrgId
,
c
.
SignedInUser
)
folder
,
err
:=
s
.
GetFolderById
(
c
.
ParamsInt64
(
":id"
))
if
err
!=
nil
{
...
...
pkg/api/folder_test.go
View file @
22fffe0d
...
...
@@ -133,8 +133,8 @@ func TestFoldersApiEndpoint(t *testing.T) {
})
}
func
callGetFolderByU
id
(
sc
*
scenarioContext
)
{
sc
.
handlerFunc
=
GetFolderByU
id
func
callGetFolderByU
ID
(
sc
*
scenarioContext
)
{
sc
.
handlerFunc
=
GetFolderByU
ID
sc
.
fakeReqWithParams
(
"GET"
,
sc
.
url
,
map
[
string
]
string
{})
.
exec
()
}
...
...
pkg/api/http_server.go
View file @
22fffe0d
...
...
@@ -39,7 +39,7 @@ type HttpServer struct {
httpSrv
*
http
.
Server
}
func
NewH
ttp
Server
()
*
HttpServer
{
func
NewH
TTP
Server
()
*
HttpServer
{
return
&
HttpServer
{
log
:
log
.
New
(
"http.server"
),
cache
:
gocache
.
New
(
5
*
time
.
Minute
,
10
*
time
.
Minute
),
...
...
pkg/api/index.go
View file @
22fffe0d
...
...
@@ -32,13 +32,13 @@ func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
locale
=
parts
[
0
]
}
appU
rl
:=
setting
.
AppUrl
appSubU
rl
:=
setting
.
AppSubUrl
appU
RL
:=
setting
.
AppUrl
appSubU
RL
:=
setting
.
AppSubUrl
// special case when doing localhost call from phantomjs
if
c
.
IsRenderCall
{
appU
rl
=
fmt
.
Sprintf
(
"%s://localhost:%s"
,
setting
.
Protocol
,
setting
.
HttpPort
)
appSubU
rl
=
""
appU
RL
=
fmt
.
Sprintf
(
"%s://localhost:%s"
,
setting
.
Protocol
,
setting
.
HttpPort
)
appSubU
RL
=
""
settings
[
"appSubUrl"
]
=
""
}
...
...
@@ -62,8 +62,8 @@ func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
},
Settings
:
settings
,
Theme
:
prefs
.
Theme
,
AppUrl
:
appU
rl
,
AppSubUrl
:
appSubU
rl
,
AppUrl
:
appU
RL
,
AppSubUrl
:
appSubU
RL
,
GoogleAnalyticsId
:
setting
.
GoogleAnalyticsId
,
GoogleTagManagerId
:
setting
.
GoogleTagManagerId
,
BuildVersion
:
setting
.
BuildVersion
,
...
...
@@ -80,8 +80,8 @@ func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
data
.
User
.
Name
=
data
.
User
.
Login
}
themeU
rl
Param
:=
c
.
Query
(
"theme"
)
if
themeU
rl
Param
==
"light"
{
themeU
RL
Param
:=
c
.
Query
(
"theme"
)
if
themeU
RL
Param
==
"light"
{
data
.
User
.
LightTheme
=
true
data
.
Theme
=
"light"
}
...
...
@@ -299,12 +299,12 @@ func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
}
func
Index
(
c
*
m
.
ReqContext
)
{
if
data
,
err
:=
setIndexViewData
(
c
);
err
!=
nil
{
data
,
err
:=
setIndexViewData
(
c
)
if
err
!=
nil
{
c
.
Handle
(
500
,
"Failed to get settings"
,
err
)
return
}
else
{
c
.
HTML
(
200
,
"index"
,
data
)
}
c
.
HTML
(
200
,
"index"
,
data
)
}
func
NotFoundHandler
(
c
*
m
.
ReqContext
)
{
...
...
@@ -313,10 +313,11 @@ func NotFoundHandler(c *m.ReqContext) {
return
}
if
data
,
err
:=
setIndexViewData
(
c
);
err
!=
nil
{
data
,
err
:=
setIndexViewData
(
c
)
if
err
!=
nil
{
c
.
Handle
(
500
,
"Failed to get settings"
,
err
)
return
}
else
{
c
.
HTML
(
404
,
"index"
,
data
)
}
c
.
HTML
(
404
,
"index"
,
data
)
}
pkg/api/login.go
View file @
22fffe0d
...
...
@@ -14,7 +14,7 @@ import (
)
const
(
V
IEW_INDEX
=
"index"
V
iewIndex
=
"index"
)
func
LoginView
(
c
*
m
.
ReqContext
)
{
...
...
@@ -40,7 +40,7 @@ func LoginView(c *m.ReqContext) {
}
if
!
tryLoginUsingRememberCookie
(
c
)
{
c
.
HTML
(
200
,
V
IEW_INDEX
,
viewData
)
c
.
HTML
(
200
,
V
iewIndex
,
viewData
)
return
}
...
...
@@ -87,7 +87,7 @@ func tryLoginUsingRememberCookie(c *m.ReqContext) bool {
return
true
}
func
LoginA
pi
Ping
(
c
*
m
.
ReqContext
)
{
func
LoginA
PI
Ping
(
c
*
m
.
ReqContext
)
{
if
!
tryLoginUsingRememberCookie
(
c
)
{
c
.
JsonApiErr
(
401
,
"Unauthorized"
,
nil
)
return
...
...
pkg/api/metrics.go
View file @
22fffe0d
...
...
@@ -20,12 +20,12 @@ func QueryMetrics(c *m.ReqContext, reqDto dtos.MetricRequest) Response {
return
ApiError
(
400
,
"No queries found in query"
,
nil
)
}
dsI
d
,
err
:=
reqDto
.
Queries
[
0
]
.
Get
(
"datasourceId"
)
.
Int64
()
dsI
D
,
err
:=
reqDto
.
Queries
[
0
]
.
Get
(
"datasourceId"
)
.
Int64
()
if
err
!=
nil
{
return
ApiError
(
400
,
"Query missing datasourceId"
,
nil
)
}
dsQuery
:=
m
.
GetDataSourceByIdQuery
{
Id
:
dsI
d
,
OrgId
:
c
.
OrgId
}
dsQuery
:=
m
.
GetDataSourceByIdQuery
{
Id
:
dsI
D
,
OrgId
:
c
.
OrgId
}
if
err
:=
bus
.
Dispatch
(
&
dsQuery
);
err
!=
nil
{
return
ApiError
(
500
,
"failed to fetch data source"
,
err
)
}
...
...
@@ -82,7 +82,7 @@ func GenerateError(c *m.ReqContext) Response {
}
// GET /api/tsdb/testdata/gensql
func
GenerateS
ql
TestData
(
c
*
m
.
ReqContext
)
Response
{
func
GenerateS
QL
TestData
(
c
*
m
.
ReqContext
)
Response
{
if
err
:=
bus
.
Dispatch
(
&
m
.
InsertSqlTestDataCommand
{});
err
!=
nil
{
return
ApiError
(
500
,
"Failed to insert test data"
,
err
)
}
...
...
pkg/api/org.go
View file @
22fffe0d
...
...
@@ -15,7 +15,7 @@ func GetOrgCurrent(c *m.ReqContext) Response {
}
// GET /api/orgs/:orgId
func
GetOrgByI
d
(
c
*
m
.
ReqContext
)
Response
{
func
GetOrgByI
D
(
c
*
m
.
ReqContext
)
Response
{
return
getOrgHelper
(
c
.
ParamsInt64
(
":orgId"
))
}
...
...
@@ -106,8 +106,8 @@ func UpdateOrg(c *m.ReqContext, form dtos.UpdateOrgForm) Response {
return
updateOrgHelper
(
form
,
c
.
ParamsInt64
(
":orgId"
))
}
func
updateOrgHelper
(
form
dtos
.
UpdateOrgForm
,
orgI
d
int64
)
Response
{
cmd
:=
m
.
UpdateOrgCommand
{
Name
:
form
.
Name
,
OrgId
:
orgI
d
}
func
updateOrgHelper
(
form
dtos
.
UpdateOrgForm
,
orgI
D
int64
)
Response
{
cmd
:=
m
.
UpdateOrgCommand
{
Name
:
form
.
Name
,
OrgId
:
orgI
D
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
==
m
.
ErrOrgNameTaken
{
return
ApiError
(
400
,
"Organization name taken"
,
err
)
...
...
@@ -128,9 +128,9 @@ func UpdateOrgAddress(c *m.ReqContext, form dtos.UpdateOrgAddressForm) Response
return
updateOrgAddressHelper
(
form
,
c
.
ParamsInt64
(
":orgId"
))
}
func
updateOrgAddressHelper
(
form
dtos
.
UpdateOrgAddressForm
,
orgI
d
int64
)
Response
{
func
updateOrgAddressHelper
(
form
dtos
.
UpdateOrgAddressForm
,
orgI
D
int64
)
Response
{
cmd
:=
m
.
UpdateOrgAddressCommand
{
OrgId
:
orgI
d
,
OrgId
:
orgI
D
,
Address
:
m
.
Address
{
Address1
:
form
.
Address1
,
Address2
:
form
.
Address2
,
...
...
@@ -149,7 +149,7 @@ func updateOrgAddressHelper(form dtos.UpdateOrgAddressForm, orgId int64) Respons
}
// GET /api/orgs/:orgId
func
DeleteOrgByI
d
(
c
*
m
.
ReqContext
)
Response
{
func
DeleteOrgByI
D
(
c
*
m
.
ReqContext
)
Response
{
if
err
:=
bus
.
Dispatch
(
&
m
.
DeleteOrgCommand
{
Id
:
c
.
ParamsInt64
(
":orgId"
)});
err
!=
nil
{
if
err
==
m
.
ErrOrgNotFound
{
return
ApiError
(
404
,
"Failed to delete organization. ID not found"
,
nil
)
...
...
pkg/api/org_invite.go
View file @
22fffe0d
...
...
@@ -96,7 +96,7 @@ func inviteExistingUserToOrg(c *m.ReqContext, user *m.User, inviteDto *dtos.AddI
return
ApiError
(
412
,
fmt
.
Sprintf
(
"User %s is already added to organization"
,
inviteDto
.
LoginOrEmail
),
err
)
}
return
ApiError
(
500
,
"Error while trying to create org user"
,
err
)
}
else
{
}
if
inviteDto
.
SendEmail
&&
util
.
IsEmail
(
user
.
Email
)
{
emailCmd
:=
m
.
SendEmailCommand
{
...
...
@@ -115,7 +115,6 @@ func inviteExistingUserToOrg(c *m.ReqContext, user *m.User, inviteDto *dtos.AddI
}
return
ApiSuccess
(
fmt
.
Sprintf
(
"Existing Grafana user %s added to org %s"
,
user
.
NameOrFallback
(),
c
.
OrgName
))
}
}
func
RevokeInvite
(
c
*
m
.
ReqContext
)
Response
{
...
...
pkg/api/org_users.go
View file @
22fffe0d
...
...
@@ -53,9 +53,9 @@ func GetOrgUsers(c *m.ReqContext) Response {
return
getOrgUsersHelper
(
c
.
ParamsInt64
(
":orgId"
),
""
,
0
)
}
func
getOrgUsersHelper
(
orgI
d
int64
,
query
string
,
limit
int
)
Response
{
func
getOrgUsersHelper
(
orgI
D
int64
,
query
string
,
limit
int
)
Response
{
q
:=
m
.
GetOrgUsersQuery
{
OrgId
:
orgI
d
,
OrgId
:
orgI
D
,
Query
:
query
,
Limit
:
limit
,
}
...
...
@@ -102,19 +102,19 @@ func updateOrgUserHelper(cmd m.UpdateOrgUserCommand) Response {
// DELETE /api/org/users/:userId
func
RemoveOrgUserForCurrentOrg
(
c
*
m
.
ReqContext
)
Response
{
userI
d
:=
c
.
ParamsInt64
(
":userId"
)
return
removeOrgUserHelper
(
c
.
OrgId
,
userI
d
)
userI
D
:=
c
.
ParamsInt64
(
":userId"
)
return
removeOrgUserHelper
(
c
.
OrgId
,
userI
D
)
}
// DELETE /api/orgs/:orgId/users/:userId
func
RemoveOrgUser
(
c
*
m
.
ReqContext
)
Response
{
userI
d
:=
c
.
ParamsInt64
(
":userId"
)
orgI
d
:=
c
.
ParamsInt64
(
":orgId"
)
return
removeOrgUserHelper
(
orgI
d
,
userId
)
userI
D
:=
c
.
ParamsInt64
(
":userId"
)
orgI
D
:=
c
.
ParamsInt64
(
":orgId"
)
return
removeOrgUserHelper
(
orgI
D
,
userID
)
}
func
removeOrgUserHelper
(
orgI
d
int64
,
userId
int64
)
Response
{
cmd
:=
m
.
RemoveOrgUserCommand
{
OrgId
:
orgI
d
,
UserId
:
userId
}
func
removeOrgUserHelper
(
orgI
D
int64
,
userID
int64
)
Response
{
cmd
:=
m
.
RemoveOrgUserCommand
{
OrgId
:
orgI
D
,
UserId
:
userID
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
==
m
.
ErrLastOrgAdmin
{
...
...
pkg/api/playlist.go
View file @
22fffe0d
...
...
@@ -127,9 +127,9 @@ func GetPlaylistItems(c *m.ReqContext) Response {
}
func
GetPlaylistDashboards
(
c
*
m
.
ReqContext
)
Response
{
playlistI
d
:=
c
.
ParamsInt64
(
":id"
)
playlistI
D
:=
c
.
ParamsInt64
(
":id"
)
playlists
,
err
:=
LoadPlaylistDashboards
(
c
.
OrgId
,
c
.
SignedInUser
,
playlistI
d
)
playlists
,
err
:=
LoadPlaylistDashboards
(
c
.
OrgId
,
c
.
SignedInUser
,
playlistI
D
)
if
err
!=
nil
{
return
ApiError
(
500
,
"Could not load dashboards"
,
err
)
}
...
...
pkg/api/playlist_play.go
View file @
22fffe0d
...
...
@@ -34,10 +34,9 @@ func populateDashboardsById(dashboardByIds []int64, dashboardIdOrder map[int64]i
return
result
,
nil
}
func
populateDashboardsByTag
(
orgI
d
int64
,
signedInUser
*
m
.
SignedInUser
,
dashboardByTag
[]
string
,
dashboardTagOrder
map
[
string
]
int
)
dtos
.
PlaylistDashboardsSlice
{
func
populateDashboardsByTag
(
orgI
D
int64
,
signedInUser
*
m
.
SignedInUser
,
dashboardByTag
[]
string
,
dashboardTagOrder
map
[
string
]
int
)
dtos
.
PlaylistDashboardsSlice
{
result
:=
make
(
dtos
.
PlaylistDashboardsSlice
,
0
)
if
len
(
dashboardByTag
)
>
0
{
for
_
,
tag
:=
range
dashboardByTag
{
searchQuery
:=
search
.
Query
{
Title
:
""
,
...
...
@@ -45,7 +44,7 @@ func populateDashboardsByTag(orgId int64, signedInUser *m.SignedInUser, dashboar
SignedInUser
:
signedInUser
,
Limit
:
100
,
IsStarred
:
false
,
OrgId
:
orgId
,
OrgId
:
orgID
,
}
if
err
:=
bus
.
Dispatch
(
&
searchQuery
);
err
==
nil
{
...
...
@@ -59,24 +58,23 @@ func populateDashboardsByTag(orgId int64, signedInUser *m.SignedInUser, dashboar
}
}
}
}
return
result
}
func
LoadPlaylistDashboards
(
orgI
d
int64
,
signedInUser
*
m
.
SignedInUser
,
playlistId
int64
)
(
dtos
.
PlaylistDashboardsSlice
,
error
)
{
playlistItems
,
_
:=
LoadPlaylistItems
(
playlistI
d
)
func
LoadPlaylistDashboards
(
orgI
D
int64
,
signedInUser
*
m
.
SignedInUser
,
playlistID
int64
)
(
dtos
.
PlaylistDashboardsSlice
,
error
)
{
playlistItems
,
_
:=
LoadPlaylistItems
(
playlistI
D
)
dashboardByI
d
s
:=
make
([]
int64
,
0
)
dashboardByI
D
s
:=
make
([]
int64
,
0
)
dashboardByTag
:=
make
([]
string
,
0
)
dashboardI
d
Order
:=
make
(
map
[
int64
]
int
)
dashboardI
D
Order
:=
make
(
map
[
int64
]
int
)
dashboardTagOrder
:=
make
(
map
[
string
]
int
)
for
_
,
i
:=
range
playlistItems
{
if
i
.
Type
==
"dashboard_by_id"
{
dashboardI
d
,
_
:=
strconv
.
ParseInt
(
i
.
Value
,
10
,
64
)
dashboardByI
ds
=
append
(
dashboardByIds
,
dashboardId
)
dashboardI
dOrder
[
dashboardId
]
=
i
.
Order
dashboardI
D
,
_
:=
strconv
.
ParseInt
(
i
.
Value
,
10
,
64
)
dashboardByI
Ds
=
append
(
dashboardByIDs
,
dashboardID
)
dashboardI
DOrder
[
dashboardID
]
=
i
.
Order
}
if
i
.
Type
==
"dashboard_by_tag"
{
...
...
@@ -87,9 +85,9 @@ func LoadPlaylistDashboards(orgId int64, signedInUser *m.SignedInUser, playlistI
result
:=
make
(
dtos
.
PlaylistDashboardsSlice
,
0
)
var
k
,
_
=
populateDashboardsById
(
dashboardByI
ds
,
dashboardId
Order
)
var
k
,
_
=
populateDashboardsById
(
dashboardByI
Ds
,
dashboardID
Order
)
result
=
append
(
result
,
k
...
)
result
=
append
(
result
,
populateDashboardsByTag
(
orgI
d
,
signedInUser
,
dashboardByTag
,
dashboardTagOrder
)
...
)
result
=
append
(
result
,
populateDashboardsByTag
(
orgI
D
,
signedInUser
,
dashboardByTag
,
dashboardTagOrder
)
...
)
sort
.
Sort
(
result
)
return
result
,
nil
...
...
pkg/api/plugins.go
View file @
22fffe0d
...
...
@@ -78,12 +78,13 @@ func GetPluginList(c *m.ReqContext) Response {
return
Json
(
200
,
result
)
}
func
GetPluginSettingByI
d
(
c
*
m
.
ReqContext
)
Response
{
pluginI
d
:=
c
.
Params
(
":pluginId"
)
func
GetPluginSettingByI
D
(
c
*
m
.
ReqContext
)
Response
{
pluginI
D
:=
c
.
Params
(
":pluginId"
)
if
def
,
exists
:=
plugins
.
Plugins
[
pluginId
];
!
exists
{
def
,
exists
:=
plugins
.
Plugins
[
pluginID
]
if
!
exists
{
return
ApiError
(
404
,
"Plugin not found, no installed plugin with that id"
,
nil
)
}
else
{
}
dto
:=
&
dtos
.
PluginSetting
{
Type
:
def
.
Type
,
...
...
@@ -100,7 +101,7 @@ func GetPluginSettingById(c *m.ReqContext) Response {
State
:
def
.
State
,
}
query
:=
m
.
GetPluginSettingByIdQuery
{
PluginId
:
pluginId
,
OrgId
:
c
.
OrgId
}
query
:=
m
.
GetPluginSettingByIdQuery
{
PluginId
:
pluginID
,
OrgId
:
c
.
OrgId
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
if
err
!=
m
.
ErrPluginSettingNotFound
{
return
ApiError
(
500
,
"Failed to get login settings"
,
nil
)
...
...
@@ -112,14 +113,13 @@ func GetPluginSettingById(c *m.ReqContext) Response {
}
return
Json
(
200
,
dto
)
}
}
func
UpdatePluginSetting
(
c
*
m
.
ReqContext
,
cmd
m
.
UpdatePluginSettingCmd
)
Response
{
pluginI
d
:=
c
.
Params
(
":pluginId"
)
pluginI
D
:=
c
.
Params
(
":pluginId"
)
cmd
.
OrgId
=
c
.
OrgId
cmd
.
PluginId
=
pluginI
d
cmd
.
PluginId
=
pluginI
D
if
_
,
ok
:=
plugins
.
Apps
[
cmd
.
PluginId
];
!
ok
{
return
ApiError
(
404
,
"Plugin not installed."
,
nil
)
...
...
@@ -133,34 +133,36 @@ func UpdatePluginSetting(c *m.ReqContext, cmd m.UpdatePluginSettingCmd) Response
}
func
GetPluginDashboards
(
c
*
m
.
ReqContext
)
Response
{
pluginI
d
:=
c
.
Params
(
":pluginId"
)
pluginI
D
:=
c
.
Params
(
":pluginId"
)
if
list
,
err
:=
plugins
.
GetPluginDashboards
(
c
.
OrgId
,
pluginId
);
err
!=
nil
{
list
,
err
:=
plugins
.
GetPluginDashboards
(
c
.
OrgId
,
pluginID
)
if
err
!=
nil
{
if
notfound
,
ok
:=
err
.
(
plugins
.
PluginNotFoundError
);
ok
{
return
ApiError
(
404
,
notfound
.
Error
(),
nil
)
}
return
ApiError
(
500
,
"Failed to get plugin dashboards"
,
err
)
}
else
{
return
Json
(
200
,
list
)
}
return
Json
(
200
,
list
)
}
func
GetPluginMarkdown
(
c
*
m
.
ReqContext
)
Response
{
pluginI
d
:=
c
.
Params
(
":pluginId"
)
pluginI
D
:=
c
.
Params
(
":pluginId"
)
name
:=
c
.
Params
(
":name"
)
if
content
,
err
:=
plugins
.
GetPluginMarkdown
(
pluginId
,
name
);
err
!=
nil
{
content
,
err
:=
plugins
.
GetPluginMarkdown
(
pluginID
,
name
)
if
err
!=
nil
{
if
notfound
,
ok
:=
err
.
(
plugins
.
PluginNotFoundError
);
ok
{
return
ApiError
(
404
,
notfound
.
Error
(),
nil
)
}
return
ApiError
(
500
,
"Could not get markdown file"
,
err
)
}
else
{
}
resp
:=
Respond
(
200
,
content
)
resp
.
Header
(
"Content-Type"
,
"text/plain; charset=utf-8"
)
return
resp
}
}
func
ImportDashboard
(
c
*
m
.
ReqContext
,
apiCmd
dtos
.
ImportDashboardCommand
)
Response
{
...
...
pkg/api/preferences.go
View file @
22fffe0d
...
...
@@ -24,8 +24,8 @@ func GetUserPreferences(c *m.ReqContext) Response {
return
getPreferencesFor
(
c
.
OrgId
,
c
.
UserId
)
}
func
getPreferencesFor
(
orgI
d
int64
,
userId
int64
)
Response
{
prefsQuery
:=
m
.
GetPreferencesQuery
{
UserId
:
userI
d
,
OrgId
:
orgId
}
func
getPreferencesFor
(
orgI
D
int64
,
userID
int64
)
Response
{
prefsQuery
:=
m
.
GetPreferencesQuery
{
UserId
:
userI
D
,
OrgId
:
orgID
}
if
err
:=
bus
.
Dispatch
(
&
prefsQuery
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to get preferences"
,
err
)
...
...
@@ -45,10 +45,10 @@ func UpdateUserPreferences(c *m.ReqContext, dtoCmd dtos.UpdatePrefsCmd) Response
return
updatePreferencesFor
(
c
.
OrgId
,
c
.
UserId
,
&
dtoCmd
)
}
func
updatePreferencesFor
(
orgI
d
int64
,
userId
int64
,
dtoCmd
*
dtos
.
UpdatePrefsCmd
)
Response
{
func
updatePreferencesFor
(
orgI
D
int64
,
userID
int64
,
dtoCmd
*
dtos
.
UpdatePrefsCmd
)
Response
{
saveCmd
:=
m
.
SavePreferencesCommand
{
UserId
:
userI
d
,
OrgId
:
orgI
d
,
UserId
:
userI
D
,
OrgId
:
orgI
D
,
Theme
:
dtoCmd
.
Theme
,
Timezone
:
dtoCmd
.
Timezone
,
HomeDashboardId
:
dtoCmd
.
HomeDashboardId
,
...
...
pkg/api/search.go
View file @
22fffe0d
...
...
@@ -25,19 +25,19 @@ func Search(c *m.ReqContext) {
permission
=
m
.
PERMISSION_EDIT
}
db
id
s
:=
make
([]
int64
,
0
)
db
ID
s
:=
make
([]
int64
,
0
)
for
_
,
id
:=
range
c
.
QueryStrings
(
"dashboardIds"
)
{
dashboardI
d
,
err
:=
strconv
.
ParseInt
(
id
,
10
,
64
)
dashboardI
D
,
err
:=
strconv
.
ParseInt
(
id
,
10
,
64
)
if
err
==
nil
{
db
ids
=
append
(
dbids
,
dashboardId
)
db
IDs
=
append
(
dbIDs
,
dashboardID
)
}
}
folderI
d
s
:=
make
([]
int64
,
0
)
folderI
D
s
:=
make
([]
int64
,
0
)
for
_
,
id
:=
range
c
.
QueryStrings
(
"folderIds"
)
{
folderI
d
,
err
:=
strconv
.
ParseInt
(
id
,
10
,
64
)
folderI
D
,
err
:=
strconv
.
ParseInt
(
id
,
10
,
64
)
if
err
==
nil
{
folderI
ds
=
append
(
folderIds
,
folderId
)
folderI
Ds
=
append
(
folderIDs
,
folderID
)
}
}
...
...
@@ -48,9 +48,9 @@ func Search(c *m.ReqContext) {
Limit
:
limit
,
IsStarred
:
starred
==
"true"
,
OrgId
:
c
.
OrgId
,
DashboardIds
:
db
id
s
,
DashboardIds
:
db
ID
s
,
Type
:
dashboardType
,
FolderIds
:
folderI
d
s
,
FolderIds
:
folderI
D
s
,
Permission
:
permission
,
}
...
...
pkg/api/team.go
View file @
22fffe0d
...
...
@@ -38,7 +38,7 @@ func UpdateTeam(c *m.ReqContext, cmd m.UpdateTeamCommand) Response {
}
// DELETE /api/teams/:teamId
func
DeleteTeamByI
d
(
c
*
m
.
ReqContext
)
Response
{
func
DeleteTeamByI
D
(
c
*
m
.
ReqContext
)
Response
{
if
err
:=
bus
.
Dispatch
(
&
m
.
DeleteTeamCommand
{
OrgId
:
c
.
OrgId
,
Id
:
c
.
ParamsInt64
(
":teamId"
)});
err
!=
nil
{
if
err
==
m
.
ErrTeamNotFound
{
return
ApiError
(
404
,
"Failed to delete Team. ID not found"
,
nil
)
...
...
@@ -82,7 +82,7 @@ func SearchTeams(c *m.ReqContext) Response {
}
// GET /api/teams/:teamId
func
GetTeamByI
d
(
c
*
m
.
ReqContext
)
Response
{
func
GetTeamByI
D
(
c
*
m
.
ReqContext
)
Response
{
query
:=
m
.
GetTeamByIdQuery
{
OrgId
:
c
.
OrgId
,
Id
:
c
.
ParamsInt64
(
":teamId"
)}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
...
...
pkg/api/user.go
View file @
22fffe0d
...
...
@@ -14,12 +14,12 @@ func GetSignedInUser(c *m.ReqContext) Response {
}
// GET /api/users/:id
func
GetUserByI
d
(
c
*
m
.
ReqContext
)
Response
{
func
GetUserByI
D
(
c
*
m
.
ReqContext
)
Response
{
return
getUserUserProfile
(
c
.
ParamsInt64
(
":id"
))
}
func
getUserUserProfile
(
userI
d
int64
)
Response
{
query
:=
m
.
GetUserProfileQuery
{
UserId
:
userI
d
}
func
getUserUserProfile
(
userI
D
int64
)
Response
{
query
:=
m
.
GetUserProfileQuery
{
UserId
:
userI
D
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
if
err
==
m
.
ErrUserNotFound
{
...
...
@@ -75,14 +75,14 @@ func UpdateUser(c *m.ReqContext, cmd m.UpdateUserCommand) Response {
//POST /api/users/:id/using/:orgId
func
UpdateUserActiveOrg
(
c
*
m
.
ReqContext
)
Response
{
userI
d
:=
c
.
ParamsInt64
(
":id"
)
orgI
d
:=
c
.
ParamsInt64
(
":orgId"
)
userI
D
:=
c
.
ParamsInt64
(
":id"
)
orgI
D
:=
c
.
ParamsInt64
(
":orgId"
)
if
!
validateUsingOrg
(
userI
d
,
orgId
)
{
if
!
validateUsingOrg
(
userI
D
,
orgID
)
{
return
ApiError
(
401
,
"Not a valid organization"
,
nil
)
}
cmd
:=
m
.
SetUsingOrgCommand
{
UserId
:
userI
d
,
OrgId
:
orgId
}
cmd
:=
m
.
SetUsingOrgCommand
{
UserId
:
userI
D
,
OrgId
:
orgID
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to change active organization"
,
err
)
...
...
@@ -116,8 +116,8 @@ func GetUserOrgList(c *m.ReqContext) Response {
return
getUserOrgList
(
c
.
ParamsInt64
(
":id"
))
}
func
getUserOrgList
(
userI
d
int64
)
Response
{
query
:=
m
.
GetUserOrgListQuery
{
UserId
:
userI
d
}
func
getUserOrgList
(
userI
D
int64
)
Response
{
query
:=
m
.
GetUserOrgListQuery
{
UserId
:
userI
D
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to get user organizations"
,
err
)
...
...
@@ -126,8 +126,8 @@ func getUserOrgList(userId int64) Response {
return
Json
(
200
,
query
.
Result
)
}
func
validateUsingOrg
(
userI
d
int64
,
orgId
int64
)
bool
{
query
:=
m
.
GetUserOrgListQuery
{
UserId
:
userI
d
}
func
validateUsingOrg
(
userI
D
int64
,
orgID
int64
)
bool
{
query
:=
m
.
GetUserOrgListQuery
{
UserId
:
userI
D
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
false
...
...
@@ -136,7 +136,7 @@ func validateUsingOrg(userId int64, orgId int64) bool {
// validate that the org id in the list
valid
:=
false
for
_
,
other
:=
range
query
.
Result
{
if
other
.
OrgId
==
orgI
d
{
if
other
.
OrgId
==
orgI
D
{
valid
=
true
}
}
...
...
@@ -146,13 +146,13 @@ func validateUsingOrg(userId int64, orgId int64) bool {
// POST /api/user/using/:id
func
UserSetUsingOrg
(
c
*
m
.
ReqContext
)
Response
{
orgI
d
:=
c
.
ParamsInt64
(
":id"
)
orgI
D
:=
c
.
ParamsInt64
(
":id"
)
if
!
validateUsingOrg
(
c
.
UserId
,
orgI
d
)
{
if
!
validateUsingOrg
(
c
.
UserId
,
orgI
D
)
{
return
ApiError
(
401
,
"Not a valid organization"
,
nil
)
}
cmd
:=
m
.
SetUsingOrgCommand
{
UserId
:
c
.
UserId
,
OrgId
:
orgI
d
}
cmd
:=
m
.
SetUsingOrgCommand
{
UserId
:
c
.
UserId
,
OrgId
:
orgI
D
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to change active organization"
,
err
)
...
...
@@ -163,13 +163,13 @@ func UserSetUsingOrg(c *m.ReqContext) Response {
// GET /profile/switch-org/:id
func
ChangeActiveOrgAndRedirectToHome
(
c
*
m
.
ReqContext
)
{
orgI
d
:=
c
.
ParamsInt64
(
":id"
)
orgI
D
:=
c
.
ParamsInt64
(
":id"
)
if
!
validateUsingOrg
(
c
.
UserId
,
orgI
d
)
{
if
!
validateUsingOrg
(
c
.
UserId
,
orgI
D
)
{
NotFoundHandler
(
c
)
}
cmd
:=
m
.
SetUsingOrgCommand
{
UserId
:
c
.
UserId
,
OrgId
:
orgI
d
}
cmd
:=
m
.
SetUsingOrgCommand
{
UserId
:
c
.
UserId
,
OrgId
:
orgI
D
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
NotFoundHandler
(
c
)
...
...
pkg/cmd/grafana-server/server.go
View file @
22fffe0d
...
...
@@ -120,7 +120,7 @@ func (g *GrafanaServerImpl) initLogging() {
}
func
(
g
*
GrafanaServerImpl
)
startHttpServer
()
error
{
g
.
httpServer
=
api
.
NewH
ttp
Server
()
g
.
httpServer
=
api
.
NewH
TTP
Server
()
err
:=
g
.
httpServer
.
Start
(
g
.
context
)
...
...
pkg/middleware/auth.go
View file @
22fffe0d
...
...
@@ -17,10 +17,10 @@ type AuthOptions struct {
}
func
getRequestUserId
(
c
*
m
.
ReqContext
)
int64
{
userI
d
:=
c
.
Session
.
Get
(
session
.
SESS_KEY_USERID
)
userI
D
:=
c
.
Session
.
Get
(
session
.
SESS_KEY_USERID
)
if
userI
d
!=
nil
{
return
userI
d
.
(
int64
)
if
userI
D
!=
nil
{
return
userI
D
.
(
int64
)
}
return
0
...
...
pkg/middleware/dashboard_redirect.go
View file @
22fffe0d
...
...
@@ -20,7 +20,7 @@ func getDashboardUrlBySlug(orgId int64, slug string) (string, error) {
return
m
.
GetDashboardUrl
(
query
.
Result
.
Uid
,
query
.
Result
.
Slug
),
nil
}
func
RedirectFromLegacyDashboardU
rl
()
macaron
.
Handler
{
func
RedirectFromLegacyDashboardU
RL
()
macaron
.
Handler
{
return
func
(
c
*
m
.
ReqContext
)
{
slug
:=
c
.
Params
(
"slug"
)
...
...
pkg/middleware/dashboard_redirect_test.go
View file @
22fffe0d
...
...
@@ -13,7 +13,7 @@ import (
func
TestMiddlewareDashboardRedirect
(
t
*
testing
.
T
)
{
Convey
(
"Given the dashboard redirect middleware"
,
t
,
func
()
{
bus
.
ClearBusHandlers
()
redirectFromLegacyDashboardUrl
:=
RedirectFromLegacyDashboardU
rl
()
redirectFromLegacyDashboardUrl
:=
RedirectFromLegacyDashboardU
RL
()
redirectFromLegacyDashboardSoloUrl
:=
RedirectFromLegacyDashboardSoloUrl
()
fakeDash
:=
m
.
NewDashboard
(
"Child dash"
)
...
...
@@ -34,9 +34,9 @@ func TestMiddlewareDashboardRedirect(t *testing.T) {
Convey
(
"Should redirect to new dashboard url with a 301 Moved Permanently"
,
func
()
{
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
301
)
redirectU
rl
,
_
:=
sc
.
resp
.
Result
()
.
Location
()
So
(
redirectU
rl
.
Path
,
ShouldEqual
,
m
.
GetDashboardUrl
(
fakeDash
.
Uid
,
fakeDash
.
Slug
))
So
(
len
(
redirectU
rl
.
Query
()),
ShouldEqual
,
2
)
redirectU
RL
,
_
:=
sc
.
resp
.
Result
()
.
Location
()
So
(
redirectU
RL
.
Path
,
ShouldEqual
,
m
.
GetDashboardUrl
(
fakeDash
.
Uid
,
fakeDash
.
Slug
))
So
(
len
(
redirectU
RL
.
Query
()),
ShouldEqual
,
2
)
})
})
...
...
@@ -47,11 +47,11 @@ func TestMiddlewareDashboardRedirect(t *testing.T) {
Convey
(
"Should redirect to new dashboard url with a 301 Moved Permanently"
,
func
()
{
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
301
)
redirectU
rl
,
_
:=
sc
.
resp
.
Result
()
.
Location
()
expectedU
rl
:=
m
.
GetDashboardUrl
(
fakeDash
.
Uid
,
fakeDash
.
Slug
)
expectedU
rl
=
strings
.
Replace
(
expectedUrl
,
"/d/"
,
"/d-solo/"
,
1
)
So
(
redirectU
rl
.
Path
,
ShouldEqual
,
expectedUrl
)
So
(
len
(
redirectU
rl
.
Query
()),
ShouldEqual
,
2
)
redirectU
RL
,
_
:=
sc
.
resp
.
Result
()
.
Location
()
expectedU
RL
:=
m
.
GetDashboardUrl
(
fakeDash
.
Uid
,
fakeDash
.
Slug
)
expectedU
RL
=
strings
.
Replace
(
expectedURL
,
"/d/"
,
"/d-solo/"
,
1
)
So
(
redirectU
RL
.
Path
,
ShouldEqual
,
expectedURL
)
So
(
len
(
redirectU
RL
.
Query
()),
ShouldEqual
,
2
)
})
})
})
...
...
pkg/middleware/recovery_test.go
View file @
22fffe0d
...
...
@@ -14,10 +14,10 @@ import (
func
TestRecoveryMiddleware
(
t
*
testing
.
T
)
{
Convey
(
"Given an api route that panics"
,
t
,
func
()
{
apiU
rl
:=
"/api/whatever"
recoveryScenario
(
"recovery middleware should return json"
,
apiU
rl
,
func
(
sc
*
scenarioContext
)
{
apiU
RL
:=
"/api/whatever"
recoveryScenario
(
"recovery middleware should return json"
,
apiU
RL
,
func
(
sc
*
scenarioContext
)
{
sc
.
handlerFunc
=
PanicHandler
sc
.
fakeReq
(
"GET"
,
apiU
rl
)
.
exec
()
sc
.
fakeReq
(
"GET"
,
apiU
RL
)
.
exec
()
sc
.
req
.
Header
.
Add
(
"content-type"
,
"application/json"
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
500
)
...
...
@@ -27,10 +27,10 @@ func TestRecoveryMiddleware(t *testing.T) {
})
Convey
(
"Given a non-api route that panics"
,
t
,
func
()
{
apiU
rl
:=
"/whatever"
recoveryScenario
(
"recovery middleware should return html"
,
apiU
rl
,
func
(
sc
*
scenarioContext
)
{
apiU
RL
:=
"/whatever"
recoveryScenario
(
"recovery middleware should return html"
,
apiU
RL
,
func
(
sc
*
scenarioContext
)
{
sc
.
handlerFunc
=
PanicHandler
sc
.
fakeReq
(
"GET"
,
apiU
rl
)
.
exec
()
sc
.
fakeReq
(
"GET"
,
apiU
RL
)
.
exec
()
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
500
)
So
(
sc
.
resp
.
Header
()
.
Get
(
"content-type"
),
ShouldEqual
,
"text/html; charset=UTF-8"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment