Skip to content

Commit

Permalink
Merge branch 'main' into feat/validate-annual-limit-2
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewleith committed Dec 5, 2024
2 parents e3b67c1 + b5a3ea6 commit f15ccd1
Show file tree
Hide file tree
Showing 26 changed files with 165 additions and 222 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/vscode/devcontainers/python:1-3.10@sha256:c5b379b09a94ac1ccb437e000dd54c96164a8322d0c53d2bcb25f225e27924e6
FROM mcr.microsoft.com/vscode/devcontainers/python:3.12

ENV POETRY_VERSION="1.7.1"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-python@b64ffcaf5b410884ad320a9cfac8866006a109aa # v4.8.0
with:
python-version: '3.10'
python-version: '3.12'
- uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # v3.8.2
with:
node-version: '16.x'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test_endpoints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Set up Python 3.10
- name: Set up Python 3.12
uses: actions/setup-python@b64ffcaf5b410884ad320a9cfac8866006a109aa # v4.8.0
with:
python-version: '3.10'
python-version: '3.12'

- name: Upgrade pip
run: python -m pip install --upgrade pip
Expand Down Expand Up @@ -45,7 +45,7 @@ jobs:
working-directory: ${{ github.workspace }}
shell: bash
run: |
mkdir -p "${{ github.workspace }}/env/" && cp -fR $(poetry env list | poetry env info -p)/lib/python3.10/site-packages "${{ github.workspace }}/env/"
mkdir -p "${{ github.workspace }}/env/" && cp -fR $(poetry env list | poetry env info -p)/lib/python3.12/site-packages "${{ github.workspace }}/env/"
- name: Install development .env file
working-directory: ${{ github.workspace }}
Expand All @@ -58,7 +58,7 @@ jobs:
echo "PYTHONPATH=/github/workspace/env/site-packages:${{ env.PYTHONPATH}}" >> $GITHUB_ENV
- name: Checks for new endpoints against AWS WAF rules
uses: cds-snc/notification-utils/.github/actions/waffles@52.2.2
uses: cds-snc/notification-utils/.github/actions/waffles@53.0.1
with:
app-loc: '/github/workspace'
app-libs: '/github/workspace/env/site-packages'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_prod_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-python@b64ffcaf5b410884ad320a9cfac8866006a109aa # v4.8.0
with:
python-version: '3.10'
python-version: '3.12'
- uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # v3.8.2
with:
node-version: '16.x'
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ coverage: venv ## Create coverage report
run-dev:
poetry run flask run -p 6012 --host=localhost

.PHONY: run-gunicorn
run-gunicorn:
PORT=6012 poetry run gunicorn -c gunicorn_config.py application

.PHONY: format
format:
ruff check --select I --fix .
Expand Down
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ https://github.com/alphagov/notifications-admin
```

Languages needed
- Python 3.10
- Python 3.12
- [Node](https://nodejs.org/) 10.15.3 or greater
- [npm](https://www.npmjs.com/) 6.4.1 or greater

Expand All @@ -58,15 +58,15 @@ On OS X:

`brew install pyenv`

2. Install Python 3.10.8 or whatever is the latest
2. Install Python 3.12.7 or whatever is the latest

`pyenv install 3.10.8`
`pyenv install 3.12.7`

3. If you expect no conflicts, set `3.10.8` as you default
3. If you expect no conflicts, set `3.12.7` as you default

`pyenv global 3.10.8`
`pyenv global 3.12.7`

4. Ensure that version `3.10.8` is now the default by running
4. Ensure that version `3.12.7` is now the default by running

`python --version`

Expand All @@ -77,15 +77,15 @@ eval "$(pyenv init -)"
```
and open a new terminal.

If you are still not running Python 3.10.8 take a look here: https://github.com/pyenv/pyenv/issues/660
If you are still not running Python 3.12.7 take a look here: https://github.com/pyenv/pyenv/issues/660

5. Install `poetry`:

`pip install poetry==1.3.2`

6. Restart your terminal and make your virtual environtment:

`mkvirtualenv -p ~/.pyenv/versions/3.10.8/bin/python notifications-admin`
`mkvirtualenv -p ~/.pyenv/versions/3.12.7/bin/python notifications-admin`

7. You can now return to your environment any time by entering

