mirror of
https://github.com/grafana/grafana.git
synced 2025-01-21 22:13:38 -06:00
teams: defaulting invalid permission level to member permission level
This commit is contained in:
parent
c823ad5de7
commit
c826f39a8b
@ -271,7 +271,10 @@ func UpdateTeamMember(cmd *m.UpdateTeamMemberCommand) error {
|
||||
return m.ErrTeamMemberNotFound
|
||||
}
|
||||
|
||||
// TODO: check to make sure that permission is a legal value
|
||||
if cmd.Permission != int64(m.PERMISSION_ADMIN) {
|
||||
cmd.Permission = 0
|
||||
}
|
||||
|
||||
member.Permission = cmd.Permission
|
||||
_, err = sess.Cols("permission").Where("org_id=? and team_id=? and user_id=?", cmd.OrgId, cmd.TeamId, cmd.UserId).Update(member)
|
||||
|
||||
|
@ -102,6 +102,34 @@ func TestTeamCommandsAndQueries(t *testing.T) {
|
||||
So(qAfterUpdate.Result[0].Permission, ShouldEqual, m.PERMISSION_ADMIN)
|
||||
})
|
||||
|
||||
Convey("Should default to member permission level when updating a user with invalid permission level", 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)
|
||||
|
||||
invalidPermissionLevel := 1337
|
||||
err = UpdateTeamMember(&m.UpdateTeamMemberCommand{
|
||||
UserId: userID,
|
||||
OrgId: testOrgId,
|
||||
TeamId: team.Id,
|
||||
Permission: int64(invalidPermissionLevel),
|
||||
})
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
qAfterUpdate := &m.GetTeamMembersQuery{OrgId: testOrgId, TeamId: team.Id}
|
||||
err = GetTeamMembers(qAfterUpdate)
|
||||
So(err, ShouldBeNil)
|
||||
So(qAfterUpdate.Result[0].Permission, ShouldEqual, 0)
|
||||
})
|
||||
|
||||
Convey("Shouldn't be able to update a user not in the team.", func() {
|
||||
err = UpdateTeamMember(&m.UpdateTeamMemberCommand{
|
||||
UserId: 1,
|
||||
|
Loading…
Reference in New Issue
Block a user