Commit Graph

158 Commits

Author SHA1 Message Date
Katie Smith
02253d32c5 Update user_json test function
Since we can't call the `api_user_active` fixture as a function with
Pytest 5, the `user_json` function can be used instead. This updates
the function to
- Stop returning `max_failed_login_count` since this is not a field that
gets returned from the api
- Return fields as strings, not UUIDS, to match the format that api
returns the data in
- Provide a way to use this function to return a user with no
permissions
2019-12-19 14:24:25 +00:00
Chris Hill-Scott
fcc84ac514 Do extra code style checks with flake8-bugbear
Flake8 Bugbear checks for some extra things that aren’t code style
errors, but are likely to introduce bugs or unexpected behaviour. A
good example is having mutable default function arguments, which get
shared between every call to the function and therefore mutating a value
in one place can unexpectedly cause it to change in another.

This commit enables all the extra warnings provided by Flake8 Bugbear,
except for the line length one (because we already lint for that
separately).

It disables:
- _B003: Assigning to os.environ_ because I don’t really understand this
- _B306: BaseException.message is removed in Python 3_ because I think
  our exceptions have a custom structure that means the `.message`
  attribute is still present
2019-11-01 10:43:01 +00:00
Chris Hill-Scott
c17aa249dc Make query string comparison ignore order
Query string ordering is non-deterministic. This can cause tests to fail
in a non helpful way when we’re comparing two URLs. The values in the
query string can match, but the string won’t because the order is
different. This commit adds some code to split up the URL and check that
each part of it matches, rather than checking the thing as a whole.
2019-07-15 14:38:01 +01:00
Chris Hill-Scott
eb3f9aad2a Add pages to let users accept the agreement online
At the moment, the process for accepting the data sharing and financial
agreement is:

1. download a pdf
* print it out
* get someone to sign it
* scan it
* email it back to us
* we rename the file and save it in Google Drive
* we then update the organisation to say the MOU is signed
* sometimes we also:
 * print it out and get it counter-signed
 * scan it again
 * email it back to the service

Let's not do that any more.

When the first service for an organisation that doesn't have the
agreement in place is in the process of going live, then they should
be able to accept the agreement online as part of the go live flow. This
commit adds the pages that let someone do that.

Where the checklist shows the agreement as **[not completed]** then
they can follow a link where they can download it (as happens now).
From here, they should then also be able to provide some info to accept
it. The info that we need is:

**Version** – because we version the agreements occasionally, we need to
know which version they are accepting.  It may not be the latest one if
they downloaded it a while ago and it took time to be signed off

**Who is accepting the agreement** – this will often be someone in the
finance team, and not necessarily a team member, so we should let the
person either accept as themselves, or on behalf of someone else. If
it's on behalf of someone else we need to the name and email address of
that person so we have that on record. Obvs if it's them accepting it
themselves, we have that already (so we just store their user ID and
not their name or email address).

We then replay the collected info back in a sort of legally
binding kind of way pulling in the organisation name too. The wording
we’re using is inspired by what GOV.UK Pay have. Then there’s a big
green button they can click to accept the agreement, which stores their
user ID and and timestamp.
2019-06-19 13:14:02 +01:00
Chris Hill-Scott
0aea038d51 Use new fields for getting orgs and services
Uses https://github.com/alphagov/notifications-api/pull/2539 to reduce
the number of API calls we make.
2019-06-17 15:56:59 +01:00
Chris Hill-Scott
f34a252e72 Remove defaults from User model
the api always returns exactly:
```
id
name
email_address
auth_type
current_session_id
failed_login_count
logged_in_at
mobile_number
organisations
password_changed_at
permissions
platform_admin
services
state
```

it does this through `models.py::User.serialize` – there is an old
Marshmallow `user_schema` in `schemas.py` but this isn’t used for
dumping return data, only parsing the json in the create user rest
endpoint.

