mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
LibraryElements: Delete invalid connections before deleting element (#50519)
This commit is contained in:
parent
7ef21662f9
commit
189b7f9c0b
@ -27,6 +27,8 @@ SELECT DISTINCT
|
||||
, (SELECT COUNT(connection_id) FROM ` + models.LibraryElementConnectionTableName + ` WHERE element_id = le.id AND kind=1) AS connected_dashboards`
|
||||
)
|
||||
|
||||
const deleteInvalidConnections = "DELETE FROM library_element_connection WHERE connection_id IN (SELECT connection_id as id FROM library_element_connection WHERE element_id=? EXCEPT SELECT id from dashboard)"
|
||||
|
||||
func getFromLibraryElementDTOWithMeta(dialect migrator.Dialect) string {
|
||||
user := dialect.Quote("user")
|
||||
userJoin := `
|
||||
@ -179,6 +181,12 @@ func (l *LibraryElementService) deleteLibraryElement(c context.Context, signedIn
|
||||
if err := l.requireEditPermissionsOnFolder(c, signedInUser, element.FolderID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete any hanging/invalid connections
|
||||
if _, err = session.Exec(deleteInvalidConnections, element.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var connectionIDs []struct {
|
||||
ConnectionID int64 `xorm:"connection_id"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user