Commit Graph

74 Commits

Author SHA1 Message Date
Alexey Bezhan
2478c6b608 Add a temporary check for service folder permission
Since we're calling `User.has_template_folder_permission` directly
in a few places (notably the `folder_path` template macro), we need
to check that the service has the feature flag enabled first. This is
usually done by the caller, but template macro doesn't have access to
`current_service`. To avoid passing it in each time the macro is called
we're adding a temporary check inside the method itself.

This commit can be reverted completely when we remove the service
feature flag.
2019-04-01 10:50:39 +01:00
Alexey Bezhan
bfe6768796 Add user permission check to template folder actions 2019-04-01 10:50:38 +01:00
Alexey Bezhan
a30c9733b0 Add a helper Service method to get a template given user has permission
Checks if the user has access to the template's parent folder and
either returns the template or a 403 response.

This method should be used instead of calling service_api_client from
the views.
2019-04-01 10:50:38 +01:00
Alexey Bezhan
e6d7f7ebeb Add a user method to check folder permission
User model is the most natural place for a permission check method,
however this means that we need to pass the full user object to
service model methods and TemplateList instead of user_id.
2019-04-01 10:50:38 +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
ce1adce97a Put current email branding in new branding request
When we get a request for new branding it’s helpful to quickly see what
the service’s current branding is, so we can get a better sense of why
they want to change it.
2019-03-18 10:50:49 +00:00
Pea (Malgorzata Tyczynska)
2bc6792c5a Merge pull request #2823 from alphagov/hide-folders-when-no-permissions
Only show folders that user has permission to see
2019-03-11 16:26:56 +00:00
Pea Tyczynska
577e25bd52 Explain the workings of get_user_template_folders 2019-03-11 14:30:50 +00:00
Pea Tyczynska
347955a378 Make sure that only templates inside visible folders are considered
When filtering by template type we should ignore any templates that
are inside folders user does not have permission for. Otherwise the
parent folder can show up as empty instead of not showing up at
all. This adds check for user_permissions to is_folder_visible on
the service model in admin.
2019-03-11 14:30:50 +00:00
Alexey Bezhan
3d401ce856 Hide current folder templates if user doesn't have a folder permission
TemplateList gets a list of templates in a current folder separately,
so we need to make sure `service.get_templates` checks for the
appropriate user permission
2019-03-11 14:30:50 +00:00
Alexey Bezhan
80bfd8e347 Add space around folder name separator when flattening folder path 2019-03-11 14:30:49 +00:00
Alexey Bezhan
1fb7a2515f Return all templates for the user if the folder permissions flag is off
Putting the permission check in the get_user_template_folders allows
us to replace `all_template_folders` usage with the new method without
having to worry about the temporary service permission flag.
2019-03-11 14:30:49 +00:00
Pea Tyczynska
de237e9e6f Test that folders are filtered based on user permission at service level 2019-03-11 14:30:49 +00:00
Chris Hill-Scott
1af844c95f Fix the logic about showing extra task list items
It should be:
- if they have said they are going to send by a certain channel, show
  the extra required task(s) for that channel
- if they haven’t said, infer from which templates they have
2019-03-08 15:21:41 +00:00
Pea Tyczynska
87fb3944ce Get template folders visible to the current user
get_template_folders can filter out folders invisible to a user
2019-03-07 16:21:34 +00:00
Chris Hill-Scott
531219b87e Make SMS sender dependent on estimated SMS volumes
We have a number of go live requests where people have said they’re
sending text messages, but haven’t changed the text message sender from
the default of `GOVUK` (we ask teams who aren’t central government to do
this). At the moment we don’t prompt them to, because we look at whether
they have text message templates as indicative of whether they’re going
to send text messages.

Now that we explicitly ask for the volumes of text messages they’re
sending we should use this to determine whether or not we prompt them to
change their text message sender because it’s a stronger signal of
intent than what templates they’ve set up.
2019-03-05 10:05:47 +00:00
Chris Hill-Scott
24ee280632 Make reply to address dependent on sending intent
We have a number of go live requests where people have said they’re
sending email, but haven’t set up a reply-to address. At the moment we
don’t prompt them to, because we look at whether they have email
templates as indicative of whether they’re going to send email.

Now that we explicitly ask for the volumes of email they’re sending we
should use this to determine whether or not we prompt them to set up an
email reply to address because it’s a stronger signal of intent than
what templates they’ve set up.
2019-03-05 10:05:47 +00:00
Chris Hill-Scott
7ac9884dd5 Tag tickets that haven’t filled volumes 2019-02-27 17:34:24 +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
Chris Hill-Scott
d82f410325 Don’t allow editing of users from other services
Currently when you load the ‘edit user’ page (which has a URL like
`/service/<service_id>/users/<user_id>`) we check that:
- you belong to the service represented by `service_id`
- you have permission to edit users on this service

We don’t check that:
- the user represented by `user_id` belongs to this service

This means that if you could somehow determine another user’s `user_id`
(which I don’t think is possible if you don’t already have the manage
service permission for that service) then you could:
- edit their permissions on your service (weird, but wouldn’t have any
  effect)
- change their email address (bad)

This commit adds checks to return a `404` any time you’re looking at a
service and trying to do stuff to a user who doesn’t belong to that
service.

We can’t add this check to the API easily because there are still times
that we want to get/modify users outside the context of a service (eg
platform admin pages, or users who have no services).
2019-02-25 17:19:07 +00:00
Chris Hill-Scott
8aeb203124 Put template type navigation in correct order
We always talk about the things you can send using Notify as _emails,
text messages and letters_, in that order.

The navigation should reflect this.
2019-02-22 17:19:39 +00:00
Pea (Malgorzata Tyczynska)
42990fe376 Merge pull request #2759 from alphagov/remove_all_service_postage_references
Remove all service postage references
2019-02-14 11:19:15 +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
0e3d47bc08 use letter branding object instead of letter_logo_filename
This is part of migrating away from dvla organisations. This only
affects in-app previews and not actual letters printed by the api.
2019-02-13 13:52:06 +00:00
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
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
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
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
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
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