This means we can rely on these keys always being in the dictionary.
2019-06-05 14:55:43 +01:00
Chris Hill-Scott
628e344b36 Make user API client return JSON, not a model
The data flow of other bits of our application looks like this:
```
                         API (returns JSON)
                                  ⬇
          API client (returns a built in type, usually `dict`)
                                  ⬇
          Model (returns an instance, eg of type `Service`)
                                  ⬇
                         View (returns HTML)
```
The user API client was architected weirdly, in that it returned a model
directly, like this:

```
                         API (returns JSON)
                                  ⬇
    API client (returns a model, of type `User`, `InvitedUser`, etc)
                                  ⬇
                         View (returns HTML)
```

This mixing of different layers of the application is bad because it
makes it hard to write model code that doesn’t have circular
dependencies. As our application gets more complicated we will be
relying more on models to manage this complexity, so we should make it
easy, not hard to write them.

It also means that most of our mocking was of the User model, not just
the underlying JSON. So it would have been easy to introduce subtle bugs
to the user model, because it wasn’t being comprehensively tested. A lot
of the changed lines of code in this commit mean changing the tests to
mock only the JSON, which means that the model layer gets implicitly
tested.

For those reasons this commit changes the user API client to return
JSON, not an instance of `User` or other models.
2019-06-05 11:13:41 +01:00
Chris Hill-Scott
61b056e490 Merge pull request #2964 from alphagov/different-back-link-from-job
Always go back to previous page from notification
2019-05-15 16:26:34 +01:00
Katie Smith
da971b2da7 Allow custom notes when service goes live
This adds an option on the organisation settings page to add
'request_to_go_live_notes'. When a service belonging to this
organisation requests to go live, any go live notes for the
organisation will be added to the Zendesk ticket in the 'Agreement
signed' section.
2019-05-14 14:24:26 +01:00
Chris Hill-Scott
b4894e7a03 Always go back to previous page from notification
When looking at a notification you can either be coming from the page
of all notifications, or from a job. Currently the back link always
takes you to the page of all notifications.

This commit makes it a bit more sophisticated so if you’ve come from
looking at a job, you go back to the job.
2019-05-09 17:33:22 +01:00
Chris Hill-Scott
08e9b35d7a Don’t ask for organisation type when we know it
Every time someone adds a new service we ask them what kind of
organisation they work for.

We can look this up based on the user’s email address now. So we should
only ask the question if:
- we don’t know about the organisation
- or we haven’t set what type of organisation it is (this shouldn’t be
  possible on productions because we’ve populated the column for all
  existing organisations and it’s impossible to add a new one without
  setting it
2019-04-18 14:08:13 +01:00
Chris Hill-Scott
72f49a9a1e Remove dependence on domains.yml from static pages
This will allow us to remove the `domains.yml` file, by using
information about organisations that is now stored in the database
instead.
2019-04-12 14:05:00 +01:00
Leo Hemsted
3e3c11f3a0 fix bug with copying template from folder in other service 2019-04-03 13:59:44 +01:00
Chris Hill-Scott
8fb576e60a Allow excluding services from live services count
Adds a front end for:
https://github.com/alphagov/notifications-api/pull/2417

> Sometimes we have to make a few services for what really is one
> service, for example GOV.UK Pay and GOV.UK Pay Direct Debit. We also
> have our own test services which aren’t included in the count of live
> services. We currently count these as one service by not including
> them in the beta partners spreadsheet.
2019-03-25 15:46:35 +00:00
Chris Hill-Scott
cff009bc0d Run isort 2019-03-25 11:23:58 +00:00
Chris Hill-Scott
936883bf7b Allow editing of an organisation’s details
Adds a user interface for updating all the columns added in
https://github.com/alphagov/notifications-api/pull/2368

Sorry for the mega commit 😓
2019-03-22 14:23:24 +00:00
Katie Smith
782bd34394 Use folder_permissions in the InvitedUser model
We were already invitializing InvitedUser with folder_permissions
(defaulting to None), but this removes the default and adds
folder_permissions to the serialize method. Folder permissions should
now always be returned from api, either as an empty list or a list of
UUIDs.
2019-03-21 10:17:05 +00:00
Chris Hill-Scott
8791134c60 Move the ‘estimated usage’ questions
We get a bunch of requests to go live where people have told us they're
going to send email but there is no email reply-to address present.

These come from 2 scenarios:

1. when there are email templates, and no reply to address – but they
   ignore the checklist
2. when there are no email templates (yet) but they provide anticipated
   volumes for email

At the moment we only auto-check for a reply to address when they have
email templates. And because the question about anticipated volumes
follows the checklist, you'll get a checklist that passes (reply
addresses not required as no templates present) - but your future intent
that differs (reply address IS required because you have anticipated
volumes).

