Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue Tracker] Redirect and error warning fixes #7323

Merged
merged 6 commits into from
Feb 9, 2021

Conversation

laemtl
Copy link
Contributor

@laemtl laemtl commented Feb 4, 2021

Fixes to address the comments on #7315

@laemtl
Copy link
Contributor Author

laemtl commented Feb 4, 2021

@maltheism I addressed your comments :)

Copy link
Member

@maltheism maltheism left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @laemtl, can you change the ajax/EditIssue.php to be the following:

    // Attachment for new issue.
    if (isset($_FILES['file'])) {
        $attachment = new \LORIS\issue_tracker\UploadHelper();
        $success = $attachment->setupUploading(
            $user,
            $_FILES,
            [
                'fileDescription' => '',
                'issueID'         => $issueID,
            ]
        );
        if (!$success) {
            showError($attachment->errorMessage);
        }
    }

the uploadhelper.class.inc

/**
     * 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 boolean success/fail
     *
     */
    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'])
        ) {
            $this->errorMessage = 'The server is not configured to receive a file this large.';
            return false;
        }
        $this->_user   = $user;
        $this->_bytes  = $files['file']['size'];
        $this->_values = $values;

        $this->_fileToUpload
            = (object) [
                'file'        => $files['file']['name'],
                'file_hash'   => $this->generateHash($files['file']['tmp_name']),
                'mime_type'   => $this->getFileMimeType($files['file']['name']),
                'tmp_name'    => $files['file']['tmp_name'],
                'size'        => $this->_bytes,
                'inserted_by' => $this->_user->getData('UserID'),
                'description' => $this->_values['fileDescription'] ?? '',
            ];

        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 true;
    }

...

/**
     * Sets $fileToUpload->full_path to be the full path
     * of where the attachment file will be stored.
     *
     * @param object $fileToUpload The file to upload
     *
     * @return boolean success/fail
     */
    function setFullPath(Object &$fileToUpload) : bool
    {
        $factory = \NDB_Factory::singleton();
        $config  = $factory->config();
        $attachment_data_dir = trim(
            rtrim(
                $config->getSetting('IssueTrackerDataPath'),
                '/'
            )
        );

        if (is_writable($attachment_data_dir)) {
            $fileToUpload->full_path = $attachment_data_dir .
                                       '/attachments';
            if (!is_dir($fileToUpload->full_path)) {
                mkdir($fileToUpload->full_path, 0770, true);
            }
            return true;
        }
        return false;
    }

I wanted to push the above changes but I think I don't have permission. The above gets the error message to display when the attachment fails for your swal. Everything else passed. :)

@maltheism maltheism added the Passed manual tests PR has been successfully tested by at least one peer label Feb 8, 2021
@driusan driusan merged commit 4861dab into aces:main Feb 9, 2021
@laemtl laemtl deleted the 2020-02-04-Issues-post-fetch-fixes branch February 10, 2021 00:25
AlexandraLivadas pushed a commit to AlexandraLivadas/Loris that referenced this pull request Jun 29, 2021
@ridz1208 ridz1208 added this to the 24.0.0 milestone Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Passed manual tests PR has been successfully tested by at least one peer
Projects
None yet
5 participants