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
b818e9f6
Commit
b818e9f6
authored
Mar 22, 2018
by
Marcus Efraimsson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into 11306-sql-table-time
parents
f0f41c2a
22fffe0d
Hide whitespace changes
Inline
Side-by-side
Showing
34 changed files
with
354 additions
and
291 deletions
+354
-291
docs/sources/reference/templating.md
+68
-1
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
+15
-16
pkg/api/org_users.go
+9
-9
pkg/api/playlist.go
+2
-2
pkg/api/playlist_play.go
+27
-29
pkg/api/plugins.go
+43
-41
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.
docs/sources/reference/templating.md
View file @
b818e9f6
+++
+++
title = "Variables"
title = "Variables"
keywords =
[
"grafana", "templating", "documentation", "guide"
]
keywords =
[
"grafana", "templating", "documentation", "guide"
, "template", "variable"
]
type = "docs"
type = "docs"
[
menu.docs
]
[
menu.docs
]
name = "Variables"
name = "Variables"
...
@@ -80,6 +80,73 @@ Option | Description
...
@@ -80,6 +80,73 @@ Option | Description
*Regex*
| Regex to filter or capture specific parts of the names return by your data source query. Optional.
*Regex*
| Regex to filter or capture specific parts of the names return by your data source query. Optional.
*Sort*
| Define sort order for options in dropdown.
**Disabled**
means that the order of options returned by your data source query will be used.
*Sort*
| Define sort order for options in dropdown.
**Disabled**
means that the order of options returned by your data source query will be used.
#### Using regex to filter/modify values in the Variable dropdown
Using the Regex Query Option, you filter the list of options returned by the Variable query or modify the options returned.
Examples of filtering on the following list of options:
```
text
backend_01
backend_02
backend_03
backend_04
```
##### Filter so that only the options that end with `01` or `02` are returned:
Regex:
```
regex
/.*[01|02]/
```
Result:
```
text
backend_01
backend_02
```
##### Filter and modify the options using a regex capture group to return part of the text:
Regex:
```
regex
/.*(01|02)/
```
Result:
```
text
01
02
```
#### Filter and modify - Prometheus Example
List of options:
```
text
up{instance="demo.robustperception.io:9090",job="prometheus"} 1 1521630638000
up{instance="demo.robustperception.io:9093",job="alertmanager"} 1 1521630638000
up{instance="demo.robustperception.io:9100",job="node"} 1 1521630638000
```
Regex:
```
regex
/.*instance="([^"]*).*/
```
Result:
```
text
demo.robustperception.io:9090
demo.robustperception.io:9093
demo.robustperception.io:9100
```
### Query expressions
### Query expressions
The query expressions are different for each data source.
The query expressions are different for each data source.
...
...
pkg/api/admin_users.go
View file @
b818e9f6
...
@@ -47,14 +47,14 @@ func AdminCreateUser(c *m.ReqContext, form dtos.AdminCreateUserForm) {
...
@@ -47,14 +47,14 @@ func AdminCreateUser(c *m.ReqContext, form dtos.AdminCreateUserForm) {
}
}
func
AdminUpdateUserPassword
(
c
*
m
.
ReqContext
,
form
dtos
.
AdminUpdateUserPasswordForm
)
{
func
AdminUpdateUserPassword
(
c
*
m
.
ReqContext
,
form
dtos
.
AdminUpdateUserPasswordForm
)
{
userI
d
:=
c
.
ParamsInt64
(
":id"
)
userI
D
:=
c
.
ParamsInt64
(
":id"
)
if
len
(
form
.
Password
)
<
4
{
if
len
(
form
.
Password
)
<
4
{
c
.
JsonApiErr
(
400
,
"New password too short"
,
nil
)
c
.
JsonApiErr
(
400
,
"New password too short"
,
nil
)
return
return
}
}
userQuery
:=
m
.
GetUserByIdQuery
{
Id
:
userI
d
}
userQuery
:=
m
.
GetUserByIdQuery
{
Id
:
userI
D
}
if
err
:=
bus
.
Dispatch
(
&
userQuery
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
userQuery
);
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Could not read user from database"
,
err
)
c
.
JsonApiErr
(
500
,
"Could not read user from database"
,
err
)
...
@@ -64,7 +64,7 @@ func AdminUpdateUserPassword(c *m.ReqContext, form dtos.AdminUpdateUserPasswordF
...
@@ -64,7 +64,7 @@ func AdminUpdateUserPassword(c *m.ReqContext, form dtos.AdminUpdateUserPasswordF
passwordHashed
:=
util
.
EncodePassword
(
form
.
Password
,
userQuery
.
Result
.
Salt
)
passwordHashed
:=
util
.
EncodePassword
(
form
.
Password
,
userQuery
.
Result
.
Salt
)
cmd
:=
m
.
ChangeUserPasswordCommand
{
cmd
:=
m
.
ChangeUserPasswordCommand
{
UserId
:
userI
d
,
UserId
:
userI
D
,
NewPassword
:
passwordHashed
,
NewPassword
:
passwordHashed
,
}
}
...
@@ -77,10 +77,10 @@ func AdminUpdateUserPassword(c *m.ReqContext, form dtos.AdminUpdateUserPasswordF
...
@@ -77,10 +77,10 @@ func AdminUpdateUserPassword(c *m.ReqContext, form dtos.AdminUpdateUserPasswordF
}
}
func
AdminUpdateUserPermissions
(
c
*
m
.
ReqContext
,
form
dtos
.
AdminUpdateUserPermissionsForm
)
{
func
AdminUpdateUserPermissions
(
c
*
m
.
ReqContext
,
form
dtos
.
AdminUpdateUserPermissionsForm
)
{
userI
d
:=
c
.
ParamsInt64
(
":id"
)
userI
D
:=
c
.
ParamsInt64
(
":id"
)
cmd
:=
m
.
UpdateUserPermissionsCommand
{
cmd
:=
m
.
UpdateUserPermissionsCommand
{
UserId
:
userI
d
,
UserId
:
userI
D
,
IsGrafanaAdmin
:
form
.
IsGrafanaAdmin
,
IsGrafanaAdmin
:
form
.
IsGrafanaAdmin
,
}
}
...
@@ -93,9 +93,9 @@ func AdminUpdateUserPermissions(c *m.ReqContext, form dtos.AdminUpdateUserPermis
...
@@ -93,9 +93,9 @@ func AdminUpdateUserPermissions(c *m.ReqContext, form dtos.AdminUpdateUserPermis
}
}
func
AdminDeleteUser
(
c
*
m
.
ReqContext
)
{
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
{
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to delete user"
,
err
)
c
.
JsonApiErr
(
500
,
"Failed to delete user"
,
err
)
...
...
pkg/api/alerting.go
View file @
b818e9f6
...
@@ -26,9 +26,9 @@ func ValidateOrgAlert(c *m.ReqContext) {
...
@@ -26,9 +26,9 @@ func ValidateOrgAlert(c *m.ReqContext) {
}
}
func
GetAlertStatesForDashboard
(
c
*
m
.
ReqContext
)
Response
{
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
)
return
ApiError
(
400
,
"Missing query parameter dashboardId"
,
nil
)
}
}
...
@@ -151,7 +151,7 @@ func GetAlertNotifications(c *m.ReqContext) Response {
...
@@ -151,7 +151,7 @@ func GetAlertNotifications(c *m.ReqContext) Response {
return
Json
(
200
,
result
)
return
Json
(
200
,
result
)
}
}
func
GetAlertNotificationByI
d
(
c
*
m
.
ReqContext
)
Response
{
func
GetAlertNotificationByI
D
(
c
*
m
.
ReqContext
)
Response
{
query
:=
&
m
.
GetAlertNotificationsQuery
{
query
:=
&
m
.
GetAlertNotificationsQuery
{
OrgId
:
c
.
OrgId
,
OrgId
:
c
.
OrgId
,
Id
:
c
.
ParamsInt64
(
"notificationId"
),
Id
:
c
.
ParamsInt64
(
"notificationId"
),
...
...
pkg/api/annotations.go
View file @
b818e9f6
...
@@ -52,7 +52,7 @@ func (e *CreateAnnotationError) Error() string {
...
@@ -52,7 +52,7 @@ func (e *CreateAnnotationError) Error() string {
}
}
func
PostAnnotation
(
c
*
m
.
ReqContext
,
cmd
dtos
.
PostAnnotationsCmd
)
Response
{
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
)
return
dashboardGuardianResponse
(
err
)
}
}
...
@@ -179,18 +179,18 @@ func PostGraphiteAnnotation(c *m.ReqContext, cmd dtos.PostGraphiteAnnotationsCmd
...
@@ -179,18 +179,18 @@ func PostGraphiteAnnotation(c *m.ReqContext, cmd dtos.PostGraphiteAnnotationsCmd
}
}
func
UpdateAnnotation
(
c
*
m
.
ReqContext
,
cmd
dtos
.
UpdateAnnotationsCmd
)
Response
{
func
UpdateAnnotation
(
c
*
m
.
ReqContext
,
cmd
dtos
.
UpdateAnnotationsCmd
)
Response
{
annotationI
d
:=
c
.
ParamsInt64
(
":annotationId"
)
annotationI
D
:=
c
.
ParamsInt64
(
":annotationId"
)
repo
:=
annotations
.
GetRepository
()
repo
:=
annotations
.
GetRepository
()
if
resp
:=
canSave
(
c
,
repo
,
annotationI
d
);
resp
!=
nil
{
if
resp
:=
canSave
(
c
,
repo
,
annotationI
D
);
resp
!=
nil
{
return
resp
return
resp
}
}
item
:=
annotations
.
Item
{
item
:=
annotations
.
Item
{
OrgId
:
c
.
OrgId
,
OrgId
:
c
.
OrgId
,
UserId
:
c
.
UserId
,
UserId
:
c
.
UserId
,
Id
:
annotationI
d
,
Id
:
annotationI
D
,
Epoch
:
cmd
.
Time
/
1000
,
Epoch
:
cmd
.
Time
/
1000
,
Text
:
cmd
.
Text
,
Text
:
cmd
.
Text
,
Tags
:
cmd
.
Tags
,
Tags
:
cmd
.
Tags
,
...
@@ -254,14 +254,14 @@ func DeleteAnnotationById(c *m.ReqContext) Response {
...
@@ -254,14 +254,14 @@ func DeleteAnnotationById(c *m.ReqContext) Response {
func
DeleteAnnotationRegion
(
c
*
m
.
ReqContext
)
Response
{
func
DeleteAnnotationRegion
(
c
*
m
.
ReqContext
)
Response
{
repo
:=
annotations
.
GetRepository
()
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
return
resp
}
}
err
:=
repo
.
Delete
(
&
annotations
.
DeleteParams
{
err
:=
repo
.
Delete
(
&
annotations
.
DeleteParams
{
RegionId
:
regionI
d
,
RegionId
:
regionI
D
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -271,13 +271,13 @@ func DeleteAnnotationRegion(c *m.ReqContext) Response {
...
@@ -271,13 +271,13 @@ func DeleteAnnotationRegion(c *m.ReqContext) Response {
return
ApiSuccess
(
"Annotation region deleted"
)
return
ApiSuccess
(
"Annotation region deleted"
)
}
}
func
canSaveByDashboardI
d
(
c
*
m
.
ReqContext
,
dashboardId
int64
)
(
bool
,
error
)
{
func
canSaveByDashboardI
D
(
c
*
m
.
ReqContext
,
dashboardID
int64
)
(
bool
,
error
)
{
if
dashboardI
d
==
0
&&
!
c
.
SignedInUser
.
HasRole
(
m
.
ROLE_EDITOR
)
{
if
dashboardI
D
==
0
&&
!
c
.
SignedInUser
.
HasRole
(
m
.
ROLE_EDITOR
)
{
return
false
,
nil
return
false
,
nil
}
}
if
dashboardI
d
>
0
{
if
dashboardI
D
>
0
{
guardian
:=
guardian
.
New
(
dashboardI
d
,
c
.
OrgId
,
c
.
SignedInUser
)
guardian
:=
guardian
.
New
(
dashboardI
D
,
c
.
OrgId
,
c
.
SignedInUser
)
if
canEdit
,
err
:=
guardian
.
CanEdit
();
err
!=
nil
||
!
canEdit
{
if
canEdit
,
err
:=
guardian
.
CanEdit
();
err
!=
nil
||
!
canEdit
{
return
false
,
err
return
false
,
err
}
}
...
@@ -293,25 +293,25 @@ func canSave(c *m.ReqContext, repo annotations.Repository, annotationId int64) R
...
@@ -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
)
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
dashboardGuardianResponse
(
err
)
}
}
return
nil
return
nil
}
}
func
canSaveByRegionI
d
(
c
*
m
.
ReqContext
,
repo
annotations
.
Repository
,
regionId
int64
)
Response
{
func
canSaveByRegionI
D
(
c
*
m
.
ReqContext
,
repo
annotations
.
Repository
,
regionID
int64
)
Response
{
items
,
err
:=
repo
.
Find
(
&
annotations
.
ItemQuery
{
RegionId
:
regionI
d
,
OrgId
:
c
.
OrgId
})
items
,
err
:=
repo
.
Find
(
&
annotations
.
ItemQuery
{
RegionId
:
regionI
D
,
OrgId
:
c
.
OrgId
})
if
err
!=
nil
||
len
(
items
)
==
0
{
if
err
!=
nil
||
len
(
items
)
==
0
{
return
ApiError
(
500
,
"Could not find annotation to update"
,
err
)
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
dashboardGuardianResponse
(
err
)
}
}
...
...
pkg/api/api.go
View file @
b818e9f6
...
@@ -15,7 +15,7 @@ func (hs *HttpServer) registerRoutes() {
...
@@ -15,7 +15,7 @@ func (hs *HttpServer) registerRoutes() {
reqGrafanaAdmin
:=
middleware
.
Auth
(
&
middleware
.
AuthOptions
{
ReqSignedIn
:
true
,
ReqGrafanaAdmin
:
true
})
reqGrafanaAdmin
:=
middleware
.
Auth
(
&
middleware
.
AuthOptions
{
ReqSignedIn
:
true
,
ReqGrafanaAdmin
:
true
})
reqEditorRole
:=
middleware
.
RoleAuth
(
m
.
ROLE_EDITOR
,
m
.
ROLE_ADMIN
)
reqEditorRole
:=
middleware
.
RoleAuth
(
m
.
ROLE_EDITOR
,
m
.
ROLE_ADMIN
)
reqOrgAdmin
:=
middleware
.
RoleAuth
(
m
.
ROLE_ADMIN
)
reqOrgAdmin
:=
middleware
.
RoleAuth
(
m
.
ROLE_ADMIN
)
redirectFromLegacyDashboardUrl
:=
middleware
.
RedirectFromLegacyDashboardU
rl
()
redirectFromLegacyDashboardUrl
:=
middleware
.
RedirectFromLegacyDashboardU
RL
()
redirectFromLegacyDashboardSoloUrl
:=
middleware
.
RedirectFromLegacyDashboardSoloUrl
()
redirectFromLegacyDashboardSoloUrl
:=
middleware
.
RedirectFromLegacyDashboardSoloUrl
()
quota
:=
middleware
.
Quota
quota
:=
middleware
.
Quota
bind
:=
binding
.
Bind
bind
:=
binding
.
Bind
...
@@ -110,7 +110,7 @@ func (hs *HttpServer) registerRoutes() {
...
@@ -110,7 +110,7 @@ func (hs *HttpServer) registerRoutes() {
r
.
Get
(
"/api/snapshots-delete/:key"
,
reqEditorRole
,
wrap
(
DeleteDashboardSnapshot
))
r
.
Get
(
"/api/snapshots-delete/:key"
,
reqEditorRole
,
wrap
(
DeleteDashboardSnapshot
))
// api renew session based on remember cookie
// 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
// authed api
r
.
Group
(
"/api"
,
func
(
apiRoute
RouteRegister
)
{
r
.
Group
(
"/api"
,
func
(
apiRoute
RouteRegister
)
{
...
@@ -139,7 +139,7 @@ func (hs *HttpServer) registerRoutes() {
...
@@ -139,7 +139,7 @@ func (hs *HttpServer) registerRoutes() {
apiRoute
.
Group
(
"/users"
,
func
(
usersRoute
RouteRegister
)
{
apiRoute
.
Group
(
"/users"
,
func
(
usersRoute
RouteRegister
)
{
usersRoute
.
Get
(
"/"
,
wrap
(
SearchUsers
))
usersRoute
.
Get
(
"/"
,
wrap
(
SearchUsers
))
usersRoute
.
Get
(
"/search"
,
wrap
(
SearchUsersWithPaging
))
usersRoute
.
Get
(
"/search"
,
wrap
(
SearchUsersWithPaging
))
usersRoute
.
Get
(
"/:id"
,
wrap
(
GetUserByI
d
))
usersRoute
.
Get
(
"/:id"
,
wrap
(
GetUserByI
D
))
usersRoute
.
Get
(
"/:id/orgs"
,
wrap
(
GetUserOrgList
))
usersRoute
.
Get
(
"/:id/orgs"
,
wrap
(
GetUserOrgList
))
// query parameters /users/lookup?loginOrEmail=admin@example.com
// query parameters /users/lookup?loginOrEmail=admin@example.com
usersRoute
.
Get
(
"/lookup"
,
wrap
(
GetUserByLoginOrEmail
))
usersRoute
.
Get
(
"/lookup"
,
wrap
(
GetUserByLoginOrEmail
))
...
@@ -149,11 +149,11 @@ func (hs *HttpServer) registerRoutes() {
...
@@ -149,11 +149,11 @@ func (hs *HttpServer) registerRoutes() {
// team (admin permission required)
// team (admin permission required)
apiRoute
.
Group
(
"/teams"
,
func
(
teamsRoute
RouteRegister
)
{
apiRoute
.
Group
(
"/teams"
,
func
(
teamsRoute
RouteRegister
)
{
teamsRoute
.
Get
(
"/:teamId"
,
wrap
(
GetTeamByI
d
))
teamsRoute
.
Get
(
"/:teamId"
,
wrap
(
GetTeamByI
D
))
teamsRoute
.
Get
(
"/search"
,
wrap
(
SearchTeams
))
teamsRoute
.
Get
(
"/search"
,
wrap
(
SearchTeams
))
teamsRoute
.
Post
(
"/"
,
bind
(
m
.
CreateTeamCommand
{}),
wrap
(
CreateTeam
))
teamsRoute
.
Post
(
"/"
,
bind
(
m
.
CreateTeamCommand
{}),
wrap
(
CreateTeam
))
teamsRoute
.
Put
(
"/:teamId"
,
bind
(
m
.
UpdateTeamCommand
{}),
wrap
(
UpdateTeam
))
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
.
Get
(
"/:teamId/members"
,
wrap
(
GetTeamMembers
))
teamsRoute
.
Post
(
"/:teamId/members"
,
bind
(
m
.
AddTeamMemberCommand
{}),
wrap
(
AddTeamMember
))
teamsRoute
.
Post
(
"/:teamId/members"
,
bind
(
m
.
AddTeamMemberCommand
{}),
wrap
(
AddTeamMember
))
teamsRoute
.
Delete
(
"/:teamId/members/:userId"
,
wrap
(
RemoveTeamMember
))
teamsRoute
.
Delete
(
"/:teamId/members/:userId"
,
wrap
(
RemoveTeamMember
))
...
@@ -192,10 +192,10 @@ func (hs *HttpServer) registerRoutes() {
...
@@ -192,10 +192,10 @@ func (hs *HttpServer) registerRoutes() {
// orgs (admin routes)
// orgs (admin routes)
apiRoute
.
Group
(
"/orgs/:orgId"
,
func
(
orgsRoute
RouteRegister
)
{
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
(
"/"
,
bind
(
dtos
.
UpdateOrgForm
{}),
wrap
(
UpdateOrg
))
orgsRoute
.
Put
(
"/address"
,
bind
(
dtos
.
UpdateOrgAddressForm
{}),
wrap
(
UpdateOrgAddress
))
orgsRoute
.
Put
(
"/address"
,
bind
(
dtos
.
UpdateOrgAddressForm
{}),
wrap
(
UpdateOrgAddress
))
orgsRoute
.
Delete
(
"/"
,
wrap
(
DeleteOrgByI
d
))
orgsRoute
.
Delete
(
"/"
,
wrap
(
DeleteOrgByI
D
))
orgsRoute
.
Get
(
"/users"
,
wrap
(
GetOrgUsers
))
orgsRoute
.
Get
(
"/users"
,
wrap
(
GetOrgUsers
))
orgsRoute
.
Post
(
"/users"
,
bind
(
m
.
AddOrgUserCommand
{}),
wrap
(
AddOrgUser
))
orgsRoute
.
Post
(
"/users"
,
bind
(
m
.
AddOrgUserCommand
{}),
wrap
(
AddOrgUser
))
orgsRoute
.
Patch
(
"/users/:userId"
,
bind
(
m
.
UpdateOrgUserCommand
{}),
wrap
(
UpdateOrgUser
))
orgsRoute
.
Patch
(
"/users/:userId"
,
bind
(
m
.
UpdateOrgUserCommand
{}),
wrap
(
UpdateOrgUser
))
...
@@ -211,9 +211,9 @@ func (hs *HttpServer) registerRoutes() {
...
@@ -211,9 +211,9 @@ func (hs *HttpServer) registerRoutes() {
// auth api keys
// auth api keys
apiRoute
.
Group
(
"/auth/keys"
,
func
(
keysRoute
RouteRegister
)
{
apiRoute
.
Group
(
"/auth/keys"
,
func
(
keysRoute
RouteRegister
)
{
keysRoute
.
Get
(
"/"
,
wrap
(
GetA
pi
Keys
))
keysRoute
.
Get
(
"/"
,
wrap
(
GetA
PI
Keys
))
keysRoute
.
Post
(
"/"
,
quota
(
"api_key"
),
bind
(
m
.
AddApiKeyCommand
{}),
wrap
(
AddA
pi
Key
))
keysRoute
.
Post
(
"/"
,
quota
(
"api_key"
),
bind
(
m
.
AddApiKeyCommand
{}),
wrap
(
AddA
PI
Key
))
keysRoute
.
Delete
(
"/:id"
,
wrap
(
DeleteA
pi
Key
))
keysRoute
.
Delete
(
"/:id"
,
wrap
(
DeleteA
PI
Key
))
},
reqOrgAdmin
)
},
reqOrgAdmin
)
// Preferences
// Preferences
...
@@ -226,16 +226,16 @@ func (hs *HttpServer) registerRoutes() {
...
@@ -226,16 +226,16 @@ func (hs *HttpServer) registerRoutes() {
datasourceRoute
.
Get
(
"/"
,
wrap
(
GetDataSources
))
datasourceRoute
.
Get
(
"/"
,
wrap
(
GetDataSources
))
datasourceRoute
.
Post
(
"/"
,
quota
(
"data_source"
),
bind
(
m
.
AddDataSourceCommand
{}),
wrap
(
AddDataSource
))
datasourceRoute
.
Post
(
"/"
,
quota
(
"data_source"
),
bind
(
m
.
AddDataSourceCommand
{}),
wrap
(
AddDataSource
))
datasourceRoute
.
Put
(
"/:id"
,
bind
(
m
.
UpdateDataSourceCommand
{}),
wrap
(
UpdateDataSource
))
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
.
Delete
(
"/name/:name"
,
wrap
(
DeleteDataSourceByName
))
datasourceRoute
.
Get
(
"/:id"
,
wrap
(
GetDataSourceByI
d
))
datasourceRoute
.
Get
(
"/:id"
,
wrap
(
GetDataSourceByI
D
))
datasourceRoute
.
Get
(
"/name/:name"
,
wrap
(
GetDataSourceByName
))
datasourceRoute
.
Get
(
"/name/:name"
,
wrap
(
GetDataSourceByName
))
},
reqOrgAdmin
)
},
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"
,
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
.
Get
(
"/plugins/:pluginId/markdown/:name"
,
wrap
(
GetPluginMarkdown
))
apiRoute
.
Group
(
"/plugins"
,
func
(
pluginRoute
RouteRegister
)
{
apiRoute
.
Group
(
"/plugins"
,
func
(
pluginRoute
RouteRegister
)
{
...
@@ -250,11 +250,11 @@ func (hs *HttpServer) registerRoutes() {
...
@@ -250,11 +250,11 @@ func (hs *HttpServer) registerRoutes() {
// Folders
// Folders
apiRoute
.
Group
(
"/folders"
,
func
(
folderRoute
RouteRegister
)
{
apiRoute
.
Group
(
"/folders"
,
func
(
folderRoute
RouteRegister
)
{
folderRoute
.
Get
(
"/"
,
wrap
(
GetFolders
))
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
.
Post
(
"/"
,
bind
(
m
.
CreateFolderCommand
{}),
wrap
(
CreateFolder
))
folderRoute
.
Group
(
"/:uid"
,
func
(
folderUidRoute
RouteRegister
)
{
folderRoute
.
Group
(
"/:uid"
,
func
(
folderUidRoute
RouteRegister
)
{
folderUidRoute
.
Get
(
"/"
,
wrap
(
GetFolderByU
id
))
folderUidRoute
.
Get
(
"/"
,
wrap
(
GetFolderByU
ID
))
folderUidRoute
.
Put
(
"/"
,
bind
(
m
.
UpdateFolderCommand
{}),
wrap
(
UpdateFolder
))
folderUidRoute
.
Put
(
"/"
,
bind
(
m
.
UpdateFolderCommand
{}),
wrap
(
UpdateFolder
))
folderUidRoute
.
Delete
(
"/"
,
wrap
(
DeleteFolder
))
folderUidRoute
.
Delete
(
"/"
,
wrap
(
DeleteFolder
))
...
@@ -268,7 +268,7 @@ func (hs *HttpServer) registerRoutes() {
...
@@ -268,7 +268,7 @@ func (hs *HttpServer) registerRoutes() {
// Dashboard
// Dashboard
apiRoute
.
Group
(
"/dashboards"
,
func
(
dashboardRoute
RouteRegister
)
{
apiRoute
.
Group
(
"/dashboards"
,
func
(
dashboardRoute
RouteRegister
)
{
dashboardRoute
.
Get
(
"/uid/:uid"
,
wrap
(
GetDashboard
))
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
.
Get
(
"/db/:slug"
,
wrap
(
GetDashboard
))
dashboardRoute
.
Delete
(
"/db/:slug"
,
wrap
(
DeleteDashboard
))
dashboardRoute
.
Delete
(
"/db/:slug"
,
wrap
(
DeleteDashboard
))
...
@@ -314,7 +314,7 @@ func (hs *HttpServer) registerRoutes() {
...
@@ -314,7 +314,7 @@ func (hs *HttpServer) registerRoutes() {
// metrics
// metrics
apiRoute
.
Post
(
"/tsdb/query"
,
bind
(
dtos
.
MetricRequest
{}),
wrap
(
QueryMetrics
))
apiRoute
.
Post
(
"/tsdb/query"
,
bind
(
dtos
.
MetricRequest
{}),
wrap
(
QueryMetrics
))
apiRoute
.
Get
(
"/tsdb/testdata/scenarios"
,
wrap
(
GetTestDataScenarios
))
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
.
Get
(
"/tsdb/testdata/random-walk"
,
wrap
(
GetTestDataRandomWalk
))
apiRoute
.
Group
(
"/alerts"
,
func
(
alertsRoute
RouteRegister
)
{
apiRoute
.
Group
(
"/alerts"
,
func
(
alertsRoute
RouteRegister
)
{
...
@@ -332,7 +332,7 @@ func (hs *HttpServer) registerRoutes() {
...
@@ -332,7 +332,7 @@ func (hs *HttpServer) registerRoutes() {
alertNotifications
.
Post
(
"/test"
,
bind
(
dtos
.
NotificationTestCommand
{}),
wrap
(
NotificationTest
))
alertNotifications
.
Post
(
"/test"
,
bind
(
dtos
.
NotificationTestCommand
{}),
wrap
(
NotificationTest
))
alertNotifications
.
Post
(
"/"
,
bind
(
m
.
CreateAlertNotificationCommand
{}),
wrap
(
CreateAlertNotification
))
alertNotifications
.
Post
(
"/"
,
bind
(
m
.
CreateAlertNotificationCommand
{}),
wrap
(
CreateAlertNotification
))
alertNotifications
.
Put
(
"/:notificationId"
,
bind
(
m
.
UpdateAlertNotificationCommand
{}),
wrap
(
UpdateAlertNotification
))
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
))
alertNotifications
.
Delete
(
"/:notificationId"
,
wrap
(
DeleteAlertNotification
))
},
reqEditorRole
)
},
reqEditorRole
)
...
...
pkg/api/apikey.go
View file @
b818e9f6
...
@@ -7,7 +7,7 @@ import (
...
@@ -7,7 +7,7 @@ import (
m
"github.com/grafana/grafana/pkg/models"
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
}
query
:=
m
.
GetApiKeysQuery
{
OrgId
:
c
.
OrgId
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
...
@@ -26,7 +26,7 @@ func GetApiKeys(c *m.ReqContext) Response {
...
@@ -26,7 +26,7 @@ func GetApiKeys(c *m.ReqContext) Response {
return
Json
(
200
,
result
)
return
Json
(
200
,
result
)
}
}
func
DeleteA
pi
Key
(
c
*
m
.
ReqContext
)
Response
{
func
DeleteA
PI
Key
(
c
*
m
.
ReqContext
)
Response
{
id
:=
c
.
ParamsInt64
(
":id"
)
id
:=
c
.
ParamsInt64
(
":id"
)
cmd
:=
&
m
.
DeleteApiKeyCommand
{
Id
:
id
,
OrgId
:
c
.
OrgId
}
cmd
:=
&
m
.
DeleteApiKeyCommand
{
Id
:
id
,
OrgId
:
c
.
OrgId
}
...
@@ -39,7 +39,7 @@ func DeleteApiKey(c *m.ReqContext) Response {
...
@@ -39,7 +39,7 @@ func DeleteApiKey(c *m.ReqContext) Response {
return
ApiSuccess
(
"API key deleted"
)
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
()
{
if
!
cmd
.
Role
.
IsValid
()
{
return
ApiError
(
400
,
"Invalid role specified"
,
nil
)
return
ApiError
(
400
,
"Invalid role specified"
,
nil
)
}
}
...
...
pkg/api/app_routes.go
View file @
b818e9f6
...
@@ -55,11 +55,11 @@ func InitAppPluginRoutes(r *macaron.Macaron) {
...
@@ -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
)
{
return
func
(
c
*
m
.
ReqContext
)
{
path
:=
c
.
Params
(
"*"
)
path
:=
c
.
Params
(
"*"
)
proxy
:=
pluginproxy
.
NewApiPluginProxy
(
c
,
path
,
route
,
appI
d
)
proxy
:=
pluginproxy
.
NewApiPluginProxy
(
c
,
path
,
route
,
appI
D
)
proxy
.
Transport
=
pluginProxyTransport
proxy
.
Transport
=
pluginProxyTransport
proxy
.
ServeHTTP
(
c
.
Resp
,
c
.
Req
.
Request
)
proxy
.
ServeHTTP
(
c
.
Resp
,
c
.
Req
.
Request
)
}
}
...
...
pkg/api/dashboard.go
View file @
b818e9f6
...
@@ -22,12 +22,12 @@ import (
...
@@ -22,12 +22,12 @@ import (
"github.com/grafana/grafana/pkg/util"
"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
{
if
!
c
.
IsSignedIn
{
return
false
,
nil
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
{
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
...
@@ -114,24 +114,22 @@ func GetDashboard(c *m.ReqContext) Response {
...
@@ -114,24 +114,22 @@ func GetDashboard(c *m.ReqContext) Response {
return
Json
(
200
,
dto
)
return
Json
(
200
,
dto
)
}
}
func
getUserLogin
(
userI
d
int64
)
string
{
func
getUserLogin
(
userI
D
int64
)
string
{
query
:=
m
.
GetUserByIdQuery
{
Id
:
userI
d
}
query
:=
m
.
GetUserByIdQuery
{
Id
:
userI
D
}
err
:=
bus
.
Dispatch
(
&
query
)
err
:=
bus
.
Dispatch
(
&
query
)
if
err
!=
nil
{
if
err
!=
nil
{
return
"Anonymous"
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
var
query
m
.
GetDashboardQuery
if
len
(
uid
)
>
0
{
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
{
}
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
{
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
...
@@ -173,7 +171,7 @@ func DeleteDashboard(c *m.ReqContext) Response {
...
@@ -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"
))
dash
,
rsp
:=
getDashboardHelper
(
c
.
OrgId
,
""
,
0
,
c
.
Params
(
":uid"
))
if
rsp
!=
nil
{
if
rsp
!=
nil
{
return
rsp
return
rsp
...
@@ -291,9 +289,8 @@ func GetHomeDashboard(c *m.ReqContext) Response {
...
@@ -291,9 +289,8 @@ func GetHomeDashboard(c *m.ReqContext) Response {
url
:=
m
.
GetDashboardUrl
(
slugQuery
.
Result
.
Uid
,
slugQuery
.
Result
.
Slug
)
url
:=
m
.
GetDashboardUrl
(
slugQuery
.
Result
.
Uid
,
slugQuery
.
Result
.
Slug
)
dashRedirect
:=
dtos
.
DashboardRedirect
{
RedirectUri
:
url
}
dashRedirect
:=
dtos
.
DashboardRedirect
{
RedirectUri
:
url
}
return
Json
(
200
,
&
dashRedirect
)
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"
)
filePath
:=
path
.
Join
(
setting
.
StaticRootPath
,
"dashboards/home.json"
)
...
@@ -339,22 +336,22 @@ func addGettingStartedPanelToHomeDashboard(dash *simplejson.Json) {
...
@@ -339,22 +336,22 @@ func addGettingStartedPanelToHomeDashboard(dash *simplejson.Json) {
// GetDashboardVersions returns all dashboard versions as JSON
// GetDashboardVersions returns all dashboard versions as JSON
func
GetDashboardVersions
(
c
*
m
.
ReqContext
)
Response
{
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
{
if
canSave
,
err
:=
guardian
.
CanSave
();
err
!=
nil
||
!
canSave
{
return
dashboardGuardianResponse
(
err
)
return
dashboardGuardianResponse
(
err
)
}
}
query
:=
m
.
GetDashboardVersionsQuery
{
query
:=
m
.
GetDashboardVersionsQuery
{
OrgId
:
c
.
OrgId
,
OrgId
:
c
.
OrgId
,
DashboardId
:
dashI
d
,
DashboardId
:
dashI
D
,
Limit
:
c
.
QueryInt
(
"limit"
),
Limit
:
c
.
QueryInt
(
"limit"
),
Start
:
c
.
QueryInt
(
"start"
),
Start
:
c
.
QueryInt
(
"start"
),
}
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
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
{
for
_
,
version
:=
range
query
.
Result
{
...
@@ -378,21 +375,21 @@ func GetDashboardVersions(c *m.ReqContext) Response {
...
@@ -378,21 +375,21 @@ func GetDashboardVersions(c *m.ReqContext) Response {
// GetDashboardVersion returns the dashboard version with the given ID.
// GetDashboardVersion returns the dashboard version with the given ID.
func
GetDashboardVersion
(
c
*
m
.
ReqContext
)
Response
{
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
{
if
canSave
,
err
:=
guardian
.
CanSave
();
err
!=
nil
||
!
canSave
{
return
dashboardGuardianResponse
(
err
)
return
dashboardGuardianResponse
(
err
)
}
}
query
:=
m
.
GetDashboardVersionQuery
{
query
:=
m
.
GetDashboardVersionQuery
{
OrgId
:
c
.
OrgId
,
OrgId
:
c
.
OrgId
,
DashboardId
:
dashI
d
,
DashboardId
:
dashI
D
,
Version
:
c
.
ParamsInt
(
":id"
),
Version
:
c
.
ParamsInt
(
":id"
),
}
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
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"
creator
:=
"Anonymous"
...
...
pkg/api/dashboard_permission.go
View file @
b818e9f6
...
@@ -10,14 +10,14 @@ import (
...
@@ -10,14 +10,14 @@ import (
)
)
func
GetDashboardPermissionList
(
c
*
m
.
ReqContext
)
Response
{
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
{
if
rsp
!=
nil
{
return
rsp
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
{
if
canAdmin
,
err
:=
g
.
CanAdmin
();
err
!=
nil
||
!
canAdmin
{
return
dashboardGuardianResponse
(
err
)
return
dashboardGuardianResponse
(
err
)
...
@@ -38,25 +38,25 @@ func GetDashboardPermissionList(c *m.ReqContext) Response {
...
@@ -38,25 +38,25 @@ func GetDashboardPermissionList(c *m.ReqContext) Response {
}
}
func
UpdateDashboardPermissions
(
c
*
m
.
ReqContext
,
apiCmd
dtos
.
UpdateDashboardAclCommand
)
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
{
if
rsp
!=
nil
{
return
rsp
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
{
if
canAdmin
,
err
:=
g
.
CanAdmin
();
err
!=
nil
||
!
canAdmin
{
return
dashboardGuardianResponse
(
err
)
return
dashboardGuardianResponse
(
err
)
}
}
cmd
:=
m
.
UpdateDashboardAclCommand
{}
cmd
:=
m
.
UpdateDashboardAclCommand
{}
cmd
.
DashboardId
=
dashI
d
cmd
.
DashboardId
=
dashI
D
for
_
,
item
:=
range
apiCmd
.
Items
{
for
_
,
item
:=
range
apiCmd
.
Items
{
cmd
.
Items
=
append
(
cmd
.
Items
,
&
m
.
DashboardAcl
{
cmd
.
Items
=
append
(
cmd
.
Items
,
&
m
.
DashboardAcl
{
OrgId
:
c
.
OrgId
,
OrgId
:
c
.
OrgId
,
DashboardId
:
dashI
d
,
DashboardId
:
dashI
D
,
UserId
:
item
.
UserId
,
UserId
:
item
.
UserId
,
TeamId
:
item
.
TeamId
,
TeamId
:
item
.
TeamId
,
Role
:
item
.
Role
,
Role
:
item
.
Role
,
...
...
pkg/api/dashboard_snapshot.go
View file @
b818e9f6
...
@@ -106,9 +106,9 @@ func DeleteDashboardSnapshot(c *m.ReqContext) Response {
...
@@ -106,9 +106,9 @@ func DeleteDashboardSnapshot(c *m.ReqContext) Response {
return
ApiError
(
404
,
"Failed to get dashboard snapshot"
,
nil
)
return
ApiError
(
404
,
"Failed to get dashboard snapshot"
,
nil
)
}
}
dashboard
:=
query
.
Result
.
Dashboard
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
()
canEdit
,
err
:=
guardian
.
CanEdit
()
if
err
!=
nil
{
if
err
!=
nil
{
return
ApiError
(
500
,
"Error while checking permissions for snapshot"
,
err
)
return
ApiError
(
500
,
"Error while checking permissions for snapshot"
,
err
)
...
...
pkg/api/dashboard_test.go
View file @
b818e9f6
...
@@ -105,7 +105,7 @@ func TestDashboardApiEndpoint(t *testing.T) {
...
@@ -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
)
{
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
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
403
)
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
...
@@ -165,7 +165,7 @@ func TestDashboardApiEndpoint(t *testing.T) {
...
@@ -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
)
{
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
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
200
)
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
...
@@ -271,7 +271,7 @@ func TestDashboardApiEndpoint(t *testing.T) {
...
@@ -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
)
{
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
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
403
)
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
...
@@ -329,7 +329,7 @@ func TestDashboardApiEndpoint(t *testing.T) {
...
@@ -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
)
{
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
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
403
)
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
...
@@ -398,7 +398,7 @@ func TestDashboardApiEndpoint(t *testing.T) {
...
@@ -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
)
{
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
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
200
)
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
...
@@ -468,7 +468,7 @@ func TestDashboardApiEndpoint(t *testing.T) {
...
@@ -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
)
{
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
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
403
)
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
...
@@ -527,7 +527,7 @@ func TestDashboardApiEndpoint(t *testing.T) {
...
@@ -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
)
{
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
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
200
)
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
...
@@ -594,7 +594,7 @@ func TestDashboardApiEndpoint(t *testing.T) {
...
@@ -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
)
{
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
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
403
)
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
Convey
(
"Should lookup dashboard by uid"
,
func
()
{
...
@@ -837,12 +837,12 @@ func CallDeleteDashboard(sc *scenarioContext) {
...
@@ -837,12 +837,12 @@ func CallDeleteDashboard(sc *scenarioContext) {
sc
.
fakeReqWithParams
(
"DELETE"
,
sc
.
url
,
map
[
string
]
string
{})
.
exec
()
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
{
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
DeleteDashboardCommand
)
error
{
return
nil
return
nil
})
})
sc
.
handlerFunc
=
DeleteDashboardByU
id
sc
.
handlerFunc
=
DeleteDashboardByU
ID
sc
.
fakeReqWithParams
(
"DELETE"
,
sc
.
url
,
map
[
string
]
string
{})
.
exec
()
sc
.
fakeReqWithParams
(
"DELETE"
,
sc
.
url
,
map
[
string
]
string
{})
.
exec
()
}
}
...
...
pkg/api/dataproxy.go
View file @
b818e9f6
...
@@ -13,19 +13,19 @@ import (
...
@@ -13,19 +13,19 @@ import (
const
HeaderNameNoBackendCache
=
"X-Grafana-NoCache"
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
)
cacheKey
:=
fmt
.
Sprintf
(
"ds-%d"
,
id
)
if
!
nocache
{
if
!
nocache
{
if
cached
,
found
:=
hs
.
cache
.
Get
(
cacheKey
);
found
{
if
cached
,
found
:=
hs
.
cache
.
Get
(
cacheKey
);
found
{
ds
:=
cached
.
(
*
m
.
DataSource
)
ds
:=
cached
.
(
*
m
.
DataSource
)
if
ds
.
OrgId
==
orgI
d
{
if
ds
.
OrgId
==
orgI
D
{
return
ds
,
nil
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
{
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -39,7 +39,7 @@ func (hs *HttpServer) ProxyDataSourceRequest(c *m.ReqContext) {
...
@@ -39,7 +39,7 @@ func (hs *HttpServer) ProxyDataSourceRequest(c *m.ReqContext) {
nocache
:=
c
.
Req
.
Header
.
Get
(
HeaderNameNoBackendCache
)
==
"true"
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
{
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Unable to load datasource meta data"
,
err
)
c
.
JsonApiErr
(
500
,
"Unable to load datasource meta data"
,
err
)
...
...
pkg/api/datasources.go
View file @
b818e9f6
...
@@ -49,7 +49,7 @@ func GetDataSources(c *m.ReqContext) Response {
...
@@ -49,7 +49,7 @@ func GetDataSources(c *m.ReqContext) Response {
return
Json
(
200
,
&
result
)
return
Json
(
200
,
&
result
)
}
}
func
GetDataSourceByI
d
(
c
*
m
.
ReqContext
)
Response
{
func
GetDataSourceByI
D
(
c
*
m
.
ReqContext
)
Response
{
query
:=
m
.
GetDataSourceByIdQuery
{
query
:=
m
.
GetDataSourceByIdQuery
{
Id
:
c
.
ParamsInt64
(
":id"
),
Id
:
c
.
ParamsInt64
(
":id"
),
OrgId
:
c
.
OrgId
,
OrgId
:
c
.
OrgId
,
...
@@ -68,14 +68,14 @@ func GetDataSourceById(c *m.ReqContext) Response {
...
@@ -68,14 +68,14 @@ func GetDataSourceById(c *m.ReqContext) Response {
return
Json
(
200
,
&
dtos
)
return
Json
(
200
,
&
dtos
)
}
}
func
DeleteDataSourceByI
d
(
c
*
m
.
ReqContext
)
Response
{
func
DeleteDataSourceByI
D
(
c
*
m
.
ReqContext
)
Response
{
id
:=
c
.
ParamsInt64
(
":id"
)
id
:=
c
.
ParamsInt64
(
":id"
)
if
id
<=
0
{
if
id
<=
0
{
return
ApiError
(
400
,
"Missing valid datasource id"
,
nil
)
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
{
if
err
!=
nil
{
return
ApiError
(
400
,
"Failed to delete datasource"
,
nil
)
return
ApiError
(
400
,
"Failed to delete datasource"
,
nil
)
}
}
...
@@ -143,7 +143,7 @@ func UpdateDataSource(c *m.ReqContext, cmd m.UpdateDataSourceCommand) Response {
...
@@ -143,7 +143,7 @@ func UpdateDataSource(c *m.ReqContext, cmd m.UpdateDataSourceCommand) Response {
cmd
.
OrgId
=
c
.
OrgId
cmd
.
OrgId
=
c
.
OrgId
cmd
.
Id
=
c
.
ParamsInt64
(
":id"
)
cmd
.
Id
=
c
.
ParamsInt64
(
":id"
)
err
:=
fillWithSecureJ
son
Data
(
&
cmd
)
err
:=
fillWithSecureJ
SON
Data
(
&
cmd
)
if
err
!=
nil
{
if
err
!=
nil
{
return
ApiError
(
500
,
"Failed to update datasource"
,
err
)
return
ApiError
(
500
,
"Failed to update datasource"
,
err
)
}
}
...
@@ -152,9 +152,8 @@ func UpdateDataSource(c *m.ReqContext, cmd m.UpdateDataSourceCommand) Response {
...
@@ -152,9 +152,8 @@ func UpdateDataSource(c *m.ReqContext, cmd m.UpdateDataSourceCommand) Response {
if
err
!=
nil
{
if
err
!=
nil
{
if
err
==
m
.
ErrDataSourceUpdatingOldVersion
{
if
err
==
m
.
ErrDataSourceUpdatingOldVersion
{
return
ApiError
(
500
,
"Failed to update datasource. Reload new version and try again"
,
err
)
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
)
ds
:=
convertModelToDtos
(
cmd
.
Result
)
return
Json
(
200
,
util
.
DynMap
{
return
Json
(
200
,
util
.
DynMap
{
...
@@ -165,12 +164,12 @@ func UpdateDataSource(c *m.ReqContext, cmd m.UpdateDataSourceCommand) Response {
...
@@ -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
{
if
len
(
cmd
.
SecureJsonData
)
==
0
{
return
nil
return
nil
}
}
ds
,
err
:=
getRawDataSourceByI
d
(
cmd
.
Id
,
cmd
.
OrgId
)
ds
,
err
:=
getRawDataSourceByI
D
(
cmd
.
Id
,
cmd
.
OrgId
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -179,8 +178,8 @@ func fillWithSecureJsonData(cmd *m.UpdateDataSourceCommand) error {
...
@@ -179,8 +178,8 @@ func fillWithSecureJsonData(cmd *m.UpdateDataSourceCommand) error {
return
m
.
ErrDatasourceIsReadOnly
return
m
.
ErrDatasourceIsReadOnly
}
}
secureJ
son
Data
:=
ds
.
SecureJsonData
.
Decrypt
()
secureJ
SON
Data
:=
ds
.
SecureJsonData
.
Decrypt
()
for
k
,
v
:=
range
secureJ
son
Data
{
for
k
,
v
:=
range
secureJ
SON
Data
{
if
_
,
ok
:=
cmd
.
SecureJsonData
[
k
];
!
ok
{
if
_
,
ok
:=
cmd
.
SecureJsonData
[
k
];
!
ok
{
cmd
.
SecureJsonData
[
k
]
=
v
cmd
.
SecureJsonData
[
k
]
=
v
...
@@ -190,10 +189,10 @@ func fillWithSecureJsonData(cmd *m.UpdateDataSourceCommand) error {
...
@@ -190,10 +189,10 @@ func fillWithSecureJsonData(cmd *m.UpdateDataSourceCommand) error {
return
nil
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
{
query
:=
m
.
GetDataSourceByIdQuery
{
Id
:
id
,
Id
:
id
,
OrgId
:
orgI
d
,
OrgId
:
orgI
D
,
}
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
...
@@ -220,7 +219,7 @@ func GetDataSourceByName(c *m.ReqContext) Response {
...
@@ -220,7 +219,7 @@ func GetDataSourceByName(c *m.ReqContext) Response {
}
}
// Get /api/datasources/id/:name
// 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
}
query
:=
m
.
GetDataSourceByNameQuery
{
Name
:
c
.
Params
(
":name"
),
OrgId
:
c
.
OrgId
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
...
...
pkg/api/folder.go
View file @
b818e9f6
...
@@ -31,7 +31,7 @@ func GetFolders(c *m.ReqContext) Response {
...
@@ -31,7 +31,7 @@ func GetFolders(c *m.ReqContext) Response {
return
Json
(
200
,
result
)
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
)
s
:=
dashboards
.
NewFolderService
(
c
.
OrgId
,
c
.
SignedInUser
)
folder
,
err
:=
s
.
GetFolderByUid
(
c
.
Params
(
":uid"
))
folder
,
err
:=
s
.
GetFolderByUid
(
c
.
Params
(
":uid"
))
...
@@ -43,7 +43,7 @@ func GetFolderByUid(c *m.ReqContext) Response {
...
@@ -43,7 +43,7 @@ func GetFolderByUid(c *m.ReqContext) Response {
return
Json
(
200
,
toFolderDto
(
g
,
folder
))
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
)
s
:=
dashboards
.
NewFolderService
(
c
.
OrgId
,
c
.
SignedInUser
)
folder
,
err
:=
s
.
GetFolderById
(
c
.
ParamsInt64
(
":id"
))
folder
,
err
:=
s
.
GetFolderById
(
c
.
ParamsInt64
(
":id"
))
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/api/folder_test.go
View file @
b818e9f6
...
@@ -133,8 +133,8 @@ func TestFoldersApiEndpoint(t *testing.T) {
...
@@ -133,8 +133,8 @@ func TestFoldersApiEndpoint(t *testing.T) {
})
})
}
}
func
callGetFolderByU
id
(
sc
*
scenarioContext
)
{
func
callGetFolderByU
ID
(
sc
*
scenarioContext
)
{
sc
.
handlerFunc
=
GetFolderByU
id
sc
.
handlerFunc
=
GetFolderByU
ID
sc
.
fakeReqWithParams
(
"GET"
,
sc
.
url
,
map
[
string
]
string
{})
.
exec
()
sc
.
fakeReqWithParams
(
"GET"
,
sc
.
url
,
map
[
string
]
string
{})
.
exec
()
}
}
...
...
pkg/api/http_server.go
View file @
b818e9f6
...
@@ -39,7 +39,7 @@ type HttpServer struct {
...
@@ -39,7 +39,7 @@ type HttpServer struct {
httpSrv
*
http
.
Server
httpSrv
*
http
.
Server
}
}
func
NewH
ttp
Server
()
*
HttpServer
{
func
NewH
TTP
Server
()
*
HttpServer
{
return
&
HttpServer
{
return
&
HttpServer
{
log
:
log
.
New
(
"http.server"
),
log
:
log
.
New
(
"http.server"
),
cache
:
gocache
.
New
(
5
*
time
.
Minute
,
10
*
time
.
Minute
),
cache
:
gocache
.
New
(
5
*
time
.
Minute
,
10
*
time
.
Minute
),
...
...
pkg/api/index.go
View file @
b818e9f6
...
@@ -32,13 +32,13 @@ func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
...
@@ -32,13 +32,13 @@ func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
locale
=
parts
[
0
]
locale
=
parts
[
0
]
}
}
appU
rl
:=
setting
.
AppUrl
appU
RL
:=
setting
.
AppUrl
appSubU
rl
:=
setting
.
AppSubUrl
appSubU
RL
:=
setting
.
AppSubUrl
// special case when doing localhost call from phantomjs
// special case when doing localhost call from phantomjs
if
c
.
IsRenderCall
{
if
c
.
IsRenderCall
{
appU
rl
=
fmt
.
Sprintf
(
"%s://localhost:%s"
,
setting
.
Protocol
,
setting
.
HttpPort
)
appU
RL
=
fmt
.
Sprintf
(
"%s://localhost:%s"
,
setting
.
Protocol
,
setting
.
HttpPort
)
appSubU
rl
=
""
appSubU
RL
=
""
settings
[
"appSubUrl"
]
=
""
settings
[
"appSubUrl"
]
=
""
}
}
...
@@ -62,8 +62,8 @@ func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
...
@@ -62,8 +62,8 @@ func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
},
},
Settings
:
settings
,
Settings
:
settings
,
Theme
:
prefs
.
Theme
,
Theme
:
prefs
.
Theme
,
AppUrl
:
appU
rl
,
AppUrl
:
appU
RL
,
AppSubUrl
:
appSubU
rl
,
AppSubUrl
:
appSubU
RL
,
GoogleAnalyticsId
:
setting
.
GoogleAnalyticsId
,
GoogleAnalyticsId
:
setting
.
GoogleAnalyticsId
,
GoogleTagManagerId
:
setting
.
GoogleTagManagerId
,
GoogleTagManagerId
:
setting
.
GoogleTagManagerId
,
BuildVersion
:
setting
.
BuildVersion
,
BuildVersion
:
setting
.
BuildVersion
,
...
@@ -80,8 +80,8 @@ func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
...
@@ -80,8 +80,8 @@ func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
data
.
User
.
Name
=
data
.
User
.
Login
data
.
User
.
Name
=
data
.
User
.
Login
}
}
themeU
rl
Param
:=
c
.
Query
(
"theme"
)
themeU
RL
Param
:=
c
.
Query
(
"theme"
)
if
themeU
rl
Param
==
"light"
{
if
themeU
RL
Param
==
"light"
{
data
.
User
.
LightTheme
=
true
data
.
User
.
LightTheme
=
true
data
.
Theme
=
"light"
data
.
Theme
=
"light"
}
}
...
@@ -299,12 +299,12 @@ func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
...
@@ -299,12 +299,12 @@ func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
}
}
func
Index
(
c
*
m
.
ReqContext
)
{
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
)
c
.
Handle
(
500
,
"Failed to get settings"
,
err
)
return
return
}
else
{
c
.
HTML
(
200
,
"index"
,
data
)
}
}
c
.
HTML
(
200
,
"index"
,
data
)
}
}
func
NotFoundHandler
(
c
*
m
.
ReqContext
)
{
func
NotFoundHandler
(
c
*
m
.
ReqContext
)
{
...
@@ -313,10 +313,11 @@ func NotFoundHandler(c *m.ReqContext) {
...
@@ -313,10 +313,11 @@ func NotFoundHandler(c *m.ReqContext) {
return
return
}
}
if
data
,
err
:=
setIndexViewData
(
c
);
err
!=
nil
{
data
,
err
:=
setIndexViewData
(
c
)
if
err
!=
nil
{
c
.
Handle
(
500
,
"Failed to get settings"
,
err
)
c
.
Handle
(
500
,
"Failed to get settings"
,
err
)
return
return
}
else
{
c
.
HTML
(
404
,
"index"
,
data
)
}
}
c
.
HTML
(
404
,
"index"
,
data
)
}
}
pkg/api/login.go
View file @
b818e9f6
...
@@ -14,7 +14,7 @@ import (
...
@@ -14,7 +14,7 @@ import (
)
)
const
(
const
(
V
IEW_INDEX
=
"index"
V
iewIndex
=
"index"
)
)
func
LoginView
(
c
*
m
.
ReqContext
)
{
func
LoginView
(
c
*
m
.
ReqContext
)
{
...
@@ -40,7 +40,7 @@ func LoginView(c *m.ReqContext) {
...
@@ -40,7 +40,7 @@ func LoginView(c *m.ReqContext) {
}
}
if
!
tryLoginUsingRememberCookie
(
c
)
{
if
!
tryLoginUsingRememberCookie
(
c
)
{
c
.
HTML
(
200
,
V
IEW_INDEX
,
viewData
)
c
.
HTML
(
200
,
V
iewIndex
,
viewData
)
return
return
}
}
...
@@ -87,7 +87,7 @@ func tryLoginUsingRememberCookie(c *m.ReqContext) bool {
...
@@ -87,7 +87,7 @@ func tryLoginUsingRememberCookie(c *m.ReqContext) bool {
return
true
return
true
}
}
func
LoginA
pi
Ping
(
c
*
m
.
ReqContext
)
{
func
LoginA
PI
Ping
(
c
*
m
.
ReqContext
)
{
if
!
tryLoginUsingRememberCookie
(
c
)
{
if
!
tryLoginUsingRememberCookie
(
c
)
{
c
.
JsonApiErr
(
401
,
"Unauthorized"
,
nil
)
c
.
JsonApiErr
(
401
,
"Unauthorized"
,
nil
)
return
return
...
...
pkg/api/metrics.go
View file @
b818e9f6
...
@@ -20,12 +20,12 @@ func QueryMetrics(c *m.ReqContext, reqDto dtos.MetricRequest) Response {
...
@@ -20,12 +20,12 @@ func QueryMetrics(c *m.ReqContext, reqDto dtos.MetricRequest) Response {
return
ApiError
(
400
,
"No queries found in query"
,
nil
)
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
{
if
err
!=
nil
{
return
ApiError
(
400
,
"Query missing datasourceId"
,
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
{
if
err
:=
bus
.
Dispatch
(
&
dsQuery
);
err
!=
nil
{
return
ApiError
(
500
,
"failed to fetch data source"
,
err
)
return
ApiError
(
500
,
"failed to fetch data source"
,
err
)
}
}
...
@@ -82,7 +82,7 @@ func GenerateError(c *m.ReqContext) Response {
...
@@ -82,7 +82,7 @@ func GenerateError(c *m.ReqContext) Response {
}
}
// GET /api/tsdb/testdata/gensql
// 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
{
if
err
:=
bus
.
Dispatch
(
&
m
.
InsertSqlTestDataCommand
{});
err
!=
nil
{
return
ApiError
(
500
,
"Failed to insert test data"
,
err
)
return
ApiError
(
500
,
"Failed to insert test data"
,
err
)
}
}
...
...
pkg/api/org.go
View file @
b818e9f6
...
@@ -15,7 +15,7 @@ func GetOrgCurrent(c *m.ReqContext) Response {
...
@@ -15,7 +15,7 @@ func GetOrgCurrent(c *m.ReqContext) Response {
}
}
// GET /api/orgs/:orgId
// GET /api/orgs/:orgId
func
GetOrgByI
d
(
c
*
m
.
ReqContext
)
Response
{
func
GetOrgByI
D
(
c
*
m
.
ReqContext
)
Response
{
return
getOrgHelper
(
c
.
ParamsInt64
(
":orgId"
))
return
getOrgHelper
(
c
.
ParamsInt64
(
":orgId"
))
}
}
...
@@ -106,8 +106,8 @@ func UpdateOrg(c *m.ReqContext, form dtos.UpdateOrgForm) Response {
...
@@ -106,8 +106,8 @@ func UpdateOrg(c *m.ReqContext, form dtos.UpdateOrgForm) Response {
return
updateOrgHelper
(
form
,
c
.
ParamsInt64
(
":orgId"
))
return
updateOrgHelper
(
form
,
c
.
ParamsInt64
(
":orgId"
))
}
}
func
updateOrgHelper
(
form
dtos
.
UpdateOrgForm
,
orgI
d
int64
)
Response
{
func
updateOrgHelper
(
form
dtos
.
UpdateOrgForm
,
orgI
D
int64
)
Response
{
cmd
:=
m
.
UpdateOrgCommand
{
Name
:
form
.
Name
,
OrgId
:
orgI
d
}
cmd
:=
m
.
UpdateOrgCommand
{
Name
:
form
.
Name
,
OrgId
:
orgI
D
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
==
m
.
ErrOrgNameTaken
{
if
err
==
m
.
ErrOrgNameTaken
{
return
ApiError
(
400
,
"Organization name taken"
,
err
)
return
ApiError
(
400
,
"Organization name taken"
,
err
)
...
@@ -128,9 +128,9 @@ func UpdateOrgAddress(c *m.ReqContext, form dtos.UpdateOrgAddressForm) Response
...
@@ -128,9 +128,9 @@ func UpdateOrgAddress(c *m.ReqContext, form dtos.UpdateOrgAddressForm) Response
return
updateOrgAddressHelper
(
form
,
c
.
ParamsInt64
(
":orgId"
))
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
{
cmd
:=
m
.
UpdateOrgAddressCommand
{
OrgId
:
orgI
d
,
OrgId
:
orgI
D
,
Address
:
m
.
Address
{
Address
:
m
.
Address
{
Address1
:
form
.
Address1
,
Address1
:
form
.
Address1
,
Address2
:
form
.
Address2
,
Address2
:
form
.
Address2
,
...
@@ -149,7 +149,7 @@ func updateOrgAddressHelper(form dtos.UpdateOrgAddressForm, orgId int64) Respons
...
@@ -149,7 +149,7 @@ func updateOrgAddressHelper(form dtos.UpdateOrgAddressForm, orgId int64) Respons
}
}
// GET /api/orgs/:orgId
// 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
:=
bus
.
Dispatch
(
&
m
.
DeleteOrgCommand
{
Id
:
c
.
ParamsInt64
(
":orgId"
)});
err
!=
nil
{
if
err
==
m
.
ErrOrgNotFound
{
if
err
==
m
.
ErrOrgNotFound
{
return
ApiError
(
404
,
"Failed to delete organization. ID not found"
,
nil
)
return
ApiError
(
404
,
"Failed to delete organization. ID not found"
,
nil
)
...
...
pkg/api/org_invite.go
View file @
b818e9f6
...
@@ -96,26 +96,25 @@ func inviteExistingUserToOrg(c *m.ReqContext, user *m.User, inviteDto *dtos.AddI
...
@@ -96,26 +96,25 @@ 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
(
412
,
fmt
.
Sprintf
(
"User %s is already added to organization"
,
inviteDto
.
LoginOrEmail
),
err
)
}
}
return
ApiError
(
500
,
"Error while trying to create org user"
,
err
)
return
ApiError
(
500
,
"Error while trying to create org user"
,
err
)
}
else
{
}
if
inviteDto
.
SendEmail
&&
util
.
IsEmail
(
user
.
Email
)
{
if
inviteDto
.
SendEmail
&&
util
.
IsEmail
(
user
.
Email
)
{
emailCmd
:=
m
.
SendEmailCommand
{
emailCmd
:=
m
.
SendEmailCommand
{
To
:
[]
string
{
user
.
Email
},
To
:
[]
string
{
user
.
Email
},
Template
:
"invited_to_org.html"
,
Template
:
"invited_to_org.html"
,
Data
:
map
[
string
]
interface
{}{
Data
:
map
[
string
]
interface
{}{
"Name"
:
user
.
NameOrFallback
(),
"Name"
:
user
.
NameOrFallback
(),
"OrgName"
:
c
.
OrgName
,
"OrgName"
:
c
.
OrgName
,
"InvitedBy"
:
util
.
StringsFallback3
(
c
.
Name
,
c
.
Email
,
c
.
Login
),
"InvitedBy"
:
util
.
StringsFallback3
(
c
.
Name
,
c
.
Email
,
c
.
Login
),
},
},
}
if
err
:=
bus
.
Dispatch
(
&
emailCmd
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to send email invited_to_org"
,
err
)
}
}
}
return
ApiSuccess
(
fmt
.
Sprintf
(
"Existing Grafana user %s added to org %s"
,
user
.
NameOrFallback
(),
c
.
OrgName
))
if
err
:=
bus
.
Dispatch
(
&
emailCmd
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to send email invited_to_org"
,
err
)
}
}
}
return
ApiSuccess
(
fmt
.
Sprintf
(
"Existing Grafana user %s added to org %s"
,
user
.
NameOrFallback
(),
c
.
OrgName
))
}
}
func
RevokeInvite
(
c
*
m
.
ReqContext
)
Response
{
func
RevokeInvite
(
c
*
m
.
ReqContext
)
Response
{
...
...
pkg/api/org_users.go
View file @
b818e9f6
...
@@ -53,9 +53,9 @@ func GetOrgUsers(c *m.ReqContext) Response {
...
@@ -53,9 +53,9 @@ func GetOrgUsers(c *m.ReqContext) Response {
return
getOrgUsersHelper
(
c
.
ParamsInt64
(
":orgId"
),
""
,
0
)
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
{
q
:=
m
.
GetOrgUsersQuery
{
OrgId
:
orgI
d
,
OrgId
:
orgI
D
,
Query
:
query
,
Query
:
query
,
Limit
:
limit
,
Limit
:
limit
,
}
}
...
@@ -102,19 +102,19 @@ func updateOrgUserHelper(cmd m.UpdateOrgUserCommand) Response {
...
@@ -102,19 +102,19 @@ func updateOrgUserHelper(cmd m.UpdateOrgUserCommand) Response {
// DELETE /api/org/users/:userId
// DELETE /api/org/users/:userId
func
RemoveOrgUserForCurrentOrg
(
c
*
m
.
ReqContext
)
Response
{
func
RemoveOrgUserForCurrentOrg
(
c
*
m
.
ReqContext
)
Response
{
userI
d
:=
c
.
ParamsInt64
(
":userId"
)
userI
D
:=
c
.
ParamsInt64
(
":userId"
)
return
removeOrgUserHelper
(
c
.
OrgId
,
userI
d
)
return
removeOrgUserHelper
(
c
.
OrgId
,
userI
D
)
}
}
// DELETE /api/orgs/:orgId/users/:userId
// DELETE /api/orgs/:orgId/users/:userId
func
RemoveOrgUser
(
c
*
m
.
ReqContext
)
Response
{
func
RemoveOrgUser
(
c
*
m
.
ReqContext
)
Response
{
userI
d
:=
c
.
ParamsInt64
(
":userId"
)
userI
D
:=
c
.
ParamsInt64
(
":userId"
)
orgI
d
:=
c
.
ParamsInt64
(
":orgId"
)
orgI
D
:=
c
.
ParamsInt64
(
":orgId"
)
return
removeOrgUserHelper
(
orgI
d
,
userId
)
return
removeOrgUserHelper
(
orgI
D
,
userID
)
}
}
func
removeOrgUserHelper
(
orgI
d
int64
,
userId
int64
)
Response
{
func
removeOrgUserHelper
(
orgI
D
int64
,
userID
int64
)
Response
{
cmd
:=
m
.
RemoveOrgUserCommand
{
OrgId
:
orgI
d
,
UserId
:
userId
}
cmd
:=
m
.
RemoveOrgUserCommand
{
OrgId
:
orgI
D
,
UserId
:
userID
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
==
m
.
ErrLastOrgAdmin
{
if
err
==
m
.
ErrLastOrgAdmin
{
...
...
pkg/api/playlist.go
View file @
b818e9f6
...
@@ -127,9 +127,9 @@ func GetPlaylistItems(c *m.ReqContext) Response {
...
@@ -127,9 +127,9 @@ func GetPlaylistItems(c *m.ReqContext) Response {
}
}
func
GetPlaylistDashboards
(
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
{
if
err
!=
nil
{
return
ApiError
(
500
,
"Could not load dashboards"
,
err
)
return
ApiError
(
500
,
"Could not load dashboards"
,
err
)
}
}
...
...
pkg/api/playlist_play.go
View file @
b818e9f6
...
@@ -34,29 +34,27 @@ func populateDashboardsById(dashboardByIds []int64, dashboardIdOrder map[int64]i
...
@@ -34,29 +34,27 @@ func populateDashboardsById(dashboardByIds []int64, dashboardIdOrder map[int64]i
return
result
,
nil
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
)
result
:=
make
(
dtos
.
PlaylistDashboardsSlice
,
0
)
if
len
(
dashboardByTag
)
>
0
{
for
_
,
tag
:=
range
dashboardByTag
{
for
_
,
tag
:=
range
dashboardByTag
{
searchQuery
:=
search
.
Query
{
searchQuery
:=
search
.
Query
{
Title
:
""
,
Title
:
""
,
Tags
:
[]
string
{
tag
},
Tags
:
[]
string
{
tag
},
SignedInUser
:
signedInUser
,
SignedInUser
:
signedInUser
,
Limit
:
100
,
Limit
:
100
,
IsStarred
:
false
,
IsStarred
:
false
,
OrgId
:
orgID
,
OrgId
:
orgId
,
}
}
if
err
:=
bus
.
Dispatch
(
&
searchQuery
);
err
==
nil
{
if
err
:=
bus
.
Dispatch
(
&
searchQuery
);
err
==
nil
{
for
_
,
item
:=
range
searchQuery
.
Result
{
for
_
,
item
:=
range
searchQuery
.
Result
{
result
=
append
(
result
,
dtos
.
PlaylistDashboard
{
result
=
append
(
result
,
dtos
.
PlaylistDashboard
{
Id
:
item
.
Id
,
Id
:
item
.
Id
,
Title
:
item
.
Title
,
Title
:
item
.
Title
,
Uri
:
item
.
Uri
,
Uri
:
item
.
Uri
,
Order
:
dashboardTagOrder
[
tag
],
Order
:
dashboardTagOrder
[
tag
],
})
})
}
}
}
}
}
}
}
...
@@ -64,19 +62,19 @@ func populateDashboardsByTag(orgId int64, signedInUser *m.SignedInUser, dashboar
...
@@ -64,19 +62,19 @@ func populateDashboardsByTag(orgId int64, signedInUser *m.SignedInUser, dashboar
return
result
return
result
}
}
func
LoadPlaylistDashboards
(
orgI
d
int64
,
signedInUser
*
m
.
SignedInUser
,
playlistId
int64
)
(
dtos
.
PlaylistDashboardsSlice
,
error
)
{
func
LoadPlaylistDashboards
(
orgI
D
int64
,
signedInUser
*
m
.
SignedInUser
,
playlistID
int64
)
(
dtos
.
PlaylistDashboardsSlice
,
error
)
{
playlistItems
,
_
:=
LoadPlaylistItems
(
playlistI
d
)
playlistItems
,
_
:=
LoadPlaylistItems
(
playlistI
D
)
dashboardByI
d
s
:=
make
([]
int64
,
0
)
dashboardByI
D
s
:=
make
([]
int64
,
0
)
dashboardByTag
:=
make
([]
string
,
0
)
dashboardByTag
:=
make
([]
string
,
0
)
dashboardI
d
Order
:=
make
(
map
[
int64
]
int
)
dashboardI
D
Order
:=
make
(
map
[
int64
]
int
)
dashboardTagOrder
:=
make
(
map
[
string
]
int
)
dashboardTagOrder
:=
make
(
map
[
string
]
int
)
for
_
,
i
:=
range
playlistItems
{
for
_
,
i
:=
range
playlistItems
{
if
i
.
Type
==
"dashboard_by_id"
{
if
i
.
Type
==
"dashboard_by_id"
{
dashboardI
d
,
_
:=
strconv
.
ParseInt
(
i
.
Value
,
10
,
64
)
dashboardI
D
,
_
:=
strconv
.
ParseInt
(
i
.
Value
,
10
,
64
)
dashboardByI
ds
=
append
(
dashboardByIds
,
dashboardId
)
dashboardByI
Ds
=
append
(
dashboardByIDs
,
dashboardID
)
dashboardI
dOrder
[
dashboardId
]
=
i
.
Order
dashboardI
DOrder
[
dashboardID
]
=
i
.
Order
}
}
if
i
.
Type
==
"dashboard_by_tag"
{
if
i
.
Type
==
"dashboard_by_tag"
{
...
@@ -87,9 +85,9 @@ func LoadPlaylistDashboards(orgId int64, signedInUser *m.SignedInUser, playlistI
...
@@ -87,9 +85,9 @@ func LoadPlaylistDashboards(orgId int64, signedInUser *m.SignedInUser, playlistI
result
:=
make
(
dtos
.
PlaylistDashboardsSlice
,
0
)
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
,
k
...
)
result
=
append
(
result
,
populateDashboardsByTag
(
orgI
d
,
signedInUser
,
dashboardByTag
,
dashboardTagOrder
)
...
)
result
=
append
(
result
,
populateDashboardsByTag
(
orgI
D
,
signedInUser
,
dashboardByTag
,
dashboardTagOrder
)
...
)
sort
.
Sort
(
result
)
sort
.
Sort
(
result
)
return
result
,
nil
return
result
,
nil
...
...
pkg/api/plugins.go
View file @
b818e9f6
...
@@ -78,48 +78,48 @@ func GetPluginList(c *m.ReqContext) Response {
...
@@ -78,48 +78,48 @@ func GetPluginList(c *m.ReqContext) Response {
return
Json
(
200
,
result
)
return
Json
(
200
,
result
)
}
}
func
GetPluginSettingByI
d
(
c
*
m
.
ReqContext
)
Response
{
func
GetPluginSettingByI
D
(
c
*
m
.
ReqContext
)
Response
{
pluginI
d
:=
c
.
Params
(
":pluginId"
)
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
)
return
ApiError
(
404
,
"Plugin not found, no installed plugin with that id"
,
nil
)
}
else
{
}
dto
:=
&
dtos
.
PluginSetting
{
dto
:=
&
dtos
.
PluginSetting
{
Type
:
def
.
Type
,
Type
:
def
.
Type
,
Id
:
def
.
Id
,
Id
:
def
.
Id
,
Name
:
def
.
Name
,
Name
:
def
.
Name
,
Info
:
&
def
.
Info
,
Info
:
&
def
.
Info
,
Dependencies
:
&
def
.
Dependencies
,
Dependencies
:
&
def
.
Dependencies
,
Includes
:
def
.
Includes
,
Includes
:
def
.
Includes
,
BaseUrl
:
def
.
BaseUrl
,
BaseUrl
:
def
.
BaseUrl
,
Module
:
def
.
Module
,
Module
:
def
.
Module
,
DefaultNavUrl
:
def
.
DefaultNavUrl
,
DefaultNavUrl
:
def
.
DefaultNavUrl
,
LatestVersion
:
def
.
GrafanaNetVersion
,
LatestVersion
:
def
.
GrafanaNetVersion
,
HasUpdate
:
def
.
GrafanaNetHasUpdate
,
HasUpdate
:
def
.
GrafanaNetHasUpdate
,
State
:
def
.
State
,
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
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
if
err
!=
m
.
ErrPluginSettingNotFound
{
if
err
!=
m
.
ErrPluginSettingNotFound
{
return
ApiError
(
500
,
"Failed to get login settings"
,
nil
)
return
ApiError
(
500
,
"Failed to get login settings"
,
nil
)
}
}
else
{
dto
.
Enabled
=
query
.
Result
.
Enabled
dto
.
Pinned
=
query
.
Result
.
Pinned
dto
.
JsonData
=
query
.
Result
.
JsonData
}
}
}
else
{
return
Json
(
200
,
dto
)
dto
.
Enabled
=
query
.
Result
.
Enabled
dto
.
Pinned
=
query
.
Result
.
Pinned
dto
.
JsonData
=
query
.
Result
.
JsonData
}
}
return
Json
(
200
,
dto
)
}
}
func
UpdatePluginSetting
(
c
*
m
.
ReqContext
,
cmd
m
.
UpdatePluginSettingCmd
)
Response
{
func
UpdatePluginSetting
(
c
*
m
.
ReqContext
,
cmd
m
.
UpdatePluginSettingCmd
)
Response
{
pluginI
d
:=
c
.
Params
(
":pluginId"
)
pluginI
D
:=
c
.
Params
(
":pluginId"
)
cmd
.
OrgId
=
c
.
OrgId
cmd
.
OrgId
=
c
.
OrgId
cmd
.
PluginId
=
pluginI
d
cmd
.
PluginId
=
pluginI
D
if
_
,
ok
:=
plugins
.
Apps
[
cmd
.
PluginId
];
!
ok
{
if
_
,
ok
:=
plugins
.
Apps
[
cmd
.
PluginId
];
!
ok
{
return
ApiError
(
404
,
"Plugin not installed."
,
nil
)
return
ApiError
(
404
,
"Plugin not installed."
,
nil
)
...
@@ -133,34 +133,36 @@ func UpdatePluginSetting(c *m.ReqContext, cmd m.UpdatePluginSettingCmd) Response
...
@@ -133,34 +133,36 @@ func UpdatePluginSetting(c *m.ReqContext, cmd m.UpdatePluginSettingCmd) Response
}
}
func
GetPluginDashboards
(
c
*
m
.
ReqContext
)
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
{
if
notfound
,
ok
:=
err
.
(
plugins
.
PluginNotFoundError
);
ok
{
return
ApiError
(
404
,
notfound
.
Error
(),
nil
)
return
ApiError
(
404
,
notfound
.
Error
(),
nil
)
}
}
return
ApiError
(
500
,
"Failed to get plugin dashboards"
,
err
)
return
ApiError
(
500
,
"Failed to get plugin dashboards"
,
err
)
}
else
{
return
Json
(
200
,
list
)
}
}
return
Json
(
200
,
list
)
}
}
func
GetPluginMarkdown
(
c
*
m
.
ReqContext
)
Response
{
func
GetPluginMarkdown
(
c
*
m
.
ReqContext
)
Response
{
pluginI
d
:=
c
.
Params
(
":pluginId"
)
pluginI
D
:=
c
.
Params
(
":pluginId"
)
name
:=
c
.
Params
(
":name"
)
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
{
if
notfound
,
ok
:=
err
.
(
plugins
.
PluginNotFoundError
);
ok
{
return
ApiError
(
404
,
notfound
.
Error
(),
nil
)
return
ApiError
(
404
,
notfound
.
Error
(),
nil
)
}
}
return
ApiError
(
500
,
"Could not get markdown file"
,
err
)
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
}
}
resp
:=
Respond
(
200
,
content
)
resp
.
Header
(
"Content-Type"
,
"text/plain; charset=utf-8"
)
return
resp
}
}
func
ImportDashboard
(
c
*
m
.
ReqContext
,
apiCmd
dtos
.
ImportDashboardCommand
)
Response
{
func
ImportDashboard
(
c
*
m
.
ReqContext
,
apiCmd
dtos
.
ImportDashboardCommand
)
Response
{
...
...
pkg/api/preferences.go
View file @
b818e9f6
...
@@ -24,8 +24,8 @@ func GetUserPreferences(c *m.ReqContext) Response {
...
@@ -24,8 +24,8 @@ func GetUserPreferences(c *m.ReqContext) Response {
return
getPreferencesFor
(
c
.
OrgId
,
c
.
UserId
)
return
getPreferencesFor
(
c
.
OrgId
,
c
.
UserId
)
}
}
func
getPreferencesFor
(
orgI
d
int64
,
userId
int64
)
Response
{
func
getPreferencesFor
(
orgI
D
int64
,
userID
int64
)
Response
{
prefsQuery
:=
m
.
GetPreferencesQuery
{
UserId
:
userI
d
,
OrgId
:
orgId
}
prefsQuery
:=
m
.
GetPreferencesQuery
{
UserId
:
userI
D
,
OrgId
:
orgID
}
if
err
:=
bus
.
Dispatch
(
&
prefsQuery
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
prefsQuery
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to get preferences"
,
err
)
return
ApiError
(
500
,
"Failed to get preferences"
,
err
)
...
@@ -45,10 +45,10 @@ func UpdateUserPreferences(c *m.ReqContext, dtoCmd dtos.UpdatePrefsCmd) Response
...
@@ -45,10 +45,10 @@ func UpdateUserPreferences(c *m.ReqContext, dtoCmd dtos.UpdatePrefsCmd) Response
return
updatePreferencesFor
(
c
.
OrgId
,
c
.
UserId
,
&
dtoCmd
)
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
{
saveCmd
:=
m
.
SavePreferencesCommand
{
UserId
:
userI
d
,
UserId
:
userI
D
,
OrgId
:
orgI
d
,
OrgId
:
orgI
D
,
Theme
:
dtoCmd
.
Theme
,
Theme
:
dtoCmd
.
Theme
,
Timezone
:
dtoCmd
.
Timezone
,
Timezone
:
dtoCmd
.
Timezone
,
HomeDashboardId
:
dtoCmd
.
HomeDashboardId
,
HomeDashboardId
:
dtoCmd
.
HomeDashboardId
,
...
...
pkg/api/search.go
View file @
b818e9f6
...
@@ -25,19 +25,19 @@ func Search(c *m.ReqContext) {
...
@@ -25,19 +25,19 @@ func Search(c *m.ReqContext) {
permission
=
m
.
PERMISSION_EDIT
permission
=
m
.
PERMISSION_EDIT
}
}
db
id
s
:=
make
([]
int64
,
0
)
db
ID
s
:=
make
([]
int64
,
0
)
for
_
,
id
:=
range
c
.
QueryStrings
(
"dashboardIds"
)
{
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
{
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"
)
{
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
{
if
err
==
nil
{
folderI
ds
=
append
(
folderIds
,
folderId
)
folderI
Ds
=
append
(
folderIDs
,
folderID
)
}
}
}
}
...
@@ -48,9 +48,9 @@ func Search(c *m.ReqContext) {
...
@@ -48,9 +48,9 @@ func Search(c *m.ReqContext) {
Limit
:
limit
,
Limit
:
limit
,
IsStarred
:
starred
==
"true"
,
IsStarred
:
starred
==
"true"
,
OrgId
:
c
.
OrgId
,
OrgId
:
c
.
OrgId
,
DashboardIds
:
db
id
s
,
DashboardIds
:
db
ID
s
,
Type
:
dashboardType
,
Type
:
dashboardType
,
FolderIds
:
folderI
d
s
,
FolderIds
:
folderI
D
s
,
Permission
:
permission
,
Permission
:
permission
,
}
}
...
...
pkg/api/team.go
View file @
b818e9f6
...
@@ -38,7 +38,7 @@ func UpdateTeam(c *m.ReqContext, cmd m.UpdateTeamCommand) Response {
...
@@ -38,7 +38,7 @@ func UpdateTeam(c *m.ReqContext, cmd m.UpdateTeamCommand) Response {
}
}
// DELETE /api/teams/:teamId
// 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
:=
bus
.
Dispatch
(
&
m
.
DeleteTeamCommand
{
OrgId
:
c
.
OrgId
,
Id
:
c
.
ParamsInt64
(
":teamId"
)});
err
!=
nil
{
if
err
==
m
.
ErrTeamNotFound
{
if
err
==
m
.
ErrTeamNotFound
{
return
ApiError
(
404
,
"Failed to delete Team. ID not found"
,
nil
)
return
ApiError
(
404
,
"Failed to delete Team. ID not found"
,
nil
)
...
@@ -82,7 +82,7 @@ func SearchTeams(c *m.ReqContext) Response {
...
@@ -82,7 +82,7 @@ func SearchTeams(c *m.ReqContext) Response {
}
}
// GET /api/teams/:teamId
// 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"
)}
query
:=
m
.
GetTeamByIdQuery
{
OrgId
:
c
.
OrgId
,
Id
:
c
.
ParamsInt64
(
":teamId"
)}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
...
...
pkg/api/user.go
View file @
b818e9f6
...
@@ -14,12 +14,12 @@ func GetSignedInUser(c *m.ReqContext) Response {
...
@@ -14,12 +14,12 @@ func GetSignedInUser(c *m.ReqContext) Response {
}
}
// GET /api/users/:id
// GET /api/users/:id
func
GetUserByI
d
(
c
*
m
.
ReqContext
)
Response
{
func
GetUserByI
D
(
c
*
m
.
ReqContext
)
Response
{
return
getUserUserProfile
(
c
.
ParamsInt64
(
":id"
))
return
getUserUserProfile
(
c
.
ParamsInt64
(
":id"
))
}
}
func
getUserUserProfile
(
userI
d
int64
)
Response
{
func
getUserUserProfile
(
userI
D
int64
)
Response
{
query
:=
m
.
GetUserProfileQuery
{
UserId
:
userI
d
}
query
:=
m
.
GetUserProfileQuery
{
UserId
:
userI
D
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
if
err
==
m
.
ErrUserNotFound
{
if
err
==
m
.
ErrUserNotFound
{
...
@@ -75,14 +75,14 @@ func UpdateUser(c *m.ReqContext, cmd m.UpdateUserCommand) Response {
...
@@ -75,14 +75,14 @@ func UpdateUser(c *m.ReqContext, cmd m.UpdateUserCommand) Response {
//POST /api/users/:id/using/:orgId
//POST /api/users/:id/using/:orgId
func
UpdateUserActiveOrg
(
c
*
m
.
ReqContext
)
Response
{
func
UpdateUserActiveOrg
(
c
*
m
.
ReqContext
)
Response
{
userI
d
:=
c
.
ParamsInt64
(
":id"
)
userI
D
:=
c
.
ParamsInt64
(
":id"
)
orgI
d
:=
c
.
ParamsInt64
(
":orgId"
)
orgI
D
:=
c
.
ParamsInt64
(
":orgId"
)
if
!
validateUsingOrg
(
userI
d
,
orgId
)
{
if
!
validateUsingOrg
(
userI
D
,
orgID
)
{
return
ApiError
(
401
,
"Not a valid organization"
,
nil
)
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
{
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to change active organization"
,
err
)
return
ApiError
(
500
,
"Failed to change active organization"
,
err
)
...
@@ -116,8 +116,8 @@ func GetUserOrgList(c *m.ReqContext) Response {
...
@@ -116,8 +116,8 @@ func GetUserOrgList(c *m.ReqContext) Response {
return
getUserOrgList
(
c
.
ParamsInt64
(
":id"
))
return
getUserOrgList
(
c
.
ParamsInt64
(
":id"
))
}
}
func
getUserOrgList
(
userI
d
int64
)
Response
{
func
getUserOrgList
(
userI
D
int64
)
Response
{
query
:=
m
.
GetUserOrgListQuery
{
UserId
:
userI
d
}
query
:=
m
.
GetUserOrgListQuery
{
UserId
:
userI
D
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to get user organizations"
,
err
)
return
ApiError
(
500
,
"Failed to get user organizations"
,
err
)
...
@@ -126,8 +126,8 @@ func getUserOrgList(userId int64) Response {
...
@@ -126,8 +126,8 @@ func getUserOrgList(userId int64) Response {
return
Json
(
200
,
query
.
Result
)
return
Json
(
200
,
query
.
Result
)
}
}
func
validateUsingOrg
(
userI
d
int64
,
orgId
int64
)
bool
{
func
validateUsingOrg
(
userI
D
int64
,
orgID
int64
)
bool
{
query
:=
m
.
GetUserOrgListQuery
{
UserId
:
userI
d
}
query
:=
m
.
GetUserOrgListQuery
{
UserId
:
userI
D
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
false
return
false
...
@@ -136,7 +136,7 @@ func validateUsingOrg(userId int64, orgId int64) bool {
...
@@ -136,7 +136,7 @@ func validateUsingOrg(userId int64, orgId int64) bool {
// validate that the org id in the list
// validate that the org id in the list
valid
:=
false
valid
:=
false
for
_
,
other
:=
range
query
.
Result
{
for
_
,
other
:=
range
query
.
Result
{
if
other
.
OrgId
==
orgI
d
{
if
other
.
OrgId
==
orgI
D
{
valid
=
true
valid
=
true
}
}
}
}
...
@@ -146,13 +146,13 @@ func validateUsingOrg(userId int64, orgId int64) bool {
...
@@ -146,13 +146,13 @@ func validateUsingOrg(userId int64, orgId int64) bool {
// POST /api/user/using/:id
// POST /api/user/using/:id
func
UserSetUsingOrg
(
c
*
m
.
ReqContext
)
Response
{
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
)
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
{
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to change active organization"
,
err
)
return
ApiError
(
500
,
"Failed to change active organization"
,
err
)
...
@@ -163,13 +163,13 @@ func UserSetUsingOrg(c *m.ReqContext) Response {
...
@@ -163,13 +163,13 @@ func UserSetUsingOrg(c *m.ReqContext) Response {
// GET /profile/switch-org/:id
// GET /profile/switch-org/:id
func
ChangeActiveOrgAndRedirectToHome
(
c
*
m
.
ReqContext
)
{
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
)
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
{
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
NotFoundHandler
(
c
)
NotFoundHandler
(
c
)
...
...
pkg/cmd/grafana-server/server.go
View file @
b818e9f6
...
@@ -120,7 +120,7 @@ func (g *GrafanaServerImpl) initLogging() {
...
@@ -120,7 +120,7 @@ func (g *GrafanaServerImpl) initLogging() {
}
}
func
(
g
*
GrafanaServerImpl
)
startHttpServer
()
error
{
func
(
g
*
GrafanaServerImpl
)
startHttpServer
()
error
{
g
.
httpServer
=
api
.
NewH
ttp
Server
()
g
.
httpServer
=
api
.
NewH
TTP
Server
()
err
:=
g
.
httpServer
.
Start
(
g
.
context
)
err
:=
g
.
httpServer
.
Start
(
g
.
context
)
...
...
pkg/middleware/auth.go
View file @
b818e9f6
...
@@ -17,10 +17,10 @@ type AuthOptions struct {
...
@@ -17,10 +17,10 @@ type AuthOptions struct {
}
}
func
getRequestUserId
(
c
*
m
.
ReqContext
)
int64
{
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
{
if
userI
D
!=
nil
{
return
userI
d
.
(
int64
)
return
userI
D
.
(
int64
)
}
}
return
0
return
0
...
...
pkg/middleware/dashboard_redirect.go
View file @
b818e9f6
...
@@ -20,7 +20,7 @@ func getDashboardUrlBySlug(orgId int64, slug string) (string, error) {
...
@@ -20,7 +20,7 @@ func getDashboardUrlBySlug(orgId int64, slug string) (string, error) {
return
m
.
GetDashboardUrl
(
query
.
Result
.
Uid
,
query
.
Result
.
Slug
),
nil
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
)
{
return
func
(
c
*
m
.
ReqContext
)
{
slug
:=
c
.
Params
(
"slug"
)
slug
:=
c
.
Params
(
"slug"
)
...
...
pkg/middleware/dashboard_redirect_test.go
View file @
b818e9f6
...
@@ -13,7 +13,7 @@ import (
...
@@ -13,7 +13,7 @@ import (
func
TestMiddlewareDashboardRedirect
(
t
*
testing
.
T
)
{
func
TestMiddlewareDashboardRedirect
(
t
*
testing
.
T
)
{
Convey
(
"Given the dashboard redirect middleware"
,
t
,
func
()
{
Convey
(
"Given the dashboard redirect middleware"
,
t
,
func
()
{
bus
.
ClearBusHandlers
()
bus
.
ClearBusHandlers
()
redirectFromLegacyDashboardUrl
:=
RedirectFromLegacyDashboardU
rl
()
redirectFromLegacyDashboardUrl
:=
RedirectFromLegacyDashboardU
RL
()
redirectFromLegacyDashboardSoloUrl
:=
RedirectFromLegacyDashboardSoloUrl
()
redirectFromLegacyDashboardSoloUrl
:=
RedirectFromLegacyDashboardSoloUrl
()
fakeDash
:=
m
.
NewDashboard
(
"Child dash"
)
fakeDash
:=
m
.
NewDashboard
(
"Child dash"
)
...
@@ -34,9 +34,9 @@ func TestMiddlewareDashboardRedirect(t *testing.T) {
...
@@ -34,9 +34,9 @@ func TestMiddlewareDashboardRedirect(t *testing.T) {
Convey
(
"Should redirect to new dashboard url with a 301 Moved Permanently"
,
func
()
{
Convey
(
"Should redirect to new dashboard url with a 301 Moved Permanently"
,
func
()
{
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
301
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
301
)
redirectU
rl
,
_
:=
sc
.
resp
.
Result
()
.
Location
()
redirectU
RL
,
_
:=
sc
.
resp
.
Result
()
.
Location
()
So
(
redirectU
rl
.
Path
,
ShouldEqual
,
m
.
GetDashboardUrl
(
fakeDash
.
Uid
,
fakeDash
.
Slug
))
So
(
redirectU
RL
.
Path
,
ShouldEqual
,
m
.
GetDashboardUrl
(
fakeDash
.
Uid
,
fakeDash
.
Slug
))
So
(
len
(
redirectU
rl
.
Query
()),
ShouldEqual
,
2
)
So
(
len
(
redirectU
RL
.
Query
()),
ShouldEqual
,
2
)
})
})
})
})
...
@@ -47,11 +47,11 @@ func TestMiddlewareDashboardRedirect(t *testing.T) {
...
@@ -47,11 +47,11 @@ func TestMiddlewareDashboardRedirect(t *testing.T) {
Convey
(
"Should redirect to new dashboard url with a 301 Moved Permanently"
,
func
()
{
Convey
(
"Should redirect to new dashboard url with a 301 Moved Permanently"
,
func
()
{
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
301
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
301
)
redirectU
rl
,
_
:=
sc
.
resp
.
Result
()
.
Location
()
redirectU
RL
,
_
:=
sc
.
resp
.
Result
()
.
Location
()
expectedU
rl
:=
m
.
GetDashboardUrl
(
fakeDash
.
Uid
,
fakeDash
.
Slug
)
expectedU
RL
:=
m
.
GetDashboardUrl
(
fakeDash
.
Uid
,
fakeDash
.
Slug
)
expectedU
rl
=
strings
.
Replace
(
expectedUrl
,
"/d/"
,
"/d-solo/"
,
1
)
expectedU
RL
=
strings
.
Replace
(
expectedURL
,
"/d/"
,
"/d-solo/"
,
1
)
So
(
redirectU
rl
.
Path
,
ShouldEqual
,
expectedUrl
)
So
(
redirectU
RL
.
Path
,
ShouldEqual
,
expectedURL
)
So
(
len
(
redirectU
rl
.
Query
()),
ShouldEqual
,
2
)
So
(
len
(
redirectU
RL
.
Query
()),
ShouldEqual
,
2
)
})
})
})
})
})
})
...
...
pkg/middleware/recovery_test.go
View file @
b818e9f6
...
@@ -14,10 +14,10 @@ import (
...
@@ -14,10 +14,10 @@ import (
func
TestRecoveryMiddleware
(
t
*
testing
.
T
)
{
func
TestRecoveryMiddleware
(
t
*
testing
.
T
)
{
Convey
(
"Given an api route that panics"
,
t
,
func
()
{
Convey
(
"Given an api route that panics"
,
t
,
func
()
{
apiU
rl
:=
"/api/whatever"
apiU
RL
:=
"/api/whatever"
recoveryScenario
(
"recovery middleware should return json"
,
apiU
rl
,
func
(
sc
*
scenarioContext
)
{
recoveryScenario
(
"recovery middleware should return json"
,
apiU
RL
,
func
(
sc
*
scenarioContext
)
{
sc
.
handlerFunc
=
PanicHandler
sc
.
handlerFunc
=
PanicHandler
sc
.
fakeReq
(
"GET"
,
apiU
rl
)
.
exec
()
sc
.
fakeReq
(
"GET"
,
apiU
RL
)
.
exec
()
sc
.
req
.
Header
.
Add
(
"content-type"
,
"application/json"
)
sc
.
req
.
Header
.
Add
(
"content-type"
,
"application/json"
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
500
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
500
)
...
@@ -27,10 +27,10 @@ func TestRecoveryMiddleware(t *testing.T) {
...
@@ -27,10 +27,10 @@ func TestRecoveryMiddleware(t *testing.T) {
})
})
Convey
(
"Given a non-api route that panics"
,
t
,
func
()
{
Convey
(
"Given a non-api route that panics"
,
t
,
func
()
{
apiU
rl
:=
"/whatever"
apiU
RL
:=
"/whatever"
recoveryScenario
(
"recovery middleware should return html"
,
apiU
rl
,
func
(
sc
*
scenarioContext
)
{
recoveryScenario
(
"recovery middleware should return html"
,
apiU
RL
,
func
(
sc
*
scenarioContext
)
{
sc
.
handlerFunc
=
PanicHandler
sc
.
handlerFunc
=
PanicHandler
sc
.
fakeReq
(
"GET"
,
apiU
rl
)
.
exec
()
sc
.
fakeReq
(
"GET"
,
apiU
RL
)
.
exec
()
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
500
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
500
)
So
(
sc
.
resp
.
Header
()
.
Get
(
"content-type"
),
ShouldEqual
,
"text/html; charset=UTF-8"
)
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