Browse Source

folder: uses service to make user admin of created folder.

Leonard Gram 6 years ago
parent
commit
da3dcd1918
2 changed files with 5 additions and 40 deletions
  1. 5 0
      pkg/api/folder.go
  2. 0 40
      pkg/services/dashboards/folder_service.go

+ 5 - 0
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))
 }

+ 0 - 40
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 {