Page 1 of 1

Generate Output Document Permissions REST API

Posted: Tue Mar 06, 2018 6:45 pm
by dice4000
Hello, whenever i try to use the REST API to generate an output document, i get the following error.

{"error":{"code":400,"message":"Bad Request: The user with \"00000000000000000000000000000001\" not have permissions to perform this action."}}

This REST function only seems to work for the user user account in which the the output document was originally generated. Is this the default behavior or is there some way to allow the Administrator or Supervisor to generate an output document through the REST API. Thanks.

Im using Processmaker 3.2 Community.

Re: Generate Output Document Permissions REST API

Posted: Tue Mar 06, 2018 10:04 pm
by amosbatto
If you want to allow Process Supervisors to generate Output Documents, edit the file workflow/engine/src/ProcessMaker/Services/Api/Cases/OutputDocument.php and change the doPostOutputDocument() function so it has the following code:
Code: Select all
    /**
     * @url POST /:app_uid/:del_index/output-document/:out_doc_uid
     *
     * @param string $app_uid     {@min 32}{@max 32}
     * @param int    $del_index   {@min 1}
     * @param string $out_doc_uid {@min 32}{@max 32}
     */
    public function doPostOutputDocument($app_uid, $del_index, $out_doc_uid)
    {
        try {
            $userUid = $this->getUserId();

            $case = new \ProcessMaker\BusinessModel\Cases();
            $outputDocument = new \ProcessMaker\BusinessModel\Cases\OutputDocument();
            
            //allow user to create output document if a process supervisor or is assigned to case:
            $aCaseInfo = $case->getApplicationRecordByPk($app_uid, [], false);
            $supervisor = new \ProcessMaker\BusinessModel\ProcessSupervisor();
            
            if ($supervisor->isUserProcessSupervisor($aCaseInfo['PRO_UID'], $userUid) === false) {
                $outputDocument->throwExceptionIfCaseNotIsInInbox($app_uid, $del_index, $userUid);
            }
            
            $outputDocument->throwExceptionIfOuputDocumentNotExistsInSteps($app_uid, $del_index, $out_doc_uid);
            $response = $outputDocument->addCasesOutputDocument($app_uid, $out_doc_uid, $userUid);

            //Return
            return $response;
        } catch (\Exception $e) {
            throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
        }
    } 

Re: Generate Output Document Permissions REST API

Posted: Tue Mar 06, 2018 10:19 pm
by amosbatto
I filed a bug report about this to change the code:
https://processmaker.atlassian.net/browse/TRI-3335

Re: Generate Output Document Permissions REST API

Posted: Tue Mar 13, 2018 2:01 pm
by dice4000
Thank you amosbatto, that worked perfectly.