Commit Graph

58 Commits

Author SHA1 Message Date
Leo Hemsted
8266635a7a remove dvla_organisation and other unused things
dvla_organisation, branding_dict, a weird `branding` property on
update_service. all gone 💥
2019-02-07 11:38:20 +00:00
Leo Hemsted
a1caf77b0e use new letter branding instead of dvla organisation id
new code is copied stylistically from the email branding patterns.
Instead of `service.dvla_organisation`, there's now
`service.letter_branding` and `service.letter_branding_id`. However,
unlike email branding we're not currently showing a preview of the
logo. That can come later when we work out how we want to do it.
2019-02-07 11:30:18 +00:00
Chris Hill-Scott
34f509af11 Fix empty folder message
Sometimes, when filtering the view by template type, the message was
saying the folder was empty, when really it should have been saying that
there were no templates of the ‘type’ you’re looking for, eg:
> There are no email templates in this folder

This was because it was looking at the filtered list of templates, not
all templates to determine whether a folder was really empty.
2019-02-05 14:28:11 +00:00
Chris Hill-Scott
0e4a22e821 Ignore case when sorting team members list
Otherwise you get A, B, C, a, b, c 😳
2019-02-01 13:09:02 +00:00
Chris Hill-Scott
88ad982bf7 Improve display of folder path when deeply nested
It’s a bit rudimentary to only show the current place in the hierarchy
and the parent. You lose a sense of how deep you are.

But we can’t just show the full path, because it can be arbitrarily
long. So what this commit does is show the full path, but truncates the
display of any items. Further-up than the current folder or its parent.

This also helps disambiguate between folders and templates, because
folders are always shown with the folder icon.

This probably won’t affect many teams, because we don’t anticipate a lot
of deep nesting.
2019-02-01 10:28:29 +00:00
Katie Smith
0bf3a4b16d Refactor to add separate letter branding client
We were getting all letter logos from a method in the email branding
client. Since we will be adding more client methods to deal with
letters, it makes things clearer to separate the email and letter
branding clients.
2019-01-29 11:37:27 +00:00
Chris Hill-Scott
558ae87baa Hide ‘back to …’ link if it’s not your service
This can happen if you click a link for a service you don’t have access
to. We shouldn’t show the back to service link in this case because:
- you shouldn’t be able to find out the service’s name from just knowing
  the link
- if you click the link you only get a `403` anyway
2019-01-15 17:31:55 +00:00
Chris Hill-Scott
206a7806d4 Allow users to navigate folders when copying
We already have a pattern for navigation folders and searching for
templates – let’s use it for the copy page too. And I reckon we can
represent services as folders if the user has multiple services they
could copy a template from.
2019-01-08 12:21:32 +00:00
Chris Hill-Scott
a8b916b57f Refactor gov user check into a decorator
We quite often use it in the same way as `@user_has_permissions`.
2018-12-12 13:42:26 +00:00
Chris Hill-Scott
126db71de6 Refactor government user check onto model 2018-12-12 12:29:08 +00:00
Chris Hill-Scott
971c64a0a9 Merge pull request #2553 from alphagov/better-live-search-team
Scope live search on team page to name and email
2018-12-05 16:46:15 +00:00
Chris Hill-Scott
eb7f421716 Remove redundant list call (sorted returns a list) 2018-12-05 16:39:23 +00:00
Alexey Bezhan
b787ca6e5b Add Service.get_days_of_retention helper method
Data retention lookup by type is only performed to get the number
of days, so we can update the service method to return the number
or the default directly.
2018-12-03 18:04:58 +00:00
Alexey Bezhan
7a7a9ae854 Cache service data retention in Redis
Adds caching for service data retention. This removes separate API
client methods to retrieve individual data retention records by id
or type in favor of a single method that fetches and caches all
retention settings configured for the service. This makes it much
easier to invalidate cache when settings change.