So let’s bring the request for anticipated volumes into the checklist,
that way we can dynamically add the requirement for a reply to address
if they say they will send email but don't have templates yet.

We should begin storing it in the database against the service to stop
people having to re-enter it each time they try to complete the go live
screens.

This also means moving the ‘consent to research question’ along with
the questions about volume, because
- we want people to answer both before going live
- we don’t want to clutter up the summary page by asking questions there
  too
2019-02-27 13:17:28 +00:00
Pea Tyczynska
f0b82e7d3b Remove all service postage references
Since service.postage field has been removed from our model
and database.
2019-02-14 11:05:39 +00:00
Leo Hemsted
5405c2e1be fix service settings letter branding tests
some tests are now expanded to handle the fact that letter branding
can be null
2019-02-07 11:38:20 +00:00
Pea Tyczynska
e1191326f4 Fix tests after enabling editing of postage on letter templates 2018-12-21 17:13:18 +00:00
Rebecca Law
28b9adf4e0 Merge pull request #2510 from alphagov/fix-user-with-no-permissions
Fix the permission check for users without permissions.
2018-11-19 17:06:33 +00:00
Rebecca Law
dd22fa06a4 Fix the permission check for users without permissions.
A users without permissions should be redirected to choose-templates page when signing in.
2018-11-19 15:26:43 +00:00
Chris Hill-Scott
738043c5c4 Show path on template and manage folder pages
So the page headings stay consistent as you click around, and make it
easy to get back where you came from.
2018-11-19 11:28:35 +00:00
Chris Hill-Scott
e04b2b5631 Split models to prevent circular imports
This commit is the first step to disentangling the models from the API
clients. With the models in the same folder as the API clients it makes
it hard to import the API clients within the model without getting a
circular import.

After this commit the user API clients still has this problem, but at
least the service API client doesn’t.
2018-10-30 15:01:36 +00:00
Chris Hill-Scott
e1197c54a5 Don’t allow indexing on service model
Making people use a property is a sure way to make sure they’re spelling
the name of the property correctly, and allows us to easily swap out
properties that call through to the underlying JSON, and properties
which are implemented as methods.
2018-10-30 14:55:01 +00:00
Leo Hemsted
efab189ae8 update jobs to take into account first class 2018-10-01 11:07:33 +01:00
Pea Tyczynska
47d047a3a8 Add postage to fixtures and test postage display on notification page 2018-09-24 11:53:40 +01:00
Katie Smith
9660f372f3 Change naming in code to use 'postage'
Renamed everything that was previously called 'letter class' or 'postage
class' to 'postage', which is the new name we have decided to use.
2018-09-19 09:20:09 +01:00
Katie Smith
de9759b99a Add letter class row to settings page, visible to platform admin
Added a new row to the settings table, 'Post class', which shows the
default letter class of a service and is only visible to Platform Admin.

Also added a new page to enable Platform Admin users to change the
default letter class for a service - this only has two options at the
moment, 1st class only and 2nd class only.
2018-09-18 10:31: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
c551ce9a42 Show jobs in basic view
There are some teams who send jobs on a daily/weekly basis. They have
team members who only use Notify for this purpose. So they would
probably benefit from basic view, because they don’t need to see the
dashboard.

This commit:
- adds a new item (uploaded files) to the basic view navigation for
  teams that have sent at least one job
- makes the job pages visible to basic view users

