diff --git a/OpenOversight/app/__init__.py b/OpenOversight/app/__init__.py index 34cf8abc6..4538914a5 100644 --- a/OpenOversight/app/__init__.py +++ b/OpenOversight/app/__init__.py @@ -48,7 +48,11 @@ def create_app(config_name="default"): # This allows the application to run without creating an email client if it is # in testing or dev mode and the service account file is empty. service_account_file_size = os.path.getsize(SERVICE_ACCOUNT_FILE) - EmailClient(dev=app.debug and service_account_file_size == 0, testing=app.testing) + EmailClient( + config=app.config, + dev=app.debug and service_account_file_size == 0, + testing=app.testing, + ) limiter.init_app(app) login_manager.init_app(app) sitemap.init_app(app) diff --git a/OpenOversight/app/email_client.py b/OpenOversight/app/email_client.py index 83568c9ee..9a860135d 100644 --- a/OpenOversight/app/email_client.py +++ b/OpenOversight/app/email_client.py @@ -18,17 +18,15 @@ class EmailClient(object): _instance = None - def __new__(cls, dev=False, testing=False): + def __new__(cls, config=None, dev=False, testing=False): if (testing or dev) and cls._instance is None: cls._instance = {} - if cls._instance is None: + if cls._instance is None and config: credentials = service_account.Credentials.from_service_account_file( SERVICE_ACCOUNT_FILE, scopes=cls.SCOPES ) - delegated_credentials = credentials.with_subject( - current_app.config["OO_SERVICE_EMAIL"] - ) + delegated_credentials = credentials.with_subject(config["OO_SERVICE_EMAIL"]) cls.service = build("gmail", "v1", credentials=delegated_credentials) cls._instance = super(EmailClient, cls).__new__(cls) return cls._instance