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
f76b98d2
Commit
f76b98d2
authored
Feb 27, 2018
by
Marcus Efraimsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboards: change dashboard/folder permission error messages
parent
03f8eff8
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
30 deletions
+30
-30
pkg/api/dashboard_permission.go
+2
-2
pkg/api/dashboard_permission_test.go
+2
-2
pkg/api/folder_permission.go
+2
-2
pkg/api/folder_permission_test.go
+2
-2
pkg/services/guardian/guardian.go
+4
-4
pkg/services/guardian/guardian_test.go
+18
-18
No files found.
pkg/api/dashboard_permission.go
View file @
f76b98d2
...
...
@@ -69,8 +69,8 @@ func UpdateDashboardPermissions(c *middleware.Context, apiCmd dtos.UpdateDashboa
if
okToUpdate
,
err
:=
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
cmd
.
Items
);
err
!=
nil
||
!
okToUpdate
{
if
err
!=
nil
{
if
err
==
guardian
.
ErrGuardian
DuplicatePermission
||
err
==
guardian
.
ErrGuardianOverride
LowerPresedence
{
if
err
==
guardian
.
ErrGuardian
PermissionExists
||
err
==
guardian
.
ErrGuardianOverride
{
return
ApiError
(
400
,
err
.
Error
(),
err
)
}
...
...
pkg/api/dashboard_permission_test.go
View file @
f76b98d2
...
...
@@ -119,7 +119,7 @@ func TestDashboardPermissionApiEndpoint(t *testing.T) {
guardian
.
MockDashboardGuardian
(
&
guardian
.
FakeDashboardGuardian
{
CanAdminValue
:
true
,
CheckPermissionBeforeUpdateValue
:
false
,
CheckPermissionBeforeUpdateError
:
guardian
.
ErrGuardian
DuplicatePermission
,
CheckPermissionBeforeUpdateError
:
guardian
.
ErrGuardian
PermissionExists
,
})
getDashboardQueryResult
:=
m
.
NewDashboard
(
"Dash"
)
...
...
@@ -149,7 +149,7 @@ func TestDashboardPermissionApiEndpoint(t *testing.T) {
guardian
.
MockDashboardGuardian
(
&
guardian
.
FakeDashboardGuardian
{
CanAdminValue
:
true
,
CheckPermissionBeforeUpdateValue
:
false
,
CheckPermissionBeforeUpdateError
:
guardian
.
ErrGuardianOverride
LowerPresedence
},
CheckPermissionBeforeUpdateError
:
guardian
.
ErrGuardianOverride
},
)
getDashboardQueryResult
:=
m
.
NewDashboard
(
"Dash"
)
...
...
pkg/api/folder_permission.go
View file @
f76b98d2
...
...
@@ -78,8 +78,8 @@ func UpdateFolderPermissions(c *middleware.Context, apiCmd dtos.UpdateDashboardA
if
okToUpdate
,
err
:=
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
cmd
.
Items
);
err
!=
nil
||
!
okToUpdate
{
if
err
!=
nil
{
if
err
==
guardian
.
ErrGuardian
DuplicatePermission
||
err
==
guardian
.
ErrGuardianOverride
LowerPresedence
{
if
err
==
guardian
.
ErrGuardian
PermissionExists
||
err
==
guardian
.
ErrGuardianOverride
{
return
ApiError
(
400
,
err
.
Error
(),
err
)
}
...
...
pkg/api/folder_permission_test.go
View file @
f76b98d2
...
...
@@ -139,7 +139,7 @@ func TestFolderPermissionApiEndpoint(t *testing.T) {
guardian
.
MockDashboardGuardian
(
&
guardian
.
FakeDashboardGuardian
{
CanAdminValue
:
true
,
CheckPermissionBeforeUpdateValue
:
false
,
CheckPermissionBeforeUpdateError
:
guardian
.
ErrGuardian
DuplicatePermission
,
CheckPermissionBeforeUpdateError
:
guardian
.
ErrGuardian
PermissionExists
,
})
mock
:=
&
fakeFolderService
{
...
...
@@ -175,7 +175,7 @@ func TestFolderPermissionApiEndpoint(t *testing.T) {
guardian
.
MockDashboardGuardian
(
&
guardian
.
FakeDashboardGuardian
{
CanAdminValue
:
true
,
CheckPermissionBeforeUpdateValue
:
false
,
CheckPermissionBeforeUpdateError
:
guardian
.
ErrGuardianOverride
LowerPresedence
},
CheckPermissionBeforeUpdateError
:
guardian
.
ErrGuardianOverride
},
)
mock
:=
&
fakeFolderService
{
...
...
pkg/services/guardian/guardian.go
View file @
f76b98d2
...
...
@@ -10,8 +10,8 @@ import (
)
var
(
ErrGuardian
DuplicatePermission
=
errors
.
New
(
"You cannot add multiple permissions for a user, team or role
"
)
ErrGuardianOverride
LowerPresedence
=
errors
.
New
(
"You cannot override a permission with a lower presedence permission
"
)
ErrGuardian
PermissionExists
=
errors
.
New
(
"This permission already exists
"
)
ErrGuardianOverride
=
errors
.
New
(
"You can only override a permission to be higher
"
)
)
// DashboardGuardian to be used for guard against operations without access on dashboard and acl
...
...
@@ -133,7 +133,7 @@ func (g *dashboardGuardianImpl) CheckPermissionBeforeUpdate(permission m.Permiss
if
(
a
.
UserId
<=
0
&&
a
.
TeamId
<=
0
&&
a
.
UserId
==
p
.
UserId
&&
a
.
TeamId
==
p
.
TeamId
&&
a
.
Role
==
p
.
Role
)
||
(
a
.
UserId
>
0
&&
a
.
UserId
==
p
.
UserId
)
||
(
a
.
TeamId
>
0
&&
a
.
TeamId
==
p
.
TeamId
)
{
return
false
,
ErrGuardian
DuplicatePermission
return
false
,
ErrGuardian
PermissionExists
}
}
...
...
@@ -154,7 +154,7 @@ func (g *dashboardGuardianImpl) CheckPermissionBeforeUpdate(permission m.Permiss
if
(
a
.
UserId
<=
0
&&
a
.
TeamId
<=
0
&&
a
.
UserId
==
existingPerm
.
UserId
&&
a
.
TeamId
==
existingPerm
.
TeamId
&&
*
a
.
Role
==
*
existingPerm
.
Role
&&
a
.
Permission
<=
existingPerm
.
Permission
)
||
(
a
.
UserId
>
0
&&
a
.
UserId
==
existingPerm
.
UserId
&&
a
.
Permission
<=
existingPerm
.
Permission
)
||
(
a
.
TeamId
>
0
&&
a
.
TeamId
==
existingPerm
.
TeamId
&&
a
.
Permission
<=
existingPerm
.
Permission
)
{
return
false
,
ErrGuardianOverride
LowerPresedence
return
false
,
ErrGuardianOverride
}
}
}
...
...
pkg/services/guardian/guardian_test.go
View file @
f76b98d2
...
...
@@ -29,7 +29,7 @@ func TestGuardian(t *testing.T) {
{
OrgId
:
1
,
DashboardId
:
1
,
UserId
:
1
,
Permission
:
m
.
PERMISSION_ADMIN
},
}
_
,
err
:=
sc
.
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
p
)
So
(
err
,
ShouldEqual
,
ErrGuardian
DuplicatePermission
)
So
(
err
,
ShouldEqual
,
ErrGuardian
PermissionExists
)
})
Convey
(
"With duplicate team/role permissions should return error"
,
func
()
{
...
...
@@ -38,7 +38,7 @@ func TestGuardian(t *testing.T) {
{
OrgId
:
1
,
DashboardId
:
1
,
TeamId
:
1
,
Permission
:
m
.
PERMISSION_ADMIN
},
}
_
,
err
:=
sc
.
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
p
)
So
(
err
,
ShouldEqual
,
ErrGuardian
DuplicatePermission
)
So
(
err
,
ShouldEqual
,
ErrGuardian
PermissionExists
)
})
Convey
(
"With duplicate everyone/role permissions should return error"
,
func
()
{
...
...
@@ -47,7 +47,7 @@ func TestGuardian(t *testing.T) {
{
OrgId
:
1
,
DashboardId
:
1
,
Permission
:
m
.
PERMISSION_ADMIN
},
}
_
,
err
:=
sc
.
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
p
)
So
(
err
,
ShouldEqual
,
ErrGuardian
DuplicatePermission
)
So
(
err
,
ShouldEqual
,
ErrGuardian
PermissionExists
)
})
})
...
...
@@ -66,7 +66,7 @@ func TestGuardian(t *testing.T) {
{
OrgId
:
1
,
DashboardId
:
3
,
UserId
:
1
,
Permission
:
m
.
PERMISSION_ADMIN
},
}
_
,
err
:=
sc
.
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
p
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
LowerPresedence
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
)
})
Convey
(
"When trying to update dashboard permissions with edit user permission should return error"
,
func
()
{
...
...
@@ -74,7 +74,7 @@ func TestGuardian(t *testing.T) {
{
OrgId
:
1
,
DashboardId
:
3
,
UserId
:
1
,
Permission
:
m
.
PERMISSION_EDIT
},
}
_
,
err
:=
sc
.
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
p
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
LowerPresedence
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
)
})
Convey
(
"When trying to update dashboard permissions with view user permission should return error"
,
func
()
{
...
...
@@ -82,7 +82,7 @@ func TestGuardian(t *testing.T) {
{
OrgId
:
1
,
DashboardId
:
3
,
UserId
:
1
,
Permission
:
m
.
PERMISSION_VIEW
},
}
_
,
err
:=
sc
.
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
p
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
LowerPresedence
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
)
})
})
...
...
@@ -109,7 +109,7 @@ func TestGuardian(t *testing.T) {
{
OrgId
:
1
,
DashboardId
:
3
,
UserId
:
1
,
Permission
:
m
.
PERMISSION_EDIT
},
}
_
,
err
:=
sc
.
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
p
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
LowerPresedence
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
)
})
Convey
(
"When trying to update dashboard permissions with view user permission should return error"
,
func
()
{
...
...
@@ -117,7 +117,7 @@ func TestGuardian(t *testing.T) {
{
OrgId
:
1
,
DashboardId
:
3
,
UserId
:
1
,
Permission
:
m
.
PERMISSION_VIEW
},
}
_
,
err
:=
sc
.
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
p
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
LowerPresedence
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
)
})
})
...
...
@@ -152,7 +152,7 @@ func TestGuardian(t *testing.T) {
{
OrgId
:
1
,
DashboardId
:
3
,
UserId
:
1
,
Permission
:
m
.
PERMISSION_VIEW
},
}
_
,
err
:=
sc
.
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
p
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
LowerPresedence
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
)
})
})
...
...
@@ -171,7 +171,7 @@ func TestGuardian(t *testing.T) {
{
OrgId
:
1
,
DashboardId
:
3
,
TeamId
:
1
,
Permission
:
m
.
PERMISSION_ADMIN
},
}
_
,
err
:=
sc
.
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
p
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
LowerPresedence
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
)
})
Convey
(
"When trying to update dashboard permissions with edit team permission should return error"
,
func
()
{
...
...
@@ -179,7 +179,7 @@ func TestGuardian(t *testing.T) {
{
OrgId
:
1
,
DashboardId
:
3
,
TeamId
:
1
,
Permission
:
m
.
PERMISSION_EDIT
},
}
_
,
err
:=
sc
.
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
p
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
LowerPresedence
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
)
})
Convey
(
"When trying to update dashboard permissions with view team permission should return error"
,
func
()
{
...
...
@@ -187,7 +187,7 @@ func TestGuardian(t *testing.T) {
{
OrgId
:
1
,
DashboardId
:
3
,
TeamId
:
1
,
Permission
:
m
.
PERMISSION_VIEW
},
}
_
,
err
:=
sc
.
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
p
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
LowerPresedence
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
)
})
})
...
...
@@ -214,7 +214,7 @@ func TestGuardian(t *testing.T) {
{
OrgId
:
1
,
DashboardId
:
3
,
TeamId
:
1
,
Permission
:
m
.
PERMISSION_EDIT
},
}
_
,
err
:=
sc
.
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
p
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
LowerPresedence
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
)
})
Convey
(
"When trying to update dashboard permissions with view team permission should return error"
,
func
()
{
...
...
@@ -222,7 +222,7 @@ func TestGuardian(t *testing.T) {
{
OrgId
:
1
,
DashboardId
:
3
,
TeamId
:
1
,
Permission
:
m
.
PERMISSION_VIEW
},
}
_
,
err
:=
sc
.
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
p
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
LowerPresedence
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
)
})
})
...
...
@@ -257,7 +257,7 @@ func TestGuardian(t *testing.T) {
{
OrgId
:
1
,
DashboardId
:
3
,
TeamId
:
1
,
Permission
:
m
.
PERMISSION_VIEW
},
}
_
,
err
:=
sc
.
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
p
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
LowerPresedence
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
)
})
})
...
...
@@ -285,7 +285,7 @@ func TestGuardian(t *testing.T) {
{
OrgId
:
1
,
DashboardId
:
3
,
Role
:
&
r
,
Permission
:
m
.
PERMISSION_EDIT
},
}
_
,
err
:=
sc
.
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
p
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
LowerPresedence
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
)
})
Convey
(
"When trying to update dashboard permissions with everyone with editor role can view permission should return error"
,
func
()
{
...
...
@@ -293,7 +293,7 @@ func TestGuardian(t *testing.T) {
{
OrgId
:
1
,
DashboardId
:
3
,
Role
:
&
r
,
Permission
:
m
.
PERMISSION_VIEW
},
}
_
,
err
:=
sc
.
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
p
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
LowerPresedence
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
)
})
})
...
...
@@ -329,7 +329,7 @@ func TestGuardian(t *testing.T) {
{
OrgId
:
1
,
DashboardId
:
3
,
Role
:
&
r
,
Permission
:
m
.
PERMISSION_VIEW
},
}
_
,
err
:=
sc
.
g
.
CheckPermissionBeforeUpdate
(
m
.
PERMISSION_ADMIN
,
p
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
LowerPresedence
)
So
(
err
,
ShouldEqual
,
ErrGuardianOverride
)
})
})
})
...
...
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