<commit_before><?php

namespace SynchWeb\Page\EM;

trait ProcessingJobs
{
    public function processingJobs()
    {
        if (!$this->has_arg('id')) {
            $this->_error('No data collection provided');
        }

        $total = $this->db->pq(
            "SELECT count(PJ.processingJobId) as total
            FROM ProcessingJob PJ
            JOIN DataCollection DC ON PJ.dataCollectionId = DC.dataCollectionId
            JOIN BLSession BLS ON DC.SESSIONID = BLS.sessionId
            LEFT JOIN AutoProcProgram app ON PJ.processingJobId = app.processingJobId
            WHERE DC.dataCollectionId = :1",
            array($this->arg('id')),
            false
        );

        /* In the test data, there are a few occurrences of multiple
           AutoProcProgram rows on a single ProcessingJob.
           <NAME> didn't know if this was a testing artifact or expected
           in normal operation, autoProcProgramId is included here just in case
         * FetchTime is to trigger re-fetches of the entities that depend on
           ProcessingJob
         */
        $processingJobs = $this->db->pq(
            "SELECT
                PJ.processingJobId,
                PJ.dataCollectionId,
                PJ.recordTimestamp,
                APP.autoProcProgramId,
                APP.processingStartTime,
                APP.processingEndTime,
                NOW() as fetchTime,
                CASE
                    WHEN (APP.processingJobId IS NULL) THEN 'submitted'
                    WHEN (APP.processingStartTime IS NULL AND APP.processingStatus IS NULL) THEN 'queued'
                    WHEN (APP.processingStartTime IS NOT NULL AND APP.processingStatus IS NULL) THEN 'running'
                    WHEN (APP.processingStartTime IS NOT NULL AND APP.processingStatus = 0) THEN 'failure'
                    WHEN (APP.processingStartTime IS NOT NULL AND APP.processingStatus = 1) THEN 'success'
                    ELSE ''
                END AS processingStatusDescription
            FROM ProcessingJob PJ
            INNER JOIN DataCollection DC ON PJ.dataCollectionId = DC.dataCollectionId
            INNER JOIN BLSession BLS ON DC.SESSIONID = BLS.sessionId
            LEFT JOIN AutoProcProgram APP ON PJ.processingJobId = APP.processingJobId
            WHERE DC.dataCollectionId = :1
            LIMIT :2, :3",
            $this->paginationArguments(array($this->arg('id'))),
            false
        );

        $this->_output(array(
            'total' => intval($total[0]['total']),
            'data' => $processingJobs,
        ));
    }
}<commit_msg>[SCI-10000] Permissions check on Processing Jobs queries<commit_after><?php

namespace SynchWeb\Page\EM;

trait ProcessingJobs
{
    public function processingJobs()
    {
        if (!$this->has_arg('id')) {
            $this->_error('No data collection provided');
        }

        $total = $this->db->pq(
            "SELECT count(pj.processingJobId) as total
            FROM ProcessingJob pj
            LEFT JOIN AutoProcProgram app ON pj.processingJobId = app.processingJobId
            INNER JOIN DataCollection dc ON dc.dataCollectionId = pj.dataCollectionId
            INNER JOIN DataCollectionGroup dcg ON dcg.dataCollectionGroupId = dc.dataCollectionGroupId
            INNER JOIN BLSession bls ON bls.sessionId = dcg.sessionId
            INNER JOIN Proposal p ON p.proposalId = bls.proposalId
            WHERE CONCAT(p.proposalCode, p.proposalNumber) = :1
            AND dc.dataCollectionId = :2",
            array($this->arg('prop'), $this->arg('id')),
            false
        );

        /* In the test data, there are a few occurrences of multiple
           AutoProcProgram rows on a single ProcessingJob.
           <NAME> didn't know if this was a testing artifact or expected
           in normal operation, autoProcProgramId is included here just in case
         * FetchTime is to trigger re-fetches of the entities that depend on
           ProcessingJob
         */
        $processingJobs = $this->db->pq(
            "SELECT
                pj.processingJobId,
                pj.dataCollectionId,
                pj.recordTimestamp,
                app.autoProcProgramId,
                app.processingStartTime,
                app.processingEndTime,
                NOW() as fetchTime,
                CASE
                    WHEN (app.processingJobId IS NULL) THEN 'submitted'
                    WHEN (app.processingStartTime IS NULL AND app.processingStatus IS NULL) THEN 'queued'
                    WHEN (app.processingStartTime IS NOT NULL AND app.processingStatus IS NULL) THEN 'running'
                    WHEN (app.processingStartTime IS NOT NULL AND app.processingStatus = 0) THEN 'failure'
                    WHEN (app.processingStartTime IS NOT NULL AND app.processingStatus = 1) THEN 'success'
                    ELSE ''
                END AS processingStatusDescription
            FROM ProcessingJob pj
            LEFT JOIN AutoProcProgram app ON app.processingJobId = pj.processingJobId
            INNER JOIN DataCollection dc ON dc.dataCollectionId = pj.dataCollectionId
            INNER JOIN DataCollectionGroup dcg ON dcg.dataCollectionGroupId = dc.dataCollectionGroupId
            INNER JOIN BLSession bls ON bls.sessionId = dcg.sessionId
            INNER JOIN Proposal p ON p.proposalId = bls.proposalId
            WHERE CONCAT(p.proposalCode, p.proposalNumber) = :1
            AND dc.dataCollectionId = :2
            LIMIT :3, :4",
            $this->paginationArguments(
                array($this->arg('prop'), $this->arg('id'))
            ),
            false
        );

        $this->_output(array(
            'total' => intval($total[0]['total']),
            'data' => $processingJobs,
        ));
    }
}
{'fraction_non_alphanumeric': 0.07790637415788565, 'fraction_numerical': 0.0036275695284159614, 'mean_word_length': 1.8663366336633664, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '909142', 'n_tokens_mistral': 1567, 'n_tokens_neox': 1462, 'n_words': 443}