mirror of
https://github.com/grafana/grafana.git
synced 2024-12-29 10:21:41 -06:00
teams: editor added as admin for created teams.
This commit is contained in:
parent
22e098b830
commit
af4994ba16
@ -154,7 +154,7 @@ func (hs *HTTPServer) registerRoutes() {
|
|||||||
|
|
||||||
// team (admin permission required)
|
// team (admin permission required)
|
||||||
apiRoute.Group("/teams", func(teamsRoute routing.RouteRegister) {
|
apiRoute.Group("/teams", func(teamsRoute routing.RouteRegister) {
|
||||||
teamsRoute.Post("/", bind(m.CreateTeamCommand{}), Wrap(CreateTeam))
|
teamsRoute.Post("/", bind(m.CreateTeamCommand{}), Wrap(hs.CreateTeam))
|
||||||
teamsRoute.Put("/:teamId", bind(m.UpdateTeamCommand{}), Wrap(UpdateTeam))
|
teamsRoute.Put("/:teamId", bind(m.UpdateTeamCommand{}), Wrap(UpdateTeam))
|
||||||
teamsRoute.Delete("/:teamId", Wrap(DeleteTeamByID))
|
teamsRoute.Delete("/:teamId", Wrap(DeleteTeamByID))
|
||||||
teamsRoute.Get("/:teamId/members", Wrap(GetTeamMembers))
|
teamsRoute.Get("/:teamId/members", Wrap(GetTeamMembers))
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// POST /api/teams
|
// POST /api/teams
|
||||||
func CreateTeam(c *m.ReqContext, cmd m.CreateTeamCommand) Response {
|
func (hs *HTTPServer) CreateTeam(c *m.ReqContext, cmd m.CreateTeamCommand) Response {
|
||||||
cmd.OrgId = c.OrgId
|
cmd.OrgId = c.OrgId
|
||||||
if err := bus.Dispatch(&cmd); err != nil {
|
if err := bus.Dispatch(&cmd); err != nil {
|
||||||
if err == m.ErrTeamNameTaken {
|
if err == m.ErrTeamNameTaken {
|
||||||
@ -17,6 +17,17 @@ func CreateTeam(c *m.ReqContext, cmd m.CreateTeamCommand) Response {
|
|||||||
return Error(500, "Failed to create Team", err)
|
return Error(500, "Failed to create Team", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.OrgRole == m.ROLE_EDITOR && hs.Cfg.EditorsCanOwn {
|
||||||
|
addMemberCmd := m.AddTeamMemberCommand{
|
||||||
|
UserId: c.SignedInUser.UserId,
|
||||||
|
OrgId: cmd.OrgId,
|
||||||
|
TeamId: cmd.Result.Id,
|
||||||
|
Permission: int64(m.PERMISSION_ADMIN),
|
||||||
|
}
|
||||||
|
err := bus.Dispatch(&addMemberCmd)
|
||||||
|
c.Logger.Error("Could not add creator to team.", "error", err)
|
||||||
|
}
|
||||||
|
|
||||||
return JSON(200, &util.DynMap{
|
return JSON(200, &util.DynMap{
|
||||||
"teamId": cmd.Result.Id,
|
"teamId": cmd.Result.Id,
|
||||||
"message": "Team created",
|
"message": "Team created",
|
||||||
|
@ -17,6 +17,7 @@ type TeamMember struct {
|
|||||||
TeamId int64
|
TeamId int64
|
||||||
UserId int64
|
UserId int64
|
||||||
External bool
|
External bool
|
||||||
|
Permission int64
|
||||||
|
|
||||||
Created time.Time
|
Created time.Time
|
||||||
Updated time.Time
|
Updated time.Time
|
||||||
@ -30,6 +31,7 @@ type AddTeamMemberCommand struct {
|
|||||||
OrgId int64 `json:"-"`
|
OrgId int64 `json:"-"`
|
||||||
TeamId int64 `json:"-"`
|
TeamId int64 `json:"-"`
|
||||||
External bool `json:"-"`
|
External bool `json:"-"`
|
||||||
|
Permission int64 `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RemoveTeamMemberCommand struct {
|
type RemoveTeamMemberCommand struct {
|
||||||
|
@ -54,4 +54,10 @@ func addTeamMigrations(mg *Migrator) {
|
|||||||
mg.AddMigration("Add column external to team_member table", NewAddColumnMigration(teamMemberV1, &Column{
|
mg.AddMigration("Add column external to team_member table", NewAddColumnMigration(teamMemberV1, &Column{
|
||||||
Name: "external", Type: DB_Bool, Nullable: true,
|
Name: "external", Type: DB_Bool, Nullable: true,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
mg.AddMigration("Add column permission to team_member table", NewAddColumnMigration(teamMemberV1, &Column{
|
||||||
|
Name: "permission",
|
||||||
|
Type: DB_BigInt,
|
||||||
|
Nullable: true,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
@ -246,6 +246,7 @@ func AddTeamMember(cmd *m.AddTeamMemberCommand) error {
|
|||||||
External: cmd.External,
|
External: cmd.External,
|
||||||
Created: time.Now(),
|
Created: time.Now(),
|
||||||
Updated: time.Now(),
|
Updated: time.Now(),
|
||||||
|
Permission: cmd.Permission,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := sess.Insert(&entity)
|
_, err := sess.Insert(&entity)
|
||||||
|
Loading…
Reference in New Issue
Block a user