From bba3e06f98ca86e6e02e1f10977124d305541eab Mon Sep 17 00:00:00 2001 From: Daniel Kirsch Date: Mon, 22 Jan 2024 01:06:15 +0100 Subject: [PATCH] Patches for custom workflow users --- Workflows/Config/config.php | 1 + Workflows/Entities/Workflow.php | 18 ++++++++++++++++-- .../Http/Controllers/WorkflowsController.php | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Workflows/Config/config.php b/Workflows/Config/config.php index b5c3f64..4cc173a 100644 --- a/Workflows/Config/config.php +++ b/Workflows/Config/config.php @@ -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', ''), ]; diff --git a/Workflows/Entities/Workflow.php b/Workflows/Entities/Workflow.php index 621a53a..94a4ca4 100644 --- a/Workflows/Entities/Workflow.php +++ b/Workflows/Entities/Workflow.php @@ -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; @@ -694,7 +696,7 @@ public static function runAutomaticForConversation($conversation, $trigger = '') /** * Run manually. */ - public function runManually($conversation) + public function runManually($conversation, $userRunningTheWorkflow=null) { // $workflow = Workflow::find($workflow_id); @@ -702,11 +704,16 @@ public function runManually($conversation) // 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) @@ -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; } diff --git a/Workflows/Http/Controllers/WorkflowsController.php b/Workflows/Http/Controllers/WorkflowsController.php index d36acd1..719ad5f 100644 --- a/Workflows/Http/Controllers/WorkflowsController.php +++ b/Workflows/Http/Controllers/WorkflowsController.php @@ -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) {