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
52c154a2
Unverified
Commit
52c154a2
authored
Nov 17, 2020
by
Arve Knudsen
Committed by
GitHub
Nov 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backend: Rename variables for style conformance (#29097)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
parent
94840b3a
Hide whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
164 additions
and
163 deletions
+164
-163
pkg/api/dashboard_permission.go
+5
-5
pkg/api/dashboard_permission_test.go
+5
-5
pkg/api/dtos/acl.go
+2
-2
pkg/api/folder_permission.go
+5
-5
pkg/api/folder_permission_test.go
+5
-5
pkg/cmd/grafana-cli/commands/commandstest/fake_api_client.go
+4
-4
pkg/cmd/grafana-cli/commands/install_command.go
+3
-3
pkg/cmd/grafana-cli/commands/install_command_test.go
+4
-4
pkg/cmd/grafana-cli/commands/listremote_command.go
+1
-1
pkg/cmd/grafana-cli/commands/ls_command.go
+1
-1
pkg/cmd/grafana-cli/commands/upgrade_all_command.go
+4
-4
pkg/cmd/grafana-cli/models/model.go
+3
-3
pkg/cmd/grafana-cli/services/services.go
+1
-1
pkg/infra/log/file.go
+18
-18
pkg/infra/log/file_test.go
+2
-2
pkg/infra/metrics/settings.go
+0
-1
pkg/infra/serverlock/model.go
+2
-1
pkg/infra/serverlock/serverlock.go
+1
-1
pkg/infra/serverlock/serverlock_test.go
+1
-1
pkg/models/dashboard_acl.go
+8
-7
pkg/services/dashboards/acl_service.go
+9
-9
pkg/services/guardian/guardian.go
+2
-2
pkg/services/guardian/guardian_util_test.go
+14
-14
pkg/services/sqlstore/dashboard_acl.go
+6
-6
pkg/services/sqlstore/dashboard_acl_test.go
+32
-32
pkg/services/sqlstore/dashboard_folder_test.go
+12
-12
pkg/services/sqlstore/org_test.go
+5
-5
pkg/services/sqlstore/sqlbuilder_test.go
+5
-5
pkg/services/sqlstore/team_test.go
+2
-2
pkg/services/sqlstore/user_test.go
+2
-2
No files found.
pkg/api/dashboard_permission.go
View file @
52c154a2
...
...
@@ -56,14 +56,14 @@ func UpdateDashboardPermissions(c *models.ReqContext, apiCmd dtos.UpdateDashboar
}
cmd
:=
models
.
UpdateDashboardAclCommand
{}
cmd
.
DashboardI
d
=
dashID
cmd
.
DashboardI
D
=
dashID
for
_
,
item
:=
range
apiCmd
.
Items
{
cmd
.
Items
=
append
(
cmd
.
Items
,
&
models
.
DashboardAcl
{
OrgI
d
:
c
.
OrgId
,
DashboardI
d
:
dashID
,
UserI
d
:
item
.
UserId
,
TeamI
d
:
item
.
TeamId
,
OrgI
D
:
c
.
OrgId
,
DashboardI
D
:
dashID
,
UserI
D
:
item
.
UserID
,
TeamI
D
:
item
.
TeamID
,
Role
:
item
.
Role
,
Permission
:
item
.
Permission
,
Created
:
time
.
Now
(),
...
...
pkg/api/dashboard_permission_test.go
View file @
52c154a2
...
...
@@ -31,7 +31,7 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
cmd
:=
dtos
.
UpdateDashboardAclCommand
{
Items
:
[]
dtos
.
DashboardAclUpdateItem
{
{
UserI
d
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
{
UserI
D
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
},
}
...
...
@@ -69,7 +69,7 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
cmd
:=
dtos
.
UpdateDashboardAclCommand
{
Items
:
[]
dtos
.
DashboardAclUpdateItem
{
{
UserI
d
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
{
UserI
D
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
},
}
...
...
@@ -121,7 +121,7 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
cmd
:=
dtos
.
UpdateDashboardAclCommand
{
Items
:
[]
dtos
.
DashboardAclUpdateItem
{
{
UserI
d
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
{
UserI
D
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
},
}
...
...
@@ -154,7 +154,7 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
cmd
:=
dtos
.
UpdateDashboardAclCommand
{
Items
:
[]
dtos
.
DashboardAclUpdateItem
{
{
UserI
d
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
{
UserI
D
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
},
}
...
...
@@ -188,7 +188,7 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
cmd
:=
dtos
.
UpdateDashboardAclCommand
{
Items
:
[]
dtos
.
DashboardAclUpdateItem
{
{
UserI
d
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
{
UserI
D
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
},
}
...
...
pkg/api/dtos/acl.go
View file @
52c154a2
...
...
@@ -7,8 +7,8 @@ type UpdateDashboardAclCommand struct {
}
type
DashboardAclUpdateItem
struct
{
UserI
d
int64
`json:"userId"`
TeamI
d
int64
`json:"teamId"`
UserI
D
int64
`json:"userId"`
TeamI
D
int64
`json:"teamId"`
Role
*
models
.
RoleType
`json:"role,omitempty"`
Permission
models
.
PermissionType
`json:"permission"`
}
pkg/api/folder_permission.go
View file @
52c154a2
...
...
@@ -67,14 +67,14 @@ func UpdateFolderPermissions(c *models.ReqContext, apiCmd dtos.UpdateDashboardAc
}
cmd
:=
models
.
UpdateDashboardAclCommand
{}
cmd
.
DashboardI
d
=
folder
.
Id
cmd
.
DashboardI
D
=
folder
.
Id
for
_
,
item
:=
range
apiCmd
.
Items
{
cmd
.
Items
=
append
(
cmd
.
Items
,
&
models
.
DashboardAcl
{
OrgI
d
:
c
.
OrgId
,
DashboardI
d
:
folder
.
Id
,
UserI
d
:
item
.
UserId
,
TeamI
d
:
item
.
TeamId
,
OrgI
D
:
c
.
OrgId
,
DashboardI
D
:
folder
.
Id
,
UserI
D
:
item
.
UserID
,
TeamI
D
:
item
.
TeamID
,
Role
:
item
.
Role
,
Permission
:
item
.
Permission
,
Created
:
time
.
Now
(),
...
...
pkg/api/folder_permission_test.go
View file @
52c154a2
...
...
@@ -33,7 +33,7 @@ func TestFolderPermissionAPIEndpoint(t *testing.T) {
cmd
:=
dtos
.
UpdateDashboardAclCommand
{
Items
:
[]
dtos
.
DashboardAclUpdateItem
{
{
UserI
d
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
{
UserI
D
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
},
}
...
...
@@ -70,7 +70,7 @@ func TestFolderPermissionAPIEndpoint(t *testing.T) {
cmd
:=
dtos
.
UpdateDashboardAclCommand
{
Items
:
[]
dtos
.
DashboardAclUpdateItem
{
{
UserI
d
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
{
UserI
D
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
},
}
...
...
@@ -122,7 +122,7 @@ func TestFolderPermissionAPIEndpoint(t *testing.T) {
cmd
:=
dtos
.
UpdateDashboardAclCommand
{
Items
:
[]
dtos
.
DashboardAclUpdateItem
{
{
UserI
d
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
{
UserI
D
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
},
}
...
...
@@ -162,7 +162,7 @@ func TestFolderPermissionAPIEndpoint(t *testing.T) {
cmd
:=
dtos
.
UpdateDashboardAclCommand
{
Items
:
[]
dtos
.
DashboardAclUpdateItem
{
{
UserI
d
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
{
UserI
D
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
},
}
...
...
@@ -198,7 +198,7 @@ func TestFolderPermissionAPIEndpoint(t *testing.T) {
cmd
:=
dtos
.
UpdateDashboardAclCommand
{
Items
:
[]
dtos
.
DashboardAclUpdateItem
{
{
UserI
d
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
{
UserI
D
:
1000
,
Permission
:
models
.
PERMISSION_ADMIN
},
},
}
...
...
pkg/cmd/grafana-cli/commands/commandstest/fake_api_client.go
View file @
52c154a2
...
...
@@ -12,9 +12,9 @@ type FakeGrafanaComClient struct {
ListAllPluginsFunc
func
(
repoUrl
string
)
(
models
.
PluginRepo
,
error
)
}
func
(
client
*
FakeGrafanaComClient
)
GetPlugin
(
pluginI
d
,
repoUrl
string
)
(
models
.
Plugin
,
error
)
{
func
(
client
*
FakeGrafanaComClient
)
GetPlugin
(
pluginI
D
,
repoUrl
string
)
(
models
.
Plugin
,
error
)
{
if
client
.
GetPluginFunc
!=
nil
{
return
client
.
GetPluginFunc
(
pluginI
d
,
repoUrl
)
return
client
.
GetPluginFunc
(
pluginI
D
,
repoUrl
)
}
return
models
.
Plugin
{},
nil
...
...
@@ -28,9 +28,9 @@ func (client *FakeGrafanaComClient) DownloadFile(pluginName string, tmpFile *os.
return
nil
}
func
(
client
*
FakeGrafanaComClient
)
ListAllPlugins
(
repoU
rl
string
)
(
models
.
PluginRepo
,
error
)
{
func
(
client
*
FakeGrafanaComClient
)
ListAllPlugins
(
repoU
RL
string
)
(
models
.
PluginRepo
,
error
)
{
if
client
.
ListAllPluginsFunc
!=
nil
{
return
client
.
ListAllPluginsFunc
(
repoU
rl
)
return
client
.
ListAllPluginsFunc
(
repoU
RL
)
}
return
models
.
PluginRepo
{},
nil
}
pkg/cmd/grafana-cli/commands/install_command.go
View file @
52c154a2
...
...
@@ -132,11 +132,11 @@ func InstallPlugin(pluginName, version string, c utils.CommandLine, client utils
res
,
_
:=
services
.
ReadPlugin
(
pluginFolder
,
pluginName
)
for
_
,
v
:=
range
res
.
Dependencies
.
Plugins
{
if
err
:=
InstallPlugin
(
v
.
I
d
,
""
,
c
,
client
);
err
!=
nil
{
return
errutil
.
Wrapf
(
err
,
"failed to install plugin '%s'"
,
v
.
I
d
)
if
err
:=
InstallPlugin
(
v
.
I
D
,
""
,
c
,
client
);
err
!=
nil
{
return
errutil
.
Wrapf
(
err
,
"failed to install plugin '%s'"
,
v
.
I
D
)
}
logger
.
Infof
(
"Installed dependency: %v ✔
\n
"
,
v
.
I
d
)
logger
.
Infof
(
"Installed dependency: %v ✔
\n
"
,
v
.
I
D
)
}
return
err
...
...
pkg/cmd/grafana-cli/commands/install_command_test.go
View file @
52c154a2
...
...
@@ -99,12 +99,12 @@ func TestInstallPluginCommand(t *testing.T) {
GetPluginFunc
:
func
(
pluginId
,
repoUrl
string
)
(
models
.
Plugin
,
error
)
{
require
.
Equal
(
t
,
"test-plugin-panel"
,
pluginId
)
plugin
:=
models
.
Plugin
{
I
d
:
"test-plugin-panel"
,
I
D
:
"test-plugin-panel"
,
Category
:
""
,
Versions
:
[]
models
.
Version
{
{
Commit
:
"commit"
,
U
rl
:
"url"
,
U
RL
:
"url"
,
Version
:
"1.0.0"
,
Arch
:
map
[
string
]
models
.
ArchMeta
{
fmt
.
Sprintf
(
"%s-%s"
,
runtime
.
GOOS
,
runtime
.
GOARCH
)
:
{
...
...
@@ -237,7 +237,7 @@ type versionArg struct {
func
makePluginWithVersions
(
versions
...
versionArg
)
*
models
.
Plugin
{
plugin
:=
&
models
.
Plugin
{
I
d
:
""
,
I
D
:
""
,
Category
:
""
,
Versions
:
[]
models
.
Version
{},
}
...
...
@@ -246,7 +246,7 @@ func makePluginWithVersions(versions ...versionArg) *models.Plugin {
ver
:=
models
.
Version
{
Version
:
version
.
Version
,
Commit
:
fmt
.
Sprintf
(
"commit_%s"
,
version
.
Version
),
U
rl
:
fmt
.
Sprintf
(
"url_%s"
,
version
.
Version
),
U
RL
:
fmt
.
Sprintf
(
"url_%s"
,
version
.
Version
),
}
if
version
.
Arch
!=
nil
{
ver
.
Arch
=
map
[
string
]
models
.
ArchMeta
{}
...
...
pkg/cmd/grafana-cli/commands/listremote_command.go
View file @
52c154a2
...
...
@@ -18,7 +18,7 @@ func (cmd Command) listRemoteCommand(c utils.CommandLine) error {
if
len
(
plugin
.
Versions
)
>
0
{
ver
:=
latestSupportedVersion
(
&
plugin
)
if
ver
!=
nil
{
logger
.
Infof
(
"id: %v version: %s
\n
"
,
plugin
.
I
d
,
ver
.
Version
)
logger
.
Infof
(
"id: %v version: %s
\n
"
,
plugin
.
I
D
,
ver
.
Version
)
}
}
}
...
...
pkg/cmd/grafana-cli/commands/ls_command.go
View file @
52c154a2
...
...
@@ -47,7 +47,7 @@ func (cmd Command) lsCommand(c utils.CommandLine) error {
}
for
_
,
plugin
:=
range
plugins
{
logger
.
Infof
(
"%s %s %s
\n
"
,
plugin
.
I
d
,
color
.
YellowString
(
"@"
),
plugin
.
Info
.
Version
)
logger
.
Infof
(
"%s %s %s
\n
"
,
plugin
.
I
D
,
color
.
YellowString
(
"@"
),
plugin
.
Info
.
Version
)
}
return
nil
...
...
pkg/cmd/grafana-cli/commands/upgrade_all_command.go
View file @
52c154a2
...
...
@@ -37,7 +37,7 @@ func (cmd Command) upgradeAllCommand(c utils.CommandLine) error {
for
_
,
localPlugin
:=
range
localPlugins
{
for
_
,
p
:=
range
remotePlugins
.
Plugins
{
remotePlugin
:=
p
if
localPlugin
.
I
d
!=
remotePlugin
.
Id
{
if
localPlugin
.
I
D
!=
remotePlugin
.
ID
{
continue
}
if
shouldUpgrade
(
localPlugin
.
Info
.
Version
,
&
remotePlugin
)
{
...
...
@@ -47,14 +47,14 @@ func (cmd Command) upgradeAllCommand(c utils.CommandLine) error {
}
for
_
,
p
:=
range
pluginsToUpgrade
{
logger
.
Infof
(
"Updating %v
\n
"
,
p
.
I
d
)
logger
.
Infof
(
"Updating %v
\n
"
,
p
.
I
D
)
err
:=
services
.
RemoveInstalledPlugin
(
pluginsDir
,
p
.
I
d
)
err
:=
services
.
RemoveInstalledPlugin
(
pluginsDir
,
p
.
I
D
)
if
err
!=
nil
{
return
err
}
err
=
InstallPlugin
(
p
.
I
d
,
""
,
c
,
cmd
.
Client
)
err
=
InstallPlugin
(
p
.
I
D
,
""
,
c
,
cmd
.
Client
)
if
err
!=
nil
{
return
err
}
...
...
pkg/cmd/grafana-cli/models/model.go
View file @
52c154a2
...
...
@@ -5,7 +5,7 @@ import (
)
type
InstalledPlugin
struct
{
I
d
string
`json:"id"`
I
D
string
`json:"id"`
Name
string
`json:"name"`
Type
string
`json:"type"`
...
...
@@ -24,14 +24,14 @@ type PluginInfo struct {
}
type
Plugin
struct
{
I
d
string
`json:"id"`
I
D
string
`json:"id"`
Category
string
`json:"category"`
Versions
[]
Version
`json:"versions"`
}
type
Version
struct
{
Commit
string
`json:"commit"`
U
rl
string
`json:"url"`
U
RL
string
`json:"url"`
Version
string
`json:"version"`
// os-arch to md5 checksum to check when downloading the file
Arch
map
[
string
]
ArchMeta
`json:"arch"`
...
...
pkg/cmd/grafana-cli/services/services.go
View file @
52c154a2
...
...
@@ -84,7 +84,7 @@ func ReadPlugin(pluginDir, pluginName string) (models.InstalledPlugin, error) {
res
.
Info
.
Version
=
"0.0.0"
}
if
res
.
I
d
==
""
{
if
res
.
I
D
==
""
{
return
models
.
InstalledPlugin
{},
errors
.
New
(
"could not find plugin "
+
pluginName
+
" in "
+
pluginDir
)
}
...
...
pkg/infra/log/file.go
View file @
52c154a2
...
...
@@ -23,19 +23,19 @@ import (
type
FileLogWriter
struct
{
mw
*
MuxWriter
Format
log15
.
Format
Filename
string
Maxlines
int
maxlines
_c
urlines
int
Format
log15
.
Format
Filename
string
Maxlines
int
maxlines
C
urlines
int
// Rotate at size
Maxsize
int
maxsize
_c
ursize
int
Maxsize
int
maxsize
C
ursize
int
// Rotate daily
Daily
bool
Maxdays
int64
daily
_o
pendate
int
Daily
bool
Maxdays
int64
daily
O
pendate
int
Rotate
bool
startLock
sync
.
Mutex
...
...
@@ -105,16 +105,16 @@ func (w *FileLogWriter) StartLogger() error {
func
(
w
*
FileLogWriter
)
docheck
(
size
int
)
{
w
.
startLock
.
Lock
()
defer
w
.
startLock
.
Unlock
()
if
w
.
Rotate
&&
((
w
.
Maxlines
>
0
&&
w
.
maxlines
_c
urlines
>=
w
.
Maxlines
)
||
(
w
.
Maxsize
>
0
&&
w
.
maxsize
_c
ursize
>=
w
.
Maxsize
)
||
(
w
.
Daily
&&
time
.
Now
()
.
Day
()
!=
w
.
daily
_o
pendate
))
{
if
w
.
Rotate
&&
((
w
.
Maxlines
>
0
&&
w
.
maxlines
C
urlines
>=
w
.
Maxlines
)
||
(
w
.
Maxsize
>
0
&&
w
.
maxsize
C
ursize
>=
w
.
Maxsize
)
||
(
w
.
Daily
&&
time
.
Now
()
.
Day
()
!=
w
.
daily
O
pendate
))
{
if
err
:=
w
.
DoRotate
();
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"FileLogWriter(%q): %s
\n
"
,
w
.
Filename
,
err
)
return
}
}
w
.
maxlines
_c
urlines
++
w
.
maxsize
_c
ursize
+=
size
w
.
maxlines
C
urlines
++
w
.
maxsize
C
ursize
+=
size
}
func
(
w
*
FileLogWriter
)
createLogFile
()
(
*
os
.
File
,
error
)
{
...
...
@@ -152,16 +152,16 @@ func (w *FileLogWriter) initFd() error {
if
err
!=
nil
{
return
fmt
.
Errorf
(
"get stat: %s"
,
err
)
}
w
.
maxsize
_c
ursize
=
int
(
finfo
.
Size
())
w
.
daily
_o
pendate
=
time
.
Now
()
.
Day
()
w
.
maxsize
C
ursize
=
int
(
finfo
.
Size
())
w
.
daily
O
pendate
=
time
.
Now
()
.
Day
()
if
finfo
.
Size
()
>
0
{
count
,
err
:=
w
.
lineCounter
()
if
err
!=
nil
{
return
err
}
w
.
maxlines
_c
urlines
=
count
w
.
maxlines
C
urlines
=
count
}
else
{
w
.
maxlines
_c
urlines
=
0
w
.
maxlines
C
urlines
=
0
}
return
nil
}
...
...
pkg/infra/log/file_test.go
View file @
52c154a2
...
...
@@ -32,7 +32,7 @@ func TestLogFile(t *testing.T) {
err
:=
fileLogWrite
.
Init
()
require
.
NoError
(
t
,
err
)
assert
.
Zero
(
t
,
fileLogWrite
.
maxlines
_c
urlines
)
assert
.
Zero
(
t
,
fileLogWrite
.
maxlines
C
urlines
)
t
.
Run
(
"adding lines"
,
func
(
t
*
testing
.
T
)
{
err
:=
fileLogWrite
.
WriteLine
(
"test1
\n
"
)
...
...
@@ -42,6 +42,6 @@ func TestLogFile(t *testing.T) {
err
=
fileLogWrite
.
WriteLine
(
"test3
\n
"
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
3
,
fileLogWrite
.
maxlines
_c
urlines
)
assert
.
Equal
(
t
,
3
,
fileLogWrite
.
maxlines
C
urlines
)
})
}
pkg/infra/metrics/settings.go
View file @
52c154a2
...
...
@@ -27,7 +27,6 @@ func (im *InternalMetricsService) readSettings() error {
func
(
im
*
InternalMetricsService
)
parseGraphiteSettings
()
error
{
graphiteSection
,
err
:=
im
.
Cfg
.
Raw
.
GetSection
(
"metrics.graphite"
)
if
err
!=
nil
{
return
nil
}
...
...
pkg/infra/serverlock/model.go
View file @
52c154a2
package
serverlock
type
serverLock
struct
{
// nolint:stylecheck
Id
int64
OperationU
id
string
OperationU
ID
string
`xorm:"operation_uid"`
LastExecution
int64
Version
int64
}
pkg/infra/serverlock/serverlock.go
View file @
52c154a2
...
...
@@ -98,7 +98,7 @@ func (sl *ServerLockService) getOrCreate(ctx context.Context, actionName string)
}
lockRow
:=
&
serverLock
{
OperationU
id
:
actionName
,
OperationU
ID
:
actionName
,
LastExecution
:
0
,
}
...
...
pkg/infra/serverlock/serverlock_test.go
View file @
52c154a2
...
...
@@ -36,7 +36,7 @@ func TestServerLock(t *testing.T) {
for
i
:=
0
;
i
<
3
;
i
++
{
latest
,
err
=
sl
.
getOrCreate
(
context
.
Background
(),
operationUID
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
operationUID
,
first
.
OperationU
id
)
assert
.
Equal
(
t
,
operationUID
,
first
.
OperationU
ID
)
assert
.
Equal
(
t
,
int64
(
1
),
first
.
Id
)
}
...
...
pkg/models/dashboard_acl.go
View file @
52c154a2
...
...
@@ -32,12 +32,13 @@ var (
// Dashboard ACL model
type
DashboardAcl
struct
{
// nolint:stylecheck
Id
int64
OrgI
d
int64
DashboardI
d
int64
OrgI
D
int64
`xorm:"org_id"`
DashboardI
D
int64
`xorm:"dashboard_id"`
UserI
d
int64
TeamI
d
int64
UserI
D
int64
`xorm:"user_id"`
TeamI
D
int64
`xorm:"team_id"`
Role
*
RoleType
// pointer to be nullable
Permission
PermissionType
...
...
@@ -98,7 +99,7 @@ func (dto *DashboardAclInfoDTO) IsDuplicateOf(other *DashboardAclInfoDTO) bool {
//
type
UpdateDashboardAclCommand
struct
{
DashboardI
d
int64
DashboardI
D
int64
Items
[]
*
DashboardAcl
}
...
...
@@ -106,7 +107,7 @@ type UpdateDashboardAclCommand struct {
// QUERIES
//
type
GetDashboardAclInfoListQuery
struct
{
DashboardI
d
int64
OrgI
d
int64
DashboardI
D
int64
OrgI
D
int64
Result
[]
*
DashboardAclInfoDTO
}
pkg/services/dashboards/acl_service.go
View file @
52c154a2
...
...
@@ -7,15 +7,15 @@ import (
"github.com/grafana/grafana/pkg/models"
)
func
MakeUserAdmin
(
bus
bus
.
Bus
,
orgI
d
int64
,
userId
int64
,
dashboardId
int64
,
setViewAndEditPermissions
bool
)
error
{
func
MakeUserAdmin
(
bus
bus
.
Bus
,
orgI
D
int64
,
userID
int64
,
dashboardID
int64
,
setViewAndEditPermissions
bool
)
error
{
rtEditor
:=
models
.
ROLE_EDITOR
rtViewer
:=
models
.
ROLE_VIEWER
items
:=
[]
*
models
.
DashboardAcl
{
{
OrgI
d
:
orgId
,
DashboardI
d
:
dashboardId
,
UserI
d
:
userId
,
OrgI
D
:
orgID
,
DashboardI
D
:
dashboardID
,
UserI
D
:
userID
,
Permission
:
models
.
PERMISSION_ADMIN
,
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
...
...
@@ -25,16 +25,16 @@ func MakeUserAdmin(bus bus.Bus, orgId int64, userId int64, dashboardId int64, se
if
setViewAndEditPermissions
{
items
=
append
(
items
,
&
models
.
DashboardAcl
{
OrgI
d
:
orgId
,
DashboardI
d
:
dashboardId
,
OrgI
D
:
orgID
,
DashboardI
D
:
dashboardID
,
Role
:
&
rtEditor
,
Permission
:
models
.
PERMISSION_EDIT
,
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
},
&
models
.
DashboardAcl
{
OrgI
d
:
orgId
,
DashboardI
d
:
dashboardId
,
OrgI
D
:
orgID
,
DashboardI
D
:
dashboardID
,
Role
:
&
rtViewer
,
Permission
:
models
.
PERMISSION_VIEW
,
Created
:
time
.
Now
(),
...
...
@@ -44,7 +44,7 @@ func MakeUserAdmin(bus bus.Bus, orgId int64, userId int64, dashboardId int64, se
}
aclCmd
:=
&
models
.
UpdateDashboardAclCommand
{
DashboardI
d
:
dashboardId
,
DashboardI
D
:
dashboardID
,
Items
:
items
,
}
...
...
pkg/services/guardian/guardian.go
View file @
52c154a2
...
...
@@ -147,7 +147,7 @@ func (g *dashboardGuardianImpl) CheckPermissionBeforeUpdate(permission models.Pe
// validate that duplicate permissions don't exists
for
_
,
p
:=
range
updatePermissions
{
aclItem
:=
&
models
.
DashboardAclInfoDTO
{
DashboardId
:
p
.
DashboardI
d
,
UserId
:
p
.
UserId
,
TeamId
:
p
.
TeamId
,
Role
:
p
.
Role
,
Permission
:
p
.
Permission
}
aclItem
:=
&
models
.
DashboardAclInfoDTO
{
DashboardId
:
p
.
DashboardI
D
,
UserId
:
p
.
UserID
,
TeamId
:
p
.
TeamID
,
Role
:
p
.
Role
,
Permission
:
p
.
Permission
}
if
aclItem
.
IsDuplicateOf
(
everyoneWithAdminRole
)
{
return
false
,
ErrGuardianPermissionExists
}
...
...
@@ -192,7 +192,7 @@ func (g *dashboardGuardianImpl) GetAcl() ([]*models.DashboardAclInfoDTO, error)
return
g
.
acl
,
nil
}
query
:=
models
.
GetDashboardAclInfoListQuery
{
DashboardI
d
:
g
.
dashId
,
OrgId
:
g
.
orgId
}
query
:=
models
.
GetDashboardAclInfoListQuery
{
DashboardI
D
:
g
.
dashId
,
OrgID
:
g
.
orgId
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
nil
,
err
}
...
...
pkg/services/guardian/guardian_util_test.go
View file @
52c154a2
...
...
@@ -73,11 +73,11 @@ func permissionScenario(desc string, dashboardID int64, sc *scenarioContext, per
bus
.
ClearBusHandlers
()
bus
.
AddHandler
(
"test"
,
func
(
query
*
models
.
GetDashboardAclInfoListQuery
)
error
{
if
query
.
OrgI
d
!=
sc
.
givenUser
.
OrgId
{
sc
.
reportFailure
(
"Invalid organization id for GetDashboardAclInfoListQuery"
,
sc
.
givenUser
.
OrgId
,
query
.
OrgI
d
)
if
query
.
OrgI
D
!=
sc
.
givenUser
.
OrgId
{
sc
.
reportFailure
(
"Invalid organization id for GetDashboardAclInfoListQuery"
,
sc
.
givenUser
.
OrgId
,
query
.
OrgI
D
)
}
if
query
.
DashboardI
d
!=
sc
.
givenDashboardID
{
sc
.
reportFailure
(
"Invalid dashboard id for GetDashboardAclInfoListQuery"
,
sc
.
givenDashboardID
,
query
.
DashboardI
d
)
if
query
.
DashboardI
D
!=
sc
.
givenDashboardID
{
sc
.
reportFailure
(
"Invalid dashboard id for GetDashboardAclInfoListQuery"
,
sc
.
givenDashboardID
,
query
.
DashboardI
D
)
}
query
.
Result
=
permissions
...
...
@@ -230,14 +230,14 @@ func (sc *scenarioContext) reportFailure(desc string, expected interface{}, actu
if
p
.
Role
!=
nil
{
r
=
string
(
*
p
.
Role
)
}
buf
.
WriteString
(
fmt
.
Sprintf
(
"
\n
Update permission (%d): dashboardId=%d, userId=%d, teamId=%d, role=%v, permission=%s"
,
i
,
p
.
DashboardI
d
,
p
.
UserId
,
p
.
TeamId
,
r
,
p
.
Permission
.
String
()))
buf
.
WriteString
(
fmt
.
Sprintf
(
"
\n
Update permission (%d): dashboardId=%d, userId=%d, teamId=%d, role=%v, permission=%s"
,
i
,
p
.
DashboardI
D
,
p
.
UserID
,
p
.
TeamID
,
r
,
p
.
Permission
.
String
()))
}
sc
.
t
.
Fatalf
(
buf
.
String
())
}
func
newCustomUserPermission
(
dashboardID
int64
,
userID
int64
,
permission
models
.
PermissionType
)
*
models
.
DashboardAcl
{
return
&
models
.
DashboardAcl
{
OrgI
d
:
orgID
,
DashboardId
:
dashboardID
,
UserId
:
userID
,
Permission
:
permission
}
return
&
models
.
DashboardAcl
{
OrgI
D
:
orgID
,
DashboardID
:
dashboardID
,
UserID
:
userID
,
Permission
:
permission
}
}
func
newDefaultUserPermission
(
dashboardID
int64
,
permission
models
.
PermissionType
)
*
models
.
DashboardAcl
{
...
...
@@ -245,7 +245,7 @@ func newDefaultUserPermission(dashboardID int64, permission models.PermissionTyp
}
func
newCustomTeamPermission
(
dashboardID
int64
,
teamID
int64
,
permission
models
.
PermissionType
)
*
models
.
DashboardAcl
{
return
&
models
.
DashboardAcl
{
OrgI
d
:
orgID
,
DashboardId
:
dashboardID
,
TeamId
:
teamID
,
Permission
:
permission
}
return
&
models
.
DashboardAcl
{
OrgI
D
:
orgID
,
DashboardID
:
dashboardID
,
TeamID
:
teamID
,
Permission
:
permission
}
}
func
newDefaultTeamPermission
(
dashboardID
int64
,
permission
models
.
PermissionType
)
*
models
.
DashboardAcl
{
...
...
@@ -253,23 +253,23 @@ func newDefaultTeamPermission(dashboardID int64, permission models.PermissionTyp
}
func
newAdminRolePermission
(
dashboardID
int64
,
permission
models
.
PermissionType
)
*
models
.
DashboardAcl
{
return
&
models
.
DashboardAcl
{
OrgI
d
:
orgID
,
DashboardId
:
dashboardID
,
Role
:
&
adminRole
,
Permission
:
permission
}
return
&
models
.
DashboardAcl
{
OrgI
D
:
orgID
,
DashboardID
:
dashboardID
,
Role
:
&
adminRole
,
Permission
:
permission
}
}
func
newEditorRolePermission
(
dashboardID
int64
,
permission
models
.
PermissionType
)
*
models
.
DashboardAcl
{
return
&
models
.
DashboardAcl
{
OrgI
d
:
orgID
,
DashboardId
:
dashboardID
,
Role
:
&
editorRole
,
Permission
:
permission
}
return
&
models
.
DashboardAcl
{
OrgI
D
:
orgID
,
DashboardID
:
dashboardID
,
Role
:
&
editorRole
,
Permission
:
permission
}
}
func
newViewerRolePermission
(
dashboardID
int64
,
permission
models
.
PermissionType
)
*
models
.
DashboardAcl
{
return
&
models
.
DashboardAcl
{
OrgI
d
:
orgID
,
DashboardId
:
dashboardID
,
Role
:
&
viewerRole
,
Permission
:
permission
}
return
&
models
.
DashboardAcl
{
OrgI
D
:
orgID
,
DashboardID
:
dashboardID
,
Role
:
&
viewerRole
,
Permission
:
permission
}
}
func
toDto
(
acl
*
models
.
DashboardAcl
)
*
models
.
DashboardAclInfoDTO
{
return
&
models
.
DashboardAclInfoDTO
{
OrgId
:
acl
.
OrgI
d
,
DashboardId
:
acl
.
DashboardI
d
,
UserId
:
acl
.
UserI
d
,
TeamId
:
acl
.
TeamI
d
,
OrgId
:
acl
.
OrgI
D
,
DashboardId
:
acl
.
DashboardI
D
,
UserId
:
acl
.
UserI
D
,
TeamId
:
acl
.
TeamI
D
,
Role
:
acl
.
Role
,
Permission
:
acl
.
Permission
,
PermissionName
:
acl
.
Permission
.
String
(),
...
...
pkg/services/sqlstore/dashboard_acl.go
View file @
52c154a2
...
...
@@ -13,17 +13,17 @@ func init() {
func
UpdateDashboardAcl
(
cmd
*
models
.
UpdateDashboardAclCommand
)
error
{
return
inTransaction
(
func
(
sess
*
DBSession
)
error
{
// delete existing items
_
,
err
:=
sess
.
Exec
(
"DELETE FROM dashboard_acl WHERE dashboard_id=?"
,
cmd
.
DashboardI
d
)
_
,
err
:=
sess
.
Exec
(
"DELETE FROM dashboard_acl WHERE dashboard_id=?"
,
cmd
.
DashboardI
D
)
if
err
!=
nil
{
return
err
}
for
_
,
item
:=
range
cmd
.
Items
{
if
item
.
UserI
d
==
0
&&
item
.
TeamId
==
0
&&
(
item
.
Role
==
nil
||
!
item
.
Role
.
IsValid
())
{
if
item
.
UserI
D
==
0
&&
item
.
TeamID
==
0
&&
(
item
.
Role
==
nil
||
!
item
.
Role
.
IsValid
())
{
return
models
.
ErrDashboardAclInfoMissing
}
if
item
.
DashboardI
d
==
0
{
if
item
.
DashboardI
D
==
0
{
return
models
.
ErrDashboardPermissionDashboardEmpty
}
...
...
@@ -35,7 +35,7 @@ func UpdateDashboardAcl(cmd *models.UpdateDashboardAclCommand) error {
// Update dashboard HasAcl flag
dashboard
:=
models
.
Dashboard
{
HasAcl
:
true
}
_
,
err
=
sess
.
Cols
(
"has_acl"
)
.
Where
(
"id=?"
,
cmd
.
DashboardI
d
)
.
Update
(
&
dashboard
)
_
,
err
=
sess
.
Cols
(
"has_acl"
)
.
Where
(
"id=?"
,
cmd
.
DashboardI
D
)
.
Update
(
&
dashboard
)
return
err
})
}
...
...
@@ -50,7 +50,7 @@ func GetDashboardAclInfoList(query *models.GetDashboardAclInfoListQuery) error {
falseStr
:=
dialect
.
BooleanStr
(
false
)
if
query
.
DashboardI
d
==
0
{
if
query
.
DashboardI
D
==
0
{
sql
:=
`SELECT
da.id,
da.org_id,
...
...
@@ -114,7 +114,7 @@ func GetDashboardAclInfoList(query *models.GetDashboardAclInfoListQuery) error {
`
query
.
Result
=
make
([]
*
models
.
DashboardAclInfoDTO
,
0
)
err
=
x
.
SQL
(
rawSQL
,
query
.
OrgI
d
,
query
.
DashboardId
)
.
Find
(
&
query
.
Result
)
err
=
x
.
SQL
(
rawSQL
,
query
.
OrgI
D
,
query
.
DashboardID
)
.
Find
(
&
query
.
Result
)
}
for
_
,
p
:=
range
query
.
Result
{
...
...
pkg/services/sqlstore/dashboard_acl_test.go
View file @
52c154a2
...
...
@@ -19,8 +19,8 @@ func TestDashboardAclDataAccess(t *testing.T) {
Convey
(
"When adding dashboard permission with userId and teamId set to 0"
,
func
()
{
err
:=
testHelperUpdateDashboardAcl
(
savedFolder
.
Id
,
models
.
DashboardAcl
{
OrgI
d
:
1
,
DashboardI
d
:
savedFolder
.
Id
,
OrgI
D
:
1
,
DashboardI
D
:
savedFolder
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
,
})
So
(
err
,
ShouldEqual
,
models
.
ErrDashboardAclInfoMissing
)
...
...
@@ -28,7 +28,7 @@ func TestDashboardAclDataAccess(t *testing.T) {
Convey
(
"Given dashboard folder with default permissions"
,
func
()
{
Convey
(
"When reading folder acl should include default acl"
,
func
()
{
query
:=
models
.
GetDashboardAclInfoListQuery
{
DashboardI
d
:
savedFolder
.
Id
,
OrgId
:
1
}
query
:=
models
.
GetDashboardAclInfoListQuery
{
DashboardI
D
:
savedFolder
.
Id
,
OrgID
:
1
}
err
:=
GetDashboardAclInfoList
(
&
query
)
So
(
err
,
ShouldBeNil
)
...
...
@@ -44,7 +44,7 @@ func TestDashboardAclDataAccess(t *testing.T) {
})
Convey
(
"When reading dashboard acl should include acl for parent folder"
,
func
()
{
query
:=
models
.
GetDashboardAclInfoListQuery
{
DashboardI
d
:
childDash
.
Id
,
OrgId
:
1
}
query
:=
models
.
GetDashboardAclInfoListQuery
{
DashboardI
D
:
childDash
.
Id
,
OrgID
:
1
}
err
:=
GetDashboardAclInfoList
(
&
query
)
So
(
err
,
ShouldBeNil
)
...
...
@@ -62,13 +62,13 @@ func TestDashboardAclDataAccess(t *testing.T) {
Convey
(
"Given dashboard folder with removed default permissions"
,
func
()
{
err
:=
UpdateDashboardAcl
(
&
models
.
UpdateDashboardAclCommand
{
DashboardI
d
:
savedFolder
.
Id
,
DashboardI
D
:
savedFolder
.
Id
,
Items
:
[]
*
models
.
DashboardAcl
{},
})
So
(
err
,
ShouldBeNil
)
Convey
(
"When reading dashboard acl should return no acl items"
,
func
()
{
query
:=
models
.
GetDashboardAclInfoListQuery
{
DashboardI
d
:
childDash
.
Id
,
OrgId
:
1
}
query
:=
models
.
GetDashboardAclInfoListQuery
{
DashboardI
D
:
childDash
.
Id
,
OrgID
:
1
}
err
:=
GetDashboardAclInfoList
(
&
query
)
So
(
err
,
ShouldBeNil
)
...
...
@@ -79,15 +79,15 @@ func TestDashboardAclDataAccess(t *testing.T) {
Convey
(
"Given dashboard folder permission"
,
func
()
{
err
:=
testHelperUpdateDashboardAcl
(
savedFolder
.
Id
,
models
.
DashboardAcl
{
OrgI
d
:
1
,
UserI
d
:
currentUser
.
Id
,
DashboardI
d
:
savedFolder
.
Id
,
OrgI
D
:
1
,
UserI
D
:
currentUser
.
Id
,
DashboardI
D
:
savedFolder
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
,
})
So
(
err
,
ShouldBeNil
)
Convey
(
"When reading dashboard acl should include acl for parent folder"
,
func
()
{
query
:=
models
.
GetDashboardAclInfoListQuery
{
DashboardI
d
:
childDash
.
Id
,
OrgId
:
1
}
query
:=
models
.
GetDashboardAclInfoListQuery
{
DashboardI
D
:
childDash
.
Id
,
OrgID
:
1
}
err
:=
GetDashboardAclInfoList
(
&
query
)
So
(
err
,
ShouldBeNil
)
...
...
@@ -98,15 +98,15 @@ func TestDashboardAclDataAccess(t *testing.T) {
Convey
(
"Given child dashboard permission"
,
func
()
{
err
:=
testHelperUpdateDashboardAcl
(
childDash
.
Id
,
models
.
DashboardAcl
{
OrgI
d
:
1
,
UserI
d
:
currentUser
.
Id
,
DashboardI
d
:
childDash
.
Id
,
OrgI
D
:
1
,
UserI
D
:
currentUser
.
Id
,
DashboardI
D
:
childDash
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
,
})
So
(
err
,
ShouldBeNil
)
Convey
(
"When reading dashboard acl should include acl for parent folder and child"
,
func
()
{
query
:=
models
.
GetDashboardAclInfoListQuery
{
OrgI
d
:
1
,
DashboardId
:
childDash
.
Id
}
query
:=
models
.
GetDashboardAclInfoListQuery
{
OrgI
D
:
1
,
DashboardID
:
childDash
.
Id
}
err
:=
GetDashboardAclInfoList
(
&
query
)
So
(
err
,
ShouldBeNil
)
...
...
@@ -122,15 +122,15 @@ func TestDashboardAclDataAccess(t *testing.T) {
Convey
(
"Given child dashboard permission in folder with no permissions"
,
func
()
{
err
:=
testHelperUpdateDashboardAcl
(
childDash
.
Id
,
models
.
DashboardAcl
{
OrgI
d
:
1
,
UserI
d
:
currentUser
.
Id
,
DashboardI
d
:
childDash
.
Id
,
OrgI
D
:
1
,
UserI
D
:
currentUser
.
Id
,
DashboardI
D
:
childDash
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
,
})
So
(
err
,
ShouldBeNil
)
Convey
(
"When reading dashboard acl should include default acl for parent folder and the child acl"
,
func
()
{
query
:=
models
.
GetDashboardAclInfoListQuery
{
OrgI
d
:
1
,
DashboardId
:
childDash
.
Id
}
query
:=
models
.
GetDashboardAclInfoListQuery
{
OrgI
D
:
1
,
DashboardID
:
childDash
.
Id
}
err
:=
GetDashboardAclInfoList
(
&
query
)
So
(
err
,
ShouldBeNil
)
...
...
@@ -150,14 +150,14 @@ func TestDashboardAclDataAccess(t *testing.T) {
Convey
(
"Should be able to add dashboard permission"
,
func
()
{
err
:=
testHelperUpdateDashboardAcl
(
savedFolder
.
Id
,
models
.
DashboardAcl
{
OrgI
d
:
1
,
UserI
d
:
currentUser
.
Id
,
DashboardI
d
:
savedFolder
.
Id
,
OrgI
D
:
1
,
UserI
D
:
currentUser
.
Id
,
DashboardI
D
:
savedFolder
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
,
})
So
(
err
,
ShouldBeNil
)
q1
:=
&
models
.
GetDashboardAclInfoListQuery
{
DashboardI
d
:
savedFolder
.
Id
,
OrgId
:
1
}
q1
:=
&
models
.
GetDashboardAclInfoListQuery
{
DashboardI
D
:
savedFolder
.
Id
,
OrgID
:
1
}
err
=
GetDashboardAclInfoList
(
q1
)
So
(
err
,
ShouldBeNil
)
...
...
@@ -172,7 +172,7 @@ func TestDashboardAclDataAccess(t *testing.T) {
err
:=
testHelperUpdateDashboardAcl
(
savedFolder
.
Id
)
So
(
err
,
ShouldBeNil
)
q3
:=
&
models
.
GetDashboardAclInfoListQuery
{
DashboardI
d
:
savedFolder
.
Id
,
OrgId
:
1
}
q3
:=
&
models
.
GetDashboardAclInfoListQuery
{
DashboardI
D
:
savedFolder
.
Id
,
OrgID
:
1
}
err
=
GetDashboardAclInfoList
(
q3
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
q3
.
Result
),
ShouldEqual
,
0
)
...
...
@@ -186,14 +186,14 @@ func TestDashboardAclDataAccess(t *testing.T) {
Convey
(
"Should be able to add a user permission for a team"
,
func
()
{
err
:=
testHelperUpdateDashboardAcl
(
savedFolder
.
Id
,
models
.
DashboardAcl
{
OrgI
d
:
1
,
TeamI
d
:
group1
.
Result
.
Id
,
DashboardI
d
:
savedFolder
.
Id
,
OrgI
D
:
1
,
TeamI
D
:
group1
.
Result
.
Id
,
DashboardI
D
:
savedFolder
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
,
})
So
(
err
,
ShouldBeNil
)
q1
:=
&
models
.
GetDashboardAclInfoListQuery
{
DashboardI
d
:
savedFolder
.
Id
,
OrgId
:
1
}
q1
:=
&
models
.
GetDashboardAclInfoListQuery
{
DashboardI
D
:
savedFolder
.
Id
,
OrgID
:
1
}
err
=
GetDashboardAclInfoList
(
q1
)
So
(
err
,
ShouldBeNil
)
So
(
q1
.
Result
[
0
]
.
DashboardId
,
ShouldEqual
,
savedFolder
.
Id
)
...
...
@@ -203,14 +203,14 @@ func TestDashboardAclDataAccess(t *testing.T) {
Convey
(
"Should be able to update an existing permission for a team"
,
func
()
{
err
:=
testHelperUpdateDashboardAcl
(
savedFolder
.
Id
,
models
.
DashboardAcl
{
OrgI
d
:
1
,
TeamI
d
:
group1
.
Result
.
Id
,
DashboardI
d
:
savedFolder
.
Id
,
OrgI
D
:
1
,
TeamI
D
:
group1
.
Result
.
Id
,
DashboardI
D
:
savedFolder
.
Id
,
Permission
:
models
.
PERMISSION_ADMIN
,
})
So
(
err
,
ShouldBeNil
)
q3
:=
&
models
.
GetDashboardAclInfoListQuery
{
DashboardI
d
:
savedFolder
.
Id
,
OrgId
:
1
}
q3
:=
&
models
.
GetDashboardAclInfoListQuery
{
DashboardI
D
:
savedFolder
.
Id
,
OrgID
:
1
}
err
=
GetDashboardAclInfoList
(
q3
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
q3
.
Result
),
ShouldEqual
,
1
)
...
...
@@ -225,7 +225,7 @@ func TestDashboardAclDataAccess(t *testing.T) {
var
rootFolderId
int64
=
0
Convey
(
"When reading dashboard acl should return default permissions"
,
func
()
{
query
:=
models
.
GetDashboardAclInfoListQuery
{
DashboardI
d
:
rootFolderId
,
OrgId
:
1
}
query
:=
models
.
GetDashboardAclInfoListQuery
{
DashboardI
D
:
rootFolderId
,
OrgID
:
1
}
err
:=
GetDashboardAclInfoList
(
&
query
)
So
(
err
,
ShouldBeNil
)
...
...
pkg/services/sqlstore/dashboard_folder_test.go
View file @
52c154a2
...
...
@@ -41,9 +41,9 @@ func TestDashboardFolderDataAccess(t *testing.T) {
Convey
(
"and acl is set for dashboard folder"
,
func
()
{
var
otherUser
int64
=
999
err
:=
testHelperUpdateDashboardAcl
(
folder
.
Id
,
models
.
DashboardAcl
{
DashboardI
d
:
folder
.
Id
,
OrgI
d
:
1
,
UserI
d
:
otherUser
,
DashboardI
D
:
folder
.
Id
,
OrgI
D
:
1
,
UserI
D
:
otherUser
,
Permission
:
models
.
PERMISSION_EDIT
,
})
So
(
err
,
ShouldBeNil
)
...
...
@@ -62,7 +62,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
Convey
(
"when the user is given permission"
,
func
()
{
err
:=
testHelperUpdateDashboardAcl
(
folder
.
Id
,
models
.
DashboardAcl
{
DashboardI
d
:
folder
.
Id
,
OrgId
:
1
,
UserId
:
currentUser
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
,
DashboardI
D
:
folder
.
Id
,
OrgID
:
1
,
UserID
:
currentUser
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
,
})
So
(
err
,
ShouldBeNil
)
...
...
@@ -105,7 +105,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
err
:=
testHelperUpdateDashboardAcl
(
folder
.
Id
)
So
(
err
,
ShouldBeNil
)
err
=
testHelperUpdateDashboardAcl
(
childDash
.
Id
,
models
.
DashboardAcl
{
DashboardI
d
:
folder
.
Id
,
OrgId
:
1
,
UserId
:
otherUser
,
Permission
:
models
.
PERMISSION_EDIT
,
DashboardI
D
:
folder
.
Id
,
OrgID
:
1
,
UserID
:
otherUser
,
Permission
:
models
.
PERMISSION_EDIT
,
})
So
(
err
,
ShouldBeNil
)
...
...
@@ -120,7 +120,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
})
Convey
(
"when the user is given permission to child"
,
func
()
{
err
:=
testHelperUpdateDashboardAcl
(
childDash
.
Id
,
models
.
DashboardAcl
{
DashboardI
d
:
childDash
.
Id
,
OrgId
:
1
,
UserId
:
currentUser
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
})
err
:=
testHelperUpdateDashboardAcl
(
childDash
.
Id
,
models
.
DashboardAcl
{
DashboardI
D
:
childDash
.
Id
,
OrgID
:
1
,
UserID
:
currentUser
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
})
So
(
err
,
ShouldBeNil
)
Convey
(
"should be able to search for child dashboard but not folder"
,
func
()
{
...
...
@@ -181,7 +181,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
Convey
(
"and acl is set for one dashboard folder"
,
func
()
{
var
otherUser
int64
=
999
err
:=
testHelperUpdateDashboardAcl
(
folder1
.
Id
,
models
.
DashboardAcl
{
DashboardI
d
:
folder1
.
Id
,
OrgId
:
1
,
UserId
:
otherUser
,
Permission
:
models
.
PERMISSION_EDIT
,
DashboardI
D
:
folder1
.
Id
,
OrgID
:
1
,
UserID
:
otherUser
,
Permission
:
models
.
PERMISSION_EDIT
,
})
So
(
err
,
ShouldBeNil
)
...
...
@@ -221,7 +221,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
Convey
(
"and a dashboard with an acl is moved to the folder without an acl"
,
func
()
{
err
:=
testHelperUpdateDashboardAcl
(
childDash1
.
Id
,
models
.
DashboardAcl
{
DashboardI
d
:
childDash1
.
Id
,
OrgId
:
1
,
UserId
:
otherUser
,
Permission
:
models
.
PERMISSION_EDIT
,
DashboardI
D
:
childDash1
.
Id
,
OrgID
:
1
,
UserID
:
otherUser
,
Permission
:
models
.
PERMISSION_EDIT
,
})
So
(
err
,
ShouldBeNil
)
...
...
@@ -344,7 +344,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
Convey
(
"Should have write access to one dashboard folder if default role changed to view for one folder"
,
func
()
{
err
:=
testHelperUpdateDashboardAcl
(
folder1
.
Id
,
models
.
DashboardAcl
{
DashboardI
d
:
folder1
.
Id
,
OrgId
:
1
,
UserId
:
editorUser
.
Id
,
Permission
:
models
.
PERMISSION_VIEW
,
DashboardI
D
:
folder1
.
Id
,
OrgID
:
1
,
UserID
:
editorUser
.
Id
,
Permission
:
models
.
PERMISSION_VIEW
,
})
So
(
err
,
ShouldBeNil
)
...
...
@@ -408,7 +408,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
Convey
(
"Should be able to get one dashboard folder if default role changed to edit for one folder"
,
func
()
{
err
:=
testHelperUpdateDashboardAcl
(
folder1
.
Id
,
models
.
DashboardAcl
{
DashboardI
d
:
folder1
.
Id
,
OrgId
:
1
,
UserId
:
viewerUser
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
,
DashboardI
D
:
folder1
.
Id
,
OrgID
:
1
,
UserID
:
viewerUser
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
,
})
So
(
err
,
ShouldBeNil
)
...
...
@@ -439,7 +439,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
Convey
(
"and admin permission is given for user with org role viewer in one dashboard folder"
,
func
()
{
err
:=
testHelperUpdateDashboardAcl
(
folder1
.
Id
,
models
.
DashboardAcl
{
DashboardI
d
:
folder1
.
Id
,
OrgId
:
1
,
UserId
:
viewerUser
.
Id
,
Permission
:
models
.
PERMISSION_ADMIN
,
DashboardI
D
:
folder1
.
Id
,
OrgID
:
1
,
UserID
:
viewerUser
.
Id
,
Permission
:
models
.
PERMISSION_ADMIN
,
})
So
(
err
,
ShouldBeNil
)
...
...
@@ -455,7 +455,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
Convey
(
"and edit permission is given for user with org role viewer in one dashboard folder"
,
func
()
{
err
:=
testHelperUpdateDashboardAcl
(
folder1
.
Id
,
models
.
DashboardAcl
{
DashboardI
d
:
folder1
.
Id
,
OrgId
:
1
,
UserId
:
viewerUser
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
,
DashboardI
D
:
folder1
.
Id
,
OrgID
:
1
,
UserID
:
viewerUser
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
,
})
So
(
err
,
ShouldBeNil
)
...
...
pkg/services/sqlstore/org_test.go
View file @
52c154a2
...
...
@@ -287,10 +287,10 @@ func TestAccountDataAccess(t *testing.T) {
dash1
:=
insertTestDashboard
(
t
,
"1 test dash"
,
ac1
.
OrgId
,
0
,
false
,
"prod"
,
"webapp"
)
dash2
:=
insertTestDashboard
(
t
,
"2 test dash"
,
ac3
.
OrgId
,
0
,
false
,
"prod"
,
"webapp"
)
err
=
testHelperUpdateDashboardAcl
(
dash1
.
Id
,
models
.
DashboardAcl
{
DashboardI
d
:
dash1
.
Id
,
OrgId
:
ac1
.
OrgId
,
UserId
:
ac3
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
})
err
=
testHelperUpdateDashboardAcl
(
dash1
.
Id
,
models
.
DashboardAcl
{
DashboardI
D
:
dash1
.
Id
,
OrgID
:
ac1
.
OrgId
,
UserID
:
ac3
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
})
So
(
err
,
ShouldBeNil
)
err
=
testHelperUpdateDashboardAcl
(
dash2
.
Id
,
models
.
DashboardAcl
{
DashboardI
d
:
dash2
.
Id
,
OrgId
:
ac3
.
OrgId
,
UserId
:
ac3
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
})
err
=
testHelperUpdateDashboardAcl
(
dash2
.
Id
,
models
.
DashboardAcl
{
DashboardI
D
:
dash2
.
Id
,
OrgID
:
ac3
.
OrgId
,
UserID
:
ac3
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
})
So
(
err
,
ShouldBeNil
)
Convey
(
"When org user is deleted"
,
func
()
{
...
...
@@ -299,7 +299,7 @@ func TestAccountDataAccess(t *testing.T) {
So
(
err
,
ShouldBeNil
)
Convey
(
"Should remove dependent permissions for deleted org user"
,
func
()
{
permQuery
:=
&
models
.
GetDashboardAclInfoListQuery
{
DashboardI
d
:
1
,
OrgId
:
ac1
.
OrgId
}
permQuery
:=
&
models
.
GetDashboardAclInfoListQuery
{
DashboardI
D
:
1
,
OrgID
:
ac1
.
OrgId
}
err
=
GetDashboardAclInfoList
(
permQuery
)
So
(
err
,
ShouldBeNil
)
...
...
@@ -307,7 +307,7 @@ func TestAccountDataAccess(t *testing.T) {
})
Convey
(
"Should not remove dashboard permissions for same user in another org"
,
func
()
{
permQuery
:=
&
models
.
GetDashboardAclInfoListQuery
{
DashboardI
d
:
2
,
OrgId
:
ac3
.
OrgId
}
permQuery
:=
&
models
.
GetDashboardAclInfoListQuery
{
DashboardI
D
:
2
,
OrgID
:
ac3
.
OrgId
}
err
=
GetDashboardAclInfoList
(
permQuery
)
So
(
err
,
ShouldBeNil
)
...
...
@@ -323,7 +323,7 @@ func TestAccountDataAccess(t *testing.T) {
}
func
testHelperUpdateDashboardAcl
(
dashboardId
int64
,
items
...
models
.
DashboardAcl
)
error
{
cmd
:=
models
.
UpdateDashboardAclCommand
{
DashboardI
d
:
dashboardId
}
cmd
:=
models
.
UpdateDashboardAclCommand
{
DashboardI
D
:
dashboardId
}
for
_
,
i
:=
range
items
{
item
:=
i
item
.
Created
=
time
.
Now
()
...
...
pkg/services/sqlstore/sqlbuilder_test.go
View file @
52c154a2
...
...
@@ -260,11 +260,11 @@ func createDummyDashboard(dashboardProps DashboardProps) (*models.Dashboard, err
func
createDummyAcl
(
dashboardPermission
*
DashboardPermission
,
search
Search
,
dashboardId
int64
)
(
int64
,
error
)
{
acl
:=
&
models
.
DashboardAcl
{
OrgI
d
:
1
,
OrgI
D
:
1
,
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
Permission
:
dashboardPermission
.
Permission
,
DashboardI
d
:
dashboardId
,
DashboardI
D
:
dashboardId
,
}
var
user
*
models
.
User
...
...
@@ -275,7 +275,7 @@ func createDummyAcl(dashboardPermission *DashboardPermission, search Search, das
return
0
,
err
}
acl
.
UserI
d
=
user
.
Id
acl
.
UserI
D
=
user
.
Id
}
if
dashboardPermission
.
Team
{
...
...
@@ -299,7 +299,7 @@ func createDummyAcl(dashboardPermission *DashboardPermission, search Search, das
}
}
acl
.
TeamI
d
=
team
.
Id
acl
.
TeamI
D
=
team
.
Id
}
if
len
(
string
(
dashboardPermission
.
Role
))
>
0
{
...
...
@@ -307,7 +307,7 @@ func createDummyAcl(dashboardPermission *DashboardPermission, search Search, das
}
updateAclCmd
:=
&
models
.
UpdateDashboardAclCommand
{
DashboardI
d
:
dashboardId
,
DashboardI
D
:
dashboardId
,
Items
:
[]
*
models
.
DashboardAcl
{
acl
},
}
err
=
UpdateDashboardAcl
(
updateAclCmd
)
...
...
pkg/services/sqlstore/team_test.go
View file @
52c154a2
...
...
@@ -242,7 +242,7 @@ func TestTeamCommandsAndQueries(t *testing.T) {
So
(
err
,
ShouldBeNil
)
err
=
AddTeamMember
(
&
models
.
AddTeamMemberCommand
{
OrgId
:
testOrgId
,
TeamId
:
groupId
,
UserId
:
userIds
[
2
]})
So
(
err
,
ShouldBeNil
)
err
=
testHelperUpdateDashboardAcl
(
1
,
models
.
DashboardAcl
{
DashboardI
d
:
1
,
OrgId
:
testOrgId
,
Permission
:
models
.
PERMISSION_EDIT
,
TeamId
:
groupId
})
err
=
testHelperUpdateDashboardAcl
(
1
,
models
.
DashboardAcl
{
DashboardI
D
:
1
,
OrgID
:
testOrgId
,
Permission
:
models
.
PERMISSION_EDIT
,
TeamID
:
groupId
})
So
(
err
,
ShouldBeNil
)
err
=
DeleteTeam
(
&
models
.
DeleteTeamCommand
{
OrgId
:
testOrgId
,
Id
:
groupId
})
So
(
err
,
ShouldBeNil
)
...
...
@@ -251,7 +251,7 @@ func TestTeamCommandsAndQueries(t *testing.T) {
err
=
GetTeamById
(
query
)
So
(
err
,
ShouldEqual
,
models
.
ErrTeamNotFound
)
permQuery
:=
&
models
.
GetDashboardAclInfoListQuery
{
DashboardI
d
:
1
,
OrgId
:
testOrgId
}
permQuery
:=
&
models
.
GetDashboardAclInfoListQuery
{
DashboardI
D
:
1
,
OrgID
:
testOrgId
}
err
=
GetDashboardAclInfoList
(
permQuery
)
So
(
err
,
ShouldBeNil
)
...
...
pkg/services/sqlstore/user_test.go
View file @
52c154a2
...
...
@@ -287,7 +287,7 @@ func TestUserDataAccess(t *testing.T) {
So
(
err
,
ShouldBeNil
)
err
=
testHelperUpdateDashboardAcl
(
1
,
models
.
DashboardAcl
{
DashboardI
d
:
1
,
OrgId
:
users
[
0
]
.
OrgId
,
UserId
:
users
[
1
]
.
Id
,
DashboardI
D
:
1
,
OrgID
:
users
[
0
]
.
OrgId
,
UserID
:
users
[
1
]
.
Id
,
Permission
:
models
.
PERMISSION_EDIT
,
})
So
(
err
,
ShouldBeNil
)
...
...
@@ -308,7 +308,7 @@ func TestUserDataAccess(t *testing.T) {
So
(
len
(
query
.
Result
),
ShouldEqual
,
1
)
permQuery
:=
&
models
.
GetDashboardAclInfoListQuery
{
DashboardI
d
:
1
,
OrgId
:
users
[
0
]
.
OrgId
}
permQuery
:=
&
models
.
GetDashboardAclInfoListQuery
{
DashboardI
D
:
1
,
OrgID
:
users
[
0
]
.
OrgId
}
err
=
GetDashboardAclInfoList
(
permQuery
)
So
(
err
,
ShouldBeNil
)
...
...
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