Commit 0d61f895 by Leonard Gram

teams: cleanup.

parent 3be1d71f
...@@ -41,7 +41,12 @@ func (hs *HTTPServer) CreateTeam(c *m.ReqContext, cmd m.CreateTeamCommand) Respo ...@@ -41,7 +41,12 @@ func (hs *HTTPServer) CreateTeam(c *m.ReqContext, cmd m.CreateTeamCommand) Respo
func UpdateTeam(c *m.ReqContext, cmd m.UpdateTeamCommand) Response { func UpdateTeam(c *m.ReqContext, cmd m.UpdateTeamCommand) Response {
cmd.OrgId = c.OrgId cmd.OrgId = c.OrgId
cmd.Id = c.ParamsInt64(":teamId") cmd.Id = c.ParamsInt64(":teamId")
if err := teams.UpdateTeam(c.SignedInUser, &cmd); err != nil {
if err := teams.CanUpdateTeam(cmd.OrgId, cmd.Id, c.SignedInUser); err != nil {
return Error(403, "User not allowed to update team", err)
}
if err := bus.Dispatch(&cmd); err != nil {
if err == m.ErrTeamNameTaken { if err == m.ErrTeamNameTaken {
return Error(400, "Team name taken", err) return Error(400, "Team name taken", err)
} }
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
m "github.com/grafana/grafana/pkg/models" m "github.com/grafana/grafana/pkg/models"
) )
func canUpdateTeam(orgId int64, teamId int64, user *m.SignedInUser) error { func CanUpdateTeam(orgId int64, teamId int64, user *m.SignedInUser) error {
if user.OrgRole == m.ROLE_ADMIN { if user.OrgRole == m.ROLE_ADMIN {
return nil return nil
} }
...@@ -34,11 +34,3 @@ func canUpdateTeam(orgId int64, teamId int64, user *m.SignedInUser) error { ...@@ -34,11 +34,3 @@ func canUpdateTeam(orgId int64, teamId int64, user *m.SignedInUser) error {
return m.ErrNotAllowedToUpdateTeam return m.ErrNotAllowedToUpdateTeam
} }
func UpdateTeam(user *m.SignedInUser, cmd *m.UpdateTeamCommand) error {
if err := canUpdateTeam(cmd.OrgId, cmd.Id, user); err != nil {
return err
}
return bus.Dispatch(cmd)
}
...@@ -40,12 +40,12 @@ func TestUpdateTeam(t *testing.T) { ...@@ -40,12 +40,12 @@ func TestUpdateTeam(t *testing.T) {
return nil return nil
}) })
err := UpdateTeam(&editor, &updateTeamCmd) err := CanUpdateTeam(&editor, &updateTeamCmd)
So(err, ShouldEqual, m.ErrNotAllowedToUpdateTeam) So(err, ShouldEqual, m.ErrNotAllowedToUpdateTeam)
}) })
}) })
Convey("Given an editor and a team he is a member of", func() { Convey("Given an editor and a team he is an admin in", func() {
Convey("Should be able to update the team", func() { Convey("Should be able to update the team", func() {
teamUpdatedCallback := updateTeamCalled() teamUpdatedCallback := updateTeamCalled()
...@@ -59,7 +59,7 @@ func TestUpdateTeam(t *testing.T) { ...@@ -59,7 +59,7 @@ func TestUpdateTeam(t *testing.T) {
return nil return nil
}) })
err := UpdateTeam(&editor, &updateTeamCmd) err := CanUpdateTeam(&editor, &updateTeamCmd)
So(teamUpdatedCallback(), ShouldBeTrue) So(teamUpdatedCallback(), ShouldBeTrue)
So(err, ShouldBeNil) So(err, ShouldBeNil)
}) })
...@@ -88,7 +88,7 @@ func TestUpdateTeam(t *testing.T) { ...@@ -88,7 +88,7 @@ func TestUpdateTeam(t *testing.T) {
return nil return nil
}) })
err := UpdateTeam(&editor, &cmd) err := CanUpdateTeam(&editor, &cmd)
So(err, ShouldEqual, m.ErrNotAllowedToUpdateTeamInDifferentOrg) So(err, ShouldEqual, m.ErrNotAllowedToUpdateTeamInDifferentOrg)
}) })
}) })
...@@ -96,12 +96,18 @@ func TestUpdateTeam(t *testing.T) { ...@@ -96,12 +96,18 @@ func TestUpdateTeam(t *testing.T) {
Convey("Given an org admin and a team", func() { Convey("Given an org admin and a team", func() {
Convey("Should be able to update the team", func() { Convey("Should be able to update the team", func() {
teamUpdatedCallback := updateTeamCalled() teamUpdatedCallback := updateTeamCalled()
err := UpdateTeam(&admin, &updateTeamCmd) err := CanUpdateTeam(&admin, &updateTeamCmd)
So(teamUpdatedCallback(), ShouldBeTrue) So(teamUpdatedCallback(), ShouldBeTrue)
So(err, ShouldBeNil) So(err, ShouldBeNil)
}) })
}) })
Convey("Given that the editorsCanOwn feature toggle is disabled", func() {
Convey("Given an editor and a team he is an admin", func() {
})
})
}) })
} }
......
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