Skip to content

Commit

Permalink
Merge branch 'main' into renovate/all-non-major-github-action
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbahrai authored May 6, 2024
2 parents 70a972e + 435c2d8 commit c6a28c2
Show file tree
Hide file tree
Showing 30 changed files with 582 additions and 161 deletions.
1 change: 1 addition & 0 deletions .devcontainer/scripts/notify-dev-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ echo -e "complete -F __start_kubectl k" >> ~/.zshrc

# Smoke test
# requires adding files .env_staging and .env_prod to the root of the project
echo -e "alias smoke-local='cd /workspace && cp .env_smoke_local tests_smoke/.env && poetry run make smoke-test-local'" >> ~/.zshrc
echo -e "alias smoke-staging='cd /workspace && cp .env_smoke_staging tests_smoke/.env && poetry run make smoke-test'" >> ~/.zshrc
echo -e "alias smoke-prod='cd /workspace && cp .env_smoke_prod tests_smoke/.env && poetry run make smoke-test'" >> ~/.zshrc

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
run: |
cp -f .env.example .env
- name: Checks for new endpoints against AWS WAF rules
uses: cds-snc/notification-utils/.github/actions/waffles@2da74685e0ffb220f0403e1f2584e783be99bbad # 52.1.0
uses: cds-snc/notification-utils/.github/actions/waffles@52.2.2
with:
app-loc: '/github/workspace'
app-libs: '/github/workspace/env/site-packages'
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ format:
smoke-test:
cd tests_smoke && poetry run python smoke_test.py

.PHONY: smoke-test-local
smoke-test-local:
cd tests_smoke && poetry run python smoke_test.py --local --nofiles

.PHONY: run
run: ## Run the web app
poetry run flask run -p 6011 --host=0.0.0.0
Expand Down
22 changes: 15 additions & 7 deletions app/celery/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
from flask import current_app
from itsdangerous import BadSignature
from more_itertools import chunked
from notifications_utils.recipients import RecipientCSV
from notifications_utils.recipients import (
RecipientCSV,
try_validate_and_format_phone_number,
)
from notifications_utils.statsd_decorators import statsd
from notifications_utils.template import SMSMessageTemplate, WithSubjectTemplate
from notifications_utils.timezones import convert_utc_to_local_timezone
Expand Down Expand Up @@ -243,13 +246,18 @@ def save_smss(self, service_id: Optional[str], signed_notifications: List[Signed
sender_id = _notification.get("sender_id") # type: ignore
notification_id = _notification.get("id", create_uuid())

reply_to_text = "" # type: ignore
if sender_id:
reply_to_text = dao_get_service_sms_senders_by_id(service_id, sender_id).sms_sender
elif template.service:
reply_to_text = template.get_reply_to_text()
if "reply_to_text" in _notification and _notification["reply_to_text"]:
reply_to_text = _notification["reply_to_text"]
else:
reply_to_text = service.get_default_sms_sender() # type: ignore
reply_to_text = "" # type: ignore
if sender_id:
reply_to_text = try_validate_and_format_phone_number(
dao_get_service_sms_senders_by_id(service_id, sender_id).sms_sender
)
elif template.service:
reply_to_text = template.get_reply_to_text()
else:
reply_to_text = service.get_default_sms_sender() # type: ignore

notification: VerifiedNotification = {
**_notification, # type: ignore
Expand Down
6 changes: 6 additions & 0 deletions app/delivery/send_to_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,16 @@ def get_html_email_options(service: Service):
"fip_banner_english": False,
"fip_banner_french": True,
"logo_with_background_colour": False,
"alt_text_en": None,
"alt_text_fr": None,
}
else:
return {
"fip_banner_english": True,
"fip_banner_french": False,
"logo_with_background_colour": False,
"alt_text_en": None,
"alt_text_fr": None,
}

logo_url = get_logo_url(service.email_branding.logo) if service.email_branding.logo else None
Expand All @@ -371,6 +375,8 @@ def get_html_email_options(service: Service):
"brand_logo": logo_url,
"brand_text": service.email_branding.text,
"brand_name": service.email_branding.name,
"alt_text_en": service.email_branding.alt_text_en,
"alt_text_fr": service.email_branding.alt_text_fr,
}


Expand Down
6 changes: 5 additions & 1 deletion app/email_branding/email_branding_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"text": {"type": ["string", "null"]},
"logo": {"type": ["string", "null"]},
"brand_type": {"enum": BRANDING_TYPES},
"alt_text_en": {"type": "string"},
"alt_text_fr": {"type": "string"},
},
"required": ["name"],
"required": ["name", "alt_text_en", "alt_text_fr"],
}

post_update_email_branding_schema = {
Expand All @@ -24,6 +26,8 @@
"text": {"type": ["string", "null"]},
"logo": {"type": ["string", "null"]},
"brand_type": {"enum": BRANDING_TYPES},
"alt_text_en": {"type": "string"},
"alt_text_fr": {"type": "string"},
},
"required": [],
}
5 changes: 5 additions & 0 deletions app/job/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ def create_job(service_id):
)

if template.template_type == SMS_TYPE:
# set sender_id if missing
default_senders = [x for x in service.service_sms_senders if x.is_default]
default_sender_id = default_senders[0].id if default_senders else None
data["sender_id"] = data.get("sender_id", default_sender_id)

