Require confirmation and block deleting library actions still referenced by node groups.
This commit is contained in:
@@ -49,6 +49,7 @@ var (
|
||||
errActionIDRequired = errors.New("action id is required")
|
||||
errActionWidgetTypeNeeded = errors.New("widget_type is required when show_widget is true")
|
||||
errActionWidgetTypeBad = errors.New("widget_type must be memory, disk, or raw")
|
||||
errActionInUse = errors.New("action is used by node action groups; remove or clone to customize first")
|
||||
)
|
||||
|
||||
func actionsGetHandler(configDir string) http.HandlerFunc {
|
||||
@@ -221,6 +222,16 @@ func actionsDeleteHandler(configDir string) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
groups, err := settings.LoadNodeActionGroupsOrEmpty(configDir)
|
||||
if err != nil {
|
||||
writeJSON(writer, http.StatusInternalServerError, apiErrorResponse{Error: err.Error()})
|
||||
return
|
||||
}
|
||||
if settings.LibraryActionInUse(groups, actionID) {
|
||||
writeJSON(writer, http.StatusConflict, apiErrorResponse{Error: errActionInUse.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
store.Actions = append(store.Actions[:index], store.Actions[index+1:]...)
|
||||
if err := settings.SaveActions(configDir, store); err != nil {
|
||||
writeJSON(writer, http.StatusInternalServerError, apiErrorResponse{Error: err.Error()})
|
||||
|
||||
Reference in New Issue
Block a user