mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-26 12:31:52 -05:00
Updated all usage of datetime.utcnow() to
app.utils utc_now() function. Added new endpoint
/service/{{service_id}}/notifications/month
This commit is contained in:
@@ -706,7 +706,7 @@ def get_monthly_notification_stats_by_user(service_id, user_id):
|
||||
|
||||
statistics.add_monthly_notification_status_stats(data, stats)
|
||||
|
||||
now = datetime.utcnow()
|
||||
now = utc_now()
|
||||
if end_date > now:
|
||||
todays_deltas = fetch_notification_status_for_service_for_day(
|
||||
now, service_id=service_id
|
||||
@@ -749,6 +749,35 @@ def get_single_month_notification_stats_by_user(service_id, user_id):
|
||||
return jsonify(stats)
|
||||
|
||||
|
||||
@service_blueprint.route("/<uuid:service_id>/notifications/month", methods=["GET"])
|
||||
def get_single_month_notification_stats_for_service(service_id):
|
||||
# check service_id validity
|
||||
dao_fetch_service_by_id(service_id)
|
||||
|
||||
try:
|
||||
month = int(request.args.get("month", "NaN"))
|
||||
year = int(request.args.get("year", "NaN"))
|
||||
except ValueError:
|
||||
raise InvalidRequest(
|
||||
"Both a month and year are required as numbers", status_code=400
|
||||
)
|
||||
|
||||
month_year = datetime(year, month, 10, 00, 00, 00)
|
||||
days = get_number_of_days_for_month(year, month)
|
||||
start_date, end_date = get_month_start_and_end_date_in_utc(month_year)
|
||||
|
||||
stats = {}
|
||||
for d in range(days):
|
||||
new_date = start_date + timedelta(days=d)
|
||||
if new_date <= end_date:
|
||||
key = new_date.strftime("%Y-%m-%d")
|
||||
stats[key] = statistics.format_statistics(
|
||||
dao_fetch_stats_for_service_from_day(service_id, new_date)
|
||||
)
|
||||
|
||||
return jsonify(stats)
|
||||
|
||||
|
||||
def get_detailed_service(service_id, today_only=False):
|
||||
service = dao_fetch_service_by_id(service_id)
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ from alembic import op
|
||||
from sqlalchemy import text
|
||||
|
||||
from app.hashing import hashpw
|
||||
from app.utils import utc_now
|
||||
|
||||
revision = "0025_notify_service_data"
|
||||
down_revision = "0024_add_research_mode_defaults"
|
||||
@@ -32,7 +33,7 @@ def upgrade():
|
||||
"""
|
||||
conn.execute(
|
||||
text(user_insert),
|
||||
{"user_id": user_id, "time_now": datetime.utcnow(), "password": password},
|
||||
{"user_id": user_id, "time_now": utc_now(), "password": password},
|
||||
)
|
||||
service_history_insert = """INSERT INTO services_history (id, name, created_at, active, message_limit, restricted, research_mode, email_from, created_by_id, reply_to_email_address, version)
|
||||
VALUES (:service_id, 'Notify service', :time_now, True, 1000, False, False, 'testsender@dispostable.com',
|
||||
@@ -41,7 +42,7 @@ def upgrade():
|
||||
"""
|
||||
conn.execute(
|
||||
text(service_history_insert),
|
||||
{"service_id": service_id, "time_now": datetime.utcnow(), "user_id": user_id},
|
||||
{"service_id": service_id, "time_now": utc_now(), "user_id": user_id},
|
||||
)
|
||||
service_insert = """INSERT INTO services (id, name, created_at, active, message_limit, restricted, research_mode, email_from, created_by_id, reply_to_email_address, version)
|
||||
VALUES (:service_id, 'Notify service', :time_now, True, 1000, False, False, 'testsender@dispostable.com',
|
||||
@@ -49,7 +50,7 @@ def upgrade():
|
||||
"""
|
||||
conn.execute(
|
||||
text(service_insert),
|
||||
{"service_id": service_id, "time_now": datetime.utcnow(), "user_id": user_id},
|
||||
{"service_id": service_id, "time_now": utc_now(), "user_id": user_id},
|
||||
)
|
||||
user_to_service_insert = """INSERT INTO user_to_service (user_id, service_id) VALUES (:user_id, :service_id)"""
|
||||
conn.execute(
|
||||
@@ -74,7 +75,7 @@ def upgrade():
|
||||
"template_id": uuid.uuid4(),
|
||||
"template_name": "Notify email verification code",
|
||||
"template_type": "email",
|
||||
"time_now": datetime.utcnow(),
|
||||
"time_now": utc_now(),
|
||||
"content": email_verification_content,
|
||||
"service_id": service_id,
|
||||
"subject": "Confirm GOV.UK Notify registration",
|
||||
@@ -87,7 +88,7 @@ def upgrade():
|
||||
"template_id": "ece42649-22a8-4d06-b87f-d52d5d3f0a27",
|
||||
"template_name": "Notify email verification code",
|
||||
"template_type": "email",
|
||||
"time_now": datetime.utcnow(),
|
||||
"time_now": utc_now(),
|
||||
"content": email_verification_content,
|
||||
"service_id": service_id,
|
||||
"subject": "Confirm GOV.UK Notify registration",
|
||||
@@ -107,7 +108,7 @@ def upgrade():
|
||||
"template_id": "4f46df42-f795-4cc4-83bb-65ca312f49cc",
|
||||
"template_name": "Notify invitation email",
|
||||
"template_type": "email",
|
||||
"time_now": datetime.utcnow(),
|
||||
"time_now": utc_now(),
|
||||
"content": invitation_content,
|
||||
"service_id": service_id,
|
||||
"subject": invitation_subject,
|
||||
@@ -120,7 +121,7 @@ def upgrade():
|
||||
"template_id": "4f46df42-f795-4cc4-83bb-65ca312f49cc",
|
||||
"template_name": "Notify invitation email",
|
||||
"template_type": "email",
|
||||
"time_now": datetime.utcnow(),
|
||||
"time_now": utc_now(),
|
||||
"content": invitation_content,
|
||||
"service_id": service_id,
|
||||
"subject": invitation_subject,
|
||||
@@ -135,7 +136,7 @@ def upgrade():
|
||||
"template_id": "36fb0730-6259-4da1-8a80-c8de22ad4246",
|
||||
"template_name": "Notify SMS verify code",
|
||||
"template_type": "sms",
|
||||
"time_now": datetime.utcnow(),
|
||||
"time_now": utc_now(),
|
||||
"content": sms_code_content,
|
||||
"service_id": service_id,
|
||||
"subject": None,
|
||||
@@ -149,7 +150,7 @@ def upgrade():
|
||||
"template_id": "36fb0730-6259-4da1-8a80-c8de22ad4246",
|
||||
"template_name": "Notify SMS verify code",
|
||||
"template_type": "sms",
|
||||
"time_now": datetime.utcnow(),
|
||||
"time_now": utc_now(),
|
||||
"content": sms_code_content,
|
||||
"service_id": service_id,
|
||||
"subject": None,
|
||||
@@ -172,7 +173,7 @@ def upgrade():
|
||||
"template_id": "474e9242-823b-4f99-813d-ed392e7f1201",
|
||||
"template_name": "Notify password reset email",
|
||||
"template_type": "email",
|
||||
"time_now": datetime.utcnow(),
|
||||
"time_now": utc_now(),
|
||||
"content": password_reset_content,
|
||||
"service_id": service_id,
|
||||
"subject": "Reset your GOV.UK Notify password",
|
||||
@@ -186,7 +187,7 @@ def upgrade():
|
||||
"template_id": "474e9242-823b-4f99-813d-ed392e7f1201",
|
||||
"template_name": "Notify password reset email",
|
||||
"template_type": "email",
|
||||
"time_now": datetime.utcnow(),
|
||||
"time_now": utc_now(),
|
||||
"content": password_reset_content,
|
||||
"service_id": service_id,
|
||||
"subject": "Reset your GOV.UK Notify password",
|
||||
|
||||
@@ -11,6 +11,8 @@ from datetime import datetime
|
||||
|
||||
from sqlalchemy import text
|
||||
|
||||
from app.utils import utc_now
|
||||
|
||||
revision = "0028_fix_reg_template_history"
|
||||
down_revision = "0026_rename_notify_service"
|
||||
|
||||
@@ -38,7 +40,7 @@ def upgrade():
|
||||
"id": "ece42649-22a8-4d06-b87f-d52d5d3f0a27",
|
||||
"name": "Notify email verification code",
|
||||
"type": "email",
|
||||
"time_now": datetime.utcnow(),
|
||||
"time_now": utc_now(),
|
||||
"content": email_verification_content,
|
||||
"service_id": service_id,
|
||||
"subject": "Confirm GOV.UK Notify registration",
|
||||
|
||||
@@ -14,6 +14,8 @@ from alembic import op
|
||||
from flask import current_app
|
||||
from sqlalchemy import text
|
||||
|
||||
from app.utils import utc_now
|
||||
|
||||
revision = "0082_add_go_live_template"
|
||||
down_revision = "0081_noti_status_as_enum"
|
||||
|
||||
@@ -89,7 +91,7 @@ GOV.UK Notify team
|
||||
"template_id": template_id,
|
||||
"template_name": template_name,
|
||||
"template_type": "email",
|
||||
"time_now": datetime.utcnow(),
|
||||
"time_now": utc_now(),
|
||||
"content": template_content,
|
||||
"notify_service_id": current_app.config["NOTIFY_SERVICE_ID"],
|
||||
"subject": template_subject,
|
||||
|
||||
@@ -9,6 +9,8 @@ Create Date: 2017-08-29 14:09:41.042061
|
||||
# revision identifiers, used by Alembic.
|
||||
from sqlalchemy import text
|
||||
|
||||
from app.utils import utc_now
|
||||
|
||||
revision = "0117_international_sms_notify"
|
||||
down_revision = "0115_add_inbound_numbers"
|
||||
|
||||
@@ -22,7 +24,7 @@ NOTIFY_SERVICE_ID = "d6aa2c68-a2d9-4437-ab19-3ae8eb202553"
|
||||
def upgrade():
|
||||
input_params = {
|
||||
"notify_service_id": NOTIFY_SERVICE_ID,
|
||||
"datetime_now": datetime.utcnow(),
|
||||
"datetime_now": utc_now(),
|
||||
}
|
||||
conn = op.get_bind()
|
||||
conn.execute(
|
||||
|
||||
@@ -12,6 +12,8 @@ from alembic import op
|
||||
from flask import current_app
|
||||
from sqlalchemy import text
|
||||
|
||||
from app.utils import utc_now
|
||||
|
||||
revision = "0134_add_email_2fa_template"
|
||||
down_revision = "0133_set_services_sms_prefix"
|
||||
|
||||
@@ -44,7 +46,7 @@ def upgrade():
|
||||
"template_id": template_id,
|
||||
"template_name": template_name,
|
||||
"template_type": "email",
|
||||
"time_now": datetime.utcnow(),
|
||||
"time_now": utc_now(),
|
||||
"content": template_content,
|
||||
"notify_service_id": current_app.config["NOTIFY_SERVICE_ID"],
|
||||
"subject": template_subject,
|
||||
|
||||
@@ -13,6 +13,7 @@ from alembic import op
|
||||
from sqlalchemy import text
|
||||
|
||||
from app.dao.date_util import get_current_calendar_year_start_year
|
||||
from app.utils import utc_now
|
||||
|
||||
revision = "0139_migrate_sms_allowance_data"
|
||||
down_revision = "0138_sms_sender_nullable"
|
||||
@@ -34,7 +35,7 @@ def upgrade():
|
||||
input_params = {
|
||||
"current_year": current_year,
|
||||
"default_limit": default_limit,
|
||||
"time_now": datetime.utcnow(),
|
||||
"time_now": utc_now(),
|
||||
}
|
||||
insert_row_if_not_exist = """
|
||||
INSERT INTO annual_billing
|
||||
|
||||
@@ -12,6 +12,8 @@ from alembic import op
|
||||
from flask import current_app
|
||||
from sqlalchemy import text
|
||||
|
||||
from app.utils import utc_now
|
||||
|
||||
revision = "0171_add_org_invite_template"
|
||||
down_revision = "0170_hidden_non_nullable"
|
||||
|
||||
@@ -53,7 +55,7 @@ def upgrade():
|
||||
"template_id": template_id,
|
||||
"template_name": template_name,
|
||||
"template_type": "email",
|
||||
"time_now": datetime.utcnow(),
|
||||
"time_now": utc_now(),
|
||||
"content": template_content,
|
||||
"notify_service_id": current_app.config["NOTIFY_SERVICE_ID"],
|
||||
"subject": template_subject,
|
||||
|
||||
@@ -12,6 +12,8 @@ from alembic import op
|
||||
from flask import current_app
|
||||
from sqlalchemy import text
|
||||
|
||||
from app.utils import utc_now
|
||||
|
||||
revision = "0265_add_confirm_edit_templates"
|
||||
down_revision = "0264_add_folder_permissions_perm"
|
||||
|
||||
@@ -57,7 +59,7 @@ def upgrade():
|
||||
"template_id": email_template_id,
|
||||
"template_name": email_template_name,
|
||||
"template_type": "email",
|
||||
"time_now": datetime.utcnow(),
|
||||
"time_now": utc_now(),
|
||||
"content": email_template_content,
|
||||
"notify_service_id": current_app.config["NOTIFY_SERVICE_ID"],
|
||||
"subject": email_template_subject,
|
||||
@@ -78,7 +80,7 @@ def upgrade():
|
||||
"template_id": mobile_template_id,
|
||||
"template_name": mobile_template_name,
|
||||
"template_type": "sms",
|
||||
"time_now": datetime.utcnow(),
|
||||
"time_now": utc_now(),
|
||||
"content": mobile_template_content,
|
||||
"notify_service_id": current_app.config["NOTIFY_SERVICE_ID"],
|
||||
"subject": None,
|
||||
|
||||
@@ -12,6 +12,8 @@ from alembic import op
|
||||
from flask import current_app
|
||||
from sqlalchemy import text
|
||||
|
||||
from app.utils import utc_now
|
||||
|
||||
revision = "0294_add_verify_reply_to"
|
||||
down_revision = "0293_drop_complaint_fk"
|
||||
|
||||
@@ -58,7 +60,7 @@ def upgrade():
|
||||
"template_id": email_template_id,
|
||||
"template_name": email_template_name,
|
||||
"template_type": "email",
|
||||
"time_now": datetime.utcnow(),
|
||||
"time_now": utc_now(),
|
||||
"content": email_template_content,
|
||||
"notify_service_id": current_app.config["NOTIFY_SERVICE_ID"],
|
||||
"subject": email_template_subject,
|
||||
|
||||
@@ -12,6 +12,8 @@ from datetime import datetime
|
||||
from alembic import op
|
||||
from sqlalchemy import text
|
||||
|
||||
from app.utils import utc_now
|
||||
|
||||
revision = "0330_broadcast_invite_email"
|
||||
down_revision = "0329_purge_broadcast_data"
|
||||
|
||||
@@ -60,7 +62,7 @@ def upgrade():
|
||||
input_params = {
|
||||
"template_id": template_id,
|
||||
"template_name": broadcast_invitation_template_name,
|
||||
"time_now": datetime.utcnow(),
|
||||
"time_now": utc_now(),
|
||||
"content": broadcast_invitation_content,
|
||||
"service_id": service_id,
|
||||
"subject": broadcast_invitation_subject,
|
||||
|
||||
@@ -13,6 +13,8 @@ from alembic import op
|
||||
from flask import current_app
|
||||
from sqlalchemy import text
|
||||
|
||||
from app.utils import utc_now
|
||||
|
||||
revision = "0347_add_dvla_volumes_template"
|
||||
down_revision = "0346_notify_number_sms_sender"
|
||||
|
||||
@@ -57,7 +59,7 @@ def upgrade():
|
||||
"template_id": email_template_id,
|
||||
"template_name": email_template_name,
|
||||
"template_type": "email",
|
||||
"time_now": datetime.utcnow(),
|
||||
"time_now": utc_now(),
|
||||
"content": email_template_content,
|
||||
"notify_service_id": current_app.config["NOTIFY_SERVICE_ID"],
|
||||
"subject": email_template_subject,
|
||||
|
||||
@@ -16,6 +16,7 @@ from alembic import op
|
||||
from app import db
|
||||
from app.dao.users_dao import get_user_by_email
|
||||
from app.models import User
|
||||
from app.utils import utc_now
|
||||
|
||||
revision = "0401_add_e2e_test_user"
|
||||
down_revision = "0400_add_total_message_limit"
|
||||
@@ -32,11 +33,11 @@ def upgrade():
|
||||
"password": password,
|
||||
"mobile_number": "+12025555555",
|
||||
"state": "active",
|
||||
"created_at": datetime.datetime.utcnow(),
|
||||
"password_changed_at": datetime.datetime.utcnow(),
|
||||
"created_at": utc_now(),
|
||||
"password_changed_at": utc_now(),
|
||||
"failed_login_count": 0,
|
||||
"platform_admin": "f",
|
||||
"email_access_validated_at": datetime.datetime.utcnow(),
|
||||
"email_access_validated_at": utc_now(),
|
||||
}
|
||||
conn = op.get_bind()
|
||||
insert_sql = """
|
||||
|
||||
Reference in New Issue
Block a user