-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api, main: port various functionality (bug 1887013)
WIP
- Loading branch information
Showing
23 changed files
with
86 additions
and
59 deletions.
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
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
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 |
---|---|---|
|
@@ -23,26 +23,26 @@ def init_app(self, app): | |
def suppressed(self): | ||
return ( | ||
self.flask_app is None | ||
or bool(self.flask_app.config.get("MAIL_SUPPRESS_SEND")) | ||
or not self.flask_app.config.get("MAIL_SERVER") | ||
or bool(settings.MAIL_SUPPRESS_SEND) | ||
or not settings.MAIL_SERVER | ||
) | ||
|
||
@property | ||
def default_from(self): | ||
return self.flask_app.config.get("MAIL_FROM") or "[email protected]" | ||
return settings.MAIL_FROM or "[email protected]" | ||
|
||
@contextmanager | ||
def connection(self): | ||
if self.suppressed: | ||
raise ValueError("Supressed SMTP has no connection") | ||
|
||
host = self.flask_app.config.get("MAIL_SERVER") or None | ||
port = self.flask_app.config.get("MAIL_PORT") or None | ||
use_ssl = self.flask_app.config.get("MAIL_USE_SSL") | ||
use_tls = self.flask_app.config.get("MAIL_USE_TLS") | ||
host = settings.MAIL_SERVER or None | ||
port = settings.MAIL_PORT or None | ||
use_ssl = settings.MAIL_USE_SSL | ||
use_tls = settings.MAIL_USE_TLS | ||
|
||
username = self.flask_app.config.get("MAIL_USERNAME") or None | ||
password = self.flask_app.config.get("MAIL_PASSWORD") or None | ||
username = settings.MAIL_USERNAME or None | ||
password = settings.MAIL_PASSWORD or None | ||
|
||
smtp_class = smtplib.SMTP_SSL if use_ssl else smtplib.SMTP | ||
c = smtp_class(host, port) | ||
|
@@ -60,7 +60,7 @@ def recipient_allowed(self, email): | |
if self.flask_app is None: | ||
return True | ||
|
||
whitelist = self.flask_app.config.get("MAIL_RECIPIENT_WHITELIST") or None | ||
whitelist = settings.MAIL_RECIPIENT_WHITELIST or None | ||
if whitelist is None: | ||
return True | ||
|
||
|
@@ -82,10 +82,8 @@ def ready(self): | |
logger.warning( | ||
"SMTP is suppressed, assuming ready", | ||
extra={ | ||
"MAIL_SERVER": self.flask_app.config.get("MAIL_SERVER"), | ||
"MAIL_SUPPRESS_SEND": self.flask_app.config.get( | ||
"MAIL_SUPPRESS_SEND" | ||
), | ||
"MAIL_SERVER": settings.MAIL_SERVER, | ||
"MAIL_SUPPRESS_SEND": settings.MAIL_SUPPRESS_SEND, | ||
}, | ||
) | ||
return True | ||
|
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,35 @@ | ||
from django.http import HttpResponse | ||
|
||
|
||
class ProblemException(Exception): | ||
def __init__(self, *, status=500, title=None, detail=None, type=None, instance=None, headers=None, ext=None): | ||
# TODO: this should be reimplemented as either middleware or HttpResponse return values. | ||
super().__init__(self) | ||
|
||
|
||
def problem(status, title, detail, type=None, instance=None, headers=None, ext=None): | ||
return HttpResponse(content=detail, headers=headers, status_code=status) | ||
|
||
|
||
request = { | ||
"headers": {}, | ||
} | ||
|
||
session = {} | ||
|
||
|
||
class g: | ||
auth0_user = None | ||
access_token = None | ||
access_token_payload = None | ||
_request_start_timestamp = None | ||
|
||
|
||
class FlaskApi: | ||
@classmethod | ||
def get_response(self, _problem): | ||
return _problem | ||
|
||
|
||
class ConnexionResponse(HttpResponse): | ||
pass |