Commit Graph

2056 Commits

Author SHA1 Message Date
Chris Hill-Scott
0888bdf5d4 Put ‘copy’ at end of new template name
In multiple user research sessions we’ve noticed people edit the
auto-generated template name to put something at the end of it.

This is fiddly because of the quotes we put around the name:
> Copy of ‘Exiting template’

It also means that if they keep our prefix then the template doesn’t
sort alongside the one it’s replacing.

This commit changes the name of copied templates to better match the
behaviour our users are showing.

Also adds a bit of auto numbering, just as a nice detail.
2018-11-13 15:25:02 +00:00
Chris Hill-Scott
872b3f9c94 Make existing_keys a required argument
Because we should always expect its presence, even it’s an empty list.
And because having mutable default arguments can have nasty side
effects.
2018-11-13 14:27:01 +00:00
Chris Hill-Scott
045a4bb7f1 Swap order of arguments to get_template_folders
So that the order is the same as the arguments passed to `get_templates`
2018-11-13 12:29:57 +00:00
Chris Hill-Scott
10fe78bb31 Only show relevant folders
A folder is relevant if it, or any of its descents contain a template of
the kind you’re looking for.

If you’re not filtering by template type then you should see all
folders.
2018-11-13 11:10:20 +00:00
Pea Tyczynska
565d29ed43 Add a new endpoint for managing a folder, use it to rename folder
- Add a GET / POST view: manage template folder
- Add a template for that view, where a user can rename their
folder
- Add an API client method for updating a folder

- Test the new feature, including the test that service without
permissions cannot manage a folder
2018-11-13 10:38:56 +00:00
Chris Hill-Scott
8bedcb5af8 Move data transformation into the form
Follows what we’re doing with the folders stuff. Avoids having too many
very straightforward methods on the model. Especially when the data they
need is only used by the form. So it’s better to encapsulate the logic
in the form.
2018-11-13 09:57:17 +00:00
Chris Hill-Scott
591bbe9a49 Don’t do multiple get API calls when revoking
It’s redundant to make two API calls here, one to get all keys and one
to get a single key. Since the API calls are sequential we can speed
things up by getting the one key from the list of all keys.
2018-11-12 16:11:13 +00:00
Chris Hill-Scott
d1c9dcfb1d Put API keys on service model
Similar to how we put templates on the service model, it means less
logic needs to happen in the view code.
2018-11-12 16:11:13 +00:00
Katie Smith
0f90bde958 Store the sender_id that should be used for a job in S3 metadata
Currently, a user can select a reply-to email address or text message
sender when uploading a CSV file but this is ignored and the default is
always used instead. As a first step towards changing this, this adds
the sender_id (if selected) to the S3 metadata so that this information
can be used when processing the job.
2018-11-12 13:34:33 +00:00
Chris Hill-Scott
3cac9ac5cc Rename method to be more explicit 2018-11-12 09:21:47 +00:00
Chris Hill-Scott
40f676d3ad Move labels of template types out of model
The model shouldn’t have to care about how things are labelled in the
UI, it should only care about the data.
2018-11-12 09:16:14 +00:00
Chris Hill-Scott
c18a38d4f1 Make handling of None values in forms clearer
If the browser posts the value of `<input value='None'>` to the server
it does so as a string.

We want to post a value of `None` (actually JSON `null`) to the API. To
do this we:
- set the value in the form class to `'None'` (ie a string)
- convert to `None` (as a type) afterwards

However seeing `x = 'None'` in code looks a bit like a mistake. So to
make sure it looks deliberate and clear what is happening this commit:
- makes a reusable constant for `'None'`
- adds a comment explaining why it’s a string
2018-11-12 09:04:39 +00:00
Chris Hill-Scott
cdb5b47c4d Post to the API when moving folders and templates
This commit adds logic to:
- take the list of selected folders and templates
- split it into two lists (of folders and templates)
- `POST` that data to the API, to effect the movement of said folders
  and templates

