Commit Graph

184 Commits

Author SHA1 Message Date
Pea Tyczynska
52526f2b9f Test aggregate_notifications_stats 2019-01-16 11:24:24 +00:00
Pea Tyczynska
06ab25665e Use single api call for service notification stats and template
usage stats.
2019-01-16 10:35:59 +00:00
Pea Tyczynska
e5647703b3 Remove support for old template statistics api response 2019-01-15 16:44:37 +00:00
Pea Tyczynska
4fe239abb2 Add support for new template statistics API response
The new API response for template statistics returns separate
count for each status. We get rid of template stats for cancelled
notifications and group the rest of the statuses together.
2019-01-15 16:22:27 +00:00
Alexey Bezhan
46bfb541c8 Group new template-statistics response by template
New API template-statistics response returns notification counts for
each template and status combination. This can be used for both
service statistics counts and template statistics by grouping the
counts either by status or by template.
2019-01-15 15:55:04 +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
Katie Smith
4188c0297d Display letter postage on the usage page
The monthly letter cost was already broken down by price on the usage
page, but this change adds postage details to the usage page too.
2018-10-03 13:20:44 +01:00
Katie Smith
b1f2b1bc0f Update billing mocks and get_sum_billing_units function
Updated the 'get_sum_billing_units' function to no longer multiply the
billing units by the rate multiplier. The billing_units that come from
notifications-api already consist of the billable_units * rate_multiplier.
The rate_multiplier is also not returned from the api response anymore.

Also updated the billing mocks since these were not mocking the right fields in
the JSON responses from the API billing endpoints, and added the new
'postage' field which will get returned from the monthly-usage endpoint
in notifications-api.
2018-10-03 12:05:49 +01:00
Chris Hill-Scott
bbdbe61cad Let users with empty permissions see certain pages
We’re going to make it possible for some users to be members of a
service, but not have any permissions (not even `view_activity`).

There are some pages that these users should still be able to see
These are the pages that a user with ‘basic view’ would have been able
to see, excluding those that let them send messages.
2018-08-09 11:56:15 +01:00
Chris Hill-Scott
b35f6e9d5f Merge pull request #2180 from alphagov/service-model
Make a service model
2018-07-31 13:31:09 +01:00
Chris Hill-Scott
1304561a70 Use service model to look up service attributes
This is better than just keying into the JSON because it means you get
an exception straight away when looking up a key that doesn’t exist
(which via mocking you could ordinarily miss).
2018-07-30 14:56:36 +01:00
Chris Hill-Scott
036923c382 Make a service model and use for permissions
Having the service floating about as JSON is a bit flakey. Could easily
introduce a mistake where you mistype the name of a key and silently
get `None`.

Also means doing awkward things like `if 'permission' in
current_service['permissions']`, whereas for users we can do the
much cleaner `user.has_permission()`.

So this commit:
- introduces a model
- adds a `.has_permission` method similar to the one we have for users
2018-07-30 14:56:36 +01:00
Chris Hill-Scott
505de52d38 Check if any jobs exist before querying jobs
At the moment the dashboard does two API calls to find out if a service
has:

1. Scheduled jobs
2. Normal jobs

API calls are slow because they are synchronous, go over the network and
touch the database. We can’t cache these API calls because:
- a scheduled job could become a normal job at any time
- the statistics on a normal job are constantly updating

However there are plenty of services which don’t have any jobs, and
probably never will. And finding out if a service has any jobs is
reliably cacheable (because as soon as a service creates its first job
it has some jobs).

So this commit:
- refactors the way we get scheduled/normal jobs into the job_api_client
  to make the view a bit slimmer
- makes an additional, Redis-wrapped call to find out if any jobs exist
  before trying to get the jobs

This should result in a speedup on the dashboard, and can be used in the
future if there’s anywhere else we want to show or hide something
depending on whether a service has created any jobs (I have some ideas).
2018-07-30 11:14:01 +01:00
Pea Tyczynska
72e8303987 Remove view displaying data form monthly_billing table 2018-07-24 14:32:33 +01:00
Chris Hill-Scott
b21c0da683 Make sure caseworking users clear their invite
There was a bug where caseworking users skipped the part of the invite
flow where their invite was cleared from the session. This caused
a 500 if they later tried to create another service.

