Commit Graph

2259 Commits

Author SHA1 Message Date
Chris Hill-Scott
69aa4d0025 Merge pull request #1877 from alphagov/job-csv-upgrade
Add original file data to job downloads
2018-03-02 12:46:20 +00:00
Rebecca Law
fa0196bc88 Update the free allowance when the organisation type is changed.
The free allowance affect the number of free text messages a services get per yer.
This allowance is being set properly when an organisation is created by not updated.
This PR updates the free allowance when the organisation type is updated.
The free allowance can also be changed if service has an exceptional free allowance.
2018-03-02 10:48:59 +00:00
Ken Tsang
ba6a0e6466 Fix sorting of imports 2018-03-01 23:50:55 +00:00
Ken Tsang
ff457b8407 Refactor to handle API errors for preview 2018-03-01 23:50:55 +00:00
Ken Tsang
64e706ec76 Refactor imports 2018-03-01 15:24:26 +00:00
Richard Chapman
c52657146a Removed unneeded parameters after update to api.
Updated the tests to take the removal into account.

Tidied up unused imports
2018-03-01 15:23:16 +00:00
Ken Tsang
6279169b18 WIP refactor preview pdf 2018-03-01 15:21:50 +00:00
Katie Smith
68fc6b5cb4 Merge pull request #1914 from alphagov/reject-sms-senders-starting-with-00
Update SMS sender validation to reject senders starting with 00
2018-03-01 13:56:23 +00:00
Chris Hill-Scott
76da1ab28d Stop creating tour text messages as priority
Since we send all one off messages as priority now[1], we don’t need to
explicitly mark this template as being priority.

This stops the (potential) problem of people skipping the tour, still
having this template and then modifying it to send other messages,
potentially in high volumes from CSV files or the API. I don’t think
this is a real problem now, but worth cleaning this up.

Currently:
- 827 priority templates in the database
- 195 of which are not deleted
- 18 of which are not called ‘Example text message template’
- 3 of which look like genuine use cases, not from services that we run

[1]: https://github.com/alphagov/notifications-api/pull/1722
2018-02-28 17:00:36 +00:00
Chris Hill-Scott
aa7287bf64 Catch exceptions caused by ambiguous Excel files
Excel stores dates as floating point numbers, counting the days (or
fraction thereof) since 1900 (except when it counts from 1904).

However it also, incorrectly, recognises 1900 as a leap year. This means
that it’s ambiguous whether day 59 is February 28th, or February 27th,
depending if you’re counting up or down. In fact any number less than 60
is, therefore, ambiguous.

This shouldn’t really matter since no-one is going to be using dates in
the year 1900 in Notify messages. _Except_ when Excel misidentifies a
cell as containing a date. For example, if you have the number `9`
inside a cell, it means _house number 9_ if the next cell contains
_example_ street. but Excel is all like ‘oh they must want January 9th
1900!’ No. Bad Excel.

There’s not much we can do about this, but we can at least give people
an error message with the workaround, which is what this commit does.

Most of this commit message is paraphrased from:
http://xlrd.readthedocs.io/en/latest/dates.html
2018-02-28 15:09:55 +00: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
Alexey Bezhan
acfe8092fc Add route secret key header to the API requests
Currently requests to the API made from the admin app are going from
PaaS admin app to the nginx router ELB, which then routes them back
to the api app on PaaS.

This makes sense for external requests, but for requests made from
the admin app we could skip nginx and go directly to the api PaaS
host, which should reduce load on the nginx instances and
potentially reduce latency of the api requests.

API apps on PaaS are checking the X-Custom-Forwarder header (which
is set by nginx on proxy_pass requests) to only allow requests going
through the proxy.

This adds the custom header to the API client requests, so that they
can pass that header check without going through nginx.
2018-02-28 11:28:46 +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
d0ffff9e02 Check for reply to email address before going live
We require that a user has a real reply-to email address before going
live. We can partially automate this by at least telling users who
haven’t done this.

This only applies for users that have email templates; we shouldn’t
bother users who aren’t going to send emails about this.
2018-02-27 15:24:52 +00:00
Chris Hill-Scott
7be08e2f74 Check for templates before going live
We need users to have created some templates before they go live, so we
can see what kind of messages they intend to send.

We can do this automatically based on the work done in
https://github.com/alphagov/notifications-admin/pull/1892
2018-02-27 15:23:41 +00:00
Chris Hill-Scott
ca3fdfd907 Check for team members on request to go live page
One of the things that we want to check before a service goes live is
that they have at least two team members with the manage service
permission. Anyone who can make a request to go live has this
permission, so that means one additional user is needed. This is what we
can automatically communicate to the user.

Under the hood this makes use of the logic added in
https://github.com/alphagov/notifications-admin/pull/1891
2018-02-27 15:17:31 +00:00
Rebecca Law
d638b446f5 Merge branch 'master' into becca-invite-users 2018-02-27 10:13:40 +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
Chris Hill-Scott
96aac519cc Extend user client to count users with permission
One of the things we need to know for a service to go live is whether
they have at least two users with the ‘manage service’ permission.

