Skip to content

Commit 07bab77

Browse files
authored
Merge pull request #8368 from ProcessMaker/feature/FOUR-25246
FOUR-25246: Delete the Backend changes related to the Task Notification Email
2 parents 675c80b + 299f67b commit 07bab77

File tree

2 files changed

+0
-98
lines changed

2 files changed

+0
-98
lines changed

ProcessMaker/Repositories/TokenRepository.php

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,6 @@ public function persistActivityActivated(ActivityInterface $activity, TokenInter
176176
if (!is_null($user)) {
177177
// Review if the task has enable the action by email
178178
$this->validateAndSendActionByEmail($activity, $token, $user->email);
179-
// Review if the user has enable the email notification
180-
$isEmailTaskValid = $this->validateEmailUserNotification($token, $user);
181-
// Define the flag if the email needs to sent
182-
$token->is_emailsent = $isEmailTaskValid ? 1 : 0;
183179
}
184180
$this->instanceRepository->persistInstanceUpdated($token->getInstance());
185181
}
@@ -231,71 +227,6 @@ private function validateAndSendActionByEmail(ActivityInterface $activity, Token
231227
}
232228
}
233229

234-
/**
235-
* Validates the user's email notification settings and sends an email if enabled.
236-
*
237-
* @param TokenInterface $token The token containing task information.
238-
* @param User $user The user to whom the email notification will be sent.
239-
* @return mixed|null Returns the result of the email sending operation or null if not sent.
240-
*/
241-
private function validateEmailUserNotification(TokenInterface $token, User $user)
242-
{
243-
try {
244-
Log::Info('User isEmailTaskEnable: ' . $user->email_task_notification);
245-
// Return if email task notification is not enabled or email is empty
246-
if ($user->email_task_notification === 0 || empty($user->email)) {
247-
return null;
248-
}
249-
// Prepare data for the email
250-
$data = $this->prepareEmailData($token, $user);
251-
252-
// Send Email
253-
return (new TaskActionByEmail())->sendAbeEmail($data['configEmail'], $user->email, $data['emailData']);
254-
} catch (\Exception $e) {
255-
// Catch and log the error
256-
Log::error('Failed to validate and send email task notification', [
257-
'error' => $e->getMessage(),
258-
]);
259-
}
260-
}
261-
262-
/**
263-
* Prepares the email data and configuration for sending an email notification.
264-
*
265-
* @param TokenInterface $token The token containing task information.
266-
* @param User $user The user for whom the email data is being prepared.
267-
* @return array An associative array containing 'emailData' and 'configEmail'.
268-
*/
269-
private function prepareEmailData(TokenInterface $token, User $user)
270-
{
271-
// Get the case
272-
$caseTitle = ProcessRequest::where('id', $token->process_request_id)->value('case_title');
273-
// Prepare the email data
274-
$taskName = $token->element_name ?? '';
275-
$emailData = [
276-
'firstname' => $user->firstname ?? '',
277-
'assigned_by' => Auth::user()->fullname ?? __('System'),
278-
'element_name' => $taskName,
279-
'case_title' => $caseTitle, // Populate this if needed
280-
'due_date' => $token->due_at ?? '',
281-
'link_review_task' => config('app.url') . '/' . 'tasks/' . $token->id . '/edit',
282-
'imgHeader' => config('app.url') . '/img/processmaker_login.png',
283-
];
284-
// Get the screen by key
285-
$screen = Screen::getScreenByKey('default-email-task-notification');
286-
// Prepare the email configuration
287-
$configEmail = [
288-
'emailServer' => 0, // Use the default email server
289-
'subject' => "{$user->firstname} assigned you in '{$taskName}'",
290-
'screenEmailRef' => $screen->id ?? 0, // Define here the screen to use
291-
];
292-
293-
return [
294-
'emailData' => $emailData,
295-
'configEmail' => $configEmail,
296-
];
297-
}
298-
299230
/**
300231
* Get due Variable
301232
*

tests/Feature/TaskControllerTest.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -146,33 +146,4 @@ public function testReturnMessageTokenNoFound()
146146
$response->assertSee('Token not found');
147147
$response->assertStatus(404);
148148
}
149-
150-
/**
151-
* Test email task notification
152-
*/
153-
public function testEmailTaskNotificationInFormTask()
154-
{
155-
$user = User::factory()->create([
156-
'email_task_notification' => 1,
157-
]);
158-
Auth::login($user);
159-
$process = Process::factory()->create([
160-
'bpmn' => file_get_contents(__DIR__ . '/../Fixtures/email_task_notification_process.bpmn'),
161-
]);
162-
// Start a request
163-
$route = route('api.process_events.trigger', [$process->id, 'event' => 'node_1']);
164-
$data = [];
165-
$response = $this->apiCall('POST', $route, $data);
166-
$response->assertStatus(201);
167-
// Find the request
168-
$instance = ProcessRequest::first();
169-
$task = ProcessRequestToken::where('element_type', 'task')->where('process_id', $process->id)->where('status', 'ACTIVE')->first();
170-
$this->assertEquals(0, $task->is_emailsent);
171-
$user = User::where('id', $task->user_id)->first();
172-
$user->email_task_notification = 1;
173-
$user->save();
174-
WorkflowManager::completeTask($process, $instance, $task, []);
175-
$task = ProcessRequestToken::where('element_type', 'task')->where('process_id', $process->id)->where('status', 'ACTIVE')->first();
176-
$this->assertEquals(0, $task->is_emailsent);
177-
}
178149
}

0 commit comments

Comments
 (0)