From 5adde259d307ac36277b419475712503cf25d63e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=A4ggmark?= Date: Fri, 8 Mar 2019 14:37:21 +0100 Subject: [PATCH] teams: team update test --- pkg/api/team.go | 3 ++- pkg/services/teams/team.go | 10 ++++++++ pkg/services/teams/teams_test.go | 42 ++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 pkg/services/teams/team.go create mode 100644 pkg/services/teams/teams_test.go diff --git a/pkg/api/team.go b/pkg/api/team.go index da72bda472b..3d357fa9763 100644 --- a/pkg/api/team.go +++ b/pkg/api/team.go @@ -4,6 +4,7 @@ import ( "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/bus" m "github.com/grafana/grafana/pkg/models" + "github.com/grafana/grafana/pkg/services/teams" "github.com/grafana/grafana/pkg/util" ) @@ -40,7 +41,7 @@ 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 := bus.Dispatch(&cmd); err != nil { + if err := teams.UpdateTeam(c.SignedInUser, &cmd); err != nil { if err == m.ErrTeamNameTaken { return Error(400, "Team name taken", err) } diff --git a/pkg/services/teams/team.go b/pkg/services/teams/team.go new file mode 100644 index 00000000000..4bd4b78d587 --- /dev/null +++ b/pkg/services/teams/team.go @@ -0,0 +1,10 @@ +package teams + +import ( + "github.com/grafana/grafana/pkg/bus" + m "github.com/grafana/grafana/pkg/models" +) + +func UpdateTeam(user m.SignedInUser, cmd *m.UpdateTeamCommand) error { + return bus.Dispatch(cmd) +} diff --git a/pkg/services/teams/teams_test.go b/pkg/services/teams/teams_test.go new file mode 100644 index 00000000000..aaa19440bb4 --- /dev/null +++ b/pkg/services/teams/teams_test.go @@ -0,0 +1,42 @@ +package teams + +import ( + . "github.com/smartystreets/goconvey/convey" + m "github.com/grafana/grafana/pkg/models" +) + + +func TestUpdateTeam(t *testing.T) { + Convey("Updating a team as an editor", t, func() { + Convey("Given an editor and a team he isn't a member of", func() { + + UpdateTeam(editor, m.UpdateTeamCommand{ + Id: 0, + Name: "", + Email: "", + OrgId: 0, + }) + }) + + // the editor should not be able to update the team if they aren't members of it + + fakeDash := m.NewDashboard("Child dash") + fakeDash.Id = 1 + fakeDash.FolderId = 1 + fakeDash.HasAcl = false + + bus.AddHandler("test", func(query *m.GetDashboardsBySlugQuery) error { + dashboards := []*m.Dashboard{fakeDash} + query.Result = dashboards + return nil + }) + + var getDashboardQueries []*m.GetDashboardQuery + + bus.AddHandler("test", func(query *m.GetDashboardQuery) error { + query.Result = fakeDash + getDashboardQueries = append(getDashboardQueries, query) + return nil + }) + + bus.AddHandler("test", func(query *m.IsDashboardProvisionedQuery) error {