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
2a88052c
Commit
2a88052c
authored
Mar 06, 2019
by
Leonard Gram
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
teams: can update team members permission.
parent
7888457a
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
0 deletions
+74
-0
pkg/api/api.go
+1
-0
pkg/api/team_members.go
+15
-0
pkg/models/team_member.go
+7
-0
pkg/services/sqlstore/team.go
+24
-0
pkg/services/sqlstore/team_test.go
+27
-0
No files found.
pkg/api/api.go
View file @
2a88052c
...
...
@@ -159,6 +159,7 @@ func (hs *HTTPServer) registerRoutes() {
teamsRoute
.
Delete
(
"/:teamId"
,
Wrap
(
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
.
Delete
(
"/:teamId/members/:userId"
,
Wrap
(
RemoveTeamMember
))
teamsRoute
.
Get
(
"/:teamId/preferences"
,
Wrap
(
GetTeamPreferences
))
teamsRoute
.
Put
(
"/:teamId/preferences"
,
bind
(
dtos
.
UpdatePrefsCmd
{}),
Wrap
(
UpdateTeamPreferences
))
...
...
pkg/api/team_members.go
View file @
2a88052c
...
...
@@ -50,6 +50,21 @@ func AddTeamMember(c *m.ReqContext, cmd m.AddTeamMemberCommand) Response {
})
}
// PUT /:teamId/members/:userId
func
UpdateTeamMember
(
c
*
m
.
ReqContext
,
cmd
m
.
UpdateTeamMemberCommand
)
Response
{
cmd
.
TeamId
=
c
.
ParamsInt64
(
":teamId"
)
cmd
.
UserId
=
c
.
ParamsInt64
(
":userId"
)
cmd
.
OrgId
=
c
.
OrgId
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
==
m
.
ErrTeamMemberNotFound
{
return
Error
(
404
,
"Team member not found."
,
nil
)
}
return
Error
(
500
,
"Failed to update team member."
,
err
)
}
return
Success
(
"Team member updated"
)
}
// DELETE /api/teams/:teamId/members/:userId
func
RemoveTeamMember
(
c
*
m
.
ReqContext
)
Response
{
if
err
:=
bus
.
Dispatch
(
&
m
.
RemoveTeamMemberCommand
{
OrgId
:
c
.
OrgId
,
TeamId
:
c
.
ParamsInt64
(
":teamId"
),
UserId
:
c
.
ParamsInt64
(
":userId"
)});
err
!=
nil
{
...
...
pkg/models/team_member.go
View file @
2a88052c
...
...
@@ -34,6 +34,13 @@ type AddTeamMemberCommand struct {
Permission
int64
`json:"-"`
}
type
UpdateTeamMemberCommand
struct
{
UserId
int64
`json:"-"`
OrgId
int64
`json:"-"`
TeamId
int64
`json:"-"`
Permission
int64
`json:"permission"`
}
type
RemoveTeamMemberCommand
struct
{
OrgId
int64
`json:"-"`
UserId
int64
...
...
pkg/services/sqlstore/team.go
View file @
2a88052c
...
...
@@ -18,6 +18,7 @@ func init() {
bus
.
AddHandler
(
"sql"
,
GetTeamsByUser
)
bus
.
AddHandler
(
"sql"
,
AddTeamMember
)
bus
.
AddHandler
(
"sql"
,
UpdateTeamMember
)
bus
.
AddHandler
(
"sql"
,
RemoveTeamMember
)
bus
.
AddHandler
(
"sql"
,
GetTeamMembers
)
}
...
...
@@ -254,6 +255,29 @@ func AddTeamMember(cmd *m.AddTeamMemberCommand) error {
})
}
// UpdateTeamMember updates a team member
func
UpdateTeamMember
(
cmd
*
m
.
UpdateTeamMemberCommand
)
error
{
return
inTransaction
(
func
(
sess
*
DBSession
)
error
{
rawSql
:=
`SELECT * FROM team_member WHERE org_id=? and team_id=? and user_id=?`
var
member
m
.
TeamMember
exists
,
err
:=
sess
.
SQL
(
rawSql
,
cmd
.
OrgId
,
cmd
.
TeamId
,
cmd
.
UserId
)
.
Get
(
&
member
)
if
err
!=
nil
{
return
err
}
if
!
exists
{
return
m
.
ErrTeamMemberNotFound
}
member
.
Permission
=
cmd
.
Permission
_
,
err
=
sess
.
Update
(
member
)
return
err
})
}
// RemoveTeamMember removes a member from a team
func
RemoveTeamMember
(
cmd
*
m
.
RemoveTeamMemberCommand
)
error
{
return
inTransaction
(
func
(
sess
*
DBSession
)
error
{
...
...
pkg/services/sqlstore/team_test.go
View file @
2a88052c
...
...
@@ -75,6 +75,33 @@ func TestTeamCommandsAndQueries(t *testing.T) {
So
(
q2
.
Result
[
0
]
.
External
,
ShouldEqual
,
true
)
})
Convey
(
"Should be able to update users in a team"
,
func
()
{
userId
:=
userIds
[
0
]
team
:=
group1
.
Result
addMemberCmd
:=
m
.
AddTeamMemberCommand
{
OrgId
:
testOrgId
,
TeamId
:
team
.
Id
,
UserId
:
userId
}
err
=
AddTeamMember
(
&
addMemberCmd
)
So
(
err
,
ShouldBeNil
)
qBeforeUpdate
:=
&
m
.
GetTeamMembersQuery
{
OrgId
:
testOrgId
,
TeamId
:
team
.
Id
}
err
=
GetTeamMembers
(
qBeforeUpdate
)
So
(
err
,
ShouldBeNil
)
So
(
qBeforeUpdate
.
Result
[
0
]
.
Permission
,
ShouldEqual
,
0
)
err
=
UpdateTeamMember
(
&
m
.
UpdateTeamMemberCommand
{
UserId
:
userId
,
OrgId
:
testOrgId
,
TeamId
:
team
.
Id
,
Permission
:
int64
(
m
.
PERMISSION_ADMIN
),
})
So
(
err
,
ShouldBeNil
)
qAfterUpdate
:=
&
m
.
GetTeamMembersQuery
{
OrgId
:
testOrgId
,
TeamId
:
team
.
Id
}
err
=
GetTeamMembers
(
qAfterUpdate
)
So
(
err
,
ShouldBeNil
)
So
(
qAfterUpdate
.
Result
[
0
]
.
Permission
,
ShouldEqual
,
m
.
PERMISSION_ADMIN
)
})
Convey
(
"Should be able to search for teams"
,
func
()
{
query
:=
&
m
.
SearchTeamsQuery
{
OrgId
:
testOrgId
,
Query
:
"group"
,
Page
:
1
}
err
=
SearchTeams
(
query
)
...
...
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