Commit Graph

78 Commits

Author SHA1 Message Date
Chris Hill-Scott
c1a5cad0d6 Add function to estimate letter delivery date
Letter delivery depends on:
- how long it takes to print
- how long it takes to post

Both of these process are impacted by weekends, because people don’t
work on weekends.

It also depends on if you submit your letter before or after 5pm,
because that’s the cut off time for getting a letter printed on a given
day – ie after 5pm on Monday is effectively the same as Tuesday and so
on.

But I reckon all our users need to know is roughly how long it will take
until the letter turns up on the user’s doorstep. So this commit adds
a function to calculate this. Doesn’t surface it on the front end _yet_.
2017-07-12 15:11:39 +01:00
Katie Smith
aaadd867f7 Refactor code to check whether email/sms is enabled 2017-07-05 09:15:58 +01:00
Chris Hill-Scott
4798258e62 Add redact_missing argument to get_template
Adds an interface to use:
https://github.com/alphagov/notifications-utils/pull/171
2017-06-30 14:04:10 +01:00
Leo Hemsted
09dc85e5bc Clean up code to remove unnecessary paths.
Status code was overcomplex, given how we control the inputs. Now, it
expects a single value, rather than a comma separated list, and if you
give something it doesn't expect it just returns all. Note, it won't
select the correct box - but if you've been manually editing the URL
that's your own problem ¯\_(ツ)_/¯

Also, as this page will only ever be shown from the tour (tutorial),
it doesn't need some non-help things - such as the download csv button
and associated endpoint.
2017-06-16 15:28:17 +01:00
Leo Hemsted
c5f92eabfb add add one-off notification status
completely mimicks the job status page, and as such, all the code and
templates have been taken from the job page. This page performs
exactly the same as the job page for now

