-
Notifications
You must be signed in to change notification settings - Fork 415
[Bugfix] Mail 047999: Fix CC/BCC Mails Generic Placeholder not replaced with corresponding value #11713
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
Open
fhelfer
wants to merge
2
commits into
ILIAS-eLearning:release_10
Choose a base branch
from
fhelfer:mail/mantis/47999
base: release_10
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+190
−56
Open
[Bugfix] Mail 047999: Fix CC/BCC Mails Generic Placeholder not replaced with corresponding value #11713
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
components/ILIAS/Mail/classes/class.ilMailTemplatePlaceholderToEmptyResolver.php
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
components/ILIAS/Mail/tests/ilMailTemplatePlaceholderToEmptyResolverTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * This file is part of ILIAS, a powerful learning management system | ||
| * published by ILIAS open source e-Learning e.V. | ||
| * | ||
| * ILIAS is licensed with the GPL-3.0, | ||
| * see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
| * You should have received a copy of said license along with the | ||
| * source code, too. | ||
| * | ||
| * If this is not the case or you just want to try ILIAS, you'll find | ||
| * us at: | ||
| * https://www.ilias.de | ||
| * https://github.com/ILIAS-eLearning | ||
| * | ||
| *********************************************************************/ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use OrgUnit\PublicApi\OrgUnitUserService; | ||
|
|
||
| class ilMailTemplatePlaceholderToEmptyResolverTest extends ilMailBaseTestCase | ||
| { | ||
| public function testNullRecipientResolvesContextPlaceholdersAndKeepsRecipientDependentNames(): void | ||
| { | ||
| $lng = $this->getMockBuilder(ilLanguage::class) | ||
| ->disableOriginalConstructor() | ||
| ->onlyMethods(['txt', 'loadLanguageModule']) | ||
| ->getMock(); | ||
| $lng->method('txt')->willReturnArgument(0); | ||
| $this->setGlobalVariable('lng', $lng); | ||
| ilDatePresentation::setLanguage($lng); | ||
|
|
||
| $env_helper = $this->createMock(ilMailEnvironmentHelper::class); | ||
| $env_helper->method('getClientId')->willReturn('phpunit_client'); | ||
| $env_helper->method('getHttpPath')->willReturn('https://ilias.example/'); | ||
|
|
||
| $lng_helper = $this->createMock(ilMailLanguageHelper::class); | ||
| $lng_helper->method('getCurrentLanguage')->willReturn($lng); | ||
|
|
||
| $context = new class ( | ||
| new OrgUnitUserService(), | ||
| $env_helper, | ||
| new ilMailUserHelper(), | ||
| $lng_helper | ||
| ) extends ilMailTemplateContext { | ||
| public function getId(): string | ||
| { | ||
| return 'phpunit_context'; | ||
| } | ||
|
|
||
| public function getTitle(): string | ||
| { | ||
| return 'phpunit'; | ||
| } | ||
|
|
||
| public function getDescription(): string | ||
| { | ||
| return 'phpunit'; | ||
| } | ||
|
|
||
| public function getSpecificPlaceholders(): array | ||
| { | ||
| return [ | ||
| 'course_title' => [ | ||
| 'placeholder' => 'COURSE_TITLE', | ||
| 'label' => 'Course Title', | ||
| ], | ||
| ]; | ||
| } | ||
|
|
||
| public function resolveSpecificPlaceholder( | ||
| string $placeholder_id, | ||
| array $context_parameters, | ||
| ilObjUser $recipient = null | ||
| ): string { | ||
| if ('course_title' === $placeholder_id) { | ||
| return 'My Course'; | ||
| } | ||
|
|
||
| return ''; | ||
| } | ||
| }; | ||
|
|
||
| $resolver = new ilMailTemplatePlaceholderResolver(new Mustache_Engine()); | ||
| $message = 'Hello {{FIRST_NAME}} {{LAST_NAME}}, welcome to {{COURSE_TITLE}} at {{ILIAS_URL}}{{INSTALLATION_NAME}}'; | ||
|
|
||
| $resolved = $resolver->resolve($context, $message, null, ['ref_id' => 123]); | ||
|
|
||
| $this->assertStringContainsString('FIRST_NAME', $resolved); | ||
| $this->assertStringContainsString('LAST_NAME', $resolved); | ||
| $this->assertStringNotContainsString('{{FIRST_NAME}}', $resolved); | ||
| $this->assertStringNotContainsString('{{LAST_NAME}}', $resolved); | ||
| $this->assertStringContainsString('My Course', $resolved); | ||
| $this->assertStringContainsString('https://ilias.example/', $resolved); | ||
| $this->assertStringContainsString('phpunit_client', $resolved); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requiresRecipientshould be part of the array shape definition (PHPDocs)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the interim fix, we also need to add requiresRecipient to all mail contexts. Right now there’s no reliable way to tell which specific placeholders are user-specific vs. context-specific. Generic ones already have it; specific ones don’t — and some contexts still short-circuit everything when there’s no recipient. Study Programme is the worst offender: if (is_null($recipient)) { return ''; } wipes all placeholders, even ones that only need the object/context (title, link, etc.).
Long-term (planned for ILIAS 12): a proper refactor. Placeholders become small classes implementing interfaces, collected the same way mail signatures already work — placeholder classes + a supports() check on the consumer side. Contexts would declare what they support (installation, user, object/course/study programme, …), and only matching placeholders get resolved. That way we reuse placeholders across contexts instead of reimplementing them in every il*MailTemplateContext.