Expand Down Expand Up @@ -278,7 +278,7 @@ https://github.com/alphagov/notifications-admin
```

Langages nécessaires
- Python 3.10
- Python 3.12
- [Node](https://nodejs.org/) 10.15.3 ou supérieur
- [npm](https://www.npmjs.com/) 6.4.1 ou plus
```shell
Expand All @@ -302,15 +302,15 @@ Sur macOS :

`brew install pyenv`

2. Installez Python 3.10.8 ou la dernière version
1. Installez Python 3.12.7 ou la dernière version

`pyenv install 3.10.8`
`pyenv install 3.12.7`

3. Si vous n'attendez aucun conflit, mettez `3.10.8` comme valeur par défaut
3. Si vous n'attendez aucun conflit, mettez `3.12.7` comme valeur par défaut

`pyenv global 3.10.8`
`pyenv global 3.12.7`

4. Assurez-vous que la version 3.10.8 est maintenant la version par défaut en exécutant
4. Assurez-vous que la version 3.12.7 est maintenant la version par défaut en exécutant

`python --version`

Expand All @@ -320,7 +320,7 @@ eval "$(pyenv init --path)"
eval "$(pyenv init -)"
```
et ouvrez un nouveau terminal.
Si vous n’utilisez toujours pas Python 3.10.8, jetez un coup d’œil ici : https://github.com/pyenv/pyenv/issues/660
Si vous n’utilisez toujours pas Python 3.12.7, jetez un coup d’œil ici : https://github.com/pyenv/pyenv/issues/660

5. Installez `virtualenv` :

Expand All @@ -331,12 +331,12 @@ Si vous n’utilisez toujours pas Python 3.10.8, jetez un coup d’œil ici : ht
```
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source ~/.pyenv/versions/3.10.8/bin/virtualenvwrapper.sh
source ~/.pyenv/versions/3.12.7/bin/virtualenvwrapper.sh
```

7. Redémarrez votre terminal et créez votre environnement virtuel :

`mkvirtualenv -p ~/.pyenv/versions/3.10.8/bin/python notifications-admin`
`mkvirtualenv -p ~/.pyenv/versions/3.12.7/bin/python notifications-admin`

8. Vous pouvez maintenant retourner dans votre environnement à tout moment en entrant

Expand Down
2 changes: 1 addition & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def get_locale():
application.jinja_env.globals["show_tou_prompt"] = show_tou_prompt
application.jinja_env.globals["parse_ua"] = parse
application.jinja_env.globals["events_key"] = EVENTS_KEY
application.jinja_env.globals["now"] = datetime.now
application.jinja_env.globals["now"] = datetime.utcnow

# Initialize Salesforce Account list
if application.config["FF_SALESFORCE_CONTACT"]:
Expand Down
3 changes: 0 additions & 3 deletions app/main/views/service_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from flask_babel import lazy_gettext as _l
from flask_login import current_user
from notifications_python_client.errors import HTTPError
from notifications_utils.decorators import requires_feature

from app import (
billing_api_client,
Expand Down Expand Up @@ -1131,7 +1130,6 @@ def set_sms_message_limit(service_id):

@main.route("/service/<service_id>/service_settings/set-sms-annual-limit", methods=["GET", "POST"])
@user_is_platform_admin
@requires_feature("FF_ANNUAL_LIMIT") # TODO: FF_ANNUAL_LIMIT removal
def set_sms_annual_limit(service_id):
form = SMSAnnualMessageLimit(message_limit=current_service.sms_annual_limit)

Expand All @@ -1150,7 +1148,6 @@ def set_sms_annual_limit(service_id):

@main.route("/service/<service_id>/service_settings/set-email-annual.html", methods=["GET", "POST"])
@user_is_platform_admin
@requires_feature("FF_ANNUAL_LIMIT") # TODO: FF_ANNUAL_LIMIT removal
def set_email_annual_limit(service_id):
form = EmailAnnualMessageLimit(message_limit=current_service.email_annual_limit)

Expand Down
7 changes: 5 additions & 2 deletions app/notify_client/notification_counts_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
class NotificationCounts:
def get_all_notification_counts_for_today(self, service_id):
# try to get today's stats from redis
todays_sms = int(redis_client.get(sms_daily_count_cache_key(service_id)))
todays_email = int(redis_client.get(email_daily_count_cache_key(service_id)))
todays_sms = redis_client.get(sms_daily_count_cache_key(service_id))
todays_sms = int(todays_sms) if todays_sms is not None else None

todays_email = redis_client.get(email_daily_count_cache_key(service_id))
todays_email = int(todays_email) if todays_email is not None else None

if todays_sms is not None and todays_email is not None:
return {"sms": todays_sms, "email": todays_email}
Expand Down
46 changes: 0 additions & 46 deletions app/notify_client/template_statistics_api_client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from itertools import groupby

from app.notify_client import NotifyAdminAPIClient
from app.utils import DELIVERED_STATUSES, FAILURE_STATUSES


class TemplateStatisticsApiClient(NotifyAdminAPIClient):
Expand All @@ -20,46 +17,3 @@ def get_template_statistics_for_template(self, service_id, template_id):


template_statistics_client = TemplateStatisticsApiClient()


class TemplateStatistics:
def __init__(self, stats):
self.stats = stats

def as_aggregates(self):
template_statistics = self._filter_out_cancelled_stats(self.stats)
notifications = {
template_type: {status: 0 for status in ("requested", "delivered", "failed")} for template_type in ["sms", "email"]
}
for stat in template_statistics:
notifications[stat["template_type"]]["requested"] += stat["count"]
if stat["status"] in DELIVERED_STATUSES:
notifications[stat["template_type"]]["delivered"] += stat["count"]
elif stat["status"] in FAILURE_STATUSES:
notifications[stat["template_type"]]["failed"] += stat["count"]

return notifications

def as_template_usage(self, sort_key="count"):
template_statistics = self._filter_out_cancelled_stats(self.stats)
templates = []
for k, v in groupby(
sorted(template_statistics, key=lambda x: x["template_id"]),
key=lambda x: x["template_id"],
):
template_stats = list(v)

templates.append(
{
"template_id": k,
"template_name": template_stats[0]["template_name"],
"template_type": template_stats[0]["template_type"],
"is_precompiled_letter": template_stats[0]["is_precompiled_letter"],
"count": sum(s["count"] for s in template_stats),
}
)

return sorted(templates, key=lambda x: x[sort_key], reverse=True)

def _filter_out_cancelled_stats(self, template_statistics):
return [s for s in template_statistics if s["status"] != "cancelled"]
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
{% else %}
{{ _("To request a daily limit above {} text messages, {}").format(current_service.sms_daily_limit, content_link(_("contact us"), url_for('main.contact'), is_external_link=true)) }}
{%- endif -%}
</p>
</p>
17 changes: 2 additions & 15 deletions app/templates/views/service-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,7 @@ <h2 class="heading-small p-0 m-0">{{ _('Your service is in trial mode') }}</h2>
{% call settings_row(if_has_permission='email') %}
{% set txt = _('Annual maximum</br>(April 1 to March 31)') %}
{{ text_field(txt) }}
{# TODO: FF_ANNUAL_LIMIT removal #}
{% if config["FF_ANNUAL_LIMIT"] %}
{% set annual_limit = _('{} emails').format((current_service.email_annual_limit) | format_number) %}
{% else %}
{% set annual_limit = _('{} million emails').format((limits.free_yearly_email//1000000) | format_number) %}
{% endif%}
{% set annual_limit = _('{} emails').format((current_service.email_annual_limit) | format_number) %}
{{ text_field(annual_limit, attributes="data-testid=email-annual-limit") }}
{{ text_field('')}}
{% endcall %}
Expand Down Expand Up @@ -271,12 +266,7 @@ <h2 class="heading-small p-0 m-0">{{ _('Your service is in trial mode') }}</h2>
{% call settings_row(if_has_permission='sms') %}
{% set txt = _('Annual maximum</br>(April 1 to March 31)') %}
{{ text_field(txt) }}
{# TODO: FF_ANNUAL_LIMIT removal #}
{% if config["FF_ANNUAL_LIMIT"] %}
{% set annual_sms_limit = _('{} text messages').format((current_service.sms_annual_limit) | format_number) %}
{% else %}
{% set annual_sms_limit = _('{} text messages').format((limits.free_yearly_sms) | format_number) %}
{% endif%}
{% set annual_sms_limit = _('{} text messages').format((current_service.sms_annual_limit) | format_number) %}
{{ text_field(annual_sms_limit, attributes="data-testid=sms-annual-limit") }}
{{ text_field('')}}
{% endcall %}
Expand Down Expand Up @@ -383,8 +373,6 @@ <h2 class="heading-medium">{{ _('Platform admin settings') }}</h2>
) }}
{% endcall %}

{# TODO: FF_ANNUAL_LIMIT removal #}
{% if config["FF_ANNUAL_LIMIT"] %}
{% call row() %}
{% set txt = _('Annual email limit') %}
{{ text_field(txt)}}
Expand All @@ -408,7 +396,6 @@ <h2 class="heading-medium">{{ _('Platform admin settings') }}</h2>
for=txt
) }}
{% endcall %}
{% endif %}

{% call row() %}
{% set txt = _('API rate limit per minute') %}
Expand Down
10 changes: 0 additions & 10 deletions app/translations/csv/fr.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2028,13 +2028,3 @@
"resets at 7pm Eastern Time","Réinitialisation à 19 h, heure de l’Est"
"Visit usage report","Consulter le rapport d’utilisation"
"Month by month totals","Totaux mensuels"
"<strong>{}</strong> can only send <strong>{}</strong> more {} until annual limit resets","FR: <strong>{}</strong> can only send <strong>{}</strong> more {} until annual limit resets"
"To send some of these messages now, edit the spreadsheet to <strong>{}</strong> recipients maximum. ","FR: To send some of these messages now, edit the spreadsheet to <strong>{}</strong> recipients maximum. "
"To send to recipients you removed, wait until <strong>April 1, {}</strong> or contact them some other way.","FR: To send to recipients you removed, wait until <strong>April 1, {}</strong> or contact them some other way"
"These messages exceed the annual limit","FR: These messages exceed the annual limit"
"<strong>{}</strong> cannot send any more {} until <strong>April 1, {}</strong>","FR: <strong>{}</strong> cannot send any more {} until <strong>April 1, {}</strong>"
"For more information, visit the <a href={}>usage report for {}</a>.","FR: For more information, visit the <a href={}>usage report for {}</a>."
"This message exceeds your annual limit","FR: This message exceeds your annual limit"
"email messages","courriels"
"Sending paused until annual limit resets","FR: Sending paused until annual limit resets"
"Sending paused until 7pm ET. You can schedule more messages to send later.","FR: Sending paused until 7pm ET. You can schedule more messages to send later."
2 changes: 1 addition & 1 deletion ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10-alpine3.18@sha256:d5ee9613c89c9bd4c4112465d2136512ea8629bce6ff15fa27144f3cc16b5c6b
FROM python:3.12.7-alpine3.20

ENV PYTHONDONTWRITEBYTECODE 1
ENV POETRY_VERSION="1.7.1"
Expand Down
4 changes: 2 additions & 2 deletions ci/Dockerfile.lambda
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARG POETRY_VERSION="1.7.1"
ARG POETRY_VIRTUALENVS_CREATE="false"

# Build image
FROM python:3.10-alpine3.18@sha256:d5ee9613c89c9bd4c4112465d2136512ea8629bce6ff15fa27144f3cc16b5c6b as base
FROM python:3.12-alpine3.20@sha256:5049c050bdc68575a10bcb1885baa0689b6c15152d8a56a7e399fb49f783bf98 as base

ARG APP_DIR
ARG APP_VENV
Expand Down Expand Up @@ -68,7 +68,7 @@ RUN . ${APP_VENV}/bin/activate \
&& make generate-version-file

# Final image
FROM python:3.10-alpine3.18@sha256:d5ee9613c89c9bd4c4112465d2136512ea8629bce6ff15fa27144f3cc16b5c6b as lambda
FROM python:3.12-alpine3.20@sha256:5049c050bdc68575a10bcb1885baa0689b6c15152d8a56a7e399fb49f783bf98 as lambda

ARG APP_DIR
ARG APP_VENV
Expand Down
2 changes: 1 addition & 1 deletion ci/Dockerfile.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10-alpine3.16@sha256:afe68972cc00883d70b3760ee0ffbb7375cf09706c122dda7063ffe64c5be21b
FROM python:3.12-alpine3.20@sha256:5049c050bdc68575a10bcb1885baa0689b6c15152d8a56a7e399fb49f783bf98

ENV PYTHONDONTWRITEBYTECODE 1

Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[mypy]
python_version = 3.10
python_version = 3.12

[mypy-pytest.*]
ignore_missing_imports = True
Expand Down
Loading

0 comments on commit f15ccd1

Please sign in to comment.