-
Notifications
You must be signed in to change notification settings - Fork 83
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
Support branded templates #328
Merged
Merged
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3ff6526
support branded templates (untested)
ara4n d052dad
changelog
ara4n 17c8f18
typo
ara4n f79e626
Share code to get brand.
clokep 0401d18
Update docstrings.
clokep 0ed271f
Safely load branded templates.
clokep 6432299
Improve comments about the config.
clokep ebb779d
Add basic tests.
clokep f720665
Do not iterate the brands every request.
clokep 95899ff
Formatting.
clokep 2c830b8
Also use the abstracted code when storing invites.
clokep 46f6971
Remove a todo which was done.
clokep 525bd4f
Fix tests.
clokep 348d1e1
Fix IS tests.
clokep 129abc7
Rename file properly.
clokep b8a8874
Better backwards compatibility.
clokep 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 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 @@ | ||
Move templates to a per-brand subdirectory of /res. Add templates.path and brand.default config options |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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 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 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 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 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 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 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 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,83 @@ | ||
# Copyright 2021 The Matrix.org Foundation C.I.C. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os.path | ||
from mock import Mock, patch | ||
|
||
from twisted.web.client import Response | ||
from twisted.trial import unittest | ||
|
||
from sydent.db.invite_tokens import JoinTokenStore | ||
from sydent.http.httpclient import FederationHttpClient | ||
from sydent.http.servlets.store_invite_servlet import StoreInviteServlet | ||
from tests.utils import make_request, make_sydent | ||
|
||
|
||
class TestRequestCode(unittest.TestCase): | ||
def setUp(self): | ||
# Create a new sydent | ||
config = { | ||
"general": { | ||
# TODO How to get this dynamically. | ||
"templates.path": "/Users/clokep/matrix/sydent/res", | ||
} | ||
} | ||
self.sydent = make_sydent(test_config=config) | ||
|
||
def _render_request(self, request): | ||
# Patch out the email sending so we can investigate the resulting email. | ||
with patch("sydent.util.emailutils.smtplib") as smtplib: | ||
request.render(self.sydent.servlets.emailRequestCode) | ||
|
||
# Fish out the SMTP object and return it. | ||
smtp = smtplib.SMTP.return_value | ||
smtp.sendmail.assert_called_once() | ||
|
||
return smtp | ||
|
||
def test_request_code(self): | ||
self.sydent.run() | ||
|
||
request, channel = make_request( | ||
self.sydent.reactor, "POST", "/_matrix/identity/v1/validate/email/requestToken", | ||
{ | ||
"email": "test@test", | ||
"client_secret": "oursecret", | ||
"send_attempt": 0, | ||
} | ||
) | ||
smtp = self._render_request(request) | ||
self.assertEqual(channel.code, 200) | ||
|
||
# Ensure the email is as expected. | ||
email_contents = smtp.sendmail.call_args[0][2].decode("utf-8") | ||
self.assertIn("Confirm your email address for Matrix", email_contents) | ||
|
||
def test_branded_request_code(self): | ||
self.sydent.run() | ||
|
||
request, channel = make_request( | ||
self.sydent.reactor, "POST", "/_matrix/identity/v1/validate/email/requestToken?brand=vector-im", | ||
{ | ||
"email": "test@test", | ||
"client_secret": "oursecret", | ||
"send_attempt": 0, | ||
} | ||
) | ||
smtp = self._render_request(request) | ||
self.assertEqual(channel.code, 200) | ||
|
||
# Ensure the email is as expected. | ||
email_contents = smtp.sendmail.call_args[0][2].decode("utf-8") | ||
self.assertIn("Confirm your email address for Element", email_contents) |
This file contains 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
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.
How I wish this code was shared with synapse. 😢