I’ve tried to architect it in such a way that we can easily add more
template ‘operations’ in the future, as we add more forms to the choose
template page.
2018-11-12 08:37:46 +00:00
Chris Hill-Scott
980d66bdaa Add helper function for filtering templates by type
This code was making the view method more cluttered than it needed to
be. Moving it will help make space for the `post` request handling code.
2018-11-12 08:37:46 +00:00
Chris Hill-Scott
2743216519 Show form elements for templates and folders
This commit adds:
- checkboxes to let you select a template or folder
- radio buttons to let you select where to move those template(s) and/or
  folder(s) to

It only does the `get` part of this work; handling the `post` and
calling API will be done in a subsequent commit.
2018-11-12 08:37:46 +00:00
Chris Hill-Scott
921de47164 Refactor template navigation options into model
This has two advantages:
- less logic in the view
- lets us filer the available navigation by which channels (email, text
  letter) a service has available
2018-11-12 08:37:46 +00:00
Rebecca Law
146c7915b2 Create a template in a folder. 2018-11-08 15:53:33 +00:00
Alexey Bezhan
622fdfedc9 Merge pull request #2452 from alphagov/create-template-folders
Create template folders
2018-11-08 11:58:39 +00:00
Chris Hill-Scott
c0c0015dc4 Merge pull request #2448 from alphagov/alphabetical-sort-letter-brandings
Make letter brandings easier to find with sorting and filtering
2018-11-07 13:50:05 +00:00
Chris Hill-Scott
514a98f946 Make hex colour code error more helpful
I just got stuck for like a whole minute on this.
2018-11-07 10:49:04 +00:00
Chris Hill-Scott
156d38499a Remove integration testing content
This is covered in the new client library documentation. All of the
client libraries now have their documentation published in the new
format.
2018-11-06 17:24:30 +00:00
Alexey Bezhan
75b4533805 Fix template type selector to preserve current folder 2018-11-06 13:45:42 +00:00
Alexey Bezhan
aaca537792 Create new folders inside the current folder
When adding a new folder it is created inside the currently active
one. The user is returned to the previously active folder page,
which shows the added folder.

This adds a new route to the add template/folder views. Thankfully,
`url_for` recognizes when `template_folder_id` is `None` and will use
the URL without `/folders/...`, so users without folder permissions
should be unaffected by this change.
2018-11-06 13:45:42 +00:00
Alexey Bezhan
20abe96fc9 Link template folders to their contents
Clicking on template folder navigates to a page that displays that
folder's contents.

This reuses the existing choose template view by adding a filter
based on optional `template_folder_id` argument.

Service model methods are rewritten to match `all_templates` and
`get_template`. New `get_template_folder_path` method returns a
list of folders (from root to the current one) that the selected
folder is nested inside.
2018-11-06 13:13:13 +00:00
Alexey Bezhan
29bed8ba55 Add Service.get_templates method with filters by type and folder
With the addition of template folders we need to filter templates
based on a combination of type and parent folder ID.

This replaces the existing `templates_by_type` method with
`get_templates`, which supports both type and parent folder filters,
avoiding a need to create specific methods for each use case.

We still need the templates property to exist in some way in order
to cache it, but it needs to be clear that it's different from
`.get_templates`. One option was to make it "private" (i.e. `_templates`),
and always use `.get_templates` in the rest of the code, but this requires
adding "include all folders" to `.get_templates`, which doesn't have an
obvious interface since `parent_folder_id=None` already means "top-level
only".

This will probably come up again when we need to look into adding
templates from nested folders into the page for live search, but
for now renaming `Service.templates` to `.all_templates` makes it
clear what the property contains.
2018-11-06 13:13:13 +00:00
Leo Hemsted
078595da9d show list of template folders on the choose templates page
Not linking anywhere yet. Also not sorted, and not filtered by
parent_id.
2018-11-06 13:13:13 +00:00
Leo Hemsted
1ecf360e7f add template folder form 2018-11-06 13:13:12 +00:00
Leo Hemsted
7cbf5de240 add new template folder
The add new templates page now has option to add template folders.
Tweaked wording of other options and h1 to clarify options since it's
not all about templates any more.

