mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
teams: team update test
This commit is contained in:
committed by
Leonard Gram
parent
3c46b786d2
commit
5adde259d3
@@ -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)
|
||||
}
|
||||
|
||||
10
pkg/services/teams/team.go
Normal file
10
pkg/services/teams/team.go
Normal file
@@ -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)
|
||||
}
|
||||
42
pkg/services/teams/teams_test.go
Normal file
42
pkg/services/teams/teams_test.go
Normal file
@@ -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 {
|
||||
Reference in New Issue
Block a user