Commit Graph

64 Commits

Author SHA1 Message Date
Carlo Costino
9a83ba7475 Localize notification_utils to the admin
This changeset pulls in all of the notification_utils code directly into the admin and removes it as an external dependency. We are doing this to cut down on operational maintenance of the project and will begin removing parts of it no longer needed for the admin.

Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
2024-05-16 10:37:37 -04:00
Kenneth Kehl
8c9721d8e2 notify-api-412 use black to enforce python coding style 2023-08-25 09:12:23 -07:00
Kenneth Kehl
c6eb007386 merge from main 2023-08-25 08:57:24 -07:00
Jonathan Bobel
348e29fb40 - Removed links to the gov uk stylesheets
- Deleted /stylesheets folder
- Removed sass build from gulpfile
- Changed gov links to usa links
- Changed other govuk styles, like breadcrumbs
- Changed name of uk_components file to us_components
- Fixed a few tests that broke on account of the changes
2023-08-08 16:19:17 -04:00
Tim Lowden
f8daea1879 Updating for US English
Words found:
personalis*
customis*
organis*
colour
behaviour
2022-12-20 09:44:33 -05:00
stvnrlly
3386317f5b trim non-existant pages further 2022-11-02 11:02:32 -04:00
stvnrlly
f16b5dd1c4 remove broadcast-related code 2022-10-04 03:04:13 +00:00
Chris Hill-Scott
291906e9fd Don’t allow <text> elements in letter logos
To render text in an SVG consistently the system rendering the SVG must
have the fonts specified by the SVG installed.

If the fonts are not installed then the renderer will fall back to a
system font and the text will look different. This is especially bad
news for branding where the right font is an integral part of any brand.

To fix this, the text should instead be converted to `<path>` elements.
This process is sometimes called ‘outlining’.

A few of our logos had this problem, and I’ve fixed most of them by
hand. Adding this validation will stop the problem, coming up again.
2022-01-06 17:39:01 +00:00
Chris Hill-Scott
5558af2527 Refactor for reuse 2022-01-06 17:39:01 +00:00
Chris Hill-Scott
b74fcf2570 Bump WTForms and Flask-WTF to latest versions
WTForms versions less than 3.0.0 have a security vulnerability where
arbitrary HTML can be inserted into the label of a form, allowing the
possibility of a cross-site scripting attack.

I don’t know if there’s anywhere we put user-generated content into form
labels but it’s possible we are vulnerable somewhere.

This require moving some imports because as of
https://github.com/wtforms/wtforms/pull/614/files
there is no longer a separate module for HTML 5 fields, they are now
considered core fields.

As of https://github.com/wtforms/wtforms/issues/445/files custom
implementations of `pre_validate` or `post_validate` must raise
`ValidationError` to trigger a validation message, where we were raising
`ValueError` this was no longer being caught.

As of https://github.com/wtforms/wtforms/pull/355/files `StringField`
returns `None` for empty data, not `''` but our `validate_email_address`
function only accepts strings.
2021-11-30 17:33:13 +00:00
David McDonald
a6cac27957 Allow straight single quote in sms sender names
This is so we can allow the sender name 'UC' for DWP.

