Commit Graph

55 Commits

Author SHA1 Message Date
Katie Smith
8f7a05200d Add function to map template-preview errors to user-friendly errors
Template preview now returns a short string as it's error message plus
a list of invalid pages.
2019-10-21 08:35:04 +01:00
Pea Tyczynska
4a679a6583 Letter job can't be cancelled if already printed
Non-cancellable letter statuses mean that it's too late to cancel a job
2019-07-04 14:44:21 +01:00
Chris Hill-Scott
55d4810c4b Don’t convert Excel reports to CSV before output
Converting Python data to CSV makes every field a string. This means
that in the report we return to the user every field will be a string,
even if it’s come from an `int` type in Python. This is because the CSV
‘standard’ doesn’t support any kind of typing.

Excel does support types for fields, so we can make our reports more
useful by preserving these types. This is particularly relevant in the
report we generate for performance platform, which needs the `count`
column to be a number type.

This commit adds extra code paths to the `Spreadsheet` class which mean
that it can be instantiated from either CSV data or a list of Python
data. Previously we were converting the Python data to CSV as an
intermediate step, before instantiating the class.
2019-05-07 16:07:23 +01:00
Chris Hill-Scott
9d99c78c3a Remove code that reads domains.yml
Since we’ve removed calls to this code from the rest of the app, it can
safely be removed now.
2019-04-12 15:23:08 +01:00
Chris Hill-Scott
032cbf9a17 Flag go live requests from DWP
It’s not enough to check that they’ve signed the agreement. We have to
make sure we inform them every time a service wants to go live.
2019-02-19 11:18:50 +00:00
Chris Hill-Scott
978719cd20 Ensure domains are canonicalised
So, each domain owner only has one entry in the file (but can still
have multiple domains).
2019-02-12 13:33:14 +00:00
Chris Hill-Scott
70ac96fed9 Make sure all domains are lowercased 2019-02-12 13:33:14 +00:00
Chris Hill-Scott
ba8d2ff1e3 Don’t let domains have none values 2019-02-12 13:33:13 +00:00
Katie Smith
f005d7a569 Refactor to split s3_client.py into multiple files
Separated s3_client.py into 3 files - for logos, CSV files and the MOU.
This helps to keep things clearer now that we need to add lots more logo
functions for letters.
2019-02-06 17:26:58 +00:00
Chris Hill-Scott
a093b8d976 Use Babergh as the example in tests
Because Aberdeenshire have signed the agreement.
2019-01-08 15:12:52 +00:00
Pea Tyczynska
1858ee93fd Notifications CSV Report now also shows sender email address 2018-12-07 11:20:20 +00:00
Katie Smith
088d6ee4b0 Content changes for notification pages
This commit adds content pages for the notifications pages, particularly
the letter pages, which will make things clearer now that we will soon be allowing
letters to be cancelled.

The main changes are:
* The confirmation banner for letters sent from a CSV file now states when
printing will start.
* We state the CSV file that notifications were sent from on the
notifications page
* The notification page for letters shows when printing starts (today,
tomorrow, or that date that the letter was printed)
2018-12-03 10:42:47 +00:00
Chris Hill-Scott
bc6b9c7af7 Use named arguments for clearer string formatting
Helps when the string is long.

Also helps disambiguate between the CDN domain used for the logos and
those for CSS/JS.
2018-11-29 11:56:01 +00:00
Leo Hemsted
32f39475d2 remove dupe of get_letter_timings
it was moved from admin to utils a while ago
2018-09-28 15:02:32 +01:00
Chris Hill-Scott
20e71499f0 List who sent a message in CSV download
This is useful if you have lots of people sending messages and want to
report on who’s doing what.

Needs the API updating to return `created_by_name` in its response.
2018-09-06 14:52:31 +01:00
Chris Hill-Scott
47c9b71fa8 Add canonical domain info to agreement class
Because we alias domains (eg `foo.gsi.gov.uk` to `foo.gov.uk`, or where
a local council has multiple domains) it could be hard to look up a
brand (which has one domain field).

