From 996df4fd3277c27066bf7f446f86a33fa3aba022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20Sander?= Date: Tue, 26 Nov 2024 22:03:18 +0100 Subject: [PATCH] feat(qseow): Add `--new-app-delete` option to `qseow field-scramble` command Implements last parts of #522 --- src/lib/cli/qseow-scramble-field.js | 21 +++++++++-------- src/lib/cmd/qseow/scramblefield.js | 36 +++++++++++++++++++++++++++++ src/lib/util/qseow/app.js | 2 +- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/lib/cli/qseow-scramble-field.js b/src/lib/cli/qseow-scramble-field.js index 4f64107..53c2afc 100644 --- a/src/lib/cli/qseow-scramble-field.js +++ b/src/lib/cli/qseow-scramble-field.js @@ -39,26 +39,29 @@ export function setupQseowScrambleFieldCommand(qseow) { .requiredOption('--app-id ', 'Qlik Sense app ID to be scrambled') .requiredOption('--field-name ', 'name of field(s) to be scrambled') .requiredOption('--new-app-name ', 'name of new app that will contain scrambled data. Not used if --new-app-cmd=replace') + .option( + '--new-app-delete', + 'should the new scrambled app be deleted after the operation is complete? If not, the new app will be placed in the My Work stream' + ) .addOption( new Option( '--new-app-cmd ', - 'what to do with the new app. If nothing is specified in this option the new app will be placed in My Work. WHen specifying "replace": If the replaced app is published, only the sheets that were originally published with the app are replaced. If the replaced app is not published, the entire app is replaced.' + 'what to do with the new app. If nothing is specified in this option the new app will be placed in My Work.\n"publish": publish the new app to the stream specified by --new-app-cmd-id or --new-app-cmd-name. The new app will NOT remain in My Work.\n"replace": Replace an existing published or unpublished app. If the app is published, only the sheets that were originally published with the app are replaced. If the replaced app is not published, the entire app is replaced.' ) - .choices(['publish', 'replace']) + .choices(['', 'publish', 'replace']) .default('') ) .addOption( - new Option('--new-app-cmd-id ', 'stream/app ID that --new-app-cmd acts on. Cannot be used with --new-app-cmd-name').default( - '' - ) + new Option('--new-app-cmd-id ', 'stream/app ID that --new-app-cmd acts on. Cannot be used with --new-app-cmd-name') + .default('') + .conflicts('new-app-cmd-name') ) .addOption( - new Option( - '--new-app-cmd-name ', - 'stream/app name that --new-app-cmd acts on. Cannot be used with --new-app-cmd-id' - ).default('') + new Option('--new-app-cmd-name ', 'stream/app name that --new-app-cmd acts on. Cannot be used with --new-app-cmd-id') + .default('') + .conflicts('new-app-cmd-id') ) .addOption(new Option('--force', 'force delete and replace operations to proceed without asking for confirmation')); diff --git a/src/lib/cmd/qseow/scramblefield.js b/src/lib/cmd/qseow/scramblefield.js index a68202c..bb642ab 100644 --- a/src/lib/cmd/qseow/scramblefield.js +++ b/src/lib/cmd/qseow/scramblefield.js @@ -338,6 +338,42 @@ export async function scrambleField(options) { } } } + + // Finally, should the new app be deleted? + // This is specified with the --new-app-delete option + if (options.newAppDelete) { + // Delete the new app + if (!options.force) { + const answer = await yesno({ + question: `Do you want to delete the new, scrambled app "${options.newAppName}" with app ID ${newAppId}? (y/n)`, + }); + + if (answer) { + const resultDelete = await deleteAppById(newAppId, options); + if (resultDelete) { + logger.info(`Deleted new, scrambled app "${options.newAppName}" with app ID ${newAppId}`); + scrambleResult.status = 'success'; + } else { + logger.error(`Error deleting new, scrambled app "${options.newAppName}" with app ID ${newAppId}`); + scrambleResult.status = 'error'; + } + } else { + logger.warn( + `Did not delete new, scrambled app "${options.newAppName}" with app ID ${newAppId}. The app is still available in My Work.` + ); + scrambleResult.status = 'aborted'; + } + } else { + const resultDelete = await deleteAppById(newAppId, options); + if (resultDelete) { + logger.info(`Deleted new, scrambled app "${options.newAppName}" with app ID ${newAppId}`); + scrambleResult.status = 'success'; + } else { + logger.error(`Error deleting new, scrambled app "${options.newAppName}" with app ID ${newAppId}`); + scrambleResult.status = 'error'; + } + } + } } // Return the result of the scramble operation diff --git a/src/lib/util/qseow/app.js b/src/lib/util/qseow/app.js index e0972f4..84e6454 100644 --- a/src/lib/util/qseow/app.js +++ b/src/lib/util/qseow/app.js @@ -161,7 +161,7 @@ export async function getAppById(appId, optionsParam) { return false; } catch (err) { - catchLog('GET APP BY ID', err); + // catchLog('GET APP BY ID', err); return false; } }