From 7595ed066867d8dc0caab54acc7da14f64343024 Mon Sep 17 00:00:00 2001 From: Gabriel MABILLE Date: Fri, 7 Oct 2022 14:30:15 +0200 Subject: [PATCH] FIX: Remove RBAC datasource permissions upon datasource deletion (#56530) * FIX: Remove RBAC datasource permissions upon datasource deletion * Use scope provider instead * Fix test --- pkg/services/datasources/service/store.go | 2 +- pkg/services/datasources/service/store_test.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/services/datasources/service/store.go b/pkg/services/datasources/service/store.go index 17d1478fd20..e2a55cf12f8 100644 --- a/pkg/services/datasources/service/store.go +++ b/pkg/services/datasources/service/store.go @@ -144,7 +144,7 @@ func (ss *SqlStore) DeleteDataSource(ctx context.Context, cmd *datasources.Delet // Remove associated AccessControl permissions if _, errDeletingPerms := sess.Exec("DELETE FROM permission WHERE scope=?", - ac.Scope("datasources", "id", fmt.Sprint(dsQuery.Result.Id))); errDeletingPerms != nil { + ac.Scope(datasources.ScopeProvider.GetResourceScope(dsQuery.Result.Uid))); errDeletingPerms != nil { return errDeletingPerms } } diff --git a/pkg/services/datasources/service/store_test.go b/pkg/services/datasources/service/store_test.go index 3fa78eda363..a4348160470 100644 --- a/pkg/services/datasources/service/store_test.go +++ b/pkg/services/datasources/service/store_test.go @@ -3,7 +3,6 @@ package service import ( "context" "errors" - "fmt" "strconv" "testing" "time" @@ -319,7 +318,7 @@ func TestIntegrationDataAccess(t *testing.T) { _, err := sess.Table("permission").Insert(ac.Permission{ RoleID: 1, Action: "datasources:read", - Scope: ac.Scope("datasources", "id", fmt.Sprintf("%d", ds.Id)), + Scope: datasources.ScopeProvider.GetResourceScope(ds.Uid), Updated: time.Now(), Created: time.Now(), })