Skip to content

Commit 0b502cb

Browse files
wouterjfabpot
authored andcommitted
[Security][Notifier] Added integration of Login Link with the Notifier component
1 parent ed0218e commit 0b502cb

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CHANGELOG
1010
* added the `t()` function to easily create `TranslatableMessage` objects
1111
* Added support for extracting messages from the `t()` function
1212
* Added `field_*` Twig functions to access string values from Form fields
13+
* changed the `importance` context option of `NotificationEmail` to allow `null`
1314

1415
5.0.0
1516
-----

Mime/NotificationEmail.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class NotificationEmail extends TemplatedEmail
3737
'action_url' => null,
3838
'markdown' => false,
3939
'raw' => false,
40+
'footer_text' => 'Notification e-mail sent by Symfony',
4041
];
4142

4243
public function __construct(Headers $headers = null, AbstractPart $body = null)
@@ -57,6 +58,18 @@ public function __construct(Headers $headers = null, AbstractPart $body = null)
5758
parent::__construct($headers, $body);
5859
}
5960

61+
/**
62+
* Creates a NotificationEmail instance that is appropriate to send to normal (non-admin) users.
63+
*/
64+
public static function asPublicEmail(Headers $headers = null, AbstractPart $body = null): self
65+
{
66+
$email = new static($headers, $body);
67+
$email->context['importance'] = null;
68+
$email->context['footer_text'] = null;
69+
70+
return $email;
71+
}
72+
6073
/**
6174
* @return $this
6275
*/
@@ -166,7 +179,9 @@ public function getPreparedHeaders(): Headers
166179

167180
$importance = $this->context['importance'] ?? self::IMPORTANCE_LOW;
168181
$this->priority($this->determinePriority($importance));
169-
$headers->setHeaderBody('Text', 'Subject', sprintf('[%s] %s', strtoupper($importance), $this->getSubject()));
182+
if ($this->context['importance']) {
183+
$headers->setHeaderBody('Text', 'Subject', sprintf('[%s] %s', strtoupper($importance), $this->getSubject()));
184+
}
170185

171186
return $headers;
172187
}

Resources/views/Email/zurb_2/notification/body.html.twig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<row>
1717
<columns large="12" small="12">
1818
{% block lead %}
19-
<small><strong>{{ importance|upper }}</strong></small>
19+
{% if importance is not null %}<small><strong>{{ importance|upper }}</strong></small>{% endif %}
2020
<p class="lead">
2121
{{ email.subject }}
2222
</p>
@@ -49,13 +49,15 @@
4949
<wrapper class="secondary">
5050
<spacer size="16"></spacer>
5151
{% block footer %}
52+
{% if footer_text is defined and footer_text is not null %}
5253
<row>
5354
<columns small="12" large="6">
5455
{% block footer_content %}
55-
<p><small>Notification e-mail sent by Symfony</small></p>
56+
<p><small>{{ footer_text }}</small></p>
5657
{% endblock %}
5758
</columns>
5859
</row>
60+
{% endif %}
5961
{% endblock %}
6062
</wrapper>
6163
</container>

Tests/Mime/NotificationEmailTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function test()
2626
'markdown' => true,
2727
'raw' => false,
2828
'a' => 'b',
29+
'footer_text' => 'Notification e-mail sent by Symfony',
2930
], $email->getContext());
3031
}
3132

@@ -47,6 +48,7 @@ public function testSerialize()
4748
'markdown' => false,
4849
'raw' => true,
4950
'a' => 'b',
51+
'footer_text' => 'Notification e-mail sent by Symfony',
5052
], $email->getContext());
5153
}
5254

@@ -63,4 +65,32 @@ public function testSubject()
6365
$headers = $email->getPreparedHeaders();
6466
$this->assertSame('[LOW] Foo', $headers->get('Subject')->getValue());
6567
}
68+
69+
public function testPublicMail()
70+
{
71+
$email = NotificationEmail::asPublicEmail()
72+
->markdown('Foo')
73+
->action('Bar', 'http://example.com/')
74+
->context(['a' => 'b'])
75+
;
76+
77+
$this->assertEquals([
78+
'importance' => null,
79+
'content' => 'Foo',
80+
'exception' => false,
81+
'action_text' => 'Bar',
82+
'action_url' => 'http://example.com/',
83+
'markdown' => true,
84+
'raw' => false,
85+
'a' => 'b',
86+
'footer_text' => null,
87+
], $email->getContext());
88+
}
89+
90+
public function testPublicMailSubject()
91+
{
92+
$email = NotificationEmail::asPublicEmail()->from('[email protected]')->subject('Foo');
93+
$headers = $email->getPreparedHeaders();
94+
$this->assertSame('Foo', $headers->get('Subject')->getValue());
95+
}
6696
}

0 commit comments

Comments
 (0)