Lookup by id or type is provided by helper methods in the service
model.
2018-12-03 17:57:02 +00:00
Chris Hill-Scott
8807028097 Refactor team members into the model
Follows the pattern we’re using elsewhere of having less logic in the
view methods.
2018-12-03 12:07:58 +00:00
Chris Hill-Scott
ee991d0142 Allow any sub-items to be moved from a folder
Since you can now see them when searching you should also be able to
select and move them. Which means that they needed to be included in
the `Form`’s list of possible choices of things to move.
2018-11-23 16:29:21 +00:00
Chris Hill-Scott
82d8207612 Refactor template list logic into one place
The Jinja template for the ‘choose templates’ page is now pulling in
data from a lot of diparate places in order to work out what to show. As
we add more logic about what to show (in order to make the live search
work) it’s going to get harder to have all this logic in the Jinja
template.

This commit refactors it back into Python where we have more language
features for managing complex logic.

It’s a bit weird to call this file a model, in that it’s dealing with
some presentational logic, rather than just data. Conceptually it’s more
like a view model[1].

1. https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel
2018-11-23 14:00:40 +00:00
Chris Hill-Scott
5d13c639b1 Fix logic around showing search box
It was looking at the count of items at the root level (because it was
passing `parent_folder_id=None` as an argument).

This changes it to look at the total count of items for a service (which
was the intended behaviour).
2018-11-20 16:12:50 +00:00
Chris Hill-Scott
400c25e15f Make search box appear based on all templates
We reckon it’s jarring to have the search box appear and disappear as
you navigate through the folders.

Instead it should appear whenever your service has more things
(templates or folders) than you can easily keep in your head (let’s go
with 7 for now).

This keeps the bahviour the same for current services that don’t have
any folders.
2018-11-20 12:29:39 +00:00
Chris Hill-Scott
32c36bf70b Make the empty folder state more useful
Currently if there’s nothing in a folder you just get an empty page.
This looks a bit broken, or like the page hasn’t finished loading.

This commit adds a message to the page to show that it’s intentionally
blank.

The message is contextual based on type of template, because there might
be templates in the current folder, even if you can’t see them at the
moment (because you’re filtering).
2018-11-20 12:29:38 +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
d49622c5dc Style folder hierarchy in headings
This makes the display of folders in the `<h1>` look like the prototype.

It alters the behaviour we’ve initially built here by only ever showing
a maximum of two levels of hierarchy (the current folders and its
parent).
2018-11-19 10:50:03 +00:00
Chris Hill-Scott
9e4abbc511 Refactor duplicative methods
These methods were both doing the exact same thing. There may well be
others in the future that also need to do this thing.
2018-11-14 10:16:55 +00:00
Chris Hill-Scott
7f171ba4ea Merge pull request #2462 from alphagov/api-key-sort-order
Sort API keys alphabetically
2018-11-14 10:13:36 +00:00
Chris Hill-Scott
666381e23d Pre-populate rename folder form with current name
Often people will be editing the existing name, not changing it
completely.

This matches what we do when someone wants to rename their template or
service.
2018-11-13 16:05:05 +00:00
Chris Hill-Scott
63060d926f Rename method
Starting with `is` helps indicate that it’s going to return a boolean,
not perform an action (which is what a verb like `show` implies).
2018-11-13 12:31:31 +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
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
2639e2c46f Sort API keys alphabetically
Currently the order of API keys seems to be non-deterministic:
d46caa184e/app/dao/api_key_dao.py (L32-L39)

Generally we sort things alphabetically, unless there’s a good reason to
do otherwise.

This commit sorts the API keys alphabetically.
2018-11-12 16:11:13 +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
Chris Hill-Scott
4c9f667de3 Sort folders alphabetically
To match the order in which templates are sorted.
2018-11-12 11:53:37 +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
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
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
Chris Hill-Scott
4df96f3682 Add model properties for template and folder IDs
We’re going to need a way to find out if, for a given ID:
1. its a template or a folder
2. if it belongs to a given service

To do 2., we can make a set of all the IDs, to see if a given ID is a
member of that set.

To do 1. we can make two sets, one for templates and one for folders.

The natural home for these sets is on the service model.
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
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
1c9e42f85d Remove update_with_properties method
It’s more Pythonic, and better abstracted from the underlying API to
use keyword arguments instead.
2018-11-05 17:56:11 +00:00
Chris Hill-Scott
b3a7210baf Stop passing SMS sender when updating permissions
This is a redundant argument which no longer seems to be used by
anything.
2018-11-05 17:16:31 +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