mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-16 20:48:37 -04:00
remove dead code
This commit is contained in:
@@ -9,10 +9,9 @@ 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 VirusScanError(Exception):
|
||||
# def __init__(self, message):
|
||||
# super().__init__(message)
|
||||
|
||||
|
||||
class InvalidRequest(Exception):
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from datetime import timedelta
|
||||
# from datetime import timedelta
|
||||
|
||||
from flask import Blueprint, jsonify, request
|
||||
|
||||
@@ -8,7 +8,7 @@ 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)
|
||||
# DEFAULT_MAX_AGE = timedelta(days=10000)
|
||||
|
||||
|
||||
# 400 counts as a permanent failure so SNS will not retry.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import enum
|
||||
from datetime import timedelta
|
||||
|
||||
# from datetime import timedelta
|
||||
from json import decoder
|
||||
|
||||
import requests
|
||||
@@ -8,7 +9,7 @@ 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)
|
||||
# DEFAULT_MAX_AGE = timedelta(days=10000)
|
||||
|
||||
|
||||
class SNSMessageType(enum.Enum):
|
||||
|
||||
108
app/user/rest.py
108
app/user/rest.py
@@ -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 (
|
||||
from app.dao.users_dao import ( # get_user_and_accounts,; update_user_password,
|
||||
count_user_verify_codes,
|
||||
create_secret_code,
|
||||
create_user_code,
|
||||
@@ -29,7 +29,6 @@ from app.dao.users_dao import (
|
||||
reset_failed_login_count,
|
||||
save_model_user,
|
||||
save_user_attribute,
|
||||
update_user_password,
|
||||
use_user_code,
|
||||
)
|
||||
from app.enums import CodeType, KeyType, NotificationType, TemplateType
|
||||
@@ -40,11 +39,10 @@ from app.notifications.process_notifications import (
|
||||
send_notification_to_queue,
|
||||
)
|
||||
from app.schema_validation import validate
|
||||
from app.schemas import (
|
||||
from app.schemas import ( # user_update_password_schema_load_json,
|
||||
create_user_schema,
|
||||
email_data_request_schema,
|
||||
partial_email_data_request_schema,
|
||||
user_update_password_schema_load_json,
|
||||
user_update_schema_load_json,
|
||||
)
|
||||
from app.user.users_schema import (
|
||||
@@ -616,55 +614,55 @@ 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_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
|
||||
# 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)
|
||||
# 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
|
||||
# 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_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)
|
||||
# user_update_password_schema_load_json.load(req_json)
|
||||
|
||||
update_user_password(user, password)
|
||||
return jsonify(data=user.serialize()), 200
|
||||
# update_user_password(user, password)
|
||||
# return jsonify(data=user.serialize()), 200
|
||||
|
||||
|
||||
@user_blueprint.route("/<uuid:user_id>/organizations-and-services", methods=["GET"])
|
||||
@@ -674,15 +672,15 @@ 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_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):
|
||||
|
||||
22
app/utils.py
22
app/utils.py
@@ -61,9 +61,9 @@ 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_midnight_for_day_before(date):
|
||||
# day_before = date - timedelta(1)
|
||||
# return get_midnight_in_utc(day_before)
|
||||
|
||||
|
||||
def get_month_from_utc_column(column):
|
||||
@@ -113,18 +113,18 @@ 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 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 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
|
||||
# def get_reference_from_personalisation(personalisation):
|
||||
# if personalisation:
|
||||
# return personalisation.get("reference")
|
||||
# return None
|
||||
|
||||
|
||||
# Function used for debugging.
|
||||
|
||||
Reference in New Issue
Block a user