Commit Graph

144 Commits

Author SHA1 Message Date
Alexey Bezhan
5198009550 Merge pull request #2300 from alphagov/submit-returned-letters
Add a platform admin page to submit returned letter references
2018-09-07 15:06:24 +01:00
Alexey Bezhan
b75681dfbc Add a platform admin page to submit returned letter references
A platform admin form accepts a list of references (one per line)
received from DVLA and sends them to the API to update notification
statuses.

References we get from DVLA start with `NOTIFY00\d`, which isn't
part of the reference we store in the database, so we remove them
before sending the data to the API.

The new `returned-letter` status should be treated as `delivered`
for now until we decide a way to display returned letters to users.
2018-09-07 11:13:01 +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
45eb16b4db Check text message sender before going live
We often check that a service has an appropriate text message sender as
a condition of them going live. We don’t mention this anywhere.

The services for whom GOVUK is definitely not an appropriate sender are
those in local government. As we have more of these teams starting to
use Notify, we should streamline the process by making this check
automated.

This commit adds that check, for teams who:
- have text message templates
- have self-declared as NHS or local government
2018-08-29 11:29:44 +01:00
Chris Hill-Scott
5a52eafb84 Fix ‘Back’ link from first step of fix one off
If you skip past the templates page (because you don’t have the edit
permission) but then click back you end up in a loop which redirects you
to the page you’re already on.

This commit makes sure that you’re sent back a step further, so you
don’t get stuck in that loop.
2018-08-10 09:16:18 +01:00
Chris Hill-Scott
92a258dc41 Use model for template previews 2018-07-30 14:56:36 +01:00
Chris Hill-Scott
660fadbce7 Make the guessing a bit more sophisticated
Things we’ve noticed from looking at real data that we could handle in a
smarter way:
- removing numbers (there might be a tom.smith2@dept.gov.uk if tom.smith
  is already taken)
- removing middle initials (again, these tend to be used for
  disambiguation and aren’t included when we ask people for their names)
- ignoring email addresses which only have someone’s initial, not their
  first name (because we can’t make a decent guess in this case)
2018-07-11 13:31:38 +01:00
Chris Hill-Scott
3683f99c3b Guess people’s names when they’re invited
Most people’s names, especially in government are in the format
firstname.lastname@department.gov.uk. This means that you can pretty
reliably guess that their name is ‘Firstname Lastname’.

When users are invited to Notify we know their email address already.

So this commit pre-populates the registration form based on this guess.

This is a nice little detail, but it should also stop the browser
pre-filling the name field with someone’s email address (which I think
happens because the browser assumes a registration form will have an
email field).
2018-07-11 10:35:25 +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
Rebecca Law
72b0637f92 Add the download activity link for notifications.
This works locally for a long running request and a large number of messages. However I suspect that nginx may be timing out the request. I'd like to try this on staging.
2018-06-25 16:29:40 +01:00
Chris Hill-Scott
f8546c8611 Refactor to be more DRY 2018-05-09 13:44:42 +01:00
Chris Hill-Scott
dc6d66daba Make people sign in to get the agreement
Currently we have a bunch of users who aren’t signed in asking us for
the agreement.

This is bad because:
- it’s slower (for them) than just being able to download it
- it creates work for us

We can’t just offer the agreement to anyone, but we can offer to it to
anyone who’s signed in because we now let people self-select which
version to download when we can’t tell which one to give them.
2018-05-09 13:41:51 +01:00
Chris Hill-Scott
793842bb3b Let users download the crown agreement
This (partially) reverts commit dca5546cbd

Depends on

- [ ] agreement being uploaded to the bucket in all environments as
      `crown.pdf`
2018-05-02 09:54:13 +01:00
Chris Hill-Scott
bc8bc727f3 Limit length of filename
S3 has a limit of 2kb for metadata:

> the user-defined metadata is limited to 2 KB in size. The size of
> user-defined metadata is measured by taking the sum of the number of
> bytes in the UTF-8 encoding of each key and value.

– https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#object-metadata

This means we have a limit of 1870 bytes for the filename:
```python
encoded = 'notification_count50000template_id665d26e7-ceac-4cc5-82ed-63d773d21561validTrueoriginal_file_name'.encode('utf-8')
sys.getsizeof(b)
>>> 130
2000-130
>>> 1870
```

Or, in other words, ~918 characters:
```python
sys.getsizeof(('ü'*918).encode('utf-8'))
>>> 1869
```
2018-04-30 11:44:00 +01:00
Chris Hill-Scott
dca5546cbd Only offer agreement download to non-crown for now
We don’t have the crown agreement in a nice downloadable format at the
moment.
2018-03-28 12:43:03 +01:00
Chris Hill-Scott
c7ab9f7f1a Link to the page to download the agreement
We prefer people downloading the agreement if they can. If we don’t know
which agreement they should be using (ie we don’t know their crown
status) then we fall back to having them contact us.
2018-03-27 11:35:17 +01:00
Chris Hill-Scott
68292d2299 Add endpoints to serve the agreement
Rather than making users contact us to get the agreement, we should just
let them download it, when we know which version to send them.

This commit adds two endpoints:
- one to serve a page which links to the agreement
- one to serve the agreement itself

These pages are not linked to anywhere because the underlying files
don’t exist yet. So I haven’t bothered putting real content on the page
yet either. I imagine the deploy sequence will be:

1. Upload the files to the buckets in each environment
2. Deploy this code through each enviroment, checking the links work
3. Make another PR to start linking to the endpoints added by this
   commit
