Skip to content

Commit

Permalink
[Issue Tracker] Redirect and error warning fixes (aces#7323)
Browse files Browse the repository at this point in the history
Fixes aces#7320 
Fixes aces#7321
  • Loading branch information
laemtl authored and AlexandraLivadas committed Jun 29, 2021
1 parent f336fe3 commit e34d62b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
5 changes: 4 additions & 1 deletion modules/issue_tracker/ajax/EditIssue.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,17 @@ function editIssue()
// Attachment for new issue.
if (isset($_FILES['file'])) {
$attachment = new \LORIS\issue_tracker\UploadHelper();
$attachment->setupUploading(
$success = $attachment->setupUploading(
$user,
$_FILES,
[
'fileDescription' => '',
'issueID' => $issueID,
]
);
if (!$success) {
showError($attachment->errorMessage);
}
}

// Adding new assignee to watching
Expand Down
15 changes: 13 additions & 2 deletions modules/issue_tracker/jsx/IssueForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ class IssueForm extends Component {
}).then((response) => {
if (!response.ok) {
console.error(response.status);
this.setState({
error: 'An error occurred when loading the form!\n Error: ' +
response.status + ' (' + response.statusText + ')',
});
return;
}

Expand Down Expand Up @@ -384,6 +388,7 @@ class IssueForm extends Component {
}
);
}).catch((error) => {
// Network error
console.error(error);
this.setState({
loadError: 'An error occurred when loading the form!',
Expand Down Expand Up @@ -428,6 +433,12 @@ class IssueForm extends Component {
}).then((response) => {
if (!response.ok) {
console.error(response.status);
response.json().then((data) => {
this.setState({submissionResult: 'error'});
let msgType = 'error';
let message = data.message || 'Failed to submit issue :(';
this.showAlertMessage(msgType, message);
});
return;
}

Expand All @@ -443,8 +454,8 @@ class IssueForm extends Component {
});
});
}).catch((error) => {
// Network error
console.error(error);

this.setState({submissionResult: 'error'});
let msgType = 'error';
let message = 'Failed to submit issue :(';
Expand Down Expand Up @@ -540,7 +551,7 @@ class IssueForm extends Component {
allowOutsideClick: false,
allowEscapeKey: false,
showConfirmButton: confirmation,
}, callback.bind(this));
}).then(callback.bind(this));
}
}

Expand Down
35 changes: 19 additions & 16 deletions modules/issue_tracker/php/uploadhelper.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,29 @@ class UploadHelper
*/
private $_values;

/**
* The error message if something fails.
*/
public $errorMessage;

/**
* Setup uploading configurations.
*
* @param \User $user The user uploading.
* @param array $files The $_FILES array content.
* @param array $values The post message array content.
*
* @return array (success|error) with a message for the frontend.
* @return boolean success/fail
*/
function setupUploading(\User $user, array $files, array $values) : array
function setupUploading(\User $user, array $files, array $values) : bool
{
// Check if post.ini max_post configured for the file_size.
if (!isset($files['file']['tmp_name'])
|| empty($files['file']['tmp_name'])
) {
return [
'error' =>
'The server is not configured to receive a file this large.'
];
$this->errorMessage
= 'The server is not configured to receive a file this large.';
return false;
}
$this->_user = $user;
$this->_bytes = $files['file']['size'];
Expand All @@ -83,14 +87,16 @@ class UploadHelper
'description' => $this->_values['fileDescription'] ?? '',
];

$this->setFullPath($this->_fileToUpload);
if (!$this->setFullPath($this->_fileToUpload)) {
$this->errorMessage = 'The server is not configured for attachments';
return false;
}

$DB = \NDB_Factory::singleton()->database();
$DB->beginTransaction();
$this->registerFile($this->_fileToUpload);
$this->endWithSuccess();

return ['success' => true];
return true;
}

/**
Expand All @@ -99,10 +105,9 @@ class UploadHelper
*
* @param object $fileToUpload The file to upload
*
* @return void
* @throws \LorisException
* @return boolean success/fail
*/
function setFullPath(Object &$fileToUpload) : void
function setFullPath(Object &$fileToUpload) : bool
{
$factory = \NDB_Factory::singleton();
$config = $factory->config();
Expand All @@ -119,11 +124,9 @@ class UploadHelper
if (!is_dir($fileToUpload->full_path)) {
mkdir($fileToUpload->full_path, 0770, true);
}
} else {
throw new \LorisException(
'Issue_Tracker attachments directory not writable.'
);
return true;
}
return false;

}

Expand Down

0 comments on commit e34d62b

Please sign in to comment.