Skip to content

Commit

Permalink
(HP-2023) Added deleteProfile action
Browse files Browse the repository at this point in the history
  • Loading branch information
NikoHelle committed Oct 14, 2023
1 parent c6cccda commit d2578b8
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 22 deletions.
94 changes: 94 additions & 0 deletions src/gdprApi/actions/deleteProfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { loader } from 'graphql.macro';
import to from 'await-to-js';

import {
ActionExecutor,
ActionProps,
QueueController,
getData,
} from '../../common/actionQueue/actionQueue';
import graphqlClient from '../../graphql/client';
import {
DeleteMyProfileMutationInput,
GdprDeleteMyProfileMutation,
GdprDeleteMyProfileMutationVariables,
TranslationLanguage,
} from '../../graphql/generatedTypes';
import { Mutable } from '../../graphql/typings';
import { getActionResultAndErrorMessage } from './utils';
import {
getStoredKeycloakAuthCode,
getStoredTunnistamoAuthCode,
} from './authCodeParser';

const DELETE_PROFILE = loader('../graphql/GdprDeleteMyProfileMutation.graphql');

const deleteProfileType = 'deleteProfile';

export const getDeleteProfileResult = (queueController: QueueController) =>
getActionResultAndErrorMessage<boolean>(deleteProfileType, queueController)
.result;

const deleteProfileExecutor: ActionExecutor = async (
action,
queueController
) => {
const authorizationCode = getStoredTunnistamoAuthCode(queueController);
const authorizationCodeKeycloak = getStoredKeycloakAuthCode(queueController);
if (!authorizationCode) {
return Promise.reject('No tunnistamo authorization code');
}
const language = getData(action, 'language') as TranslationLanguage;
const input: Mutable<DeleteMyProfileMutationInput> = {
authorizationCode,
dryRun: true,
};
if (typeof authorizationCodeKeycloak === 'string') {
input.authorizationCodeKeycloak = authorizationCodeKeycloak;
}
const [error, result] = await to(
graphqlClient.mutate<
GdprDeleteMyProfileMutation,
GdprDeleteMyProfileMutationVariables
>({
mutation: DELETE_PROFILE,
fetchPolicy: 'no-cache',
variables: {
input,
language,
},
})
);
if (error) {
return Promise.reject(error);
}
/*
const { failures, successful } = parseDeleteProfileResult(returnedData);
if (!failures.length) {
trackEvent({ category: 'action', action: 'Delete profile' });
history.push('/profile-deleted');
} else {
setResultError({ failures, successful });
}
*/
if (!result || !result.data) {
return Promise.reject(new Error('Delete profile failed'));
}
return Promise.resolve(true);
};

export function createDeleteProfileAction(
language: TranslationLanguage
): ActionProps {
return {
type: deleteProfileType,
executor: deleteProfileExecutor,
options: {
noStorage: true,
idleWhenActive: true,
data: {
language,
},
},
};
}
48 changes: 26 additions & 22 deletions src/gdprApi/actions/queues.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TranslationLanguage } from '../../graphql/generatedTypes';
import {
tunnistamoAuthCodeCallbackUrlAction,
keycloakAuthCodeCallbackUrlAction,
Expand All @@ -14,6 +15,7 @@ import {
tunnistamoRedirectionInitializationAction,
keycloakRedirectionInitializationAction,
} from './authCodeRedirectionInitialization';
import { createDeleteProfileAction } from './deleteProfile';
import { createDeleteServiceConnectionAction } from './deleteServiceConnection';
import { downloadAsFileAction } from './downloadAsFile';
import { getDownloadDataAction } from './getDownloadData';
Expand Down Expand Up @@ -45,21 +47,24 @@ export function getQueue({
catcherAction,
] = createRedirectorAndCatcherActionProps(startPagePath);
const infoAction = createQueueInfoAction(queueName);
const commonAuthCodeActions = [
tunnistamoRedirectionInitializationAction,
tunnistamoAuthCodeRedirectionAction,
tunnistamoAuthCodeCallbackUrlAction,
tunnistamoAuthCodeParserAction,
loadKeycloakConfigAction,
keycloakRedirectionInitializationAction,
keycloakAuthCodeRedirectionAction,
keycloakAuthCodeCallbackUrlAction,
keycloakAuthCodeParserAction,
redirectorAction,
catcherAction,
];
if (queueName === 'downloadProfile') {
return [
getServiceConnectionsAction,
getGdprQueryScopesAction,
tunnistamoRedirectionInitializationAction,
tunnistamoAuthCodeRedirectionAction,
tunnistamoAuthCodeCallbackUrlAction,
tunnistamoAuthCodeParserAction,
loadKeycloakConfigAction,
keycloakRedirectionInitializationAction,
keycloakAuthCodeRedirectionAction,
keycloakAuthCodeCallbackUrlAction,
keycloakAuthCodeParserAction,
redirectorAction,
catcherAction,
...commonAuthCodeActions,
getDownloadDataAction,
downloadAsFileAction,
infoAction,
Expand All @@ -72,20 +77,19 @@ export function getQueue({
return [
createActionForGettingSpecificServiceConnection(serviceName),
getGdprDeleteScopesAction,
tunnistamoRedirectionInitializationAction,
tunnistamoAuthCodeRedirectionAction,
tunnistamoAuthCodeCallbackUrlAction,
tunnistamoAuthCodeParserAction,
loadKeycloakConfigAction,
keycloakRedirectionInitializationAction,
keycloakAuthCodeRedirectionAction,
keycloakAuthCodeCallbackUrlAction,
keycloakAuthCodeParserAction,
redirectorAction,
catcherAction,
...commonAuthCodeActions,
createDeleteServiceConnectionAction(serviceName),
infoAction,
];
}
if (queueName === 'deleteProfile') {
return [
getServiceConnectionsAction,
getGdprDeleteScopesAction,
...commonAuthCodeActions,
createDeleteProfileAction('FI' as TranslationLanguage),
infoAction,
];
}
return [];
}

0 comments on commit d2578b8

Please sign in to comment.