Added api client and stuff for it
2018-11-06 13:13:12 +00:00
Chris Hill-Scott
10013a19aa Add live search to letter brandings
Matches what we do for email branding, makes the one you’re lookig for
quicker to find.
2018-11-06 13:08:58 +00:00
Chris Hill-Scott
43988661d6 Sort selected item to the top
When you land on the page it’s good to be able to quickly see what the
currently-set value is, before you change it.

This is unnecessarily hard if the selected item is buried half way down
the page. This commit moves it to the top.
2018-11-06 13:06:48 +00:00
Chris Hill-Scott
c960fef8f8 Always put HM Government at the top of the list
It’s the default, so we should treat it the same way we treat GOV.UK in
the email branding selection.
2018-11-06 13:04:45 +00:00
Chris Hill-Scott
65cc6adabf Sort letter brandings alphabetically
Currently the brandings have non-deterministic sorting, which means
the order changes from page load to page load. This makes it hard to
find the item you’re looking for.

This commit sorts them by the name of the branding, same as for email
brandings.
2018-11-06 13:02:40 +00:00
Chris Hill-Scott
684d4f7782 Refactor setting value on letter branding form
WTForms lets you pre-populate a form’s value by passing it in as an
argument to the constructor.

This will be good for us because it will let us access that value in
the constructor later on.
2018-11-06 13:00:30 +00:00
Chris Hill-Scott
48b0d4194e Use model to toggle research mode
Just a nice bit of encapsulation, rather than passing `current_service`
through to a method on `current_service`.
2018-11-05 17:15:52 +00:00
Chris Hill-Scott
318f846630 Move service permission handle inside the model
These helper functions for modifying a service permission were just
floating around loose in the view code.

A much better home for them is on the model. This will also make it
easy to reuse them in other views if we ever need to.
2018-11-05 17:15:52 +00:00
Chris Hill-Scott
a69551b2cb Use model to update service properties
We have a lot of places in settings where we update something by passing
in the `service_id`. `current_service` already knows about `service_id`,
so it’s cleaner to encapsulate these updates inside the model.
2018-11-05 17:15:52 +00:00
Chris Hill-Scott
39c51dd994 Show all letter pages on the notification page
Sometimes a long placeholder can push stuff onto a new page, so we need
to take the personalisation into account when counting pages.
2018-11-02 14:30:18 +00:00
Chris Hill-Scott
a79dfd1d6e Always show download link for PDF
This feature is useful for people to try the letter thing out and see
how it feels, maybe print one on their own printer before incurring
cost.
2018-10-31 14:22:27 +00:00
Chris Hill-Scott
3a62946ecd Let people send one off letters
We didn’t used to allow this because it wasn’t really possible with the
old DVLA set up and we didn’t think there’s a need.

We think it’s possible now because, even though it’s cumbersome, it’s
better than the manual process.
2018-10-31 12:19:19 +00:00
Chris Hill-Scott
67534f838d Don’t allow use of .get() 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.

The API should always return something in the JSON for a property, even
if it’s just `None`.
2018-10-30 15:09:54 +00:00
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
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
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
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
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
Leo Hemsted
c898284c3b fix pdf download link trying to request a page count
It doesn't make sense to get a pdf for only one page - the template
preview app just returns a 400 if you try. So we shouldn't try!
2018-10-15 14:32:10 +01:00
Tom Byers
e92230a0ef Allow coloured branding without logo in preview
Coloured brandings can just be a coloured
background with text. At the moment the /_email
preview page assumes a logo image will be part of
a brand so looks broken.
2018-10-11 10:50:42 +01:00
Pea Tyczynska
291b2cf2ba Improve error handling for precompiled validation preview 2018-10-05 16:27:57 +01:00