2018-03-27 11:35:17 +01:00
Chris Hill-Scott
0f8a6ca2fb Merge pull request #1969 from alphagov/no-free-text-from-url
Don’t populate support form with arbitrary text
2018-03-21 14:34:19 +00:00
Chris Hill-Scott
64b5f03dcd Don’t populate support form with arbitrary text
I don’t think it’s a massive risk (we’re certainly mitigating against
any XSS), but having a page on a GOV.UK domain where you can prefill
text on the page from a query string probably isn’t great.

So this commit restricts prefilling the support form to a set of
named questions.
2018-03-20 16:07:23 +00:00
Katie Smith
4db75f6a58 Display the two new virus states for letters
Precompiled letters can now have two additional states:
* pending-virus-check
* virus-scan-failed

Both new states should show in the notifications dashboard, and
virus-scan-failed should appear as an error state, with a descriptive
message. You should not be able to preview a letter in one of the two
new states, so the preview link has been removed for precompiled letters
in these states.
2018-03-20 14:54:29 +00:00
Leo Hemsted
90c40075c8 Merge pull request #1954 from alphagov/choose-accounts
Choose accounts
2018-03-19 15:26:06 +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
Leo Hemsted
1cd8000236 remove browsableitem
it was only used by the choose service page, and then only in kludgy
ways (eg: creating a list containing one item called "add service"),
so lets rip it out and make this page bespoke. Especially now that it's
changed so much.
2018-03-14 15:39:55 +00:00
Leo Hemsted
ee665caa7d get orgs and services from user
this endpoint should probably only be used for the choose-service page
also create an OrganisationBrowsableItem to aid rendering of them
in the front-end.
2018-03-14 15:39:55 +00:00
Chris Hill-Scott
548ece6c22 Merge pull request #1925 from alphagov/refactored-csv-processing
Bring in refactored CSV processing
2018-03-09 15:16:37 +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
b0278c5649 Refactor to put user logic inside class 2018-03-08 15:26:55 +00:00
Chris Hill-Scott
f6f5faa361 Bring in refactored CSV processing
Shouldn’t be any functional changes here, just things being named more
clearly.
2018-03-08 13:30:20 +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
Leo Hemsted
3ae815528c add restrict_admin_usage arg to admin_override
rather than allow admins to do everything specifically, we should
only block them from things we conciously don't want them to do.
This is "Don't let platform admins send letters from services they're
not in". Everything else the platform admins can do.

This is step one, adding a restrict_admin_usage flag, and setting that
for those restricted endpoints around creating api keys, uploading CSVs
and sending one-off messages.

Also, this commit separates the two use cases for permissions:
* user.has_permission for access control
* user.has_permission_for_service for user info - this is used for
  showing checkboxes on the manage-users page for example

With this, we can remove the admin_override flag from the permission
decorator.
2018-03-06 13:08:06 +00:00
Leo Hemsted
7ddad7c99e dont use has_permissions to check for platform admins
platform_admin is a separate concept to permissions, so by removing the
checks for it from the current_user.has_permissions function, we can
simplify things greatly. We already record on the user whether they're
a platform admin anyway.
2018-03-06 13:08:06 +00:00
Chris Hill-Scott
032ce6960b Refactor to not repeat loop and variables
This commit just cleans up the code a bit to:
- have less duplication
- do less assignment of single-use variables
2018-02-28 10:51:13 +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
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
5404107842 Split email list out again
The list of email domains is a different list from the list of all
government domains. And because the list of all government domains is
really long now, it could be unnecessarily slow to search through when
(a lot of the time) all we care about is whether the email address ends
with `.gov.uk`.
2018-02-26 08:53:47 +00:00
Chris Hill-Scott
9e8d69da7d Get rid of the regex
Regexes are hard to read, and this one is probably quite slow because
the string formatting means it can never be precompiled.
2018-02-26 08:53:47 +00:00
Chris Hill-Scott
be18448f2a Refactor to only sort once
Rather than doing the sort every time an instance is initiated, we can
speed things up by just doing it the once when the app starts up.
2018-02-26 08:53:47 +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
Chris Hill-Scott
911fc3ff4c Start adding extra information about each domain
In some cases we can tell based on someone’s email domain whether they
work for a central or local government organisation, and whether they
will need to sign the MOU or agreement in order to go live. So this
commit creates a structure to store this information.
2018-02-26 08:53:46 +00:00
Chris Hill-Scott
156625a994 Remove raw string notation
Makes it fiddlier to add new domains, and is only needed to generate the
regular expression. Much cleaner to just insert them as part of
generating the regular expression.
2018-02-26 08:53:46 +00:00
Chris Hill-Scott
3e79ae1bfe Encapsulate domain list in class
Code shouldn’t be accessing this list directly; the class should provide
a sensible interface to the data.
2018-02-26 08:53:46 +00:00
Chris Hill-Scott
7c339b808e Refactor logic around gov domains into a class
This gives us space to add more logic in the future, and expose more
information than whether a given domain is/isn’t government.
2018-02-26 08:53:45 +00:00
Chris Hill-Scott
d9a63c07a9 Refactor user permissions to use args, not list
This makes the interface a bit cleaner and less verbose.
2018-01-16 11:22:57 +00:00
Rebecca Law
59ac514655 Fix bug. 2018-01-12 14:03:31 +00:00
Rebecca Law
08e5f68461 A little refactoring 2018-01-12 12:06:07 +00:00
Rebecca Law
6070e2e197 Merge branch 'master' into download_link-activity-page 2018-01-10 16:06:40 +00:00