Commit Graph

6305 Commits

Author SHA1 Message Date
Chris Hill-Scott
1e2608d2e0 Refactor settings page to use service model
There’s a lot of code in service settings which:
- talks to the API directly through the clients
- passes that information through to the Jinja template

By encapsulating this logic in the service model:
- the Jinja template can access the data directly
- the logic can be reused across multiple methods
2018-10-30 15:07:52 +00:00
Chris Hill-Scott
526f2d7900 Use service model for the copy page
The view here is rebuilding a pseudo-service object. Now that service
objects have templates it’s cleaner to use the actual service object.

Requires a small change to the `templates_by_type` method so that it can
filter by one or many template types (a user should be able to copy any
template whose type is enabled for their service, and the service
they’re copying from).
2018-10-30 15:05:47 +00:00
Chris Hill-Scott
7d57c73411 Import clients from own files, not from app.py
Being able to import things at the top level is much cleaner.
2018-10-30 15:03:42 +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
9e798506c5 Initialise clients outside the app
This avoids the annoying problem where you can’t import a client unless
the app has already been initialised.
2018-10-30 14:59:24 +00:00
Chris Hill-Scott
2bf2103cce Re-sort order in which clients are initialised
This separates the non-API clients from the API clients.
2018-10-30 14:57:16 +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
Chris Hill-Scott
780b9bb715 Use cached property from werkzeug.utils
This means we can have a method on the service model which hits the API
(or Redis) but can be called multiple times (within the context of a
request) without making multiple network requests.

It does this by storing the results of the method on the object’s
internal `__dict__` the first time the method is called.
2018-10-30 14:55:01 +00:00
Chris Hill-Scott
b48305c50d Don’t have service model inherit from dict
Inheriting from `dict` has some unexpected side effects that don’t
happen with plain object. The one we want to avoid right now is that
a dict doesn’t seem to implement `__dict__` in a normal way, which
is required by `werkzeug.utils.cached_property`.
2018-10-30 14:55:00 +00:00
Chris Hill-Scott
1e6b79a546 Put templates on service model
We do a lot of logic around choosing which templates to show. This logic
is all inside one view method.

It makes it cleaner to break this logic up into functions. But this
would mean passing around variables from one function to another.
Putting these methods onto a class (the service model) means that
there’s a place to store this data (rather than having to pass it around
a lot).

Making this code more manageable is important so that when we have
templates and folders it’s easy to encapsulate the logic around
combining the two.
2018-10-30 14:55:00 +00:00
Chris Hill-Scott
d69e8b50cd Only initialised service model once per request
`_get_current_service` is a function which gets called every time
`current_service` is referenced in a view method or Jinja template.

Because the service model was getting initialised inside this function
it was being reconstructed many times in one request. On the service
settings page, for example, it was getting initialised 43 times, adding
about 200ms to the response time.

This commit moves its initialisation to the point where we’re getting
the data from the API, which only happens once per request.
2018-10-30 14:55:00 +00:00
Chris Hill-Scott
f6ff070f80 Merge pull request #2287 from alphagov/remove-old-key-info-2
Remove old API key and service ID combo
2018-10-30 10:13:19 +00:00
Chris Hill-Scott
d5d1f7394d Remove old API key and service ID combo
Once all our users have upgraded to the latest clients they won’t need
this. The latest clients only use the combined key and service ID.

Discuss: when can we safely remove it?
2018-10-30 10:01:37 +00:00
Chris Hill-Scott
08cd8e2a2d Merge pull request #2425 from alphagov/pyup-update-pytest-xdist-1.23.2-to-1.24.0
Update pytest-xdist to 1.24.0
2018-10-30 09:32:06 +00:00
Chris Hill-Scott
2f5e029c87 Merge pull request #2360 from alphagov/pyup-update-ago-0.0.92-to-0.0.93
Update ago to 0.0.93
2018-10-30 09:30:43 +00:00
Katie Smith
734cae73cf Merge pull request #2426 from alphagov/minor-fix
Add missing argument to function
2018-10-30 08:19:18 +00:00
Katie Smith
3431996860 Add required argument to function 2018-10-30 07:56:27 +00:00
pyup-bot
8e296b1c90 Update pytest-xdist from 1.23.2 to 1.24.0 2018-10-29 21:06:18 +00:00
Chris Hill-Scott
2d3c1b2ead Freeze requirements 2018-10-29 16:40:29 +00:00
pyup-bot
81c5e2c6c4 Update ago from 0.0.92 to 0.0.93 2018-10-29 16:39:35 +00:00
Chris Hill-Scott
6cfa533b75 Merge pull request #2374 from alphagov/cancelled-letter-status
Show if a letter has been cancelled
2018-10-29 16:29:33 +00:00
Chris Hill-Scott
85d5a44c85 Merge pull request #2422 from alphagov/pyup-update-pytz-2018.5-to-2018.7
Update pytz to 2018.7
2018-10-29 16:27:23 +00:00
Chris Hill-Scott
14b8ca19db Freeze requirements 2018-10-29 16:06:46 +00:00
pyup-bot
c0b11c7a15 Update pytz from 2018.5 to 2018.7 2018-10-29 16:05:02 +00:00
Katie Smith
9d4b2e1014 Merge pull request #2420 from alphagov/pyup-update-pytest-3.9.2-to-3.9.3
Update pytest to 3.9.3
2018-10-29 13:34:26 +00:00
Katie Smith
b02877df7d Merge pull request #2421 from alphagov/bump-utils-30.5.6
Update notifications-utils to 30.5.6
2018-10-29 13:34:08 +00:00
Chris Hill-Scott
f1a9761ea1 Show letters that fail validation as cancelled
At the moment we show precompiled letters that have failed the
validation as having been sent. This is confusing.