I think we should do this now, rather than as a later enhancement to
basic view. We only have one chance to announce the feature, so teams
who do send jobs may otherwise discount it as not useful for them and
the opportunity to have them use it is lost.
2018-08-01 10:45:02 +01:00
Katie Smith
e1d4181be3 Add page to change a service's contact link
Added a page which lets users with the 'manage_service' permission change the
contact link for their service. There are no links to this page yet
since only services using document download will need to set a contact
link.
2018-06-11 10:36:18 +01:00
Leo Hemsted
e8ef6fa174 don't swallow HTTP errors from create_event
tests weren't patching out create_event (which is invoked every time a
user logs in). This was getting caught by our egress proxy on jenkins.
We didn't notice because the event handler code was swallowing all
exceptions and not re-raising.

This changes that code to no longer swallow exceptions. Since we did
that, we also need to update all the tests that test log-in to mock
the call
2018-05-03 16:14:13 +01:00
kentsanggds
91adca10b5 Merge pull request #1961 from alphagov/ken-show-client-reference
Add client reference to API Integration / message log
2018-03-20 10:54:47 +00:00
Ken Tsang
c3238d8f68 Tests page when client_reference exists in noti 2018-03-19 16:12:14 +00:00
Leo Hemsted
8ef36f13f2 finish tests for choose account page 2018-03-14 15:39:55 +00:00
Leo Hemsted
b7b9b8dd90 make sure mock login sets up session correctly 2018-03-14 15:39:55 +00:00
kentsanggds
d11fafdf0d Merge pull request #1926 from alphagov/ken-remove-link-from-preview-precompiled
Remove link from preview precompiled view and dashboard
2018-03-08 15:28:47 +00:00
Ken Tsang
bcf86239c6 Remove template link from preview for precompiled letters 2018-03-07 23:13:36 +00:00
Leo Hemsted
17061e0d06 map roles and db permissions
in the db, we have several rows for single permissions - we separate
`send_messages` into `send_texts`, `send_emails` and `send_letters`,
and also `manage_service` into `manage_users` and `manage_settings`.

But on the front end we don't do anything with this distinction. It's
unhelpful for us to have to think about permissions as groups of things
when we can never split them up at all. So we should combine them. This
commit makes sure:
* when user models are read  (from JSON direct from the API), we
  should transform them from db permissions into roles.
* when permissions are persisted (editing permissions, and creating
  invites), we should send db permissions to the API.

All other interaction with permissions (should just be the endpoint
decorator and checks in html templates generally) should use admin
roles.
2018-03-06 13:08:06 +00:00
chrisw
22bbc0d6d8 invite-team-members 2018-02-23 11:43:13 +00:00
chrisw
9ad4435d94 Change organisations to email branding 2018-02-07 17:41:23 +00:00
Leo Hemsted
2edb1eb704 remove free sms fragment limit from go live flow 2018-01-16 17:40:31 +00:00
chrisw
7271d4fbde Allow letter templates to select the default contact block from the list 2018-01-10 11:20:40 +00:00
Chris Hill-Scott
b24c23fe3b Lint for print statements
flake8-print is a flake8 plugin that checks for `print()` statements in
Python files.

This should save us having to manually spot these when reviewing pull
requests.

The `--enable=T` flag needs to be set until this bug is fixed:
https://github.com/JBKahn/flake8-print/issues/27
2018-01-05 12:14:28 +00:00
chrisw
43c14fb756 Allow service to set callback url for notifications 2017-12-08 10:52:50 +00:00
Chris Hill-Scott
a358acfd05 Remove references to computed service attribute
`prefix_sms` is the real database column, which should be referred to
from now on.
2017-11-16 11:35:05 +00:00
Leo Hemsted
65ba7e88c8 refactor RegisterFromInvite to make auth_type required, and update test fixtures 2017-11-14 15:18:14 +00:00
Chris Hill-Scott
6d3855bba4 Allow updates to SMS prefixing setting
We’re extracting this from being determined based on what the sender
name is to its own setting.

This commit will let users set it independently.

Until the explicitly set it, it will still be determined based on
whether their default sender name matches the default for the platform.
2017-11-06 11:24:46 +00:00