| 586 | } |
| 587 | |
| 588 | func DeleteTaskPluginVersion(c *gin.Context) { |
| 589 | key := c.Param("key") |
| 590 | version := c.Param("version") |
| 591 | plugin, lookupErr := model.GetTaskPluginVersion(key, version) |
| 592 | if lookupErr != nil { |
| 593 | if errors.Is(lookupErr, gorm.ErrRecordNotFound) { |
| 594 | common.ApiErrorMsg(c, "override plugin version not found; factory plugins cannot be deleted") |
| 595 | return |
| 596 | } |
| 597 | common.ApiError(c, lookupErr) |
| 598 | return |
| 599 | } |
| 600 | if plugin.Active { |
| 601 | versions, err := model.ListTaskPluginVersions(key) |
| 602 | if err != nil { |
| 603 | common.ApiError(c, err) |
| 604 | return |
| 605 | } |
| 606 | // Deleting the active version promotes the newest remaining one, in |
| 607 | // the order model.DeleteTaskPluginVersion uses. When that one is |
| 608 | // switched off or none is left, a version that was serving hands the |
| 609 | // key back to the factory built-in. |
| 610 | var promoted *model.TaskPlugin |
| 611 | for i := range versions { |
| 612 | if versions[i].Version != version { |
| 613 | promoted = &versions[i] |
| 614 | break |
| 615 | } |
| 616 | } |
| 617 | switch { |
| 618 | case promoted != nil && promoted.Enabled: |
| 619 | if rejectTaskPluginRoutingConflict(c, key, promoted) { |
| 620 | return |
| 621 | } |
| 622 | case plugin.Enabled && !setting.IsTaskPluginFactoryDisabled(key): |
| 623 | if rejectTaskPluginRoutingConflict(c, key, nil) { |
| 624 | return |
| 625 | } |
| 626 | } |
| 627 | } |
| 628 | if plugin.Active && !taskPluginHasFactory(key) { |
| 629 | channels, inFlight, usageErr := model.GetTaskPluginUsage(key) |
| 630 | if usageErr != nil { |
| 631 | common.ApiError(c, usageErr) |
| 632 | return |
| 633 | } |
| 634 | if (len(channels) > 0 || inFlight > 0) && c.Query("force") != "true" { |
| 635 | c.JSON(200, gin.H{"success": false, "message": "task plugin is still in use", "data": gin.H{"channels": channels, "in_flight_count": inFlight}}) |
| 636 | return |
| 637 | } |
| 638 | } |
| 639 | _, err := model.DeleteTaskPluginVersion(key, version) |
| 640 | if err != nil { |
| 641 | if errors.Is(err, gorm.ErrRecordNotFound) { |
| 642 | common.ApiErrorMsg(c, "override plugin version not found; factory plugins cannot be deleted") |
| 643 | return |
| 644 | } |
| 645 | common.ApiError(c, err) |