This commit makes sure that both types of user have the invite cleared
from the session after accepting it.
2018-07-05 13:40:40 +01:00
Chris Hill-Scott
7c849dccb7 Redirect caseworking users off dashboard
They don’t have permission to see it; their home page is the list of
templates.
2018-07-05 11:53:42 +01:00
Rebecca Law
6bdb8b7210 Rename the method for usage and update the tests. 2018-05-29 15:31:40 +01:00
Rebecca Law
9d8868010f Start using the data from ft_billing for the usage page.
I've left the old usage page there so we can compare the reports if we have questions. There are known issues with the old report, especially for email and letters.
2018-05-24 16:14:36 +01:00
Rebecca Law
cd09c391e8 Letter have multliple rates, the agregate number was not taking that into account for the usage page. 2018-05-22 17:37:48 +01:00
Leo Hemsted
3097fb75ee fix usage page sms rate calculation
usage page used to make the assumption that the first row of the usage
stats would always be SMS. This now isn't always the case, so make sure
when working out the rate, it only looks at sms rows. Specifically, it
takes the rate from the first stats row. This makes a big assumption
that all the rows will have the same rate per financial year.
2018-05-17 10:40:48 +01:00
Rebecca Law
d8c8b6a454 Temporary endpoint to test the new usage page updates.
This code will go away once we are happy the results match.
2018-05-16 12:26:11 +01:00
Leo Hemsted
78a6f86043 use service statistics endpoint instead of detailed service
we're not actually looking at the detailed service aspects - just
the stats. We're doing this in three places:

* dashboard
* notification activity page
* when checking jobs to see if we're over the daily limit

change these places to use a new api endpoint (service/id/statistics),
which hopefully be a little more performant, and will definitely be a
little more organised - moving away from generic endpoints with loads
of optional parameters.

We still need the detailed endpoints for the platform admin page tho.

Depends on https://github.com/alphagov/notifications-api/pull/1865
2018-05-09 14:00:24 +01:00
chrisw
78d16709d6 reading messages for inbox from new most_recent endpoint
avoids us having to work out and display most recent messages
only on the front-end - it's now all done in api
2018-04-05 13:54:37 +01:00
chrisw
1d32c766e8 remove X messages from Y users msg 2018-04-04 15:43:07 +01:00
chrisw
f5c467e4ff add pagination to inbox page 2018-04-04 15:41:17 +01:00
Chris Hill-Scott
d75f89daf5 Limit number of navigable financial years to 3
Because more than 3 looks ugly.
2018-04-03 18:13:38 +01:00
Leo Hemsted
4a08cf81e7 remove admin_override from all has_permissions usage
as previously pointed out, it's not used anywhere.
2018-03-06 13:08:07 +00:00
Leo Hemsted
09824078dd remove all instances of db style permissions
lots of renaming of send_texts/emails/letters to send_messages, and
manage_settings/users to manage_service
2018-03-06 13:08:06 +00:00
Chris Hill-Scott
f3a0c505bd Enforce order and style of imports
Done using isort[1], with the following command:
```
isort -rc ./app ./tests
```

Adds linting to the `run_tests.sh` script to stop badly-sorted imports
getting re-introduced.

Chosen style is ‘Vertical Hanging Indent’ with trailing commas, because
I think it gives the cleanest diffs, eg:
```
from third_party import (
    lib1,
    lib2,
    lib3,
    lib4,
)
```

1. https://pypi.python.org/pypi/isort
2018-02-27 16:35:13 +00:00
Chris Hill-Scott
95482363aa Remove dashboard from dashboard URL
It’s weird that `/services/<service_id>` returns `404`. The home page
for every service is the dashboard – should be possible to get there
from any other page just by stemming the URL.

Also makes it consistent with organisations, which will have
`/organisations/<org_id>`.
2018-02-14 10:39:44 +00:00
Rebecca Law
5dedeaa89c Remove reversed in favour of reverse=True 2018-02-01 13:43:16 +00:00
Rebecca Law
07e5e67bd0 The performance of the inbox page had degraded to the point of failing to load.
We pin pointed the problem to a bad loop that was calling the format_phone_number_human_readable 216 for 25 rows, yikes.

