From da3dcd19184dacf4533b99d8532c6ea217378d25 Mon Sep 17 00:00:00 2001 From: Leonard Gram Date: Tue, 5 Mar 2019 16:53:16 +0100 Subject: [PATCH] folder: uses service to make user admin of created folder. --- pkg/api/folder.go | 5 +++ pkg/services/dashboards/folder_service.go | 40 ----------------------- 2 files changed, 5 insertions(+), 40 deletions(-) diff --git a/pkg/api/folder.go b/pkg/api/folder.go index 4e106dc6452..4e66439219d 100644 --- a/pkg/api/folder.go +++ b/pkg/api/folder.go @@ -61,6 +61,11 @@ func (hs *HTTPServer) CreateFolder(c *m.ReqContext, cmd m.CreateFolderCommand) R return toFolderError(err) } + if hs.Cfg.EditorsCanOwn { + aclService := dashboards.NewAclService() + aclService.MakeUserAdmin(c.OrgId, c.SignedInUser.UserId, cmd.Result.Id) + } + g := guardian.New(cmd.Result.Id, c.OrgId, c.SignedInUser) return JSON(200, toFolderDto(g, cmd.Result)) } diff --git a/pkg/services/dashboards/folder_service.go b/pkg/services/dashboards/folder_service.go index 917852f4781..b521b0e5213 100644 --- a/pkg/services/dashboards/folder_service.go +++ b/pkg/services/dashboards/folder_service.go @@ -5,7 +5,6 @@ import ( "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/guardian" "github.com/grafana/grafana/pkg/services/search" - "time" ) // FolderService service for operating on folders @@ -115,45 +114,6 @@ func (dr *dashboardServiceImpl) CreateFolder(cmd *models.CreateFolderCommand) er return toFolderError(err) } - rtEditor := models.ROLE_EDITOR - rtViewer := models.ROLE_VIEWER - - items := []*models.DashboardAcl{ - { - OrgId: dr.orgId, - DashboardId: saveDashboardCmd.Result.Id, - UserId: saveDashboardCmd.Result.CreatedBy, - Permission: models.PERMISSION_ADMIN, - Created: time.Now(), - Updated: time.Now(), - }, - { - OrgId: dr.orgId, - DashboardId: saveDashboardCmd.Result.Id, - Role: &rtEditor, - Permission: models.PERMISSION_EDIT, - Created: time.Now(), - Updated: time.Now(), - }, - { - OrgId: dr.orgId, - DashboardId: saveDashboardCmd.Result.Id, - Role: &rtViewer, - Permission: models.PERMISSION_VIEW, - Created: time.Now(), - Updated: time.Now(), - }, - } - - aclCmd := &models.UpdateDashboardAclCommand{ - DashboardId: saveDashboardCmd.Result.Id, - Items: items, - } - - if err = bus.Dispatch(aclCmd); err != nil { - return err - } - query := models.GetDashboardQuery{OrgId: dr.orgId, Id: saveDashboardCmd.Result.Id} dashFolder, err = getFolder(query) if err != nil {