So this commit adds a method to the client to count how many users have
a given permission. We can do logic on this count later. But having the
counting done in the client feels like a cleaner separation of concerns.

Meant some refactoring of the way `service_id` is extracted from the
request, in order to make it easier to mock.
2018-02-26 08:53:45 +00:00
Chris Hill-Scott
56833b1d10 Add test for existing get users client method
Want to make sure it’s doing what I expect before I build another method
that calls through to it.
2018-02-26 08:53:45 +00:00
Chris Hill-Scott
51f0320aec Add API client method to count templates
When users request to go live we check stuff like:
- if they’ve added templates
- if they have email templates (then we can check their reply to
  address)

This commit adds a method to do this programatically rather than
manually.

We _could_ do this in SQL, but for page that’s used intermittently it
doesn’t feel worth the work/optimisation (and the client method is at
least in place now if we do ever need to lean on this code more
heavily).
2018-02-26 08:53:45 +00:00
Chris Hill-Scott
103a36a5da Hide ‘request to go live’ from API only users
Users who have the ‘manage API keys’ permission can see the settings
page. But they don’t have permission to request to go live.

At the moment they can still see the link, though clicking it gives them
a 403 error. This commit changes it so that they can’t see the link, and
tells them who they should speak to about going live (their manager).
2018-02-26 08:53:45 +00:00
Rebecca Law
803c195947 Removed edit permissions on the org users page.
Remove a user from organisation can be done later.
2018-02-23 17:27:28 +00:00
Rebecca Law
8f5b6491f3 Fix failing tests 2018-02-23 17:09:41 +00:00
chrisw
22bbc0d6d8 invite-team-members 2018-02-23 11:43:13 +00:00
kentsanggds
b7b25c7d16 Merge pull request #1894 from alphagov/ken-add-precompiled-letter-button
Add button to toggle precompiled letters on/off
2018-02-22 11:40:43 +00:00
Ken Tsang
df41fcfdd0 Add button to toggle precompiled letters on/off 2018-02-21 17:41:19 +00:00
Chris Hill-Scott
7dc278c959 Split into two pages
A lot of users aren’t reading or paying attention to the checklist on
the request to go live page. We think that we can get more people to
read it by putting it on its own page, where users won’t jump straight
to filling in the form.

This will, later on, let us make this page smarter by automatically
detecting if they’ve done the necessary things.
2018-02-20 12:28:32 +00:00
Chris Hill-Scott
4e2b4b5ac7 Rename endpoint
Every endpoint in this file is to do with a service. Putting service in
the name is redundant.
2018-02-20 12:27:53 +00:00
chrisw
14b80622b7 link-service-to-organisations-tweaks 2018-02-20 11:30:46 +00:00
chrisw
dd2231056d organisation dashboard page 2018-02-19 16:56:16 +00:00
Rebecca Law
2b739535d4 Added an edge case test 2018-02-15 16:39:42 +00:00
Rebecca Law
6bd99e0599 Added a validation for a minimum of 3 character.
If the SMS sender is less than 3 characters one of our providers will return an error.
2018-02-15 16:06:44 +00:00
Rebecca Law
3f52454691 Remove allow/stop send pdf letters button.
Now that we only use the pdf letter flow, we can remove the button for the platform admin users.
2018-02-14 17:09:13 +00:00
Chris Hill-Scott
56969c2379 Merge pull request #1865 from alphagov/no-slash-dashboard
Remove dashboard from dashboard URL
2018-02-14 16:30:17 +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 Waszczuk
34f1b40dbc Merge pull request #1858 from gov-cjwaszczuk/link-service-to-organisation
Link services to organisations (Admin)
2018-02-14 12:30:15 +00:00
Chris Hill-Scott
95482363aa Remove dashboard from dashboard URL
It’s weird that `/services/<service_id>` returns `404`. The home page
for every service is the dashboard – should be possible to get there
from any other page just by stemming the URL.

Also makes it consistent with organisations, which will have
`/organisations/<org_id>`.
2018-02-14 10:39:44 +00:00
Katie Smith
84d810b981 Pass service_id through to API '/service/unique' endpoint
Notifications-api now needs the service_id to check the uniqueness of
the service name when trying to change it. This is to allow a user to
successfully change the pluralization or the case of their service name.
2018-02-13 15:57:19 +00:00
chrisw
1450138b9c link-services-to-organisations 2018-02-13 12:49:57 +00:00
Ken Tsang
11a7fc49b7 Renamed create to add for organisations 2018-02-12 12:27:06 +00:00
Ken Tsang
a200f1a17e Go to organisation stub page which will eventually show list of services 2018-02-12 12:27:06 +00:00
Ken Tsang
f0e8661e34 Add organisations pages to show orgs and create/edit them 2018-02-12 12:27:06 +00:00
Chris Hill-Scott
52241b8f3e Use client from app in tests
Means we don’t have to instantiate it in every test, keeps things
consistent with parent commit.
2018-02-09 15:04:52 +00:00