Skip to content

Commit de02293

Browse files
committed
Merge branch 'master' of github.com:chamilo/chamilo-lms
2 parents b581b5f + 83717b7 commit de02293

File tree

9 files changed

+74
-83
lines changed

9 files changed

+74
-83
lines changed

config/packages/security.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ security:
7676
context: main
7777
provider: app_user_provider
7878
json_login:
79-
check_path: authentication_token
79+
check_path: /api/authentication_token
8080
success_handler: lexik_jwt_authentication.handler.authentication_success
8181
failure_handler: lexik_jwt_authentication.handler.authentication_failure
8282
# guard:

public/main/inc/lib/api.lib.php

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7111,59 +7111,6 @@ function api_format_time($time, $originFormat = 'php')
71117111
return $formattedTime;
71127112
}
71137113

7114-
function api_set_noreply_and_from_address_to_mailer(
7115-
TemplatedEmail $email,
7116-
array $sender,
7117-
array $replyToAddress = []
7118-
): void {
7119-
$validator = Container::getLegacyHelper()->getValidator();
7120-
$emailConstraint = new Assert\Email();
7121-
7122-
$noReplyAddress = api_get_setting('noreply_email_address');
7123-
$avoidReplyToAddress = false;
7124-
7125-
if (!empty($noReplyAddress)) {
7126-
// $avoidReplyToAddress = api_get_configuration_value('mail_no_reply_avoid_reply_to');
7127-
}
7128-
7129-
// Default values
7130-
$notification = new Notification();
7131-
$defaultSenderName = $notification->getDefaultPlatformSenderName();
7132-
$defaultSenderEmail = $notification->getDefaultPlatformSenderEmail();
7133-
7134-
// If the parameter is set don't use the admin.
7135-
$senderName = !empty($sender['name']) ? $sender['name'] : $defaultSenderName;
7136-
$senderEmail = !empty($sender['email']) ? $sender['email'] : $defaultSenderEmail;
7137-
7138-
// Send errors to the platform admin
7139-
$adminEmail = api_get_setting('admin.administrator_email');
7140-
7141-
$adminEmailValidation = $validator->validate($adminEmail, $emailConstraint);
7142-
7143-
if (!empty($adminEmail) && 0 === $adminEmailValidation->count()) {
7144-
$email
7145-
->getHeaders()
7146-
->addIdHeader('Errors-To', $adminEmail)
7147-
;
7148-
}
7149-
7150-
if (!$avoidReplyToAddress && !empty($replyToAddress)) {
7151-
$replyToEmailValidation = $validator->validate($replyToAddress['mail'], $emailConstraint);
7152-
7153-
if (0 === $replyToEmailValidation->count()) {
7154-
$email->addReplyTo(new Address($replyToAddress['mail'], $replyToAddress['name']));
7155-
}
7156-
}
7157-
7158-
$senderName = $defaultSenderName;
7159-
$senderEmail = $defaultSenderEmail;
7160-
$email->sender(new Address($senderEmail, $senderName));
7161-
7162-
if ($senderEmail) {
7163-
$email->from(new Address($senderEmail, $senderName));
7164-
}
7165-
}
7166-
71677114
/**
71687115
* Sends an email
71697116
* Sender name and email can be specified, if not specified

public/main/inc/lib/notification.lib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __construct()
7373
}
7474
} else {
7575
// Default no-reply email
76-
$this->adminEmail = api_get_setting('mail.noreply_email_address');
76+
$this->adminEmail = api_get_setting('mail.mailer_from_email');
7777
$this->adminName = api_get_setting('platform.site_name');
7878
$this->titlePrefix = '['.api_get_setting('platform.site_name').'] ';
7979

public/main/survey/surveyUtil.class.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,19 +2660,10 @@ public static function sendInvitationMail(
26602660
}
26612661

26622662
// Sending the mail
2663-
$sender_name = api_get_person_name($_user['firstName'], $_user['lastName'], null, PERSON_NAME_EMAIL_ADDRESS);
2664-
$sender_email = $_user['mail'];
26652663
$sender_user_id = api_get_user_id();
26662664

2667-
$replyto = [];
26682665
if ('noreply' === api_get_setting('survey_email_sender_noreply')) {
2669-
$noreply = api_get_setting('noreply_email_address');
2670-
if (!empty($noreply)) {
2671-
$replyto['Reply-to'] = $noreply;
2672-
$sender_name = $noreply;
2673-
$sender_email = $noreply;
2674-
$sender_user_id = null;
2675-
}
2666+
$sender_user_id = null;
26762667
}
26772668

26782669
// Optionally: finding the e-mail of the course user
@@ -2696,9 +2687,6 @@ public static function sendInvitationMail(
26962687
$invitedUser,
26972688
$invitation_title,
26982689
$full_invitation_text,
2699-
$sender_name,
2700-
$sender_email,
2701-
$replyto
27022690
);
27032691
}
27042692
}

src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,11 +1187,6 @@ public static function getExistingSettings(): array
11871187
'title' => 'Mail: XOAuth2 options',
11881188
'comment' => 'If you use some XOAuth2-based e-mail service, use this setting in JSON to save your specific configuration (see example) and select XOAuth2 in the mail service setting.',
11891189
],
1190-
[
1191-
'name' => 'noreply_email_address',
1192-
'title' => 'No-reply e-mail address',
1193-
'comment' => 'This is the e-mail address to be used when an e-mail has to be sent specifically requesting that no answer be sent in return. Generally, this e-mail address should be configured on your server to drop/ignore any incoming e-mail.',
1194-
],
11951190
],
11961191
'search' => [
11971192
[

src/CoreBundle/Helpers/MailHelper.php

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,68 @@
66

77
namespace Chamilo\CoreBundle\Helpers;
88

9+
use Chamilo\CoreBundle\Settings\SettingsManager;
910
use Exception;
11+
use Notification;
1012
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
1113
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
1214
use Symfony\Component\Mailer\MailerInterface;
1315
use Symfony\Component\Mime\Address;
1416
use Symfony\Component\Mime\BodyRendererInterface;
1517
use Symfony\Component\Mime\Part\DataPart;
18+
use Symfony\Component\Validator\Constraints as Assert;
19+
use Symfony\Component\Validator\Validator\ValidatorInterface;
1620

1721
final class MailHelper
1822
{
1923
public function __construct(
2024
private readonly MailerInterface $mailer,
2125
private readonly BodyRendererInterface $bodyRenderer,
2226
private readonly ThemeHelper $themeHelper,
27+
private readonly ValidatorInterface $validator,
28+
private readonly SettingsManager $settingsManager,
2329
) {}
2430

31+
private function setNoreplyAndFromAddress(
32+
TemplatedEmail $email,
33+
array $sender,
34+
array $replyToAddress = []
35+
): void {
36+
$emailConstraint = new Assert\Email();
37+
38+
// Default values
39+
$notification = new Notification();
40+
$defaultSenderName = $notification->getDefaultPlatformSenderName();
41+
$defaultSenderEmail = $notification->getDefaultPlatformSenderEmail();
42+
43+
// If the parameter is set, don't use the admin.
44+
$senderName = !empty($sender['name']) ? $sender['name'] : $defaultSenderName;
45+
$senderEmail = !empty($sender['email']) ? $sender['email'] : $defaultSenderEmail;
46+
47+
// Send errors to the platform admin
48+
$adminEmail = $this->settingsManager->getSetting('admin.administrator_email');
49+
50+
$adminEmailValidation = $this->validator->validate($adminEmail, $emailConstraint);
51+
52+
if (!empty($adminEmail) && 0 === $adminEmailValidation->count()) {
53+
$email
54+
->getHeaders()
55+
->addIdHeader('Errors-To', $adminEmail)
56+
;
57+
}
58+
59+
// Reply to first
60+
if (!empty($replyToAddress)) {
61+
$replyToEmailValidation = $this->validator->validate($replyToAddress['mail'], $emailConstraint);
62+
63+
if (0 === $replyToEmailValidation->count()) {
64+
$email->addReplyTo(new Address($replyToAddress['mail'], $replyToAddress['name']));
65+
}
66+
}
67+
68+
$email->from(new Address($senderEmail, $senderName));
69+
}
70+
2571
public function send(
2672
string $recipientName,
2773
string $recipientEmail,
@@ -41,7 +87,7 @@ public function send(
4187

4288
$templatedEmail = new TemplatedEmail();
4389

44-
api_set_noreply_and_from_address_to_mailer(
90+
$this->setNoreplyAndFromAddress(
4591
$templatedEmail,
4692
['name' => $senderName, 'email' => $senderEmail],
4793
!empty($extra_headers['reply_to']) ? $extra_headers['reply_to'] : []
@@ -86,12 +132,7 @@ public function send(
86132
}
87133
}
88134

89-
$noReply = api_get_setting('noreply_email_address');
90-
$automaticEmailText = '';
91-
92-
if (!empty($noReply)) {
93-
$automaticEmailText = '<br />'.get_lang('This is an automatic email message. Please do not reply to it.');
94-
}
135+
$automaticEmailText = '<br />'.get_lang('This is an automatic email message. Please do not reply to it.');
95136

96137
$params = [
97138
'mail_header_style' => api_get_setting('mail.mail_header_style'),
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/* For licensing terms, see /license.txt */
4+
5+
declare(strict_types=1);
6+
7+
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
8+
9+
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
10+
use Doctrine\DBAL\Schema\Schema;
11+
12+
class Version20250725104800 extends AbstractMigrationChamilo
13+
{
14+
public function getDescription(): string
15+
{
16+
return "Remove noreply_email_address setting";
17+
}
18+
19+
public function up(Schema $schema): void
20+
{
21+
$this->addSql("DELETE FROM settings WHERE variable = 'noreply_email_address'");
22+
}
23+
}

