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
adf0390b
Commit
adf0390b
authored
Mar 14, 2019
by
Leonard Gram
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
teams: local access to bus, moving away from dep on global.
parent
6589a4e5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
29 deletions
+29
-29
pkg/api/api.go
+6
-6
pkg/api/team.go
+10
-10
pkg/api/team_members.go
+8
-8
pkg/services/teamguardian/team.go
+1
-1
pkg/services/teamguardian/teams_test.go
+4
-4
No files found.
pkg/api/api.go
View file @
adf0390b
...
...
@@ -155,14 +155,14 @@ func (hs *HTTPServer) registerRoutes() {
// team (admin permission required)
apiRoute
.
Group
(
"/teams"
,
func
(
teamsRoute
routing
.
RouteRegister
)
{
teamsRoute
.
Post
(
"/"
,
bind
(
m
.
CreateTeamCommand
{}),
Wrap
(
hs
.
CreateTeam
))
teamsRoute
.
Put
(
"/:teamId"
,
bind
(
m
.
UpdateTeamCommand
{}),
Wrap
(
UpdateTeam
))
teamsRoute
.
Delete
(
"/:teamId"
,
Wrap
(
DeleteTeamByID
))
teamsRoute
.
Put
(
"/:teamId"
,
bind
(
m
.
UpdateTeamCommand
{}),
Wrap
(
hs
.
UpdateTeam
))
teamsRoute
.
Delete
(
"/:teamId"
,
Wrap
(
hs
.
DeleteTeamByID
))
teamsRoute
.
Get
(
"/:teamId/members"
,
Wrap
(
GetTeamMembers
))
teamsRoute
.
Post
(
"/:teamId/members"
,
bind
(
m
.
AddTeamMemberCommand
{}),
Wrap
(
AddTeamMember
))
teamsRoute
.
Put
(
"/:teamId/members/:userId"
,
bind
(
m
.
UpdateTeamMemberCommand
{}),
Wrap
(
UpdateTeamMember
))
teamsRoute
.
Post
(
"/:teamId/members"
,
bind
(
m
.
AddTeamMemberCommand
{}),
Wrap
(
hs
.
AddTeamMember
))
teamsRoute
.
Put
(
"/:teamId/members/:userId"
,
bind
(
m
.
UpdateTeamMemberCommand
{}),
Wrap
(
hs
.
UpdateTeamMember
))
teamsRoute
.
Delete
(
"/:teamId/members/:userId"
,
Wrap
(
hs
.
RemoveTeamMember
))
teamsRoute
.
Get
(
"/:teamId/preferences"
,
Wrap
(
GetTeamPreferences
))
teamsRoute
.
Put
(
"/:teamId/preferences"
,
bind
(
dtos
.
UpdatePrefsCmd
{}),
Wrap
(
UpdateTeamPreferences
))
teamsRoute
.
Get
(
"/:teamId/preferences"
,
Wrap
(
hs
.
GetTeamPreferences
))
teamsRoute
.
Put
(
"/:teamId/preferences"
,
bind
(
dtos
.
UpdatePrefsCmd
{}),
Wrap
(
hs
.
UpdateTeamPreferences
))
},
reqCanAccessTeams
)
// team without requirement of user to be org admin
...
...
pkg/api/team.go
View file @
adf0390b
...
...
@@ -43,15 +43,15 @@ 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
:=
teamguardian
.
CanAdmin
(
cmd
.
OrgId
,
cmd
.
Id
,
c
.
SignedInUser
);
err
!=
nil
{
if
err
:=
teamguardian
.
CanAdmin
(
hs
.
Bus
,
cmd
.
OrgId
,
cmd
.
Id
,
c
.
SignedInUser
);
err
!=
nil
{
return
Error
(
403
,
"Not allowed to update team"
,
err
)
}
if
err
:=
b
us
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
:=
hs
.
B
us
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
==
m
.
ErrTeamNameTaken
{
return
Error
(
400
,
"Team name taken"
,
err
)
}
...
...
@@ -62,16 +62,16 @@ func UpdateTeam(c *m.ReqContext, cmd m.UpdateTeamCommand) Response {
}
// DELETE /api/teams/:teamId
func
DeleteTeamByID
(
c
*
m
.
ReqContext
)
Response
{
func
(
hs
*
HTTPServer
)
DeleteTeamByID
(
c
*
m
.
ReqContext
)
Response
{
orgId
:=
c
.
OrgId
teamId
:=
c
.
ParamsInt64
(
":teamId"
)
user
:=
c
.
SignedInUser
if
err
:=
teamguardian
.
CanAdmin
(
orgId
,
teamId
,
user
);
err
!=
nil
{
if
err
:=
teamguardian
.
CanAdmin
(
hs
.
Bus
,
orgId
,
teamId
,
user
);
err
!=
nil
{
return
Error
(
403
,
"Not allowed to delete team"
,
err
)
}
if
err
:=
b
us
.
Dispatch
(
&
m
.
DeleteTeamCommand
{
OrgId
:
orgId
,
Id
:
teamId
});
err
!=
nil
{
if
err
:=
hs
.
B
us
.
Dispatch
(
&
m
.
DeleteTeamCommand
{
OrgId
:
orgId
,
Id
:
teamId
});
err
!=
nil
{
if
err
==
m
.
ErrTeamNotFound
{
return
Error
(
404
,
"Failed to delete Team. ID not found"
,
nil
)
}
...
...
@@ -136,11 +136,11 @@ func GetTeamByID(c *m.ReqContext) Response {
}
// GET /api/teams/:teamId/preferences
func
GetTeamPreferences
(
c
*
m
.
ReqContext
)
Response
{
func
(
hs
*
HTTPServer
)
GetTeamPreferences
(
c
*
m
.
ReqContext
)
Response
{
teamId
:=
c
.
ParamsInt64
(
":teamId"
)
orgId
:=
c
.
OrgId
if
err
:=
teamguardian
.
CanAdmin
(
orgId
,
teamId
,
c
.
SignedInUser
);
err
!=
nil
{
if
err
:=
teamguardian
.
CanAdmin
(
hs
.
Bus
,
orgId
,
teamId
,
c
.
SignedInUser
);
err
!=
nil
{
return
Error
(
403
,
"Not allowed to view team preferences."
,
err
)
}
...
...
@@ -148,11 +148,11 @@ func GetTeamPreferences(c *m.ReqContext) Response {
}
// PUT /api/teams/:teamId/preferences
func
UpdateTeamPreferences
(
c
*
m
.
ReqContext
,
dtoCmd
dtos
.
UpdatePrefsCmd
)
Response
{
func
(
hs
*
HTTPServer
)
UpdateTeamPreferences
(
c
*
m
.
ReqContext
,
dtoCmd
dtos
.
UpdatePrefsCmd
)
Response
{
teamId
:=
c
.
ParamsInt64
(
":teamId"
)
orgId
:=
c
.
OrgId
if
err
:=
teamguardian
.
CanAdmin
(
orgId
,
teamId
,
c
.
SignedInUser
);
err
!=
nil
{
if
err
:=
teamguardian
.
CanAdmin
(
hs
.
Bus
,
orgId
,
teamId
,
c
.
SignedInUser
);
err
!=
nil
{
return
Error
(
403
,
"Not allowed to update team preferences."
,
err
)
}
...
...
pkg/api/team_members.go
View file @
adf0390b
...
...
@@ -30,15 +30,15 @@ func GetTeamMembers(c *m.ReqContext) Response {
}
// POST /api/teams/:teamId/members
func
AddTeamMember
(
c
*
m
.
ReqContext
,
cmd
m
.
AddTeamMemberCommand
)
Response
{
func
(
hs
*
HTTPServer
)
AddTeamMember
(
c
*
m
.
ReqContext
,
cmd
m
.
AddTeamMemberCommand
)
Response
{
cmd
.
OrgId
=
c
.
OrgId
cmd
.
TeamId
=
c
.
ParamsInt64
(
":teamId"
)
if
err
:=
teamguardian
.
CanAdmin
(
cmd
.
OrgId
,
cmd
.
TeamId
,
c
.
SignedInUser
);
err
!=
nil
{
if
err
:=
teamguardian
.
CanAdmin
(
hs
.
Bus
,
cmd
.
OrgId
,
cmd
.
TeamId
,
c
.
SignedInUser
);
err
!=
nil
{
return
Error
(
403
,
"Not allowed to add team member"
,
err
)
}
if
err
:=
b
us
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
:=
hs
.
B
us
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
==
m
.
ErrTeamNotFound
{
return
Error
(
404
,
"Team not found"
,
nil
)
}
...
...
@@ -56,11 +56,11 @@ func AddTeamMember(c *m.ReqContext, cmd m.AddTeamMemberCommand) Response {
}
// PUT /:teamId/members/:userId
func
UpdateTeamMember
(
c
*
m
.
ReqContext
,
cmd
m
.
UpdateTeamMemberCommand
)
Response
{
func
(
hs
*
HTTPServer
)
UpdateTeamMember
(
c
*
m
.
ReqContext
,
cmd
m
.
UpdateTeamMemberCommand
)
Response
{
teamId
:=
c
.
ParamsInt64
(
":teamId"
)
orgId
:=
c
.
OrgId
if
err
:=
teamguardian
.
CanAdmin
(
orgId
,
teamId
,
c
.
SignedInUser
);
err
!=
nil
{
if
err
:=
teamguardian
.
CanAdmin
(
hs
.
Bus
,
orgId
,
teamId
,
c
.
SignedInUser
);
err
!=
nil
{
return
Error
(
403
,
"Not allowed to update team member"
,
err
)
}
...
...
@@ -72,7 +72,7 @@ func UpdateTeamMember(c *m.ReqContext, cmd m.UpdateTeamMemberCommand) Response {
cmd
.
UserId
=
c
.
ParamsInt64
(
":userId"
)
cmd
.
OrgId
=
orgId
if
err
:=
b
us
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
:=
hs
.
B
us
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
==
m
.
ErrTeamMemberNotFound
{
return
Error
(
404
,
"Team member not found."
,
nil
)
}
...
...
@@ -87,7 +87,7 @@ func (hs *HTTPServer) RemoveTeamMember(c *m.ReqContext) Response {
teamId
:=
c
.
ParamsInt64
(
":teamId"
)
userId
:=
c
.
ParamsInt64
(
":userId"
)
if
err
:=
teamguardian
.
CanAdmin
(
orgId
,
teamId
,
c
.
SignedInUser
);
err
!=
nil
{
if
err
:=
teamguardian
.
CanAdmin
(
hs
.
Bus
,
orgId
,
teamId
,
c
.
SignedInUser
);
err
!=
nil
{
return
Error
(
403
,
"Not allowed to remove team member"
,
err
)
}
...
...
@@ -96,7 +96,7 @@ func (hs *HTTPServer) RemoveTeamMember(c *m.ReqContext) Response {
protectLastAdmin
=
true
}
if
err
:=
b
us
.
Dispatch
(
&
m
.
RemoveTeamMemberCommand
{
OrgId
:
orgId
,
TeamId
:
teamId
,
UserId
:
userId
,
ProtectLastAdmin
:
protectLastAdmin
});
err
!=
nil
{
if
err
:=
hs
.
B
us
.
Dispatch
(
&
m
.
RemoveTeamMemberCommand
{
OrgId
:
orgId
,
TeamId
:
teamId
,
UserId
:
userId
,
ProtectLastAdmin
:
protectLastAdmin
});
err
!=
nil
{
if
err
==
m
.
ErrTeamNotFound
{
return
Error
(
404
,
"Team not found"
,
nil
)
}
...
...
pkg/services/teamguardian/team.go
View file @
adf0390b
...
...
@@ -5,7 +5,7 @@ import (
m
"github.com/grafana/grafana/pkg/models"
)
func
CanAdmin
(
orgId
int64
,
teamId
int64
,
user
*
m
.
SignedInUser
)
error
{
func
CanAdmin
(
bus
bus
.
Bus
,
orgId
int64
,
teamId
int64
,
user
*
m
.
SignedInUser
)
error
{
if
user
.
OrgRole
==
m
.
ROLE_ADMIN
{
return
nil
}
...
...
pkg/services/teamguardian/teams_test.go
View file @
adf0390b
...
...
@@ -33,7 +33,7 @@ func TestUpdateTeam(t *testing.T) {
return
nil
})
err
:=
CanAdmin
(
testTeam
.
OrgId
,
testTeam
.
Id
,
&
editor
)
err
:=
CanAdmin
(
bus
.
GetBus
(),
testTeam
.
OrgId
,
testTeam
.
Id
,
&
editor
)
So
(
err
,
ShouldEqual
,
m
.
ErrNotAllowedToUpdateTeam
)
})
})
...
...
@@ -50,7 +50,7 @@ func TestUpdateTeam(t *testing.T) {
return
nil
})
err
:=
CanAdmin
(
testTeam
.
OrgId
,
testTeam
.
Id
,
&
editor
)
err
:=
CanAdmin
(
bus
.
GetBus
(),
testTeam
.
OrgId
,
testTeam
.
Id
,
&
editor
)
So
(
err
,
ShouldBeNil
)
})
})
...
...
@@ -72,14 +72,14 @@ func TestUpdateTeam(t *testing.T) {
return
nil
})
err
:=
CanAdmin
(
testTeamOtherOrg
.
OrgId
,
testTeamOtherOrg
.
Id
,
&
editor
)
err
:=
CanAdmin
(
bus
.
GetBus
(),
testTeamOtherOrg
.
OrgId
,
testTeamOtherOrg
.
Id
,
&
editor
)
So
(
err
,
ShouldEqual
,
m
.
ErrNotAllowedToUpdateTeamInDifferentOrg
)
})
})
Convey
(
"Given an org admin and a team"
,
func
()
{
Convey
(
"Should be able to update the team"
,
func
()
{
err
:=
CanAdmin
(
testTeam
.
OrgId
,
testTeam
.
Id
,
&
admin
)
err
:=
CanAdmin
(
bus
.
GetBus
(),
testTeam
.
OrgId
,
testTeam
.
Id
,
&
admin
)
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