From 73366ff84c29e9751531dbb71c505ab9e06a2eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Manuel=20Mari=C3=B1as=20Bascoy?= Date: Tue, 21 Nov 2023 12:41:28 +0100 Subject: [PATCH] refactor conditions in validateUpdatePluginProposalActions --- modules/client/src/internal/utils.ts | 34 +++++++++++++++++----------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/modules/client/src/internal/utils.ts b/modules/client/src/internal/utils.ts index 894e04a11..cf72d6855 100644 --- a/modules/client/src/internal/utils.ts +++ b/modules/client/src/internal/utils.ts @@ -1550,7 +1550,16 @@ export async function validateUpdatePluginProposalActions( ...recCauses.proposalSettingsErrorCauses, ]; } - } else if (isPluginUpdateActionWithRootPermission(classifiedActions)) { + return { + // every item in the array should be empty + isValid: actionErrorCauses.every((cause) => cause.length === 0) && + proposalSettingsErrorCauses.length === 0, + actionErrorCauses, + proposalSettingsErrorCauses, + }; + } + + if (isPluginUpdateActionWithRootPermission(classifiedActions)) { // initialize the causes array // we always use the index 0 // because this is going to be called recursively @@ -1640,22 +1649,21 @@ export async function validateUpdatePluginProposalActions( ...recCauses.proposalSettingsErrorCauses, ]; } - } else { - // add invalid actions to the causes array - // return, if this is inside the recursion - // it will be added to the array return { - isValid: false, - proposalSettingsErrorCauses: [ProposalSettingsErrorCause.INVALID_ACTIONS], - actionErrorCauses: actionErrorCauses, + // every item in the array should be empty + isValid: actionErrorCauses.every((cause) => cause.length === 0) && + proposalSettingsErrorCauses.length === 0, + actionErrorCauses, + proposalSettingsErrorCauses, }; } + // add invalid actions to the causes array + // return, if this is inside the recursion + // it will be added to the array return { - // every item in the array should be empty - isValid: actionErrorCauses.every((cause) => cause.length === 0) && - proposalSettingsErrorCauses.length === 0, - actionErrorCauses, - proposalSettingsErrorCauses, + isValid: false, + proposalSettingsErrorCauses: [ProposalSettingsErrorCause.INVALID_ACTIONS], + actionErrorCauses: actionErrorCauses, }; }