From f35b8174aa9b3f41f6a91275970c9e93646ea5e2 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 11 Oct 2020 11:11:20 -0700 Subject: [PATCH] Re-saving edited providers will forcibly save them --- .../Creators/createSaveProviderHandler.js | 24 +++++++++++++------ src/Sonarr.Api.V3/ProviderModuleBase.cs | 7 +++--- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/frontend/src/Store/Actions/Creators/createSaveProviderHandler.js b/frontend/src/Store/Actions/Creators/createSaveProviderHandler.js index 6d555bf23..5761655d2 100644 --- a/frontend/src/Store/Actions/Creators/createSaveProviderHandler.js +++ b/frontend/src/Store/Actions/Creators/createSaveProviderHandler.js @@ -1,10 +1,12 @@ import $ from 'jquery'; +import _ from 'lodash'; import { batchActions } from 'redux-batched-actions'; import createAjaxRequest from 'Utilities/createAjaxRequest'; import getProviderState from 'Utilities/State/getProviderState'; import { set, updateItem } from '../baseActions'; const abortCurrentRequests = {}; +let lastSaveData = null; export function createCancelSaveProviderHandler(section) { return function(getState, payload, dispatch) { @@ -26,25 +28,33 @@ function createSaveProviderHandler(section, url, options = {}) { } = payload; const saveData = getProviderState({ id, ...otherPayload }, getState, section); + const requestUrl = id ? `${url}/${id}` : url; + const params = { ...queryParams }; + + // If the user is re-saving the same provider without changes + // force it to be saved. Only applies to editing existing providers. + + if (id && _.isEqual(saveData, lastSaveData)) { + params.forceSave = true; + } + + lastSaveData = saveData; const ajaxOptions = { - url: `${url}?${$.param(queryParams, true)}`, - method: 'POST', + url: `${requestUrl}?${$.param(params, true)}`, + method: id ? 'PUT' : 'POST', contentType: 'application/json', dataType: 'json', data: JSON.stringify(saveData) }; - if (id) { - ajaxOptions.url = `${url}/${id}?${$.param(queryParams, true)}`; - ajaxOptions.method = 'PUT'; - } - const { request, abortRequest } = createAjaxRequest(ajaxOptions); abortCurrentRequests[section] = abortRequest; request.done((data) => { + lastSaveData = null; + dispatch(batchActions([ updateItem({ section, ...data }), diff --git a/src/Sonarr.Api.V3/ProviderModuleBase.cs b/src/Sonarr.Api.V3/ProviderModuleBase.cs index 060d024c3..a96faace1 100644 --- a/src/Sonarr.Api.V3/ProviderModuleBase.cs +++ b/src/Sonarr.Api.V3/ProviderModuleBase.cs @@ -7,6 +7,7 @@ using NzbDrone.Common.Serializer; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Validation; using Sonarr.Http; +using Sonarr.Http.Extensions; namespace Sonarr.Api.V3 { @@ -84,10 +85,10 @@ namespace Sonarr.Api.V3 private void UpdateProvider(TProviderResource providerResource) { var providerDefinition = GetDefinition(providerResource, false); - var existingDefinition = _providerFactory.Get(providerDefinition.Id); + var forceSave = Request.GetBooleanQueryParameter("forceSave"); - // Only test existing definitions if it was previously disabled - if (providerDefinition.Enable && !existingDefinition.Enable) + // Only test existing definitions if it is enabled and forceSave isn't set. + if (providerDefinition.Enable && !forceSave) { Test(providerDefinition, false); }