Therefore we need a way of getting the canonical domain from a user’s
email address, which we can later use to look up their branding.
2018-09-05 10:32:43 +01:00
Chris Hill-Scott
ed9444b436 Fix org info in branding requests with known orgs
This wasn’t looking quite right in the case where an organisation is in
our list of domains.
2018-07-10 17:18:50 +01:00
Chris Hill-Scott
949bf6feea Add organisation info to branding requests
This will let us know which organisation the person asking for the
branding is from. This should reduce how often we have to go back to
them and ask.
2018-07-10 16:34:44 +01:00
Chris Hill-Scott
060b93c4d4 Check that all domains in our lists are valid
Since we have too many to add individual tests every time we add a new
one now.
2018-05-08 15:25:41 +01:00
Leo Hemsted
be038e345d define isort first party (app and tests)
we were seeing isort produce different outputs locally and in docker -
this was due to it having different opinions about whether the tests
module (ie all our unit tests) is a first party (local) or third party
(pip installed) import. It's a first party import, so by defining this
in the setup.cfg isort settings, we can force it to be consistent
between environments.

Note: I don't know why it was different in the first place though
2018-04-25 14:12:58 +01:00
Leo Hemsted
df30562216 fix relative datetime function to handle dates correctly
Previously, we were looking at the day of the week - so messages sent
six days ago would show up as "tomorrow". We now look at the actual
date, so that won't happen again.

We were also subtracting an hour to make 00:00 this evening show up as
"midnight today", despite it technically being tomorrow. However, this
means that 00:59 tomorrow morning would show up as "00:59 today", a
full day out. So reduce that to just a minute, so it doesn't affect
other times of day.
2018-03-21 16:08:09 +00:00
Chris Hill-Scott
056c4ebb88 Rename GovernmentDomain to AgreementInfo
This better describes the data encapsulated by this class, and how we
are now using it.
2018-03-15 10:45:34 +00:00
Chris Hill-Scott
d92ecc9237 Add human-readable form of a government domain
This makes it easier to write a good message in the request to go live
submission. And encapsulating it in the `GovernmentDomain` class keeps
the view nice and clean.
2018-03-08 16:50:18 +00:00
Chris Hill-Scott
35f523c957 Prevent cells containing commas breaking downloads
If a cell in the original file contains a comma, it comes back as two
cells in the downloaded file.

The CSV writer has logic to deal with this. It seems to work a lot
better that just concatenating the columns with commas ourselves.
2018-03-06 15:11:59 +00:00
Chris Hill-Scott
0934843815 Add original file data to job downloads
When downloading a report of a which messages from a job have been
delivered and which have failed we currently only include the Notify
data. This makes it hard to reconcile or do analysis on these reports,
because often the thing that people want to reconcile on is in the data
they’ve uploaded (eg a reference number).

Here’s an example of a user talking about this problem:

> It would also be helpful if the format of the delivery and failure
> reports could include the fields from the recipient's file. While I
> can, of course,  cross-reference one report with the other it would be
> easier if I did not have to. We send emails to individuals within
> organisations and it is not always easy to establish the organisation
> from a recipient's email address. This is particularly important when
> emails fail to be delivered as we need to contact the organisation to
> establish a new contact.

– ticket 677

We’ve also seen it when doing research with a local council.

This commit takes the original file, the data from the API, and munges
them together.
2018-02-28 10:51:13 +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
Chris Hill-Scott
59bb7bdd5d Don’t parametrize on government domains
There’s over 1000 domains in our file. This is too much for parametrize
to handle when running the tests on multiple cores. End up with this
error:
```
Different tests were collected between gw1 and gw2.
```
2018-02-26 08:53:48 +00:00
Chris Hill-Scott
b2dd5cd8ae Talk about crown/non-crown not local/central
The thing that matters for which agreement an organisation has to sign
is whether or not that organisation is crown or non-crown.

There is only a partial overlap between crown/non-crown and
local/central. We can’t infer one fro the other. So this commit makes it
explicit by marking all local government organisations as non-crown,
which is something we can know for sure.

We don’t, for example, know the inverse, that all parts of all central
government organisations are crown bodies (but we can mark some of them
as being so later on).
2018-02-26 08:53:47 +00:00
Chris Hill-Scott
7f5f0ea02b Add list of local council domains
Taken from:
https://www.gov.uk/government/uploads/system/uploads/attachment_data/file/655371/List_of_.gov.uk_domain_names_as_at_26_October_2017.csv/preview