* total, sending, delivered, failed blue boxes (though they'll just
  read 0/1 for now.
* download report button (same as with job download, except without job
  or row number in file)
* removed references to scheduled
* kept references to help (aka tour/tutorial) as that'll eventually
  change over from a job to a one-off too
2017-06-16 15:28:17 +01:00
Chris Hill-Scott
1c1c5bd758 Merge pull request #1285 from alphagov/from-always-set
Use GOVUK as fallback SMS sender
2017-05-23 13:55:35 +01:00
Chris Hill-Scott
616fec9d77 Remove 40604 as fallback
We should just be using whatever is in the database. Should not be
merged until the DB migration is done.
2017-05-23 13:36:48 +01:00
Chris Hill-Scott
8c03feb334 Show one field at a time on send yourself a test
The send yourself a test feature is useful for two things:
- constructing an email/text message/letter without uploading a CSV file
- seeing what the thing your going to send will look like (either by
  getting it in your inbox or downloading the PDF)
- learning the concept of placeholders, ie understanding they’re thing
  that gets populated with _stuff_

The problem we’re seeing is that the current UI breaks when a template
has a lot of placeholders. This is especially apparent with letter
templates, which have a minimum of 7 placeholders by virtue of the
address.

The idea behind having the form fields side-by-side was to help people
understand the relationship between their spreadsheet columns and the
placeholders. But this means that the page was doing a lot of work,
trying to teach:
- replacement of placeholders
- link between placeholders and spreadsheet columns

The latter is better explained by the example spreadsheet shown on the
upload page. So it can safely be removed from the send yourself a test
page – in other words the fields don’t need to be shown side by side.

Showing them one-at-a-time works well because:
- it’s really obvious, even on first use, what the page is asking you to
  do
- as your step through each placeholder, you see the message build up
  with the data you’ve entered – you’re learning how replacement of
  placeholders works by repetition

This also means adding a matching endpoint for viewing each step of
making the test letter as a PDF/PNG because we can’t reuse the view of
the template without any placeholders filled any more.
2017-05-22 10:50:10 +01:00
Chris Hill-Scott
d1cd74daa8 Update utils with to make letters unclickable
Brings in:
- [ ] https://github.com/alphagov/notifications-utils/pull/159

Means:
- renaming a bunch of things
- removing any CSS that targeted the link, and making it target the
  containing element too
2017-05-03 12:20:45 +01:00
Leo Hemsted
cf125d0a14 add sent as a new status
functions as delivered - shows up in delievered column, contributes
to delivered stats etc.
2017-04-27 16:17:10 +01:00
Chris Hill-Scott
05b9f6e736 Merge pull request #1237 from alphagov/multi-page-previews
Show all pages of a letter in the app
2017-04-25 15:33:22 +01:00
Chris Hill-Scott
36db0ad598 Show all pages of a letter in the app
In research we’ve seen two problems with the click-to-see-PDF thing:

- it’s not very intuitive that the letter is clickable, or what you
  can expect when clicking the letter
- people get lost of stuck in the PDF view because it opens in the same
  tab, or they open it in a new tab and then get find their way back, or
  …

So this commit changes the show template page to show the entire
contents of the letter, same as we do for emails and text messages.

Right now it only does it on the view template page. I think we’ll have
to work out a way of showing some kind of truncated version on the _Send
yourself a test_ and _Preview_ pages. But that’s for later.
2017-04-20 15:57:43 +01:00
Imdad Ahad
19f42a8984 Refactor report download:
* Remove formatting (most performance intensive) as this will happen on API
* Remove buffering of notifications so we can yield them back straight away
* Refactor existing tests to match new format of the notification resp for csv
2017-04-20 15:18:42 +01:00
Leo Hemsted
a6318f2674 remove pdf/png code from admin app entirely
while PDFs work on paas, they only do that because it turns out the
python buildpack happens to have imagemagick preinstalled - if that
ever changes then it'd break. so move those to the template preview
service. This also means we can get rid of weazyprint and wand
dependencies
2017-04-10 17:45:22 +01:00
Leo Hemsted
85404f20db bump utils to 13.10.0
pass in the base URL - if not set in the environment this is set to
localhost, but on paas we can pull this out of vcap_services so that
letters render properly on paas
2017-03-27 17:59:06 +01:00
Chris Hill-Scott
05fca0536c Make letter full-height and increase resolution
Previously we only showed the top half of a letter template, in order
to conserve space and fit multiple letter templates on one page. Now
that we have only one template per page there is space to spare. So
this commit changes the letter preview to show the full height of the
A4 page.

This also requires increasing the resolution at which the preview is
rendered so that it still looks clean at the bigger size.
2017-03-20 11:47:31 +00:00
Imdad Ahad
fc8bbc5d6f Add more logging for getting next page logic 2017-03-15 10:29:38 +00:00
Imdad Ahad
276a072a54 Add logging for streaming contents 2017-03-13 14:53:19 +00:00
Chris Hill-Scott
92a51c3a6c Pass contact block through to letter Template
So that it appears in letter previews…
2017-03-03 16:53:24 +00:00
Chris Hill-Scott
ac9d4f2daf Break down usage by month, filter by year
The previous, weekly activity breakdown was what we reckoned might be
useful. But now that we have people using the platform it feels like
aggregating a service’s usage by month is:
- matches the timeframe users report on within their organisation
- is consistent with the usage page

And like the usage page this commit also limits the page to only show
one financial year’s worth of data at once (rather than data for all
time).

This commit also makes some changes to the jobs view code so that our
aggregation of failure states is consistent between the dashboard pages
and the jobs pages.
2017-02-08 10:59:26 +00:00
Chris Hill-Scott
2a502753a4 Filter and navigate usage by financial year
Right now we tell people that the usage page is for the current
financial year. This is a lie – it’s for all time.

So this commit calls through to the API to get the stats for (by
default) the current financial year.

We already do this for the monthly breakdown, this just does the same
thing for the yearly totals.

It also adds navigation to show the data for other financial years:
- previous so you can go back and see your usage and verify that the
  bill you’re about to pay is correct
- next so that you can check what your SMS allowance is going to be
  before you actually get into it
2017-02-06 12:25:48 +00:00
Imdad Ahad
5365015adf Optimise the check 2017-01-19 10:57:11 +00:00
Imdad Ahad
6a48325b3b Fix issue where row_number starts from 3 on a job report download 2017-01-19 10:42:58 +00:00
imdadahad
b5cb34c368 Merge pull request #1070 from alphagov/return-streamed-csv
Fix timeout on download of large CSV reports
2017-01-16 10:34:25 +00:00
Imdad Ahad
59c7bc2e6f Refactor get notifications streaming including formatting 2017-01-13 11:35:27 +00:00
Imdad Ahad
e28d009fa7 Return csv download stream instead of all-in-memory 2017-01-06 17:41:24 +00:00
Chris Hill-Scott
729568d010 Improve image quality of PNGs
The PNGs we were generating looked a bit fuzzy, and the text rendering
was a bit off.

This is because we weren’t rendering them at a high enough resolution.
I’m guessing the default was 72dpi. This commit increases the resolution
to 96dpi, which (locally) seems to be enough to give a good-looking
preview.
2017-01-04 15:46:00 +00:00
Chris Hill-Scott
2854dbe3dd Refactor PNG generating endpoint for code reuse
The way we generate PNGs is the same for all the different endpoints,
so the code to do this should be shared.
2017-01-04 15:45:59 +00:00
Chris Hill-Scott
559433c5d2 Add remaining endpoints for PDFs and PNGs
Right now we can show what a letter template looks like as a PDF or PNG.

This commit completes the work so this is also possible when:

- showing a template with the placeholders replaced
- showing any version of a template

Also removes dependency on `Exception().message`, which was deprecated
in Python 2.6. See
97f82d565f
for full details.
2017-01-04 15:45:59 +00:00
Chris Hill-Scott
dc63de0f4e Incorporate breaking utils changes
Brings in:
- [ ] https://github.com/alphagov/notifications-utils/pull/94
2016-12-14 14:32:07 +00:00
Chris Hill-Scott
ae356fc741 Use PDF link renderer to preview letters
Depends on and implements:
- [x] https://github.com/alphagov/notifications-utils/pull/84
- [ ] https://github.com/alphagov/notifications-utils/pull/86
2016-12-13 10:34:19 +00:00
Chris Hill-Scott
18d11aa013 Move code for rendering messages/templates → utils
Utils is better structured to handle the logic of what thing to show
for what template type, especially now that what we show for different
template types in different contexts has diverged significantly.

See https://github.com/alphagov/notifications-utils/commit/6b39c1a for
an example of this code moving into utils

Depends on and implements:
https://github.com/alphagov/notifications-utils/pull/84

The main reason for doing this is to get Paul’s fix for the misaligned
CSV columns: https://github.com/alphagov/notifications-utils/pull/87
2016-12-05 12:11:54 +00:00
Chris Hill-Scott
34e01824fa Add errors for missing address(es) 2016-11-14 14:53:06 +00:00
Leo Hemsted
a5d228d837 ensure robustness of email_safe function
* remove leading, trailing, or consecutive periods
* strip unicode accents, umlauts, diacritics etc
2016-10-28 16:11:08 +01:00
imdadahad
847bb8ed57 Merge pull request #998 from alphagov/invite-nongov-users
Invite nongov users
2016-10-28 15:40:37 +01:00
Imdad Ahad
e58b63f504 Update regex/config and remove unused imports 2016-10-28 11:44:35 +01:00
Imdad Ahad
5ecdbb8596 Refactor to use a cleaner and lean regex 2016-10-28 10:45:05 +01:00
Leo Hemsted
26a985720c fix 500 errors with excel files > 500k size limit
werkzeug's internal workings keep files under 500kb in memory, and files
greater than 500kb as a TemporaryFile

(https://github.com/pallets/werkzeug/blob/0.11-maintenance/werkzeug/formparser.py#L38)

when we encounter a CSV or TSV, we call normalise_newlines, which invokes
`.read()`, however when we were passing straight into pyexcel, we called
`file.getvalue()` - this exists on BytesIO (small files) but not on
TemporaryFile objects (large files) - we were seeing 500 errors
2016-10-26 16:35:14 +01:00
Imdad Ahad
f33e0d0e94 Add function to check if given email in whitelist 2016-10-25 18:10:15 +01:00
Imdad Ahad
a05a36f2a8 Remove newline 2016-10-21 14:28:55 +01:00
Imdad Ahad
2a2a733a41 Fix 500s when requesting json after logged out:
* Update permissions decorator to make sure user is logged in first, else 401
* Stop further ajax json calls on failure
2016-10-21 14:24:21 +01:00
Chris Hill-Scott
6946d3af54 Make API key combination of secret and service ID
In research we’ve seen people mix up the service ID and API key because
they’re both 36 character UUIDs. We can’t get rid of the service ID
because it’s used to look up the API key.

Instead, we should change API key to be one long string, which contains
both the service ID, API key and (optionally) the name of the key. For
example:

```
casework_production-8b3aa916-ec82-434e-b0c5-d5d9b371d6a3-dcdc5083-2fee-4fba-8afd-51f3f4bcb7b0
```

We still need to keep the old, separate, key and service ID for a while
until people have updated their clients. But they’re now both on this
page, rather than on two separate pages, which should make for less
fussing anyway.

This shouldn’t be rolled out until the new clients are available.

- [ ] https://github.com/alphagov/notifications-python-client/pull/36
- [ ] https://github.com/alphagov/notifications-node-client/pull/10
- [ ] https://github.com/alphagov/notifications-ruby-client/pull/15
- [ ] https://github.com/alphagov/notifications-java-client/pull/38
- [ ] PHP????
2016-10-18 12:21:00 +01:00
Leo Hemsted
0fdd38b9c5 add tests for new jobs functionality 2016-10-10 17:15:57 +01:00
Leo Hemsted
ebb590bc5d clean up generate_previous_next_dict
separate it into two functions to avoid repeatedly passing in the same parameters everywhere, and removed some unused if blocks
2016-10-10 15:43:01 +01:00
Chris Hill-Scott
3d8d160d3e Always use 12h times
The GOV.UK content style guide says:

> - 5:30pm (not 1730hrs)
> - midnight (not 00:00)
> - midday (not 12 noon, noon or 12pm)

This commit changes all times to be 12h not 24h, and adds a special case
for when a time is exactly 12:00am or 12:00pm.
2016-08-31 16:58:34 +01:00
Chris Hill-Scott
50c20ce680 Add formatted notification status to CSV
This commit makes the CSV download use the same language for failure
reasons as the frontend.

It also adds a test around this stuff, which was patchily tested before.
2016-07-11 13:12:46 +01:00
Chris Hill-Scott
d33c254fa5 Merge pull request #743 from alphagov/hide-delivery-download-tour
Hide download CSV link when in the tour
2016-07-08 16:31:16 +01:00
Chris Hill-Scott
84a2862387 Fix 500 being thrown when uploading large files
This is re-fixing a bug which was re-introduced when adding the
`Spreadsheet` class in 1409ca36ca.

It was previously fixed in 19662d8329:

>  Fix bug with large file uploads
>
>  Depending on the size of the uploaded file, Flask will temporarily store
>  it in different ways. This means that it comes back as a `TempFile` if
>  the file is roughly <500k and as `BytesIO` if the file is larger.
>
>  `TempFile` supports the `.getvalue()` method, but `BytesIO` does not.
>  Both support the `.read()` method, so this commit changes to use that
>  instead.
2016-07-07 11:52:57 +01:00
Chris Hill-Scott
80e0832f7d Make a function for parsing help query param
Our templates are a littered with `request.args.get('help', '0')`.
This commit refactors these into a single helper method, which can be
used by the view functions, then passed to the template.

This makes the templates cleaner, and should make it easier to refactor
`help` out of the query parameters entirely in the future.
2016-07-05 17:29:41 +01:00
Leo Hemsted
539950d772 when not logged in, redirect to sign-in
parts of the initial setup/login stages were throwing 500s if user
not already in process (ie: user directly navigated to url):
* /resend-email-verification
* /text-not-received
* /send-new-code
* verify
2016-06-17 13:53:48 +01:00