Note, this is specifically only straight single quotes and not curly
quotes or double quotes. Curly quotes are not supported in the GSM
character set (https://en.wikipedia.org/wiki/GSM_03.38). There is
currently no defined user ask to support double quotes in sms sender
names.

I have tested this by sending a message through both Firetext and MMG to
make sure they both support the single quote character in SMS sender
names.

DWP also have had no particular issues using the SMS sender name with
their existing system in the past either.
2021-07-27 09:26:16 +01:00
Ben Thorner
7c27646d6a Extract user utility code into own module
This provides more room for expansion, and reduces the amount of
arbitrary code in the __init__.py file for the new package.
2021-06-09 13:19:05 +01:00
Chris Hill-Scott
2c46d023da Extract Spreadsheet model from app/utils.py
`app/utils.py` is a bit of a dumping ground for things we don’t have a
better place for.

We now have a place and structure for storing ‘model’ code (‘model’ in
the model, view, controller (MVC) sense of the word).

This commit moves the spreadsheet model to that place.
2021-01-06 12:31:39 +00:00
Chris Hill-Scott
8302b2b667 Validate length of broadcast content
Depends on:
- [ ] https://github.com/alphagov/notifications-utils/pull/826/files

Adds error messages for when the content of a broadcast template is too
long.

The error message is explicit when this is cause by non-GSM characters.
We may not want to expose this complexity to our users, but it’s useful
for now while we’re testing things out.
2020-12-29 11:29:57 +00:00
Chris Hill-Scott
c8e85efd54 Don’t allow personalisation in broadcast templates
Since we don’t have a way of filling in the personalisation at the
moment we shouldn’t allow people to make templates that require it.
2020-10-05 17:17:21 +01:00
Chris Hill-Scott
e832d18002 Make error message specific to template type 2020-07-03 15:46:00 +01:00
Chris Hill-Scott
972ba9e3da Remove term ‘blacklist’ from codebase
‘Commonly used passwords’ is more specific, and avoids the terminology
‘blacklist’ which the National Cyber Security Centre explain to be
problematic:

> It's fairly common to say whitelisting and blacklisting to describe desirable and undesirable things in cyber security. For instance, when talking about which applications you will allow or deny on your corporate network; or deciding which bad passwords you want your users not to be able to use.
>
> However, there's an issue with the terminology. It only makes sense if you equate white with 'good, permitted, safe' and black with 'bad, dangerous, forbidden'. There are some obvious problems with this. So in the name of helping to stamp out racism in cyber security, we will
> avoid this casually pejorative wording on our website in the future. No, it's not the biggest issue in the world - but to borrow a slogan from elsewhere: every little helps.

– https://www.ncsc.gov.uk/blog-post/terminology-its-not-black-and-white
2020-06-16 18:07:47 +01:00
karlchillmaid
50ae629721 Update who_can_use_notify link 2020-05-20 15:58:36 +01:00
Chris Hill-Scott
65bb72ef2f Bump WTForms to 2.3.1
This involves three changes which broke our code.

To validate email addresses, the optional dependency `email-validator`
must be installed<sup>1</sup>. But since we don’t use WTForms’ email
validation, we shouldn’t need to subclass it – it can just be its own
self contained thing. Then we don’t need to add the extra dependency.

When rendering textareas, and extra `\r\n` is inserted at the beginning
<sup>2</sup>. Browsers will strip this when displaying the textbox and
submitting the form, but some of our tests need updating to account for
this.

The error message for when you don’t choose an option from some radio
buttons has now changed. Rather than just accepting WTForms’ new
message, this commit makes the error messages like the examples from
the Design System<sup>3</sup>. By default it will say ‘Select an
option’, but by passing in an extra parameter (`thing`) it can be
customised to be more specific, for example ‘Select a type of
organisation’.

***

1. https://github.com/wtforms/wtforms/pull/429
2. https://github.com/wtforms/wtforms/issues/238
3. https://design-system.service.gov.uk/components/radios/#error-messages
2020-04-23 12:57:10 +01:00
Chris Hill-Scott
1fe3f1871e Allow underscores in SMS senders 2020-04-02 15:57:46 +01:00
Chris Hill-Scott
db2d312ba7 Link to ‘who it’s for’ when error creating account
If someone enters an email address from a domain we don’t recognise we
direct them straight to our support channel. This is causing increased
contact from suppliers and members of the public.

Now that we have a page which explains who can use Notify, let’s direct
people there first. Then if they really do need to contact support
(because we don’t recognise their organisation) then they can do so from
that page.
2020-03-26 14:55:51 +00:00
Pea Tyczynska
8a4618ffe0 Fix logo upload - we need to rewind the bytestream after we read it 2020-03-04 17:26:19 +00:00
Pea Tyczynska
44519fcf8e Do not allow to upload SVG logos with embedded raster images in them
Those are for example png or jpg images. They do not render properly.
2020-03-04 15:35:12 +00:00
Tom Byers
9f2e1498fc Update links missed in previous work
Includes those in:
- the static 5xx error page
- validation messaging
- guidance page about trial mode
- links used in tests

Issues raised in https://github.com/alphagov/notifications-admin/pull/3303#issuecomment-589572715
2020-02-25 10:52:03 +00:00
Tom Byers
5b306dde4d Revert "Convert all links to govuk frontend" 2020-02-24 11:56:38 +00:00
Tom Byers
1513cfa9e6 Update links missed in previous work
Includes those in:
- the static 5xx error page
- validation messaging
- guidance page about trial mode
- links used in tests

Issues raised in https://github.com/alphagov/notifications-admin/pull/3303#issuecomment-589572715
2020-02-21 13:59:04 +00:00
Leo Hemsted
5bbbdc3cd9 fix xss with service letter contact blocks
service contact blocks contain new lines - and jinja2 normally ignores
newlines (as in it keeps them as new lines) - but we need to turn them
into `<br>` tags so that we can show the formatting that the user has
added. We were previously just doing `{{ block | nl2br | safe }}`. nl2br
turns the new lines into `<br>` tags, and then `safe` tells jinja that
it doesn't need to escape the html.

this causes issues if the user adds `<script>alert(1)</script>` to their
contact block (or some other evil xss hack), where that will get let
through due to the safe flag

To solve this, use `Markup(html='escape')` to sanitise any html, and
then convert new lines to <br>.

bump utils

another xss
2020-01-21 17:34:49 +00:00
Pea Tyczynska
21e6d994b9 Validate service and organisation name 2019-11-20 13:31:01 +00:00
Rebecca Law
18e3eb6b32 Update tests for content changes. 2019-09-23 13:22:28 +01:00
karlchillmaid
4b2990e735 Replace isn't with is not 2019-09-23 13:22:00 +01:00
karlchillmaid
653c2c399f Replace won't with will not 2019-09-23 13:21:59 +01:00
Katie Smith
5be6b41195 Allow Welsh characters in SMS
- This brings in the latest version of notifications-utils which
allows Welsh characters in SMS templates.
- Updated the pricing page to show the new prices for SMS with certain
Welsh characters
2019-05-15 14:20:49 +01:00
Chris Hill-Scott
470b8a2912 Remove domains from branding forms
We’re deprecating storing the domain as text on a branding in favour of
a database relationship between branding and organisation.

We need to do this now in order to remove the validation on these fields
(which depends on the data in `domains.yml`)
2019-04-12 15:23:07 +01:00
Chris Hill-Scott
184a9fa605 Use email fields for feedback form
Otherwise we can end up collecting invalid email addresses…

This required some refactoring to allow our email fields to be optional
(but not by default).
2018-12-07 13:11:41 +00:00
Chris Hill-Scott
34ed0da362 Validate non canonical domains
At the moment we transform what the user gives us, so if someone enters
`digital.cabinet-office.gov.uk` it will automagically be saved as
`cabinet-office.gov.uk`. This happens without the user knowing, and
might have unintended consequences.

So let’s tell them what the problem is, and let them decide what to do
about it (which might be accepting the canonical domain, or adding a
new organisation to domains.yml first).
2018-09-06 12:35:52 +01:00
Chris Hill-Scott
80423dfb3f Don’t allow adding unknown domains to branding lookup
We should make sure we’re not putting typos in the branding list. We can
validate what gets entered here against our known list of public-sector
domains.
2018-09-05 10:32:43 +01:00
Katie Smith
58cc1604a7 Bump utils and sanitise header values
Updated notifications-utils. This brings in
- the renamed character sanitization classes
- the change to allow unicode in letter addresses (this lets us delete
a test that is no longer relevant)

Also replaced non-ascii characters in headers. This fixes a bug where
non-ascii characters in a CSV filename were causing errors since the
filename is also used in the header.
2018-05-25 10:34:47 +01:00
Katie Smith
11a6c8cfb5 Update SMS sender validation to reject senders starting with 00
Having SMS senders that start with 00 can cause issues with Firetext due
to Firetext's validation rules, so we shouldn't allow SMS senders to start
with 00.

Firetext treats a double 00 at the start of the senderID as an international
prefix, so removes them. A sender of 00447876574016 would become 447876574016.

Under Firetext's validation rules, an SMS sender of five 0s (00000) would
become  4400. This is because the first 00 are removed (as the international
prefix). The third 0 is seen as the start of a phone number, and becomes 44,
leaving the final 00 = 4400.
2018-02-28 13:40:20 +00:00
Chris Hill-Scott
f3a0c505bd Enforce order and style of imports
Done using isort[1], with the following command:
```
isort -rc ./app ./tests
```

Adds linting to the `run_tests.sh` script to stop badly-sorted imports
getting re-introduced.

Chosen style is ‘Vertical Hanging Indent’ with trailing commas, because
I think it gives the cleanest diffs, eg:
```
from third_party import (
    lib1,
    lib2,
    lib3,
    lib4,
)
```

1. https://pypi.python.org/pypi/isort
2018-02-27 16:35:13 +00:00
Leo Hemsted
31a4cc15c9 validate email addresses in one-off flow
previously we were just using the wtforms builtin email validator,
which is much more relaxed than our own one. It'd catch bad emails when
POSTing to the API, resulting in an ugly error message. It's easy work
to make sure we validate email addresses as soon as they're entered.
2018-02-14 14:35:16 +00:00
Chris Hill-Scott
934a271322 Allow full stops in SMS senders
We have a team who want their (short) web address as the text message
sender. This commit updates the validation of text message senders to
allow `.` as a valid character, which is currently blocking them from
doing this.

We can be fairly confident this works because:

- the team are sending large volumes of messages already with their
  existing provider
- we’ve tested it with all combinations of
  - both our text message providers
  - an Android phone and n iPhone
2018-01-31 11:11:44 +00:00
Chris Hill-Scott
b11653fe08 Refactor to use validator class
Using a separate validator class to check for appropriate characters in
a text message sender means that we’re not doing this validation in a
different way from the other checks (length and required). So the code
is cleaner.
2018-01-31 11:11:32 +00:00
Chris Hill-Scott
eef66b70de Reword because ‘inbetween’ isn’t a word 2017-12-11 11:19:33 +00:00
Chris Hill-Scott
242a216c1b Update error message about commas in placeholders
We call the yellow things ‘double brackets’ on the frontend, not fields
or placeholders. This error message was a bit out of date.

Also refactored it to use the `Field` class; this code was probably
written before `Field` was factored out of `Template`.
2017-12-11 11:19:33 +00:00
Chris Hill-Scott
a10e76a9c2 Stop referring to central gov in error messages 2017-08-10 13:51:46 +01:00
Leo Hemsted
f550699daf fix non-gsm error message
Use `it`/`they` depending on how many different characters you've used
Also don't wrap the message with quotes, as it looks confusing and
potentialy implies that you can't use apostrophes
2017-02-17 10:39:52 +00:00
Leo Hemsted
73a965a3c6 allow downgradeable unicode characters in SMS templates 2017-02-17 10:39:52 +00:00
Leo Hemsted
41fa158635 error when users put non-GSM chars in a sms template
additionally, this moves the formatted_list jinja macro into a python
function, so that it can be called from the form validator
2017-02-17 10:39:52 +00:00
Chris Hill-Scott
1df3c11ae9 Split support into two pages
The kind of communications we’re getting at the moment can broadly be
broken down into:
- problems
- questions and feedback

We will need to triage problems differently, because they could
potentially be urgent/severe/emergency/P1/whatever language we use.
Questions or feedback will never be P1.

Two reasons for making the user categorise their tickets themselves:

- Outside of hours we can’t get someone out of bed in order to decide if
  a ticket is a problem or just feedback

- We can tailor the subsequent pages to whether it’s a problem or
  feedback (eg showing a link to the status page if the user is having
  a problem)

This commit let’s users make the choice with a pair of radio buttons.

It also cleans up a bunch of the tests and parameterizes them so we’re
testing the flow for both ticket types.
2017-02-02 15:18:40 +00:00
Imdad Ahad
5ecdbb8596 Refactor to use a cleaner and lean regex 2016-10-28 10:45:05 +01:00