From a2403663a19b9838cb5e24a57d4a084316105b0e Mon Sep 17 00:00:00 2001 From: Erik Hanson Date: Wed, 11 Dec 2024 15:18:42 -0800 Subject: [PATCH] WIP: Add ORCID OAuth verification to invitation workflow --- .../AcceptInvitationPageStore.js | 67 ++++++++++++++++++- .../AcceptInvitationVerifyOrcid.vue | 35 ++++++++-- 2 files changed, 93 insertions(+), 9 deletions(-) diff --git a/src/pages/acceptInvitation/AcceptInvitationPageStore.js b/src/pages/acceptInvitation/AcceptInvitationPageStore.js index 41512997f..da74b0c83 100644 --- a/src/pages/acceptInvitation/AcceptInvitationPageStore.js +++ b/src/pages/acceptInvitation/AcceptInvitationPageStore.js @@ -86,7 +86,33 @@ export const useAcceptInvitationPageStore = defineComponentStore( updateAcceptInvitationPayload('affiliation', data.value.affiliation); } updateAcceptInvitationPayload('userCountry', data.value.country); - updateAcceptInvitationPayload('userOrcid', data.value.orcid); + + updateAcceptInvitationPayload('orcid', data.value.orcid); + updateAcceptInvitationPayload( + 'orcidIsVerified', + data.value.orcidIsVerified, + ); + updateAcceptInvitationPayload( + 'orcidAccessDenied', + data.value.orcidAccessDenied, + ); + updateAcceptInvitationPayload( + 'orcidAccessToken', + data.value.orcidAccessToken, + ); + updateAcceptInvitationPayload( + 'orcidAccessScope', + data.value.orcidAccessScope, + ); + updateAcceptInvitationPayload( + 'orcidRefreshToken', + data.value.orcidRefreshToken, + ); + updateAcceptInvitationPayload( + 'orcidAccessExpiresOn', + data.value.orcidAccessExpiresOn, + ); + updateAcceptInvitationPayload( 'userGroupsToAdd', data.value.userGroupsToAdd, @@ -110,6 +136,37 @@ export const useAcceptInvitationPageStore = defineComponentStore( acceptInvitationPayload.value[fieldName] = value; } + /** + * Sets ORCID data in invitation payload. If data is null, all ORCID related fields will be set to null/zero value. + * + * @param {Object|null} data - The ORCID OAuth data object. + * @param {string} data.orcid - The ORCID URL of the user. + * @param {boolean} data.orcidIsVerified - Indicates if the user's ORCID is verified. + * @param {null|string} data.orcidAccessDenied - Indicates if access to ORCID is denied (null if not denied). + * @param {string} data.orcidAccessToken - The access token for ORCID API. + * @param {string} data.orcidAccessScope - The scope of access for the ORCID API. + * @param {string} data.orcidRefreshToken - The refresh token for obtaining new access tokens. + * @param {string} data.orcidAccessExpiresOn - The expiration date and time of the access token in ISO format. + * @param data + */ + function setOrcidData(data) { + const fields = [ + 'orcid', + 'orcidIsVerified', + 'orcidAccessDenied', + 'orcidAccessToken', + 'orcidAccessScope', + 'orcidRefreshToken', + 'orcidAccessExpiresOn', + ]; + const isDataNull = data === null; + fields.forEach((fieldName) => { + acceptInvitationPayload.value[fieldName] = isDataNull + ? null + : data[fieldName]; + }); + } + /** Steps */ const currentStepId = ref( pageInitConfig.steps[0] ? pageInitConfig.steps[0].id : '', @@ -314,7 +371,12 @@ export const useAcceptInvitationPageStore = defineComponentStore( method: 'PUT', body: {invitationData: invitationRequestPayload.value}, }); - if (!acceptInvitationPayload.value.privacyStatement) { + // FIXME: Privacy statement check blocks ORCID from saving before hand. + // Can this check be moved outside of update payload check? + if ( + !acceptInvitationPayload.value.privacyStatement && + currentStep.value.id !== 'verifyOrcid' + ) { errors.value = { privacyStatement: [t('acceptInvitation.privacyStatement.validation')], }; @@ -431,6 +493,7 @@ export const useAcceptInvitationPageStore = defineComponentStore( //methods nextStep, previousStep, + setOrcidData, updateAcceptInvitationPayload, cancel, diff --git a/src/pages/acceptInvitation/AcceptInvitationVerifyOrcid.vue b/src/pages/acceptInvitation/AcceptInvitationVerifyOrcid.vue index f780e356b..8edfaff30 100644 --- a/src/pages/acceptInvitation/AcceptInvitationVerifyOrcid.vue +++ b/src/pages/acceptInvitation/AcceptInvitationVerifyOrcid.vue @@ -15,7 +15,7 @@