Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions ProcessMaker/Listeners/CommentsSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ProcessMaker\Listeners;

use Illuminate\Support\Facades\Auth;
use ProcessMaker\Models\Comment;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Models\ProcessRequestToken;
Expand All @@ -26,11 +27,27 @@ public function onActivityCompleted(ActivityCompletedEvent $event)
$user_id = $token->user ? $token->user_id : null;
$user_name = $token->user ? $token->user->fullname : __('The System');

// Check the authenticated user
$executer_user_id = null;
$executer_user = __('The System');
$user = Auth::user();
if ($user) {
$executer_user_id = $user->id;
$executer_user = $user->fullname;
}

if (!is_int($token->process_request_id)) {
return;
}

$message = ':user has completed the task :task_name';
if (!is_null($executer_user_id) && $user_id !== $executer_user_id) {
$subject = 'Task Completed by Different User';
$message = ':executer_user has completed the task :task_name (assigned to: :user)';
} else {
$subject = 'Task Complete';
$message = ':user has completed the task :task_name';
}

if ($token->is_actionbyemail) {
$message = $message . ' via email';
}
Expand All @@ -42,8 +59,8 @@ public function onActivityCompleted(ActivityCompletedEvent $event)
'user_id' => $user_id,
'commentable_type' => ProcessRequest::class,
'commentable_id' => $token->process_request_id,
'subject' => 'Task Complete',
'body' => __($message, ['user' => $user_name, 'task_name' => $token->element_name]),
'subject' => $subject,
'body' => __($message, ['user' => $user_name, 'task_name' => $token->element_name, 'executer_user' => $executer_user]),
'case_number' => $caseNumber,
]);
}
Expand Down
Loading