# calculate the number of simulated recipients
numberOfSimulated = sum(simulated_recipient(i["phone_number"].data, template.template_type) for i in recipient_csv.rows)
mixedRecipients = numberOfSimulated > 0 and numberOfSimulated != len(recipient_csv)
Expand Down
2 changes: 2 additions & 0 deletions app/user/contact_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class ContactRequest:
notification_types: str = field(default="")
expected_volume: str = field(default="")
branding_url: str = field(default="")
alt_text_en: str = field(default="")
alt_text_fr: str = field(default="")

def __post_init__(self):
# email address is mandatory for us
Expand Down
2 changes: 2 additions & 0 deletions app/user/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ def send_branding_request(user_id):
organisation_id=data["organisation_id"],
department_org_name=data["organisation_name"],
branding_url=get_logo_url(data["filename"]),
alt_text_en=data["alt_text_en"],
alt_text_fr=data["alt_text_fr"],
)
contact.tags = ["z_skip_opsgenie", "z_skip_urgent_escalation"]

Expand Down
6 changes: 6 additions & 0 deletions app/v2/notifications/post_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ def post_bulk():
increment_email_daily_count_send_warnings_if_needed(authenticated_service, len(list(recipient_csv.get_rows())))

if template.template_type == SMS_TYPE:
# set sender_id if missing
if form["validated_sender_id"] is None:
default_senders = [x for x in authenticated_service.service_sms_senders if x.is_default]
default_sender_id = default_senders[0].id if default_senders else None
form["validated_sender_id"] = default_sender_id

# calculate the number of simulated recipients
numberOfSimulated = sum(
simulated_recipient(i["phone_number"].data, template.template_type) for i in list(recipient_csv.get_rows())
Expand Down
15 changes: 13 additions & 2 deletions bin/execute_and_publish_performance_test.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
#!/bin/bash

# Setup
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
perf_test_aws_s3_bucket=${PERF_TEST_AWS_S3_BUCKET:-notify-performance-test-results-staging}
perf_test_csv_directory_path=${PERF_TEST_CSV_DIRECTORY_PATH:-/tmp/notify_performance_test}

mkdir -p $perf_test_csv_directory_path/$current_time

# Run old performance test and copy results to S3
locust --headless --config tests-perf/locust/locust.conf --html $perf_test_csv_directory_path/$current_time/index.html --csv $perf_test_csv_directory_path/$current_time/perf_test

aws s3 cp $perf_test_csv_directory_path/ "s3://$perf_test_aws_s3_bucket" --recursive || exit 1

# Sleep 15 minutes to allow the system to stabilize
sleep 900

# Run email send rate performance test
# This configuration should send 10K emails / minute for 10 minutes for 100K emails total.
# We run this test on Tuesday through Friday (just after midnight UTC) only.
if [ "$(date +%u)" -ge 2 ] && [ "$(date +%u)" -le 5 ]; then
locust --headless --host https://api.staging.notification.cdssandbox.xyz --locustfile tests-perf/locust/send_rate_email.py --users 5 --run-time 10m --spawn-rate 1
fi

# Cleanup
rm -rf $perf_test_csv_directory_path/$current_time
97 changes: 97 additions & 0 deletions migrations/versions/0448_update_verify_code2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"""
Revision ID: 0448_update_verify_code2
Revises: 0447_update_verify_code_template
Create Date: 2023-10-05 00:00:00
"""
from datetime import datetime

from alembic import op
from flask import current_app

revision = "0448_update_verify_code2"
down_revision = "0447_update_verify_code_template"

near_content = "\n".join(
[
"[[en]]",
"Hi ((name)),",
"",
"Here is your security code to log in to GC Notify:",
"",
"^ ((verify_code))",
"[[/en]]",
"",
"---",
"",
"[[fr]]",
"Bonjour ((name)),",
"",
"Voici votre code de sécurité pour vous connecter à Notification GC:",
"",
"^ ((verify_code))",
"[[/fr]]",
]
)


templates = [
{
"id": current_app.config["EMAIL_2FA_TEMPLATE_ID"],
"template_type": "email",
"subject": "Sign in | Connectez-vous",
"content": near_content,
"process_type": "priority",
},
]


def upgrade():
conn = op.get_bind()

for template in templates:
current_version = conn.execute("select version from templates where id='{}'".format(template["id"])).fetchone()
name = conn.execute("select name from templates where id='{}'".format(template["id"])).fetchone()
template["version"] = current_version[0] + 1
template["name"] = name[0]

template_update = """
UPDATE templates SET content = '{}', subject = '{}', version = '{}', updated_at = '{}'
WHERE id = '{}'
"""
template_history_insert = """
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
created_by_id, version, process_type, hidden)
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', {}, '{}', false)
"""

for template in templates:
op.execute(
template_update.format(
template["content"],
template["subject"],
template["version"],
datetime.utcnow(),
template["id"],
)
)

op.execute(
template_history_insert.format(
template["id"],
template["name"],
template["template_type"],
datetime.utcnow(),
template["content"],
current_app.config["NOTIFY_SERVICE_ID"],
template["subject"],
current_app.config["NOTIFY_USER_ID"],
template["version"],
template["process_type"],
)
)


def downgrade():
pass
Loading

0 comments on commit c6a28c2

Please sign in to comment.