Skip to content

FOUR-25246: Delete the Backend changes related to the Task Notification Email #8368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
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
69 changes: 0 additions & 69 deletions ProcessMaker/Repositories/TokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,6 @@ public function persistActivityActivated(ActivityInterface $activity, TokenInter
if (!is_null($user)) {
// Review if the task has enable the action by email
$this->validateAndSendActionByEmail($activity, $token, $user->email);
// Review if the user has enable the email notification
$isEmailTaskValid = $this->validateEmailUserNotification($token, $user);
// Define the flag if the email needs to sent
$token->is_emailsent = $isEmailTaskValid ? 1 : 0;
}
$this->instanceRepository->persistInstanceUpdated($token->getInstance());
}
Expand Down Expand Up @@ -231,71 +227,6 @@ private function validateAndSendActionByEmail(ActivityInterface $activity, Token
}
}

/**
* Validates the user's email notification settings and sends an email if enabled.
*
* @param TokenInterface $token The token containing task information.
* @param User $user The user to whom the email notification will be sent.
* @return mixed|null Returns the result of the email sending operation or null if not sent.
*/
private function validateEmailUserNotification(TokenInterface $token, User $user)
{
try {
Log::Info('User isEmailTaskEnable: ' . $user->email_task_notification);
// Return if email task notification is not enabled or email is empty
if ($user->email_task_notification === 0 || empty($user->email)) {
return null;
}
// Prepare data for the email
$data = $this->prepareEmailData($token, $user);

// Send Email
return (new TaskActionByEmail())->sendAbeEmail($data['configEmail'], $user->email, $data['emailData']);
} catch (\Exception $e) {
// Catch and log the error
Log::error('Failed to validate and send email task notification', [
'error' => $e->getMessage(),
]);
}
}

/**
* Prepares the email data and configuration for sending an email notification.
*
* @param TokenInterface $token The token containing task information.
* @param User $user The user for whom the email data is being prepared.
* @return array An associative array containing 'emailData' and 'configEmail'.
*/
private function prepareEmailData(TokenInterface $token, User $user)
{
// Get the case
$caseTitle = ProcessRequest::where('id', $token->process_request_id)->value('case_title');
// Prepare the email data
$taskName = $token->element_name ?? '';
$emailData = [
'firstname' => $user->firstname ?? '',
'assigned_by' => Auth::user()->fullname ?? __('System'),
'element_name' => $taskName,
'case_title' => $caseTitle, // Populate this if needed
'due_date' => $token->due_at ?? '',
'link_review_task' => config('app.url') . '/' . 'tasks/' . $token->id . '/edit',
'imgHeader' => config('app.url') . '/img/processmaker_login.png',
];
// Get the screen by key
$screen = Screen::getScreenByKey('default-email-task-notification');
// Prepare the email configuration
$configEmail = [
'emailServer' => 0, // Use the default email server
'subject' => "{$user->firstname} assigned you in '{$taskName}'",
'screenEmailRef' => $screen->id ?? 0, // Define here the screen to use
];

return [
'emailData' => $emailData,
'configEmail' => $configEmail,
];
}

/**
* Get due Variable
*
Expand Down
29 changes: 0 additions & 29 deletions tests/Feature/TaskControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,33 +146,4 @@ public function testReturnMessageTokenNoFound()
$response->assertSee('Token not found');
$response->assertStatus(404);
}

/**
* Test email task notification
*/
public function testEmailTaskNotificationInFormTask()
{
$user = User::factory()->create([
'email_task_notification' => 1,
]);
Auth::login($user);
$process = Process::factory()->create([
'bpmn' => file_get_contents(__DIR__ . '/../Fixtures/email_task_notification_process.bpmn'),
]);
// Start a request
$route = route('api.process_events.trigger', [$process->id, 'event' => 'node_1']);
$data = [];
$response = $this->apiCall('POST', $route, $data);
$response->assertStatus(201);
// Find the request
$instance = ProcessRequest::first();
$task = ProcessRequestToken::where('element_type', 'task')->where('process_id', $process->id)->where('status', 'ACTIVE')->first();
$this->assertEquals(0, $task->is_emailsent);
$user = User::where('id', $task->user_id)->first();
$user->email_task_notification = 1;
$user->save();
WorkflowManager::completeTask($process, $instance, $task, []);
$task = ProcessRequestToken::where('element_type', 'task')->where('process_id', $process->id)->where('status', 'ACTIVE')->first();
$this->assertEquals(0, $task->is_emailsent);
}
}
Loading