Then filtered down to councils using this script:
```python
import clipboard
import csv
with open('List_of_.gov.uk_domain_names_as_at_26_October_2017.csv') as l:
    f = csv.reader(l)
    s = ''
    for row in f:
        if 'council' in row[1].lower():
            s = s + "{}:\n    sector: local\n    owner: {}\n".format(*row)
    clipboard.copy(s)
```
2018-02-26 08:53:47 +00:00
Chris Hill-Scott
20fe084ff1 Mark central and NHS organisations w/ signed MOUs
This adds information about which orgs have signed an MOU to the domain
list. The meaning of the attribute is:
- `true`: MOU signed for the whole organisation
- `false`: no MOU for any part of the organisation
- `null` (or missing): can’t be sure if it’s true or false
2018-02-26 08:53:46 +00:00
Chris Hill-Scott
f93ef2eb3d Convert domain list to YAML
YAML is easier to edit than Python code, and having it in the root
directory of the app makes it nice and easy to find.
2018-02-26 08:53:46 +00:00
Chris Hill-Scott
91ab54e9c1 Allow lookup of org details
This commit:
- makes the logic around looking up a domain a bit more sophisticated
  by matching on the longest domain name first
- exposes the details about an organisation to consumers of the
  `GovernmentDomain` class
2018-02-26 08:53:46 +00:00
Rebecca Law
59ac514655 Fix bug. 2018-01-12 14:03:31 +00:00
Rebecca Law
e71bbc1bb5 [WIp] 2018-01-03 13:21:00 +00:00
Rebecca Law
259db9c271 Put the download csv link on the activity page.
Still needs some tests, probably some refactoring as well.
2017-12-30 16:54:39 +00:00
Ken Tsang
796fe0472f Renamed test 2017-07-28 15:19:20 +01:00
Ken Tsang
123247a178 Refactor test 2017-07-27 16:30:26 +01:00
Ken Tsang
35f66cae23 Update emails to use logos cdn 2017-07-27 16:10:59 +01:00
Chris Hill-Scott
e20483c462 Add print timings to letter timings
It will also be useful to know (especially for the API):
- when a letter was printed
- if it’s been printed or not

This commit:
- adds code to calculate these two pieces of information
- refactors the function to return a `namedtuple` – a tuple of two items
  was manageable, but with four items it was getting hard to know what
  each one meant – this lets us label each piece of information that is
  being returned
2017-07-14 20:09:23 +01:00
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
Chris Hill Scott
ecc506306b Move helper function
`test_utils.py` is actually a file for testing some utils, not
some utils for testing.

Test helper functions and fixtures are better placed in conftest,
and also means that we can use them in conftest.
2017-07-04 14:17:36 +01:00
Chris Hill-Scott
e373296bd9 Show inbound messages on the dashboard
This commit adds two things:

a section on the dashboard to show how many inbound messages the
service has received in the last 7 days, and how recently an inbound
message has been received
---

Doesn’t show the contents of any messages, just like how the rest of the
dashboard is an aggregation, never individual messages.

a page to show all the inbound messages the service has received in
the last 7 days
---

This shows the first line of the message. Eventually this will link
through to a ‘conversation’ page, where a service can see all the
messages it’s received from a given phone number.
2017-06-05 15:42:36 +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
Leo Hemsted
d6de5508ca make sure static subdir 404s correctly
before each request, we put the current service on the flask session,
except for with the static folder, cos it's not needed.... except, if
we 404, then we return the 404 template, which checks if you're logged
in or not to display different nav bar items. This was crashing when
current_service wasn't set, so we now set it.

also cleaned up some imports and stuff in test files
2017-05-04 11:28:45 +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
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
6a48325b3b Fix issue where row_number starts from 3 on a job report download 2017-01-19 10:42:58 +00:00
Imdad Ahad
50e0227480 Fairly large refactor of tests related to getting/viewing notifications 2017-01-13 11:37:14 +00:00
Imdad Ahad
1036f365fa Refactor generate csv test to expect a stream (generator) 2017-01-06 17:43:46 +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