src/CoreBundle/Settings/MailSettingsSchema.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class MailSettingsSchema extends AbstractSettingsSchema
1818
public function buildSettings(AbstractSettingsBuilder $builder): void
1919
{
2020
$builder->setDefaults([
21-
'noreply_email_address' => 'no_reply@example.com',
2221
'update_users_email_to_dummy_except_admins' => 'false',
2322
'mail_header_style' => '',
2423
'mail_content_style' => '',
@@ -45,7 +44,6 @@ public function buildSettings(AbstractSettingsBuilder $builder): void
4544
public function buildForm(FormBuilderInterface $builder): void
4645
{
4746
$builder
48-
->add('noreply_email_address', EmailType::class)
4947
->add('update_users_email_to_dummy_except_admins', YesNoType::class)
5048
->add('mail_header_style', TextType::class)
5149
->add('mail_content_style', TextType::class)

src/CoreBundle/Settings/SettingsManager.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,6 @@ private function getVariablesAndCategories(): array
605605
'show_tabs' => 'Platform',
606606
'default_forum_view' => 'Course',
607607
'platform_charset' => 'Languages',
608-
'noreply_email_address' => 'Platform',
609608
'survey_email_sender_noreply' => 'Course',
610609
'gradebook_enable' => 'Gradebook',
611610
'gradebook_score_display_coloring' => 'Gradebook',

0 commit comments

Comments
 (0)