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
38d851eb
Commit
38d851eb
authored
May 04, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Another HTTP API fix
parent
73ee8a59
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
13 deletions
+43
-13
pkg/services/sqlstore/dashboard.go
+25
-13
pkg/services/sqlstore/dashboard_test.go
+18
-0
No files found.
pkg/services/sqlstore/dashboard.go
View file @
38d851eb
...
...
@@ -23,21 +23,17 @@ func SaveDashboard(cmd *m.SaveDashboardCommand) error {
dash
:=
cmd
.
GetDashboardModel
()
// try get existing dashboard
existing
:=
m
.
Dashboard
{
Slug
:
dash
.
Slug
,
OrgId
:
dash
.
OrgId
}
hasExisting
,
err
:=
sess
.
Get
(
&
existing
)
if
err
!=
nil
{
return
err
}
var
existing
,
sameTitle
m
.
Dashboard
if
hasExisting
{
// another dashboard with same name
if
dash
.
Id
!=
existing
.
Id
{
if
cmd
.
Overwrite
{
dash
.
Id
=
existing
.
Id
}
else
{
return
m
.
ErrDashboardWithSameNameExists
}
if
dash
.
Id
>
0
{
dashWithIdExists
,
err
:=
sess
.
Where
(
"id=? AND org_id=?"
,
dash
.
Id
,
dash
.
OrgId
)
.
Get
(
&
existing
)
if
err
!=
nil
{
return
err
}
if
!
dashWithIdExists
{
return
m
.
ErrDashboardNotFound
}
// check for is someone else has written in between
if
dash
.
Version
!=
existing
.
Version
{
if
cmd
.
Overwrite
{
...
...
@@ -48,6 +44,22 @@ func SaveDashboard(cmd *m.SaveDashboardCommand) error {
}
}
sameTitleExists
,
err
:=
sess
.
Where
(
"org_id=? AND slug=?"
,
dash
.
OrgId
,
dash
.
Slug
)
.
Get
(
&
sameTitle
)
if
err
!=
nil
{
return
err
}
if
sameTitleExists
{
// another dashboard with same name
if
dash
.
Id
!=
sameTitle
.
Id
{
if
cmd
.
Overwrite
{
dash
.
Id
=
sameTitle
.
Id
}
else
{
return
m
.
ErrDashboardWithSameNameExists
}
}
}
affectedRows
:=
int64
(
0
)
if
dash
.
Id
==
0
{
...
...
pkg/services/sqlstore/dashboard_test.go
View file @
38d851eb
...
...
@@ -66,6 +66,24 @@ func TestDashboardDataAccess(t *testing.T) {
So
(
err
,
ShouldNotBeNil
)
})
Convey
(
"Should not be able to overwrite dashboard in another org"
,
func
()
{
query
:=
m
.
GetDashboardQuery
{
Slug
:
"test-dash-23"
,
OrgId
:
1
}
GetDashboard
(
&
query
)
cmd
:=
m
.
SaveDashboardCommand
{
OrgId
:
2
,
Overwrite
:
true
,
Dashboard
:
map
[
string
]
interface
{}{
"id"
:
float64
(
query
.
Result
.
Id
),
"title"
:
"Expect error"
,
"tags"
:
[]
interface
{}{},
},
}
err
:=
SaveDashboard
(
&
cmd
)
So
(
err
,
ShouldNotBeNil
)
})
Convey
(
"Should be able to search for dashboard"
,
func
()
{
query
:=
m
.
SearchDashboardsQuery
{
Title
:
"test"
,
...
...
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