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
d668550a
Commit
d668550a
authored
Mar 11, 2019
by
Leonard Gram
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
teams: added feature toggle and refactor tests
parent
0d61f895
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
45 deletions
+15
-45
pkg/api/team.go
+2
-2
pkg/services/teams/team.go
+5
-1
pkg/services/teams/teams_test.go
+8
-42
No files found.
pkg/api/team.go
View file @
d668550a
...
...
@@ -38,11 +38,11 @@ func (hs *HTTPServer) CreateTeam(c *m.ReqContext, cmd m.CreateTeamCommand) Respo
}
// PUT /api/teams/:teamId
func
UpdateTeam
(
c
*
m
.
ReqContext
,
cmd
m
.
UpdateTeamCommand
)
Response
{
func
(
hs
*
HTTPServer
)
UpdateTeam
(
c
*
m
.
ReqContext
,
cmd
m
.
UpdateTeamCommand
)
Response
{
cmd
.
OrgId
=
c
.
OrgId
cmd
.
Id
=
c
.
ParamsInt64
(
":teamId"
)
if
err
:=
teams
.
CanUpdateTeam
(
cmd
.
OrgId
,
cmd
.
Id
,
c
.
SignedInUser
);
err
!=
nil
{
if
err
:=
teams
.
CanUpdateTeam
(
cmd
.
OrgId
,
cmd
.
Id
,
c
.
SignedInUser
,
hs
.
Cfg
.
EditorsCanOwn
);
err
!=
nil
{
return
Error
(
403
,
"User not allowed to update team"
,
err
)
}
...
...
pkg/services/teams/team.go
View file @
d668550a
...
...
@@ -5,11 +5,15 @@ import (
m
"github.com/grafana/grafana/pkg/models"
)
func
CanUpdateTeam
(
orgId
int64
,
teamId
int64
,
user
*
m
.
SignedInUser
)
error
{
func
CanUpdateTeam
(
orgId
int64
,
teamId
int64
,
user
*
m
.
SignedInUser
,
editorCanOwn
bool
)
error
{
if
user
.
OrgRole
==
m
.
ROLE_ADMIN
{
return
nil
}
if
!
editorCanOwn
{
return
m
.
ErrNotAllowedToUpdateTeam
}
if
user
.
OrgId
!=
orgId
{
return
m
.
ErrNotAllowedToUpdateTeamInDifferentOrg
}
...
...
pkg/services/teams/teams_test.go
View file @
d668550a
...
...
@@ -3,7 +3,6 @@ package teams
import
(
"github.com/grafana/grafana/pkg/bus"
m
"github.com/grafana/grafana/pkg/models"
"github.com/pkg/errors"
.
"github.com/smartystreets/goconvey/convey"
"testing"
)
...
...
@@ -27,28 +26,20 @@ func TestUpdateTeam(t *testing.T) {
OrgId
:
1
,
}
updateTeamCmd
:=
m
.
UpdateTeamCommand
{
Id
:
testTeam
.
Id
,
OrgId
:
testTeam
.
OrgId
,
}
Convey
(
"Given an editor and a team he isn't a member of"
,
func
()
{
Convey
(
"Should not be able to update the team"
,
func
()
{
shouldNotUpdateTeam
()
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
GetTeamMembersQuery
)
error
{
cmd
.
Result
=
[]
*
m
.
TeamMemberDTO
{}
return
nil
})
err
:=
CanUpdateTeam
(
&
editor
,
&
updateTeamCmd
)
err
:=
CanUpdateTeam
(
testTeam
.
OrgId
,
testTeam
.
Id
,
&
editor
,
true
)
So
(
err
,
ShouldEqual
,
m
.
ErrNotAllowedToUpdateTeam
)
})
})
Convey
(
"Given an editor and a team he is an admin in"
,
func
()
{
Convey
(
"Should be able to update the team"
,
func
()
{
teamUpdatedCallback
:=
updateTeamCalled
()
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
GetTeamMembersQuery
)
error
{
cmd
.
Result
=
[]
*
m
.
TeamMemberDTO
{{
OrgId
:
testTeam
.
OrgId
,
...
...
@@ -59,8 +50,7 @@ func TestUpdateTeam(t *testing.T) {
return
nil
})
err
:=
CanUpdateTeam
(
&
editor
,
&
updateTeamCmd
)
So
(
teamUpdatedCallback
(),
ShouldBeTrue
)
err
:=
CanUpdateTeam
(
testTeam
.
OrgId
,
testTeam
.
Id
,
&
editor
,
true
)
So
(
err
,
ShouldBeNil
)
})
})
...
...
@@ -72,12 +62,6 @@ func TestUpdateTeam(t *testing.T) {
}
Convey
(
"Shouldn't be able to update the team"
,
func
()
{
cmd
:=
m
.
UpdateTeamCommand
{
Id
:
testTeamOtherOrg
.
Id
,
OrgId
:
testTeamOtherOrg
.
OrgId
,
}
shouldNotUpdateTeam
()
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
GetTeamMembersQuery
)
error
{
cmd
.
Result
=
[]
*
m
.
TeamMemberDTO
{{
OrgId
:
testTeamOtherOrg
.
OrgId
,
...
...
@@ -88,42 +72,24 @@ func TestUpdateTeam(t *testing.T) {
return
nil
})
err
:=
CanUpdateTeam
(
&
editor
,
&
cmd
)
err
:=
CanUpdateTeam
(
testTeamOtherOrg
.
OrgId
,
testTeamOtherOrg
.
Id
,
&
editor
,
true
)
So
(
err
,
ShouldEqual
,
m
.
ErrNotAllowedToUpdateTeamInDifferentOrg
)
})
})
Convey
(
"Given an org admin and a team"
,
func
()
{
Convey
(
"Should be able to update the team"
,
func
()
{
teamUpdatedCallback
:=
updateTeamCalled
()
err
:=
CanUpdateTeam
(
&
admin
,
&
updateTeamCmd
)
So
(
teamUpdatedCallback
(),
ShouldBeTrue
)
err
:=
CanUpdateTeam
(
testTeam
.
OrgId
,
testTeam
.
Id
,
&
admin
,
true
)
So
(
err
,
ShouldBeNil
)
})
})
Convey
(
"Given that the editorsCanOwn feature toggle is disabled"
,
func
()
{
Convey
(
"Given an editor and a team he is an admin"
,
func
()
{
Convey
(
"Given that the editorsCanOwn feature toggle is disabled"
,
func
()
{
Convey
(
"Editors should not be able to update teams"
,
func
()
{
err
:=
CanUpdateTeam
(
testTeam
.
OrgId
,
testTeam
.
Id
,
&
editor
,
false
)
So
(
err
,
ShouldEqual
,
m
.
ErrNotAllowedToUpdateTeam
)
})
})
})
}
func
updateTeamCalled
()
func
()
bool
{
wasCalled
:=
false
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
UpdateTeamCommand
)
error
{
wasCalled
=
true
return
nil
})
return
func
()
bool
{
return
wasCalled
}
}
func
shouldNotUpdateTeam
()
{
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
UpdateTeamCommand
)
error
{
return
errors
.
New
(
"UpdateTeamCommand not expected."
)
})
}
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