Skip to content
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

Update manage py to use app context #6423

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions securedrop/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.kdf import scrypt
from flask import current_app, url_for
from flask_babel import gettext, ngettext
from flask import url_for
from flask_babel import ngettext
from itsdangerous import TimedJSONWebSignatureSerializer, BadData
from markupsafe import Markup
from passlib.hash import argon2
Expand All @@ -22,7 +22,8 @@
from sqlalchemy import Column, Integer, String, Boolean, DateTime, LargeBinary
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound

from flask import Flask, current_app
from flask_babel import Babel, gettext
from db import db

from typing import Callable, Optional, Union, Dict, List, Any
Expand All @@ -34,6 +35,8 @@
from store import Storage

_default_instance_config: Optional["InstanceConfig"] = None
app = Flask(__name__, _default_instance_config)
babel = Babel(app)

LOGIN_HARDENING = True
if os.environ.get('SECUREDROP_ENV') == 'test':
Expand Down Expand Up @@ -519,20 +522,22 @@ def set_name(self, first_name: Optional[str], last_name: Optional[str]) -> None:
@classmethod
def check_username_acceptable(cls, username: str) -> None:
if len(username) < cls.MIN_USERNAME_LEN:
raise InvalidUsernameException(
ngettext(
'Must be at least {num} character long.',
'Must be at least {num} characters long.',
cls.MIN_USERNAME_LEN
).format(num=cls.MIN_USERNAME_LEN)
)
with app.app_context():
raise InvalidUsernameException(
ngettext(
'Must be at least {num} character long.',
'Must be at least {num} characters long.',
cls.MIN_USERNAME_LEN
).format(num=cls.MIN_USERNAME_LEN)
)
if username in cls.INVALID_USERNAMES:
raise InvalidUsernameException(
gettext(
"This username is invalid because it is reserved "
"for internal use by the software."
with app.app_context():
raise InvalidUsernameException(
gettext(
"This username is invalid because it is reserved "
"for internal use by the software."
)
)
)

@classmethod
def check_name_acceptable(cls, name: str) -> None:
Expand Down