Add URL converters for template and file types

Sometimes we manually check that a URL parameter is in a required set.
Sometimes we don’t bother.

This commit adds a URL converter to do this so that:
- we don’t have to re-write the same code every time
- it’s easier to apply this check to other endpoints

This means endpoints that previously allowed a `template_type` or
`message_type` of `None` now 404. So I’ve had to add new routes for
with URLs that don’t include such parameters.

So this…:
```
/services/128b91b6-2996-4107-bb65-51b7c24a728d/notifications/sms.csv
/services/128b91b6-2996-4107-bb65-51b7c24a728d/notifications/None.csv
```

…becomes:
```
/services/128b91b6-2996-4107-bb65-51b7c24a728d/notifications/sms.csv
/services/128b91b6-2996-4107-bb65-51b7c24a728d/notifications.csv
```

This matches what we do for the HTML-responding equivalent (see
265931d217/app/main/views/jobs.py (L215-L216))
This commit is contained in:
Chris Hill-Scott
2019-11-04 11:20:08 +00:00
parent ef335e7601
commit 545b485d86
5 changed files with 28 additions and 19 deletions

View File

@@ -83,6 +83,10 @@ from app.notify_client.template_statistics_api_client import (
template_statistics_client,
)
from app.notify_client.user_api_client import user_api_client
from app.url_converters import (
LetterFileExtensionConverter,
TemplateTypeConverter,
)
from app.utils import format_thousands, get_logo_cdn_domain, id_safe
login_manager = LoginManager()
@@ -229,6 +233,8 @@ def init_app(application):
}
application.url_map.converters['uuid'].to_python = lambda self, value: value
application.url_map.converters['template_type'] = TemplateTypeConverter
application.url_map.converters['letter_file_extension'] = LetterFileExtensionConverter
def convert_to_boolean(value):