Skip to content

Commit

Permalink
[Publication] Fix baseurl missing from emails (#9186)
Browse files Browse the repository at this point in the history
-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
  • Loading branch information
skarya22 authored Apr 16, 2024
1 parent f111b9c commit 3d53b05
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
16 changes: 8 additions & 8 deletions modules/publication/ajax/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function uploadPublication() : void
showPublicationError($e->getMessage(), 500);
}

notify($pubID, 'submission');
notify($pubID, 'submission', $_POST['baseURL']);
}

/**
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion modules/publication/jsx/uploadForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion modules/publication/jsx/viewProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] !== '') {
Expand Down

0 comments on commit 3d53b05

Please # to comment.