This PR fixes that performance problem.
2018-02-01 13:26:28 +00:00
Rebecca Law
e7f94bd007 Add a template to show letter usage if the service has the letter permission 2017-12-20 16:28:40 +00:00
Rebecca Law
b7db7debc5 Add letters to usage page.
Before this goes live need to only show letters on usage if the service has the permission.
2017-12-19 14:35:10 +00:00
Rebecca Law
43747bd1ea Add letter usage to usage page.
Still need to add the summary info.
2017-12-15 17:28:52 +00:00
Richard Chapman
629593291c Used url_for and redirect
- url_for instead of constructing the url manually
- Used redirect instead of RequestRedirect to be more consistent with
other code
2017-11-24 16:34:45 +00:00
Richard Chapman
155e432aa6 Disabled the template_history endpoint
- Updated tests and added a new mock_get_monthly_template_usage
- Deleted get_monthly_template_statistics_for_service
- Added new test to test the redirection of the old endpoint
2017-11-24 15:20:40 +00:00
Richard Chapman
1681b17fab Disabled the template_history endpoint
- Removed the code for the template_history endpoint and replaced with a
redirect to the new page so that anyone is forwarded on
- Updated the template to point to the new template_usage page
2017-11-24 14:36:36 +00:00
Richard Chapman
9dbb14c9e1 Refactored to be more pythonic
Removed the nested for loops and refactored to be pythonic so it is more
maintainable in future.
2017-11-22 15:50:31 +00:00
Richard Chapman
dd2bd2f80a Removed import
An import was not required so removed it.
2017-11-22 14:38:47 +00:00
Richard Chapman
f97fa2cebc Reused the months array instead of redefining it
Re-organised the code to re-use the months array which also was not
displaying a month where there was no stats. This now gets the months,
enumerates that array updating the templates used when there are stats
items so the users sees each month of the financial year (even if there
are no stats) when there are stats they are displayed.
2017-11-22 10:37:53 +00:00
Richard Chapman
5937842ca4 Fixes to the template usage page
- When a year contains no data ensure a default set of months is
returned so that all months can be seen in the UI
- Add the template id so the user can click through to the template
2017-11-21 16:48:37 +00:00
Richard Chapman
0d36a0ef16 Updated link to for browsing to financial years
The link which when clicked allows the user to view different financial
years was pointing to the template_activity page. Updated to the link
to point to the new page.
2017-11-21 11:09:35 +00:00
Richard Chapman
2ce3cca7a8 Merge pull request #1652 from alphagov/rc-update-template-usage-to-use-new-end-point
Refactor to be more pythonic and convert float to int
2017-11-17 15:01:32 +00:00
Richard Chapman
9eb544338d Refactor to be more pythonic and convert float to int
- Implementation wasn't pythonic so updated it to be more inline with the
rest of the code for maintainability.
- The API is return a float in some cases for the month which is causing
the date to string method to fail.
2017-11-17 14:35:25 +00:00
Chris Hill-Scott
832c1cf75f Merge pull request #1634 from alphagov/smaller-font-for-bigger-numbers
Make dashboard totals smaller if numbers are big
2017-11-17 13:29:39 +00:00
Richard Chapman
de9548bba2 Only Allow Admins
Changed the decorator to only allow admin users access to the page.
2017-11-17 09:26:03 +00:00
Richard Chapman
d03df16db5 Added new template usage page which will replace template-activity
The current template-activity page is slow as it is using the end point
which uses notification_history  and hence is timing out. This adds a
new pages (so that they can be compared side by side) which will be
hidden until is is approved with the larger data set and tested.
2017-11-16 16:55:07 +00:00
Chris Hill-Scott
d6fec9f921 Add named argument for clarity 2017-11-15 09:59:52 +00:00
Chris Hill-Scott
1412933356 Make dashboard totals smaller if numbers are big
Numbers over a billion overflow the two column layout. Numbers over one
hundred thousand overflow the three column layout.

This commit makes the type size smaller in these cases, so that the
numbers still fit in the boxes.
2017-11-09 17:50:19 +00:00