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 ...@@ -23,7 +23,7 @@ func (hs *HTTPServer) CreateTeam(c *m.ReqContext, cmd m.CreateTeamCommand) Respo
UserId: c.SignedInUser.UserId, UserId: c.SignedInUser.UserId,
OrgId: cmd.OrgId, OrgId: cmd.OrgId,
TeamId: cmd.Result.Id, TeamId: cmd.Result.Id,
Permission: int64(m.PERMISSION_ADMIN), Permission: m.PERMISSION_ADMIN,
} }
if err := bus.Dispatch(&addMemberCmd); err != nil { if err := bus.Dispatch(&addMemberCmd); err != nil {
......
...@@ -17,7 +17,7 @@ type TeamMember struct { ...@@ -17,7 +17,7 @@ type TeamMember struct {
TeamId int64 TeamId int64
UserId int64 UserId int64
External bool External bool
Permission int64 Permission PermissionType
Created time.Time Created time.Time
Updated time.Time Updated time.Time
...@@ -31,14 +31,14 @@ type AddTeamMemberCommand struct { ...@@ -31,14 +31,14 @@ type AddTeamMemberCommand struct {
OrgId int64 `json:"-"` OrgId int64 `json:"-"`
TeamId int64 `json:"-"` TeamId int64 `json:"-"`
External bool `json:"-"` External bool `json:"-"`
Permission int64 `json:"-"` Permission PermissionType `json:"-"`
} }
type UpdateTeamMemberCommand struct { type UpdateTeamMemberCommand struct {
UserId int64 `json:"-"` UserId int64 `json:"-"`
OrgId int64 `json:"-"` OrgId int64 `json:"-"`
TeamId int64 `json:"-"` TeamId int64 `json:"-"`
Permission int64 `json:"permission"` Permission PermissionType `json:"permission"`
} }
type RemoveTeamMemberCommand struct { type RemoveTeamMemberCommand struct {
......
...@@ -271,6 +271,7 @@ func UpdateTeamMember(cmd *m.UpdateTeamMemberCommand) error { ...@@ -271,6 +271,7 @@ func UpdateTeamMember(cmd *m.UpdateTeamMemberCommand) error {
return m.ErrTeamMemberNotFound return m.ErrTeamMemberNotFound
} }
// TODO: check to make sure that permission is a legal value
member.Permission = cmd.Permission 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) _, 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) { ...@@ -91,7 +91,7 @@ func TestTeamCommandsAndQueries(t *testing.T) {
UserId: userId, UserId: userId,
OrgId: testOrgId, OrgId: testOrgId,
TeamId: team.Id, TeamId: team.Id,
Permission: int64(m.PERMISSION_ADMIN), Permission: m.PERMISSION_ADMIN,
}) })
So(err, ShouldBeNil) So(err, ShouldBeNil)
...@@ -107,7 +107,7 @@ func TestTeamCommandsAndQueries(t *testing.T) { ...@@ -107,7 +107,7 @@ func TestTeamCommandsAndQueries(t *testing.T) {
UserId: 1, UserId: 1,
OrgId: testOrgId, OrgId: testOrgId,
TeamId: group1.Result.Id, TeamId: group1.Result.Id,
Permission: int64(m.PERMISSION_ADMIN), Permission: m.PERMISSION_ADMIN,
}) })
So(err, ShouldEqual, m.ErrTeamMemberNotFound) So(err, ShouldEqual, m.ErrTeamMemberNotFound)
...@@ -153,7 +153,7 @@ func TestTeamCommandsAndQueries(t *testing.T) { ...@@ -153,7 +153,7 @@ func TestTeamCommandsAndQueries(t *testing.T) {
}) })
Convey("When ProtectLastAdmin is set to true", func() { 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) So(err, ShouldBeNil)
Convey("A user should not be able to remove the last admin", func() { Convey("A user should not be able to remove the last admin", func() {
...@@ -162,7 +162,7 @@ func TestTeamCommandsAndQueries(t *testing.T) { ...@@ -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() { 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}) err = RemoveTeamMember(&m.RemoveTeamMemberCommand{OrgId: testOrgId, TeamId: group1.Result.Id, UserId: userIds[0], ProtectLastAdmin: true})
So(err, ShouldEqual, nil) 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