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
0e3f9150
Commit
0e3f9150
authored
Jan 05, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added validation to stop duplicate dashboards with same name from being saved
parent
4131b755
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
88 additions
and
5 deletions
+88
-5
grafana
+1
-1
pkg/api/dashboard.go
+4
-0
pkg/models/dashboards.go
+2
-3
pkg/stores/sqlstore/dashboards.go
+11
-1
pkg/stores/sqlstore/dashboards_test.go
+70
-0
pkg/stores/sqlstore/datasource.go
+0
-0
No files found.
grafana
@
34427f34
Subproject commit 344
812f1e0f0e804f9e9dd425168069d63c3fae3
Subproject commit 344
27f34e89fe3913523b5b236a149b88931b71d
pkg/api/dashboard.go
View file @
0e3f9150
...
@@ -69,6 +69,10 @@ func PostDashboard(c *middleware.Context) {
...
@@ -69,6 +69,10 @@ func PostDashboard(c *middleware.Context) {
err
:=
bus
.
Dispatch
(
&
cmd
)
err
:=
bus
.
Dispatch
(
&
cmd
)
if
err
!=
nil
{
if
err
!=
nil
{
if
err
==
m
.
ErrDashboardWithSameNameExists
{
c
.
JsonApiErr
(
400
,
"Dashboard with the same title already exists"
,
nil
)
return
}
c
.
JsonApiErr
(
500
,
"Failed to save dashboard"
,
err
)
c
.
JsonApiErr
(
500
,
"Failed to save dashboard"
,
err
)
return
return
}
}
...
...
pkg/models/dashboards.go
View file @
0e3f9150
...
@@ -9,7 +9,8 @@ import (
...
@@ -9,7 +9,8 @@ import (
// Typed errors
// Typed errors
var
(
var
(
ErrDashboardNotFound
=
errors
.
New
(
"Account not found"
)
ErrDashboardNotFound
=
errors
.
New
(
"Account not found"
)
ErrDashboardWithSameNameExists
=
errors
.
New
(
"A dashboard with the same name already exists"
)
)
)
type
Dashboard
struct
{
type
Dashboard
struct
{
...
@@ -39,8 +40,6 @@ type SearchDashboardsQuery struct {
...
@@ -39,8 +40,6 @@ type SearchDashboardsQuery struct {
}
}
type
SaveDashboardCommand
struct
{
type
SaveDashboardCommand
struct
{
Id
string
`json:"id"`
Title
string
`json:"title"`
Dashboard
map
[
string
]
interface
{}
`json:"dashboard"`
Dashboard
map
[
string
]
interface
{}
`json:"dashboard"`
AccountId
int64
`json:"-"`
AccountId
int64
`json:"-"`
...
...
pkg/stores/sqlstore/dashboards.go
View file @
0e3f9150
...
@@ -17,7 +17,17 @@ func SaveDashboard(cmd *m.SaveDashboardCommand) error {
...
@@ -17,7 +17,17 @@ func SaveDashboard(cmd *m.SaveDashboardCommand) error {
return
inTransaction
(
func
(
sess
*
xorm
.
Session
)
error
{
return
inTransaction
(
func
(
sess
*
xorm
.
Session
)
error
{
dash
:=
cmd
.
GetDashboardModel
()
dash
:=
cmd
.
GetDashboardModel
()
var
err
error
// try get existing dashboard
existing
:=
m
.
Dashboard
{
Slug
:
dash
.
Slug
,
AccountId
:
dash
.
AccountId
}
hasExisting
,
err
:=
sess
.
Get
(
&
existing
)
if
err
!=
nil
{
return
err
}
if
hasExisting
&&
dash
.
Id
!=
existing
.
Id
{
return
m
.
ErrDashboardWithSameNameExists
}
if
dash
.
Id
==
0
{
if
dash
.
Id
==
0
{
_
,
err
=
sess
.
Insert
(
dash
)
_
,
err
=
sess
.
Insert
(
dash
)
}
else
{
}
else
{
...
...
pkg/stores/sqlstore/dashboards_test.go
0 → 100644
View file @
0e3f9150
package
sqlstore
import
(
"testing"
.
"github.com/smartystreets/goconvey/convey"
m
"github.com/torkelo/grafana-pro/pkg/models"
)
func
TestDashboardDataAccess
(
t
*
testing
.
T
)
{
Convey
(
"Testing DB"
,
t
,
func
()
{
InitTestDB
(
t
)
Convey
(
"Given saved dashboard"
,
func
()
{
var
savedDash
*
m
.
Dashboard
cmd
:=
m
.
SaveDashboardCommand
{
AccountId
:
1
,
Dashboard
:
map
[
string
]
interface
{}{
"id"
:
nil
,
"title"
:
"test dash 23"
,
"tags"
:
make
([]
interface
{},
0
),
},
}
err
:=
SaveDashboard
(
&
cmd
)
So
(
err
,
ShouldBeNil
)
savedDash
=
cmd
.
Result
Convey
(
"Should return dashboard model"
,
func
()
{
So
(
savedDash
.
Title
,
ShouldEqual
,
"test dash 23"
)
So
(
savedDash
.
Slug
,
ShouldEqual
,
"test-dash-23"
)
So
(
savedDash
.
Id
,
ShouldNotEqual
,
0
)
})
Convey
(
"Should be able to get dashboard"
,
func
()
{
query
:=
m
.
GetDashboardQuery
{
Slug
:
"test-dash-23"
,
AccountId
:
1
,
}
err
:=
GetDashboard
(
&
query
)
So
(
err
,
ShouldBeNil
)
So
(
query
.
Result
.
Title
,
ShouldEqual
,
"test dash 23"
)
So
(
query
.
Result
.
Slug
,
ShouldEqual
,
"test-dash-23"
)
})
Convey
(
"Should not be able to save dashboard with same name"
,
func
()
{
cmd
:=
m
.
SaveDashboardCommand
{
AccountId
:
1
,
Dashboard
:
map
[
string
]
interface
{}{
"id"
:
nil
,
"title"
:
"test dash 23"
,
"tags"
:
make
([]
interface
{},
0
),
},
}
err
:=
SaveDashboard
(
&
cmd
)
So
(
err
,
ShouldNotBeNil
)
})
})
})
}
pkg/stores/sqlstore/
sqlstore_
datasource.go
→
pkg/stores/sqlstore/datasource.go
View file @
0e3f9150
File moved
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