Commit c823ad5d by Leonard Gram

team: uses PermissionType instead of int64 for permissions.

parent 21d3d274
......@@ -23,7 +23,7 @@ func (hs *HTTPServer) CreateTeam(c *m.ReqContext, cmd m.CreateTeamCommand) Respo
UserId: c.SignedInUser.UserId,
OrgId: cmd.OrgId,
TeamId: cmd.Result.Id,
Permission: int64(m.PERMISSION_ADMIN),
Permission: m.PERMISSION_ADMIN,
}
if err := bus.Dispatch(&addMemberCmd); err != nil {
......
......@@ -17,7 +17,7 @@ type TeamMember struct {
TeamId int64
UserId int64
External bool
Permission int64
Permission PermissionType
Created time.Time
Updated time.Time
......@@ -27,18 +27,18 @@ type TeamMember struct {
// COMMANDS
type AddTeamMemberCommand struct {
UserId int64 `json:"userId" binding:"Required"`
OrgId int64 `json:"-"`
TeamId int64 `json:"-"`
External bool `json:"-"`
Permission int64 `json:"-"`
UserId int64 `json:"userId" binding:"Required"`
OrgId int64 `json:"-"`
TeamId int64 `json:"-"`
External bool `json:"-"`
Permission PermissionType `json:"-"`
}
type UpdateTeamMemberCommand struct {
UserId int64 `json:"-"`
OrgId int64 `json:"-"`
TeamId int64 `json:"-"`
Permission int64 `json:"permission"`
UserId int64 `json:"-"`
OrgId int64 `json:"-"`
TeamId int64 `json:"-"`
Permission PermissionType `json:"permission"`
}
type RemoveTeamMemberCommand struct {
......
......@@ -271,6 +271,7 @@ func UpdateTeamMember(cmd *m.UpdateTeamMemberCommand) error {
return m.ErrTeamMemberNotFound
}
// TODO: check to make sure that permission is a legal value
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)
......
......@@ -91,7 +91,7 @@ func TestTeamCommandsAndQueries(t *testing.T) {
UserId: userId,
OrgId: testOrgId,
TeamId: team.Id,
Permission: int64(m.PERMISSION_ADMIN),
Permission: m.PERMISSION_ADMIN,
})
So(err, ShouldBeNil)
......@@ -107,7 +107,7 @@ func TestTeamCommandsAndQueries(t *testing.T) {
UserId: 1,
OrgId: testOrgId,
TeamId: group1.Result.Id,
Permission: int64(m.PERMISSION_ADMIN),
Permission: m.PERMISSION_ADMIN,
})
So(err, ShouldEqual, m.ErrTeamMemberNotFound)
......@@ -153,7 +153,7 @@ func TestTeamCommandsAndQueries(t *testing.T) {
})
Convey("When ProtectLastAdmin is set to true", func() {
err = AddTeamMember(&m.AddTeamMemberCommand{OrgId: testOrgId, TeamId: group1.Result.Id, UserId: userIds[0], Permission: int64(m.PERMISSION_ADMIN)})
err = AddTeamMember(&m.AddTeamMemberCommand{OrgId: testOrgId, TeamId: group1.Result.Id, UserId: userIds[0], Permission: m.PERMISSION_ADMIN})
So(err, ShouldBeNil)
Convey("A user should not be able to remove the last admin", func() {
......@@ -162,7 +162,7 @@ func TestTeamCommandsAndQueries(t *testing.T) {
})
Convey("A user should be able to remove an admin if there are other admins", func() {
err = AddTeamMember(&m.AddTeamMemberCommand{OrgId: testOrgId, TeamId: group1.Result.Id, UserId: userIds[1], Permission: int64(m.PERMISSION_ADMIN)})
err = AddTeamMember(&m.AddTeamMemberCommand{OrgId: testOrgId, TeamId: group1.Result.Id, UserId: userIds[1], Permission: m.PERMISSION_ADMIN})
err = RemoveTeamMember(&m.RemoveTeamMemberCommand{OrgId: testOrgId, TeamId: group1.Result.Id, UserId: userIds[0], ProtectLastAdmin: true})
So(err, ShouldEqual, nil)
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment