Commit Graph

3682 Commits

Author SHA1 Message Date
Chris Hill-Scott
f34cd4a6b5 Merge pull request #3780 from alphagov/show-areas-not-in-library
Display areas that aren’t in the library
2021-01-28 10:21:12 +00:00
Tom Byers
0459cbe24f Merge pull request #3768 from alphagov/add-govuk-radios-6
Add GOVUK radios [part 6]
2021-01-27 14:54:30 +00:00
Chris Hill-Scott
926ada2f21 Check that all areas are in the library
We should assume to start with that areas come either from the library
or from the JSON, and not a combination of the two.
2021-01-27 14:32:35 +00:00
Chris Hill-Scott
5ae53b625b Show broadcasts created by the API
Broadcasts created by the API are different in that:
- they aren’t created by any user, so don’t have a `created_by_id`
- they are created instantly, not in steps, so don’t have an
  `updated_at` time

This commit alters the views to account for when these pieces of
information aren’t present.
2021-01-27 11:34:43 +00:00
Tom Byers
e013fbb9b3 Merge pull request #3770 from alphagov/fix-extend-params-bug
Fix bug with extend_params function
2021-01-27 10:52:51 +00:00
Tom Byers
513fbff6e0 Convert radios on set-template-sender page
Includes making the legend the h1 for the page to
follow design system guidance:

https://design-system.service.gov.uk/get-started/labels-legends-headings/
2021-01-27 10:52:24 +00:00
Tom Byers
ece956e324 Convert radios on set-sender page
Includes making the legend the page header to
follow design system guidance:

https://design-system.service.gov.uk/get-started/labels-legends-headings/

I had to add some override styles to allow the
legend to classes as a full-width column, and the
radios to be in one that is three-quarters.
2021-01-27 10:52:24 +00:00
Tom Byers
f6cef24617 Convert create API key radios to GOVUK Frontend 2021-01-27 10:52:24 +00:00
David McDonald
8e3aeea9a0 Merge pull request #3775 from alphagov/set-sender-bug
Fix bug with incorrect redirect to send_one_off
2021-01-26 13:54:18 +00:00
Tom Byers
67392e97ee Fix issue with looping in list merging
The last_dest_idx variable should always have been
tracking the last index in the source list. The
original intention, implemented incorrectly, was
to just append any items which source has no item
at that index.
2021-01-26 12:16:08 +00:00
Chris Hill-Scott
60aa2d2b42 Display areas that aren’t in the library 2021-01-26 10:49:47 +00:00
Rebecca Law
01a3df6edc Update _delete_template_cache_for_service to delete all template version cache and not just the one ending in "None"
Update all methods that were previous calling @cache.delete('service-{service-id}-template-None') to instead call _delete_template_cache_for_service
Remove call to get service templates, it's not needed since all template version cache is being deleted.
2021-01-25 16:28:20 +00:00
David McDonald
9e477011d3 Fix bug with incorrect redirect to send_one_off
If a user has only send_message permissions, when they click on a
template name they are currently taken to the `send_one_off` page. This
is incorrect as if there is more than one SMS sender or email reply to
address, then they should pick the address they wish to use.

This commit fixes that bug by redirecting them to the `set_sender`
route. Note, if there is only one sender then the `set_sender` will
redirect the user on to the `send_one_off` route.

https://www.pivotaltracker.com/story/show/176541486
2021-01-22 18:34:30 +00:00
Tom Byers
1059cf4d81 Remove extend_params in favour of merge_jsonlike
A comment on the pull request for this branch
pointed out that it's not clear why the 'items'
list is deleted and then reassigned in
extend_params:

https://github.com/alphagov/notifications-admin/pull/3770#pullrequestreview-573067465

The simple reason is that we want to use
merge_jsonlike to merge params and
param_extensions (passed in as extensions) but
merge_jsonlike doesn't merge lists correctly.

I realised that if we just make merge_jsonlike
merge lists correctly, we can use it for
everything extend_params does.

This commit does that, and replaces all calls to
extend_params with merge_jsonlike.

Because extend_params is used across many form
field classes, and so many pages, I took the
following precautions after making those changes:
1. found every use of param_extensions
2. looked at the merges onto params that each would
   cause and deduped them to a final list of 6(!)
3. tested pages containing fields from that list
4. added new testcases to the merge_jsonlike tests
   for any merges that exist in our codebase but
   not in our tests
2021-01-22 15:40:28 +00:00
Tom Byers
23d391e3fc Change how merge_jsonlike treats lists
Current behaviour is to check item-against-item
and merge based on whether items match, irrelevant
of position. This doesn't produce the results we
need for our usecases (merging data to send to
GOVUK Frontend components).

We actually want:
- items to be compared based on their position
- new primitive items at the same position to
  overwrite existing ones
- dicts or lists at the same position to be merged

For example,

Starting with this list:

[{"name": "option-1", "value": "1"}]

Merging in this list:

[{"hint": {"text": "Choose one option"}}]

You currently get this:

[
  {"name": "option-1", "value": "1"},
  {"hint": {"text": "Choose one option"}}
]

We want to get this:

[
  {
    "name": "option-1", "value": "1",
    "hint": {"text": "Choose one option"}
  }
]
2021-01-21 21:15:51 +00:00
Pea Tyczynska
e2ecff050d Merge pull request #3772 from alphagov/add-service-notes
Add service notes
2021-01-20 17:19:22 +00:00
Chris Hill-Scott
87a12b8e3b Merge pull request #3751 from alphagov/new-alert
Let users create an emergency alert without a template
2021-01-20 16:37:00 +00:00
Tom Byers
ba6b4682c3 Add comments to JS and improve selector in test
After talking with the reviewer, it was decided
that:
1. the JS could do with some comments to explain
   its structure and what various functions do
   better
2. some CSS selectors in the tests don't need to
   be as complex and simplifying them makes the
   test easier to read
2021-01-20 11:23:01 +00:00
Chris Hill-Scott
db4d9f886c Display broadcasts without a template
At the moment the admin app expects all broadcasts to have a template,
and expects the content of the alert to come from the template.

This commit makes it so those pages can still get a `Template` instance,
but populated with content straight from the `content` field in the
database.
2021-01-20 11:18:13 +00:00
Pea Tyczynska
5eb6ac2311 Add test for textarea
Also remove redundant error handling - if unexpected error happens,
it will be handled at the app level.
2021-01-19 18:25:52 +00:00
Tom Byers
9651da1292 Improve focus control of radioSelect
Makes focus shift to the first time in the range
when you select a day.

Also rewrites the code for controlling focus so it
explains itself better, now it has different
settings.
2021-01-19 14:14:37 +00:00
Tom Byers
e7291ffd51 Add expanded semantics to radioSelect buttons
All buttons that open or close a region of the
component should have aria-expanded attributes to
show:
- they have that control
- the state of the region
2021-01-19 14:14:37 +00:00
Chris Hill-Scott
74243a88fb Remove prompt from dashboard
It’s no longer true to say that you need a template to create an alert.
The grey button should be the primary call to action on this page
instead.
2021-01-18 17:09:01 +00:00
Chris Hill-Scott
8f2dc72881 Add the new alert button to previous alerts page
Feels like it should behave the same way as the current alerts page.
2021-01-18 17:09:01 +00:00
Chris Hill-Scott
99b7d8a66f Add flow for composing an alert without a template
We think that in some cases alerts will be composed in the moment, and
therefore making people first create a template is:
- not a good use of their time
- adding some conceptual complexity which they don’t need

This commit makes it possible to type some words and have them go
straight into the `content` field in the database.

In the future we might want to progressively enhance the radio buttons
so they show on the same page (like we do with the grey buttons on the
templates page).
2021-01-18 17:09:01 +00:00
Pea Tyczynska
341933478b Succesfully update service notes 2021-01-15 15:38:39 +00:00
Pea Tyczynska
6d7b16fd59 View edit service notes page 2021-01-15 13:36:12 +00:00
Pea Tyczynska
5818942908 'Change' link links to edit_service_notes 2021-01-14 18:00:44 +00:00
Pea Tyczynska
89b3f6ace2 Display notes section in Service Settings 2021-01-13 18:48:20 +00:00
Rebecca Law
6639dc6061 Add a test that the redis delete cache is being called. 2021-01-12 15:39:51 +00:00
Chris Hill-Scott
287689c1b3 Merge pull request #3763 from alphagov/count-chars-sms-broadcast-templates
Add fragment or character counting when editing text message or broadcast templates
2021-01-08 16:38:03 +00:00
Chris Hill-Scott
43e57b7089 Handle textbox without existing aria-described-by
jQuery.attr returns `undefined` if an element does not have an
attribute. We want an empty string, rather than the default of coercing
`undefined` to the string `'undefined'`.
2021-01-08 16:05:55 +00:00
Chris Hill-Scott
638e505432 Stop content length message from making page jumpy
The content length message was making the page jumpy and causing reflows
in three ways. This commit addresses each of those ways:

As the user scrolled
---

The footer went from fixed to sticky and the spacing around the message
changed. This change in spacing was needed so that the message looked
right in both contexts.

I think the best way to resolve this is to not use the sticky footer
when editing text message or broadcast templates.

On my 1440×900 screen I can fit a 5 fragment text message, plus the
‘will be charged as 5 text messages’ message, plus the save button.

Our top 10 screen resolutions according to our analytics are:

Position | Resolution | Percentage of users
---------|------------|--------------------
 1       | 1920x1080  | 27.37%
 2       | 1280×720   | 11.07%
 3       | 1366×768   |  8.88%
 4       | 1536×864   |  5.79%
 5       | 1440×900   |  4.52%
 6       | 1600×900   |  3.71%
 7       | 1280×1024  |  3.10%
 8       | 1680×1050  |  2.42%
 9       | 1920×1200  |  2.33%
10       | 2560×1440  | 1.99%

When the page first loaded
---

The message is empty so takes up no space, then the javascript fires
and inserts the message, taking up a line of space.

This is resolved by making the empty message take up space with a
non-breaking space character.

When the user first typed
---

We previously didn’t show any message until the user started typing.
This meant that, with the above fix, there was a larger than normal
empty space between the textarea and the save button.

This is resolved by always showing the message, even when the user
hasn’t typed anything yet.

***

These are design decisions which made sense when the message was
displayed along side the button, but we’ve had to change now that the
message is above the button.
2021-01-08 15:39:21 +00:00
Chris Hill-Scott
c127de4268 Move message length information before the button
We feel that this is more appropriate because it’s part of the
information you’re agreeing to before you hit submit.

Sometimes users can missing information that doesn’t start left-aligned
to the column they’re interacting with.

It also makes it closer to the Design System component.

We’re keeping it in the sticky footer, so that it’s always visible no
matter where in the message you’re scrolled to (this means you won’t
have to edited to content then scroll down to check whether you’ve
made it fit).
2021-01-08 14:55:52 +00:00
Chris Hill-Scott
6f514ef019 Describe example textbox by hint not label
The `<textarea>` should have its existing `aria-describedby` point to a
hint. Pointing to the label is bad practice as it would duplicate the
accessible name into the accessible description. It’s good not to have
that in the tests in case anyone copies the code elsewhere.
2021-01-08 12:53:06 +00:00
Chris Hill-Scott
dd30c9f970 Style template length message to sit inline
This looks tidy, and because of the sticky footer it means the message
is always visible, even if your template is quite long. So no matter
where you’re scrolled to in the template you don’t have to scroll to the
bottom to see the count update.
2021-01-08 12:49:05 +00:00
Chris Hill-Scott
d452c0081d Add throttling to AJAX calls
The endpoint that count characters should be pretty low-load because it
won’t talk to the database (unless, on the first request, the user and
service aren’t cached in Redis).

The response size is also very small, only one line of text wrapped in a
single `<span>`, so won’t be as CPU-intensive to render as a whole page.

Still, we don’t want to completely hammer the server if a user types
very quickly.

This commit adds some throttling, so that we wait until there’s a
certain amount of delay between keystrokes before firing off the request
to the backend.

I’ve set the delay at 150ms. At normal typing speed this makes the lag
feel fairly imperceptible – it feels like you get an updated count in
response to most keystrokes. It’s only if you really mash the keyboard
that the count won’t update until you take a breath.
2021-01-08 12:49:05 +00:00
Chris Hill-Scott
64835cba86 Merge pull request #3475 from alphagov/request-invite
Allow invite form to be pre-populated with an existing user
2021-01-08 11:16:18 +00:00
Chris Hill-Scott
fbd58ef1f8 Add separate messages for invited/team member
2 messages seems like a good idea.
2021-01-08 10:56:59 +00:00
Chris Hill-Scott
c3b6c03411 Add ARIA attributes from Design System component
This commit copies the same ARIA attributes that are added to the
character count component[1] in the GOV.UK Design System.

This means that screen reader users will hear the count message when
they stop typing.

1. https://design-system.service.gov.uk/components/character-count/
2021-01-07 17:14:12 +00:00
Chris Hill-Scott
3fdaa29f35 Fetch template length message as user types
This commit adds some Javascript that makes AJAX requests as the users
changes the content of their template.

It then takes the content returned by the backend and inserts it in the
page.
2021-01-07 17:11:43 +00:00
Chris Hill-Scott
48577b823e Add an endpoint to count the length of templates
Users sending text messages are sometimes unaware that long messages
will cost more.

Users sending broadcast messages need to be aware that there’s a
character limit, so they can take this into account when planning their
messages.

This commit adds an endpoint which counts the number of characters in
some template content, and returns a snippet of useful info about how
long the message is.

In subsequent commits we’ll be able to use AJAX to fetch this snippet as
the user types.

There’s a surprising amount of complexity in counting the length of
messages. So we’ll need to do this in Python because it would be too
convoluted to re-implement the length counting in client side code, let
alone ensuring it had parity with its Python equivalent.
2021-01-07 17:07:51 +00:00
Chris Hill-Scott
7a95e1618e Extract formatters into their own module
We have lots of functions for converting various types of data into
strings to be displayed to the user somewhere.

This commit collects all these functions into their own module, rather
than having them cluttering up `app/__init__.py` or buried amongst
various other things that have ended up in `app/utils.py`.
2021-01-07 11:57:30 +00:00
Tom Byers
663df4a4f9 Remove <div>s from big_number text
An accessiblity audit done as part of Notify's
service assessment raised the following problem
with our big_number component.

When you turn CSS off, the sentence in the
component is split onto separate lines.

This was because the number part is wrapped in a
<div> which browsers were interpreting as being a
separate sentence to the label.

So "1 letter", where "letter" is the label, was
seen as:

"1"
"letter"

The accessibility expert consulted on this pointed
out that this would sound confusing for users of
screen readers when moving through the document
sentence by sentence.

These changes:
- make the <div>s into <span>s which are 'phrasing
  content' and so are interpreted as part of the
  same sentence
- change the CSS so the number will still sit
  on top of its label text

The HTML5 spec has a section on how browsers
should arrange text into paragraphs that explains
what was happening in more detail:

https://www.w3.org/TR/html52/dom.html#paragraphs
2021-01-05 11:39:18 +00:00
Chris Hill-Scott
8a751aa5df Merge pull request #3750 from alphagov/validate-broadcast-content-length
Validate length of broadcast content
2021-01-04 11:21:49 +00:00
Chris Hill-Scott
d9ebb0e2a1 Merge pull request #3756 from alphagov/fix-test-failing-after-1730
Fix test that fails after 5:30pm
2021-01-04 10:13:16 +00:00
Chris Hill-Scott
a68dfae5c2 Short circuit if team member is already invited
It would be confusing if people got invited twice, so let’s tell people
if someone’s has a pending invite.
2020-12-31 14:50:13 +00:00
Chris Hill-Scott
92c6cca6a1 Don’t populate invite with users from other orgs
We shouldn’t have a page where someone can look up any other user’s
email address based on their user ID.

We also don’t want a page where a malicious user could send someone an
link which would get them invited to the service.

Restricting the invite to be populated just from users in their own
organisation doesn’t mitigate against this stuff completely, but they
probably have a way of finding out the email address of someone in their
organisation already.
2020-12-31 14:47:00 +00:00
Chris Hill-Scott
deaf2059f5 Short circuit if already a team member
It would be confusing if people got invited twice, so let’s tell people
if someone’s already been invited.
2020-12-31 14:45:58 +00:00
Chris Hill-Scott
6edc356c22 Allow invite form to be pre-populated
At the moment users must be invited to join a service. But this means:
- users must know that a service already exists
- they need to know who to ask for an invite

If the user doesn’t know these thing then sometimes they just go ahead
and set up a new service. Which means they have to get all the way to
the point of requesting to go live before we tell them that there’s
already a service with a similar name or purpose.

So we should let users:
1. discover what other services exist in their organisation
2. apply to join a service
3. automatically notify the service managers of their interest
4. be invited by a service manager
5. accept the invite

This commit implements step 4. We can just link them to the invite form
in step 3., but we should make it easy for them to send the invite,
without having to copy and paste email addresses.

So this commit let the invite form be pre-populated with an existing
user’s email address.
2020-12-31 14:35:39 +00:00