Selaa lähdekoodia

teams: cleanup.

Leonard Gram 6 vuotta sitten
vanhempi
commit
0d61f89577
3 muutettua tiedostoa jossa 18 lisäystä ja 15 poistoa
  1. 6 1
      pkg/api/team.go
  2. 1 9
      pkg/services/teams/team.go
  3. 11 5
      pkg/services/teams/teams_test.go

+ 6 - 1
pkg/api/team.go

@@ -41,7 +41,12 @@ func (hs *HTTPServer) CreateTeam(c *m.ReqContext, cmd m.CreateTeamCommand) Respo
 func UpdateTeam(c *m.ReqContext, cmd m.UpdateTeamCommand) Response {
 	cmd.OrgId = c.OrgId
 	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 {
 			return Error(400, "Team name taken", err)
 		}

+ 1 - 9
pkg/services/teams/team.go

@@ -5,7 +5,7 @@ import (
 	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 {
 		return nil
 	}
@@ -34,11 +34,3 @@ func canUpdateTeam(orgId int64, teamId int64, user *m.SignedInUser) error {
 
 	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)
-}

+ 11 - 5
pkg/services/teams/teams_test.go

@@ -40,12 +40,12 @@ func TestUpdateTeam(t *testing.T) {
 					return nil
 				})
 
-				err := UpdateTeam(&editor, &updateTeamCmd)
+				err := CanUpdateTeam(&editor, &updateTeamCmd)
 				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() {
 				teamUpdatedCallback := updateTeamCalled()
 
@@ -59,7 +59,7 @@ func TestUpdateTeam(t *testing.T) {
 					return nil
 				})
 
-				err := UpdateTeam(&editor, &updateTeamCmd)
+				err := CanUpdateTeam(&editor, &updateTeamCmd)
 				So(teamUpdatedCallback(), ShouldBeTrue)
 				So(err, ShouldBeNil)
 			})
@@ -88,7 +88,7 @@ func TestUpdateTeam(t *testing.T) {
 					return nil
 				})
 
-				err := UpdateTeam(&editor, &cmd)
+				err := CanUpdateTeam(&editor, &cmd)
 				So(err, ShouldEqual, m.ErrNotAllowedToUpdateTeamInDifferentOrg)
 			})
 		})
@@ -96,12 +96,18 @@ func TestUpdateTeam(t *testing.T) {
 		Convey("Given an org admin and a team", func() {
 			Convey("Should be able to update the team", func() {
 				teamUpdatedCallback := updateTeamCalled()
-				err := UpdateTeam(&admin, &updateTeamCmd)
+				err := CanUpdateTeam(&admin, &updateTeamCmd)
 
 				So(teamUpdatedCallback(), ShouldBeTrue)
 				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() {
+
+			})
+		})
 	})
 }