We should communicate it as having been cancelled (rather than failed),
with the implication being that Notify has come along and cancelled the
letter before printing it. I think this is conceptually what makes the
most sense.

From the user’s point of view any letters that show up as cancelled
probably need to be fixed and resent, so it makes sense to group them
with the same name.
2018-10-29 12:13:33 +00:00
Chris Hill-Scott
bbb4b87cac Show count of cancelled letters on dashboard 2018-10-29 11:51:43 +00:00
Chris Hill-Scott
c01d761a3c Show if a letter has been cancelled
At the moment we are manually cancelling letters for people when they
ask us to. Once’s we’ve done this there is no indication that it’s
happened except for the date going red on the list of letters.

This commit adds some error messaging and styling to show when a letter
is cancelled.

Letting people cancel their own letters will be a future enhancement.
2018-10-29 11:51:41 +00:00
Katie Smith
4927da62fb Update notifications-utils to 30.5.6
This brings in the change to email validation which removes obscure white space from email addresses.
2018-10-29 10:21:04 +00:00
pyup-bot
9707d030e9 Update pytest from 3.9.2 to 3.9.3 2018-10-27 19:11:14 +01:00
Katie Smith
78cb3d1165 Merge pull request #2415 from alphagov/add-edit-folders-permission-button
Add platform admin button for edit_folders permission
2018-10-25 14:21:11 +01:00
Katie Smith
a79831e997 Merge pull request #2405 from alphagov/pyup-update-pytest-3.9.1-to-3.9.2
Update pytest to 3.9.2
2018-10-25 14:21:02 +01:00
Alexey Bezhan
8d8e374fdb Merge pull request #2402 from alphagov/python-3-5-5
Bump PaaS python version to 3.5.5
2018-10-25 13:08:39 +01:00
Katie Smith
ae79a3ac75 Add platform admin button for edit_folders permission
Added a platform admin button to allow / remove the edit_folders
permission for a service.
2018-10-25 12:09:26 +01:00
Katie Smith
af29ee7ff1 Merge pull request #2407 from alphagov/stop-sending-dvla-org-id
Stop passing dvla_org_id to template preview
2018-10-24 16:28:58 +01:00
Chris Hill-Scott
465296776e Merge pull request #2406 from alphagov/service-count
Updated service count to 410 and 127 orgs
2018-10-24 14:35:03 +01:00
Katie Smith
a489e7a26b Stop passing dvla_org_id to template preview
We were passing both dvla_org_id and filename to template-preview
temporarily while we switch to only using filename. Now that
template-preview is set up to use filename, we can stop sending the
dvla_org_id too.
2018-10-23 16:21:18 +01:00
Pete Herlihy
285d91f5bc Updated service count to 410 and 127 orgs 2018-10-23 15:43:59 +01:00
pyup-bot
b8ddfe42f3 Update pytest from 3.9.1 to 3.9.2 2018-10-23 03:55:05 +01:00
Alexey Bezhan
62f83fcd1a Bump PaaS python version to 3.5.5
Python 3.5.4 support is being removed in Python buildpack 1.6.21
2018-10-22 11:26:50 +01:00
Tom Byers
02ecf1c5b4 Merge pull request #2387 from alphagov/bump-utils-to-3.5.5
Bump utils to 3.5.5
2018-10-19 16:00:56 +01:00
Katie Smith
e100a0f218 Merge pull request #2394 from alphagov/send-letter-filename-to-template-preview
Pass letter logo filename to template preview
2018-10-19 10:58:08 +01:00
Tom Byers
29c46a27f8 Stop url_for double-encoding .'s in password test
One of the changes this pulls in is encoding of
periods in the token used for new password
requests.

In real-life the resulting URL is build by
concatenating the base url with the token so it
isn't processed further.

The test for new password requests builds the URL
with url_for. This encodes the result returned so
the periods are encoded twice.
2018-10-18 16:59:52 +01:00
Tom Byers
f5014e8352 Fix references to email HTML in tests 2018-10-18 16:59:52 +01:00
Tom Byers
e9afad80ed Bump utils to 3.5.5 2018-10-18 16:59:48 +01:00
Chris Hill-Scott
e8fb7343b2 Merge pull request #2382 from alphagov/pyup-update-freezegun-0.3.10-to-0.3.11
Update freezegun to 0.3.11
2018-10-18 15:50:51 +01:00
Chris Hill-Scott
faabcb6174 Merge pull request #2389 from alphagov/pyup-update-pytest-3.8.2-to-3.9.1
Update pytest to 3.9.1
2018-10-18 15:50:44 +01:00
Chris Hill-Scott
86898903c5 Merge pull request #2393 from alphagov/rushmoor.gov.uk
Make agreement signed by Rushmoor borough council
2018-10-18 15:12:30 +01:00
Chris Hill-Scott
1d16b1fdfc Merge pull request #2392 from fidejoseph/patch-2
Update email_domains.yml
2018-10-18 15:12:23 +01:00