From 3d53b0570a0eec52fb3d08135a4091eb6ca606fd Mon Sep 17 00:00:00 2001 From: Saagar Arya <51128536+skarya22@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:57:46 -0400 Subject: [PATCH] [Publication] Fix baseurl missing from emails (#9186) -The loris baseURL is now sent from the react pages to the ajax scripts on submit for both editing and uploading a new publication, and then is sent in the email. - I did it this way as \NDB_Factory::singleton()->settings()->getBaseURL() does not work in ajax files, and since it is deprecated it made more sense to do a hotfix rather than investigating the issue with ajax. - This was noticed and fixed for files in php folders in PR#7807, however that same fix does not work for ajax. Thankfully publication is the only module with ajax still that uses getBaseUrl(). Resolves #9132 --- modules/publication/ajax/FileUpload.php | 16 ++++++++-------- modules/publication/jsx/uploadForm.js | 5 ++++- modules/publication/jsx/viewProject.js | 6 +++++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/modules/publication/ajax/FileUpload.php b/modules/publication/ajax/FileUpload.php index 9cec2979205..382e8dca285 100644 --- a/modules/publication/ajax/FileUpload.php +++ b/modules/publication/ajax/FileUpload.php @@ -138,7 +138,7 @@ function uploadPublication() : void showPublicationError($e->getMessage(), 500); } - notify($pubID, 'submission'); + notify($pubID, 'submission', $_POST['baseURL']); } /** @@ -426,12 +426,13 @@ function cleanup(int $pubID) : void /** * Send out email notifications for project submission * - * @param int $pubID publication ID - * @param string $type The notification type i.e., submission|edit|review + * @param int $pubID publication ID + * @param string $type The notification type i.e., submission|edit|review + * @param string $baseURL the base URL of the loris site * * @return void */ -function notify($pubID, $type) : void +function notify($pubID, $type, $baseURL) : void { $acceptedTypes = [ 'submission', @@ -464,12 +465,11 @@ function notify($pubID, $type) : void ); throw new \LorisException('Invalid publication ID specified.'); } - $url = \NDB_Factory::singleton()->settings()->getBaseURL(); $emailData['Title'] = $data['Title']; $emailData['Date'] = $data['DateProposed']; $emailData['User'] = $user->getFullname(); - $emailData['URL'] = $url . '/publication/view_project/?id='.$pubID; + $emailData['URL'] = $baseURL . '/publication/view_project/?id='.$pubID; $emailData['ProjectName'] = $config->getSetting('prefix'); $Notifier = new \NDB_Notifier( "publication", @@ -618,10 +618,10 @@ function editProject() : void processFiles($id); // if publication status is changed, send review email if (isset($toUpdate['PublicationStatusID'])) { - notify($id, 'review'); + notify($id, 'review', $_POST['baseURL']); } else { // otherwise send edit email - notify($id, 'edit'); + notify($id, 'edit', $_POST['baseURL']); } if (!empty($toUpdate)) { $db->update( diff --git a/modules/publication/jsx/uploadForm.js b/modules/publication/jsx/uploadForm.js index 17a4a1184b8..0ca0502d804 100644 --- a/modules/publication/jsx/uploadForm.js +++ b/modules/publication/jsx/uploadForm.js @@ -166,7 +166,10 @@ class PublicationUploadForm extends React.Component { ); return; } - let formData = this.state.formData; + let formData = { + ...this.state.formData, + baseURL: loris.BaseURL, + }; let formObj = new FormData(); for (let key in formData) { diff --git a/modules/publication/jsx/viewProject.js b/modules/publication/jsx/viewProject.js index de4678d306b..94548bcb9c6 100644 --- a/modules/publication/jsx/viewProject.js +++ b/modules/publication/jsx/viewProject.js @@ -54,7 +54,11 @@ class ViewProject extends React.Component { ); return; } - let formData = this.state.formData; + let formData = { + ...this.state.formData, + baseURL: loris.BaseURL, + }; + let formObj = new FormData(); for (let key in formData) { if (formData.hasOwnProperty(key) && formData[key] !== '') {