Skip to content

Commit

Permalink
Patches for custom workflow users
Browse files Browse the repository at this point in the history
  • Loading branch information
kirschkern committed Jan 22, 2024
1 parent a01348b commit bba3e06
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions Workflows/Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
'name' => 'Workflows',
'process_cron' => env('WORKFLOWS_PROCESS_CRON', '0 * * * *'),
'user_full_name' => env('WORKFLOWS_USER_FULL_NAME', 'Workflow'),
'user_email' => env('WORKFLOWS_USER_EMAIL', ''),
];
18 changes: 16 additions & 2 deletions Workflows/Entities/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Workflow extends Model
// This is obligatory.
public $rememberCacheDriver = 'array';

public static $userRunningTheWorkflow = null;

const TYPE_AUTOMATIC = 1;
const TYPE_MANUAL = 2;

Expand Down Expand Up @@ -694,19 +696,24 @@ public static function runAutomaticForConversation($conversation, $trigger = '')
/**
* Run manually.
*/
public function runManually($conversation)
public function runManually($conversation, $userRunningTheWorkflow=null)
{
// $workflow = Workflow::find($workflow_id);

// if (!$workflow) {
// return false;
// }

if ($userRunningTheWorkflow)
self::$userRunningTheWorkflow = $userRunningTheWorkflow;

if (!$conversation) {
return false;
}

$this->performActions($conversation);
$this->performActions($conversation, $userRunningTheWorkflow);

self::$userRunningTheWorkflow = null;
}

public static function getConditionConfig($type, $mailbox_id)
Expand Down Expand Up @@ -1379,6 +1386,13 @@ public function performActions($conversation/*, $mark_processed = true*/)
*/
public static function getUser()
{
if (self::$userRunningTheWorkflow)
return self::$userRunningTheWorkflow;

$email = config('workflows.user_email');
if ($email)
return User::where('email', $email)->first();

if (!empty(self::$wf_user)) {
return self::$wf_user;
}
Expand Down
2 changes: 1 addition & 1 deletion Workflows/Http/Controllers/WorkflowsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public function ajax(Request $request)

$prev_mailbox_id = $conversation->mailbox_id;

$workflow->runManually($conversation);
$workflow->runManually($conversation, $user);

// If conversation moved to another mailbox, check permissions.
if ($prev_mailbox_id != $conversation->mailbox_id) {
Expand Down

0 comments on commit bba3e06

Please sign in to comment.