Przeglądaj źródła

Merge branch 'dashboard_folders' of github.com:grafana/grafana into dashboard_folders

Torkel Ödegaard 8 lat temu
rodzic
commit
212a66ae5f

+ 2 - 2
pkg/api/dashboard_acl.go

@@ -27,7 +27,7 @@ func GetDashboardAclList(c *middleware.Context) Response {
 }
 }
 
 
 func PostDashboardAcl(c *middleware.Context, cmd m.SetDashboardAclCommand) Response {
 func PostDashboardAcl(c *middleware.Context, cmd m.SetDashboardAclCommand) Response {
-	dashId := c.ParamsInt64(":id")
+	dashId := c.ParamsInt64(":dashboardId")
 
 
 	guardian := guardian.NewDashboardGuardian(dashId, c.OrgId, c.SignedInUser)
 	guardian := guardian.NewDashboardGuardian(dashId, c.OrgId, c.SignedInUser)
 	if canSave, err := guardian.CanSave(); err != nil || !canSave {
 	if canSave, err := guardian.CanSave(); err != nil || !canSave {
@@ -38,7 +38,7 @@ func PostDashboardAcl(c *middleware.Context, cmd m.SetDashboardAclCommand) Respo
 	cmd.DashboardId = dashId
 	cmd.DashboardId = dashId
 
 
 	if err := bus.Dispatch(&cmd); err != nil {
 	if err := bus.Dispatch(&cmd); err != nil {
-		if err == m.ErrDashboardAclInfoMissing {
+		if err == m.ErrDashboardAclInfoMissing || err == m.ErrDashboardPermissionDashboardEmpty {
 			return ApiError(409, err.Error(), err)
 			return ApiError(409, err.Error(), err)
 		}
 		}
 		return ApiError(500, "Failed to create permission", err)
 		return ApiError(500, "Failed to create permission", err)

+ 2 - 1
pkg/models/dashboard_acl.go

@@ -24,7 +24,8 @@ func (p PermissionType) String() string {
 
 
 // Typed errors
 // Typed errors
 var (
 var (
-	ErrDashboardAclInfoMissing = errors.New("User id and user group id cannot both be empty for a dashboard permission.")
+	ErrDashboardAclInfoMissing           = errors.New("User id and user group id cannot both be empty for a dashboard permission.")
+	ErrDashboardPermissionDashboardEmpty = errors.New("Dashboard Id must be greater than zero for a dashboard permission.")
 )
 )
 
 
 // Dashboard ACL model
 // Dashboard ACL model

+ 4 - 0
pkg/services/sqlstore/dashboard_acl.go

@@ -20,6 +20,10 @@ func SetDashboardAcl(cmd *m.SetDashboardAclCommand) error {
 			return m.ErrDashboardAclInfoMissing
 			return m.ErrDashboardAclInfoMissing
 		}
 		}
 
 
+		if cmd.DashboardId == 0 {
+			return m.ErrDashboardPermissionDashboardEmpty
+		}
+
 		if res, err := sess.Query("SELECT 1 from "+dialect.Quote("dashboard_acl")+" WHERE dashboard_id =? and (user_group_id=? or user_id=?)", cmd.DashboardId, cmd.UserGroupId, cmd.UserId); err != nil {
 		if res, err := sess.Query("SELECT 1 from "+dialect.Quote("dashboard_acl")+" WHERE dashboard_id =? and (user_group_id=? or user_id=?)", cmd.DashboardId, cmd.UserGroupId, cmd.UserId); err != nil {
 			return err
 			return err
 		} else if len(res) == 1 {
 		} else if len(res) == 1 {