PanelLibrary: Adds delete Api (#29741)

* PanelLibrary: Adds delete

* Chore: fixes some comments

* Chore: changes after PR comments

* Refactor: deletes from correct org
This commit is contained in:
Hugo Häggmark
2020-12-11 06:08:32 +01:00
committed by GitHub
parent b3838d372e
commit 47afe1fa42
4 changed files with 144 additions and 53 deletions
+24 -1
View File
@@ -9,7 +9,7 @@ import (
"github.com/grafana/grafana/pkg/services/sqlstore"
)
// createLibraryPanel function adds a LibraryPanel
// createLibraryPanel function adds a Library Panel
func (lps *LibraryPanelService) createLibraryPanel(c *models.ReqContext, cmd addLibraryPanelCommand) (LibraryPanel, error) {
libraryPanel := LibraryPanel{
OrgID: c.SignedInUser.OrgId,
@@ -39,3 +39,26 @@ func (lps *LibraryPanelService) createLibraryPanel(c *models.ReqContext, cmd add
return libraryPanel, err
}
// deleteLibraryPanel function deletes a Library Panel
func (lps *LibraryPanelService) deleteLibraryPanel(c *models.ReqContext, panelID int64) error {
orgID := c.SignedInUser.OrgId
err := lps.SQLStore.WithTransactionalDbSession(context.Background(), func(session *sqlstore.DBSession) error {
result, err := session.Exec("DELETE FROM library_panel WHERE id=? and org_id=?", panelID, orgID)
if err != nil {
return err
}
if rowsAffected, err := result.RowsAffected(); err != nil {
return err
} else if rowsAffected != 1 {
return errLibraryPanelNotFound
}
return nil
})
return err
}