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
bb3183f6
Commit
bb3183f6
authored
Jan 30, 2018
by
bergquist
Committed by
Leonard Gram
Jan 31, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removes uniqnes check on slug when saving dashboards
parent
6d2a5558
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
33 additions
and
14 deletions
+33
-14
pkg/api/dashboard.go
+1
-1
pkg/models/dashboards.go
+2
-1
pkg/services/sqlstore/dashboard.go
+10
-9
pkg/services/sqlstore/dashboard_test.go
+16
-0
pkg/services/sqlstore/dashboard_version_test.go
+2
-3
tests/test-app/dashboards/connections.json
+1
-0
tests/test-app/dashboards/connections_result.json
+1
-0
No files found.
pkg/api/dashboard.go
View file @
bb3183f6
...
...
@@ -214,7 +214,7 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
}
if
err
!=
nil
{
if
err
==
m
.
ErrDashboardWithSame
Name
Exists
{
if
err
==
m
.
ErrDashboardWithSame
UID
Exists
{
return
Json
(
412
,
util
.
DynMap
{
"status"
:
"name-exists"
,
"message"
:
err
.
Error
()})
}
if
err
==
m
.
ErrDashboardVersionMismatch
{
...
...
pkg/models/dashboards.go
View file @
bb3183f6
...
...
@@ -16,7 +16,7 @@ import (
var
(
ErrDashboardNotFound
=
errors
.
New
(
"Dashboard not found"
)
ErrDashboardSnapshotNotFound
=
errors
.
New
(
"Dashboard snapshot not found"
)
ErrDashboardWithSame
NameExists
=
errors
.
New
(
"A dashboard with the same name
already exists"
)
ErrDashboardWithSame
UIDExists
=
errors
.
New
(
"A dashboard with the same uid
already exists"
)
ErrDashboardVersionMismatch
=
errors
.
New
(
"The dashboard has been changed by someone else"
)
ErrDashboardTitleEmpty
=
errors
.
New
(
"Dashboard title cannot be empty"
)
ErrDashboardFolderCannotHaveParent
=
errors
.
New
(
"A Dashboard Folder cannot be added to another folder"
)
...
...
@@ -116,6 +116,7 @@ func NewDashboardFromJson(data *simplejson.Json) *Dashboard {
dash
.
Uid
=
uid
}
else
{
dash
.
Uid
=
util
.
GenerateShortUid
()
dash
.
Data
.
Set
(
"uid"
,
dash
.
Uid
)
}
return
dash
...
...
pkg/services/sqlstore/dashboard.go
View file @
bb3183f6
...
...
@@ -25,7 +25,7 @@ func SaveDashboard(cmd *m.SaveDashboardCommand) error {
dash
:=
cmd
.
GetDashboardModel
()
// try get existing dashboard
var
existing
,
sameTitle
m
.
Dashboard
var
existing
m
.
Dashboard
if
dash
.
Id
>
0
{
dashWithIdExists
,
err
:=
sess
.
Where
(
"id=? AND org_id=?"
,
dash
.
Id
,
dash
.
OrgId
)
.
Get
(
&
existing
)
...
...
@@ -51,19 +51,20 @@ func SaveDashboard(cmd *m.SaveDashboardCommand) error {
}
}
sameTitleExists
,
err
:=
sess
.
Where
(
"org_id=? AND slug=?"
,
dash
.
OrgId
,
dash
.
Slug
)
.
Get
(
&
sameTitle
)
var
sameUid
m
.
Dashboard
sameUidExists
,
err
:=
sess
.
Where
(
"org_id=? AND uid=?"
,
dash
.
OrgId
,
dash
.
Uid
)
.
Get
(
&
sameUid
)
if
err
!=
nil
{
return
err
}
if
same
Title
Exists
{
// another dashboard with same
name
if
dash
.
Id
!=
same
Title
.
Id
{
if
same
Uid
Exists
{
// another dashboard with same
uid
if
dash
.
Id
!=
same
Uid
.
Id
{
if
cmd
.
Overwrite
{
dash
.
Id
=
same
Title
.
Id
dash
.
Version
=
same
Title
.
Version
dash
.
Id
=
same
Uid
.
Id
dash
.
Version
=
same
Uid
.
Version
}
else
{
return
m
.
ErrDashboardWithSame
Name
Exists
return
m
.
ErrDashboardWithSame
UID
Exists
}
}
}
...
...
@@ -89,7 +90,7 @@ func SaveDashboard(cmd *m.SaveDashboardCommand) error {
dash
.
Updated
=
cmd
.
UpdatedAt
}
affectedRows
,
err
=
sess
.
MustCols
(
"folder_id"
,
"has_acl"
)
.
I
d
(
dash
.
Id
)
.
Update
(
dash
)
affectedRows
,
err
=
sess
.
MustCols
(
"folder_id"
,
"has_acl"
)
.
I
D
(
dash
.
Id
)
.
Update
(
dash
)
}
if
err
!=
nil
{
...
...
pkg/services/sqlstore/dashboard_test.go
View file @
bb3183f6
...
...
@@ -207,6 +207,22 @@ func TestDashboardDataAccess(t *testing.T) {
}
err
:=
SaveDashboard
(
&
cmd
)
So
(
err
,
ShouldBeNil
)
})
Convey
(
"Should not be able to save dashboard with same uid"
,
func
()
{
cmd
:=
m
.
SaveDashboardCommand
{
OrgId
:
1
,
Dashboard
:
simplejson
.
NewFromAny
(
map
[
string
]
interface
{}{
"id"
:
nil
,
"title"
:
"test dash 23"
,
"uid"
:
"dsfalkjngailuedt"
,
}),
}
err
:=
SaveDashboard
(
&
cmd
)
So
(
err
,
ShouldBeNil
)
err
=
SaveDashboard
(
&
cmd
)
So
(
err
,
ShouldNotBeNil
)
})
...
...
pkg/services/sqlstore/dashboard_version_test.go
View file @
bb3183f6
...
...
@@ -12,7 +12,7 @@ import (
)
func
updateTestDashboard
(
dashboard
*
m
.
Dashboard
,
data
map
[
string
]
interface
{})
{
data
[
"
title"
]
=
dashboard
.
Title
data
[
"
uid"
]
=
dashboard
.
Uid
saveCmd
:=
m
.
SaveDashboardCommand
{
OrgId
:
dashboard
.
OrgId
,
...
...
@@ -44,12 +44,11 @@ func TestGetDashboardVersion(t *testing.T) {
dashCmd
:=
m
.
GetDashboardQuery
{
OrgId
:
savedDash
.
OrgId
,
Slug
:
savedDash
.
Slug
,
Uid
:
savedDash
.
Uid
,
}
err
=
GetDashboard
(
&
dashCmd
)
So
(
err
,
ShouldBeNil
)
dashCmd
.
Result
.
Data
.
Del
(
"uid"
)
eq
:=
reflect
.
DeepEqual
(
dashCmd
.
Result
.
Data
,
query
.
Result
.
Data
)
So
(
eq
,
ShouldEqual
,
true
)
})
...
...
tests/test-app/dashboards/connections.json
View file @
bb3183f6
...
...
@@ -7,6 +7,7 @@
}
],
"uid"
:
"1MHHlVjzz"
,
"title"
:
"Nginx Connections"
,
"revision"
:
25
,
"schemaVersion"
:
11
,
...
...
tests/test-app/dashboards/connections_result.json
View file @
bb3183f6
...
...
@@ -16,5 +16,6 @@
],
"schemaVersion"
:
11
,
"title"
:
"Nginx Connections"
,
"uid"
:
"1MHHlVjzz"
,
"version"
:
0
}
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