mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-17 23:34:05 -04:00
delete commented out code
This commit is contained in:
@@ -349,7 +349,7 @@
|
||||
"filename": "tests/app/user/test_rest.py",
|
||||
"hashed_secret": "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33",
|
||||
"is_verified": false,
|
||||
"line_number": 962,
|
||||
"line_number": 810,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
@@ -384,5 +384,5 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"generated_at": "2024-07-10T20:12:22Z"
|
||||
"generated_at": "2024-07-22T21:27:35Z"
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import json
|
||||
import os
|
||||
from datetime import timedelta
|
||||
|
||||
from botocore.exceptions import ClientError
|
||||
from flask import current_app
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
@@ -62,6 +63,21 @@ def check_sms_delivery_receipt(self, message_id, notification_id, sent_at):
|
||||
provider_response=provider_response,
|
||||
)
|
||||
raise self.retry(exc=ntfe)
|
||||
except ClientError as err:
|
||||
# Probably a ThrottlingException but could be something else
|
||||
error_code = err.response["Error"]["Code"]
|
||||
provider_response = (
|
||||
f"{error_code} while checking sms receipt -- still looking"
|
||||
)
|
||||
status = "pending"
|
||||
carrier = ""
|
||||
update_notification_status_by_id(
|
||||
notification_id,
|
||||
status,
|
||||
carrier=carrier,
|
||||
provider_response=provider_response,
|
||||
)
|
||||
raise self.retry(exc=err)
|
||||
|
||||
if status == "success":
|
||||
status = NotificationStatus.DELIVERED
|
||||
|
||||
@@ -9,10 +9,6 @@ from app.enums import KeyType
|
||||
from app.exceptions import ArchiveValidationError
|
||||
from notifications_utils.recipients import InvalidEmailError
|
||||
|
||||
# class VirusScanError(Exception):
|
||||
# def __init__(self, message):
|
||||
# super().__init__(message)
|
||||
|
||||
|
||||
class InvalidRequest(Exception):
|
||||
code = None
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
# from datetime import timedelta
|
||||
|
||||
from flask import Blueprint, jsonify, request
|
||||
|
||||
from app.celery.process_ses_receipts_tasks import process_ses_results
|
||||
@@ -8,7 +6,6 @@ from app.errors import InvalidRequest
|
||||
from app.notifications.sns_handlers import sns_notification_handler
|
||||
|
||||
ses_callback_blueprint = Blueprint("notifications_ses_callback", __name__)
|
||||
# DEFAULT_MAX_AGE = timedelta(days=10000)
|
||||
|
||||
|
||||
# 400 counts as a permanent failure so SNS will not retry.
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import enum
|
||||
|
||||
# from datetime import timedelta
|
||||
from json import decoder
|
||||
|
||||
import requests
|
||||
@@ -9,8 +7,6 @@ from flask import current_app, json
|
||||
from app.errors import InvalidRequest
|
||||
from app.notifications.sns_cert_validator import validate_sns_cert
|
||||
|
||||
# DEFAULT_MAX_AGE = timedelta(days=10000)
|
||||
|
||||
|
||||
class SNSMessageType(enum.Enum):
|
||||
SubscriptionConfirmation = "SubscriptionConfirmation"
|
||||
|
||||
@@ -13,7 +13,7 @@ from app.dao.service_user_dao import dao_get_service_user, dao_update_service_us
|
||||
from app.dao.services_dao import dao_fetch_service_by_id
|
||||
from app.dao.template_folder_dao import dao_get_template_folder_by_id_and_service_id
|
||||
from app.dao.templates_dao import dao_get_template_by_id
|
||||
from app.dao.users_dao import ( # get_user_and_accounts,; update_user_password,
|
||||
from app.dao.users_dao import (
|
||||
count_user_verify_codes,
|
||||
create_secret_code,
|
||||
create_user_code,
|
||||
@@ -40,7 +40,7 @@ from app.notifications.process_notifications import (
|
||||
send_notification_to_queue,
|
||||
)
|
||||
from app.schema_validation import validate
|
||||
from app.schemas import ( # user_update_password_schema_load_json,
|
||||
from app.schemas import (
|
||||
create_user_schema,
|
||||
email_data_request_schema,
|
||||
partial_email_data_request_schema,
|
||||
@@ -626,57 +626,6 @@ def get_all_users():
|
||||
return jsonify(data=result), 200
|
||||
|
||||
|
||||
# @user_blueprint.route("/reset-password", methods=["POST"])
|
||||
# def send_user_reset_password():
|
||||
# request_json = request.get_json()
|
||||
# email = email_data_request_schema.load(request_json)
|
||||
|
||||
# user_to_send_to = get_user_by_email(email["email"])
|
||||
# template = dao_get_template_by_id(current_app.config["PASSWORD_RESET_TEMPLATE_ID"])
|
||||
# service = Service.query.get(current_app.config["NOTIFY_SERVICE_ID"])
|
||||
# personalisation = {
|
||||
# "user_name": user_to_send_to.name,
|
||||
# "url": _create_reset_password_url(
|
||||
# user_to_send_to.email_address,
|
||||
# base_url=request_json.get("admin_base_url"),
|
||||
# next_redirect=request_json.get("next"),
|
||||
# ),
|
||||
# }
|
||||
# saved_notification = persist_notification(
|
||||
# template_id=template.id,
|
||||
# template_version=template.version,
|
||||
# recipient=email["email"],
|
||||
# service=service,
|
||||
# personalisation=None,
|
||||
# notification_type=template.template_type,
|
||||
# api_key_id=None,
|
||||
# key_type=KeyType.NORMAL,
|
||||
# reply_to_text=service.get_default_reply_to_email_address(),
|
||||
# )
|
||||
# saved_notification.personalisation = personalisation
|
||||
|
||||
# redis_store.set(
|
||||
# f"email-personalisation-{saved_notification.id}",
|
||||
# json.dumps(personalisation),
|
||||
# ex=60 * 60,
|
||||
# )
|
||||
# send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)
|
||||
|
||||
# return jsonify({}), 204
|
||||
|
||||
|
||||
# @user_blueprint.route("/<uuid:user_id>/update-password", methods=["POST"])
|
||||
# def update_password(user_id):
|
||||
# user = get_user_by_id(user_id=user_id)
|
||||
# req_json = request.get_json()
|
||||
# password = req_json.get("_password")
|
||||
|
||||
# user_update_password_schema_load_json.load(req_json)
|
||||
|
||||
# update_user_password(user, password)
|
||||
# return jsonify(data=user.serialize()), 200
|
||||
|
||||
|
||||
@user_blueprint.route("/report-all-users", methods=["GET"])
|
||||
def report_all_users():
|
||||
users = dao_report_users()
|
||||
@@ -690,17 +639,6 @@ def get_organizations_and_services_for_user(user_id):
|
||||
return jsonify(data)
|
||||
|
||||
|
||||
# def _create_reset_password_url(email, next_redirect, base_url=None):
|
||||
# data = json.dumps({"email": email, "created_at": str(utc_now())})
|
||||
# static_url_part = "/new-password/"
|
||||
# full_url = url_with_token(
|
||||
# data, static_url_part, current_app.config, base_url=base_url
|
||||
# )
|
||||
# if next_redirect:
|
||||
# full_url += "?{}".format(urlencode({"next": next_redirect}))
|
||||
# return full_url
|
||||
|
||||
|
||||
def _create_verification_url(user, base_url):
|
||||
data = json.dumps({"user_id": str(user.id), "email": user.email_address})
|
||||
url = "/verify-email/"
|
||||
|
||||
19
app/utils.py
19
app/utils.py
@@ -60,11 +60,6 @@ def get_midnight_in_utc(date):
|
||||
return datetime.combine(date, datetime.min.time())
|
||||
|
||||
|
||||
# def get_midnight_for_day_before(date):
|
||||
# day_before = date - timedelta(1)
|
||||
# return get_midnight_in_utc(day_before)
|
||||
|
||||
|
||||
def get_month_from_utc_column(column):
|
||||
"""
|
||||
Where queries need to count notifications by month it needs to be
|
||||
@@ -112,20 +107,6 @@ def get_dt_string_or_none(val):
|
||||
return val.strftime(DATETIME_FORMAT) if val else None
|
||||
|
||||
|
||||
# def get_uuid_string_or_none(val):
|
||||
# return str(val) if val else None
|
||||
|
||||
|
||||
# def format_sequential_number(sequential_number):
|
||||
# return format(sequential_number, "x").zfill(8)
|
||||
|
||||
|
||||
# def get_reference_from_personalisation(personalisation):
|
||||
# if personalisation:
|
||||
# return personalisation.get("reference")
|
||||
# return None
|
||||
|
||||
|
||||
# Function used for debugging.
|
||||
# Do print(hilite(message)) while debugging, then remove your print statements
|
||||
def hilite(message):
|
||||
|
||||
@@ -432,6 +432,8 @@ Rules for use:
|
||||
|
||||
### Deploying to the sandbox
|
||||
|
||||
If this is the first time you have used Terraform in this repository, you will first have to hook your copy of Terraform up to our remote state. Follow [Retrieving existing bucket credentials](https://github.com/GSA/notifications-api/tree/main/terraform#retrieving-existing-bucket-credentials).
|
||||
|
||||
1. Set up services:
|
||||
```
|
||||
$ cd terraform/sandbox
|
||||
@@ -440,6 +442,7 @@ Rules for use:
|
||||
$ terraform plan
|
||||
$ terraform apply
|
||||
```
|
||||
1. Change back to the project root directory: `cd ../..`
|
||||
1. start a poetry shell as a shortcut to load `.env` file variables: `$ poetry shell`
|
||||
1. Output requirements.txt file: `poetry export --without-hashes --format=requirements.txt > requirements.txt`
|
||||
1. Deploy the application:
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
# Terraform
|
||||
|
||||
This directory holds the Terraform modules for maintaining Notify.gov's API infrastructure. You might want to:
|
||||
* [read about the directory structure](#structure), or
|
||||
* [get set up to develop HCL code](#retrieving-existing-bucket-credentials).
|
||||
* [Set up](#retrieving-existing-bucket-credentials) the Sandbox and develop Terraform,
|
||||
* [Learn](#structure) about the directory structure, or
|
||||
* [Troubleshoot](#troubleshooting) error messages
|
||||
|
||||
The Admin app repo [has its own terraform directory](https://github.com/GSA/notifications-admin/tree/main/terraform) but a lot of the below instructions apply to both apps.
|
||||
|
||||
@@ -228,3 +229,32 @@ The audit event logs may also provide insight. They are visible in web UI or [in
|
||||
Error: Error creating SES domain identity verification: Expected domain verification Success, but was in state Pending
|
||||
```
|
||||
This error comes via the [Supplementary Service Broker](https://github.com/GSA/usnotify-ssb/) and originates from the [SMTP Brokerpak](https://github.com/GSA-TTS/datagov-brokerpak-smtp) it uses. You can run the [broker provisioning locally](https://github.com/GSA-TTS/datagov-brokerpak-smtp/tree/main/terraform/provision) to tinker with the error.
|
||||
|
||||
### Validating provider credentials
|
||||
```
|
||||
Error: validating provider credentials: retrieving caller identity from STS: operation error STS: GetCallerIdentity, https response error StatusCode: 403
|
||||
```
|
||||
The steps in [Use bootstrap credentials](#use-bootstrap-credentials) may not be complete. Or the AWS CLI may have reverted to the default profile, in which case, re-run:
|
||||
```bash
|
||||
export AWS_PROFILE=notify-terraform-backend
|
||||
```
|
||||
|
||||
### No valid credential sources
|
||||
```
|
||||
Error: No valid credential sources found
|
||||
Please see https://www.terraform.io/docs/language/settings/backends/s3.html for more information about providing credentials.
|
||||
|
||||
Error: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds: GetMetadata, request canceled, context deadline exceeded
|
||||
```
|
||||
You are not hooked up to the remote backend that stores Terraform state
|
||||
Run steps in [Retrieving existing bucket credentials](#retrieving-existing-bucket-credentials).
|
||||
|
||||
### Space Deployers will be updated in-place
|
||||
```
|
||||
# module.egress-space.cloudfoundry_space_users.deployers will be updated in-place
|
||||
~ resource "cloudfoundry_space_users" "deployers" {
|
||||
~ developers = [
|
||||
- "xxx-GUID-xxx",
|
||||
+ "yyy-GUID-yyy",
|
||||
```
|
||||
The environment was last deployed by someone other than you, using a different Space Deployer account. If you are working in the Sandbox environment, this is fine; go ahead and apply the changes. After you do, the other person evidently also working in the Sandbox env will then see the same message. The two of you might play tug-of-war with different GUIDs, but this is inconsequential.
|
||||
|
||||
@@ -6,12 +6,11 @@ locals {
|
||||
}
|
||||
|
||||
module "csv_upload_bucket" {
|
||||
source = "github.com/18f/terraform-cloudgov//s3?ref=v0.7.1"
|
||||
source = "github.com/GSA-TTS/terraform-cloudgov//s3?ref=v1.0.0"
|
||||
|
||||
cf_org_name = local.cf_org_name
|
||||
cf_space_name = local.cf_space_name
|
||||
recursive_delete = local.recursive_delete
|
||||
name = "${var.username}-csv-upload-bucket"
|
||||
cf_org_name = local.cf_org_name
|
||||
cf_space_name = local.cf_space_name
|
||||
name = "${var.username}-csv-upload-bucket"
|
||||
}
|
||||
resource "cloudfoundry_service_key" "csv_key" {
|
||||
name = local.key_name
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# import uuid
|
||||
from datetime import date, datetime
|
||||
|
||||
import pytest
|
||||
@@ -27,18 +26,6 @@ def test_get_midnight_in_utc_returns_expected_date(date, expected_date):
|
||||
assert get_midnight_in_utc(date) == expected_date
|
||||
|
||||
|
||||
# @pytest.mark.parametrize(
|
||||
# "date, expected_date",
|
||||
# [
|
||||
# (datetime(2016, 1, 15, 0, 30), datetime(2016, 1, 14, 0, 0)),
|
||||
# (datetime(2016, 7, 15, 0, 0), datetime(2016, 7, 14, 0, 0)),
|
||||
# (datetime(2016, 8, 23, 11, 59), datetime(2016, 8, 22, 0, 0)),
|
||||
# ],
|
||||
# )
|
||||
# def test_get_midnight_for_day_before_returns_expected_date(date, expected_date):
|
||||
# assert get_midnight_for_day_before(date) == expected_date
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"current_time, arg, expected_datetime",
|
||||
[
|
||||
@@ -61,40 +48,7 @@ def test_midnight_n_days_ago(current_time, arg, expected_datetime):
|
||||
assert midnight_n_days_ago(arg) == expected_datetime
|
||||
|
||||
|
||||
# def test_format_sequential_number():
|
||||
# assert format_sequential_number(123) == "0000007b"
|
||||
|
||||
|
||||
# @pytest.mark.parametrize(
|
||||
# "personalisation, expected_response",
|
||||
# [
|
||||
# ({"nothing": "interesting"}, None),
|
||||
# ({"reference": "something"}, "something"),
|
||||
# (None, None),
|
||||
# ],
|
||||
# )
|
||||
# def test_get_reference_from_personalisation(personalisation, expected_response):
|
||||
# assert get_reference_from_personalisation(personalisation) == expected_response
|
||||
|
||||
|
||||
# def test_get_uuid_string_or_none():
|
||||
# my_uuid = uuid.uuid4()
|
||||
# assert str(my_uuid) == get_uuid_string_or_none(my_uuid)
|
||||
|
||||
# assert get_uuid_string_or_none(None) is None
|
||||
|
||||
|
||||
def test_get_public_notify_type_text():
|
||||
assert (
|
||||
get_public_notify_type_text(ServicePermissionType.UPLOAD_DOCUMENT) == "document"
|
||||
)
|
||||
|
||||
|
||||
# This method is used for simulating bulk sends. We use localstack and run on a developer's machine to do the
|
||||
# simulation. Please see docs->bulk_testing.md for instructions.
|
||||
# def test_generate_csv_for_bulk_testing():
|
||||
# f = open("bulktest_100000.csv", "w")
|
||||
# f.write("phone number\n")
|
||||
# for _ in range(0, 100000):
|
||||
# f.write("16615555555\n")
|
||||
# f.close()
|
||||
|
||||
@@ -632,137 +632,6 @@ def test_remove_user_folder_permissions(admin_request, sample_user, sample_servi
|
||||
assert service_user.folders == []
|
||||
|
||||
|
||||
# @freeze_time("2016-01-01 11:09:00.061258")
|
||||
# def test_send_user_reset_password_should_send_reset_password_link(
|
||||
# admin_request, sample_user, mocker, password_reset_email_template
|
||||
# ):
|
||||
# mocked = mocker.patch("app.celery.provider_tasks.deliver_email.apply_async")
|
||||
# data = {"email": sample_user.email_address}
|
||||
# notify_service = password_reset_email_template.service
|
||||
|
||||
# admin_request.post(
|
||||
# "user.send_user_reset_password",
|
||||
# _data=data,
|
||||
# _expected_status=204,
|
||||
# )
|
||||
|
||||
# notification = Notification.query.first()
|
||||
# mocked.assert_called_once_with(
|
||||
# [str(notification.id)], queue="notify-internal-tasks"
|
||||
# )
|
||||
# assert (
|
||||
# notification.reply_to_text
|
||||
# == notify_service.get_default_reply_to_email_address()
|
||||
# )
|
||||
|
||||
|
||||
# @pytest.mark.parametrize(
|
||||
# "data, expected_url",
|
||||
# (
|
||||
# (
|
||||
# {
|
||||
# "email": "notify@digital.fake.gov",
|
||||
# },
|
||||
# ("http://localhost:6012/new-password/"),
|
||||
# ),
|
||||
# (
|
||||
# {
|
||||
# "email": "notify@digital.fake.gov",
|
||||
# "admin_base_url": "https://different.example.com",
|
||||
# },
|
||||
# ("https://different.example.com/new-password/"),
|
||||
# ),
|
||||
# ),
|
||||
# )
|
||||
# @freeze_time("2016-01-01 11:09:00.061258")
|
||||
# def test_send_user_reset_password_should_use_provided_base_url(
|
||||
# admin_request,
|
||||
# sample_user,
|
||||
# password_reset_email_template,
|
||||
# mocker,
|
||||
# data,
|
||||
# expected_url,
|
||||
# ):
|
||||
# mocker.patch("app.celery.provider_tasks.deliver_email.apply_async")
|
||||
|
||||
# admin_request.post(
|
||||
# "user.send_user_reset_password",
|
||||
# _data=data,
|
||||
# _expected_status=204,
|
||||
# )
|
||||
|
||||
# assert Notification.query.first().personalisation["url"].startswith(expected_url)
|
||||
|
||||
|
||||
# @freeze_time("2016-01-01 11:09:00.061258")
|
||||
# def test_send_user_reset_password_reset_password_link_contains_redirect_link_if_present_in_request(
|
||||
# admin_request, sample_user, mocker, password_reset_email_template
|
||||
# ):
|
||||
# mocked = mocker.patch("app.celery.provider_tasks.deliver_email.apply_async")
|
||||
# data = {"email": sample_user.email_address, "next": "blob"}
|
||||
|
||||
# admin_request.post(
|
||||
# "user.send_user_reset_password",
|
||||
# _data=data,
|
||||
# _expected_status=204,
|
||||
# )
|
||||
|
||||
# notification = Notification.query.first()
|
||||
# assert "?next=blob" in notification.content
|
||||
# mocked.assert_called_once_with(
|
||||
# [str(notification.id)], queue="notify-internal-tasks"
|
||||
# )
|
||||
|
||||
|
||||
# def test_send_user_reset_password_should_return_400_when_email_is_missing(
|
||||
# admin_request, mocker
|
||||
# ):
|
||||
# mocked = mocker.patch("app.celery.provider_tasks.deliver_email.apply_async")
|
||||
# data = {}
|
||||
|
||||
# json_resp = admin_request.post(
|
||||
# "user.send_user_reset_password",
|
||||
# _data=data,
|
||||
# _expected_status=400,
|
||||
# )
|
||||
# assert json_resp["message"] == {"email": ["Missing data for required field."]}
|
||||
# assert mocked.call_count == 0
|
||||
|
||||
|
||||
# def test_send_user_reset_password_should_return_400_when_user_doesnot_exist(
|
||||
# admin_request, mocker
|
||||
# ):
|
||||
# mocked = mocker.patch("app.celery.provider_tasks.deliver_email.apply_async")
|
||||
# bad_email_address = "bad@email.gov.uk"
|
||||
# data = {"email": bad_email_address}
|
||||
|
||||
# json_resp = admin_request.post(
|
||||
# "user.send_user_reset_password",
|
||||
# _data=data,
|
||||
# _expected_status=404,
|
||||
# )
|
||||
|
||||
# assert json_resp["message"] == "No result found"
|
||||
# assert mocked.call_count == 0
|
||||
|
||||
|
||||
# def test_send_user_reset_password_should_return_400_when_data_is_not_email_address(
|
||||
# admin_request, mocker
|
||||
# ):
|
||||
# mocked = mocker.patch("app.celery.provider_tasks.deliver_email.apply_async")
|
||||
# bad_email_address = "bad.email.gov.uk"
|
||||
# data = {"email": bad_email_address}
|
||||
|
||||
# json_resp = admin_request.post(
|
||||
# "user.send_user_reset_password",
|
||||
# _data=data,
|
||||
# _expected_status=400,
|
||||
# )
|
||||
|
||||
# assert json_resp["message"] == {"email": ["Not a valid email address"]}
|
||||
# assert mocked.call_count == 0
|
||||
|
||||
|
||||
def test_send_already_registered_email(
|
||||
admin_request, sample_user, already_registered_template, mocker
|
||||
):
|
||||
@@ -842,27 +711,6 @@ def test_send_user_confirm_new_email_returns_400_when_email_missing(
|
||||
mocked.assert_not_called()
|
||||
|
||||
|
||||
# @freeze_time("2020-02-14T12:00:00")
|
||||
# def test_update_user_password_saves_correctly(admin_request, sample_service):
|
||||
# sample_user = sample_service.users[0]
|
||||
# new_password = "1234567890"
|
||||
# data = {"_password": "1234567890"}
|
||||
|
||||
# json_resp = admin_request.post(
|
||||
# "user.update_password", user_id=str(sample_user.id), _data=data
|
||||
# )
|
||||
|
||||
# assert json_resp["data"]["password_changed_at"] is not None
|
||||
# data = {"password": new_password}
|
||||
|
||||
# admin_request.post(
|
||||
# "user.verify_user_password",
|
||||
# user_id=str(sample_user.id),
|
||||
# _data=data,
|
||||
# _expected_status=204,
|
||||
# )
|
||||
|
||||
|
||||
def test_activate_user(admin_request, sample_user):
|
||||
sample_user.state = "pending"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user