Commit Graph

248 Commits

Author SHA1 Message Date
Katie Smith
64cd8f39c2 Add the date to the service name and email_reply_to when archiving
This copies what we do to a user's email address when archiving the user
by prefixing it with `_archived_{date}`. We already prefixed the
service name and email_reply_to with `_archived`, but this didn't allow
a service with the same name to be archived more than once.
2020-05-22 09:37:45 +01:00
David McDonald
2f0b3a9636 Fix edge case in func test data purging for created_by_id
When running the purge command I found about 4 users who could not be
deleted because their user id was still referenced in the services table
as they had created the service yet they were not a member of that
service anymore.

I have fixed this by checking that if they are not a member but created
the service then we also delete the service for them.

Note, I've followed the previous convention of no tests for this
function. I've run it locally and executed the code path so there should
be no major flaws in the code. There is a small chance I wasn't able to
exactly replicate the state that existed in preview on my local but
hopefully it was close enough to be accurate.
2020-05-18 10:30:28 +01:00
Leo Hemsted
885f3122bd fix purge functional test data task
* it doesn't delete service email reply to or letter contacts, or
  contact lists. I don't think the contact lists will ever be an issue
  but it doesn't hurt to add it to the list of things to remove.
* it doesn't remove users from organisations before deleting the users

there may be more tables that link to Service that should be deleted,
but for now just add these ones that I could spot.
2020-03-30 17:45:29 +01:00
Chris Hill-Scott
b3c9680487 Give new services the upload letters permission
This will switch on this feature for new services.

After this we will:
- give existing services this permission with a database migration
- remove this permission from the codebase entirely so that everyone has
  this feature and can’t switch it off
2020-02-25 14:03:43 +00:00
David McDonald
3a0aece6a1 Up threshold for sms to telephone numbers
We were just ignoring the errors and our users were not fixing things.

Given that 500 texts cost approx £8 it's not the end of the world.

In the long run we may decide to just stop letting people try and send
messages to TV numbers but this is a quick fix to stop emails coming in
which we ignore.
2020-01-17 13:26:20 +00:00
Pea Tyczynska
1b7b26bf24 Query directly for services with high failure rate 2019-12-06 16:57:56 +00:00
Pea Tyczynska
cfbb080f57 Simplify failure rate by building separate query 2019-12-06 16:57:44 +00:00
Pea Tyczynska
53efd87e28 Check for services sending sms messages to tv numbers 2019-12-06 16:57:34 +00:00
Chris Hill-Scott
8d9038c3e9 Give GP practices NHS branding by default
Previously we were doing it based on their email address. This will also
apply it if they self-select as a GP surgery, even if they don’t have an
NHS email address.
2019-08-28 15:33:00 +01:00
Pea (Malgorzata Tyczynska)
7e43b5bbc3 Merge pull request #2587 from alphagov/find_services_by_partial_name
Find services by partial name
2019-08-16 11:21:19 +01:00
Rebecca Law
fdee6cbfb2 As per PR comments:
- Remove Organisation.services
- added backref='services' to Services.organisation relationship and removed redundant foreign_keys argument.
2019-08-14 13:23:20 +01:00
Rebecca Law
55dc7184cc Add organisation_id to Service.
This is the second commit in the series to add organisation_id to Service.
- Data migration to update services.organisation_id from data in organisation_to_service
 (The rollback will lose any updates to organisation unless the script is updated to set organistion_to_service from service.organisation_id )
- Update Service.organisation relationship to a ForeignKey relationship to Organisation.
- Update Organisation.services to a backref relationship to Service.
2019-08-13 17:25:30 +01:00
Pea Tyczynska
52a1316a7e Find services by partial name 2019-08-13 17:20:37 +01:00
Rebecca Law
12f305bf86 - Migration to add Service.organisation_id
- Add oranisation_id to Service data model.
- Update methods to create service and associate service to organisation to set the organisation_id on the Service.
- Create the missing test, if the service user email matches a domain for an organisation then associate the service to the organisation and inherit crown and organisation_type from the organisation.
2019-08-12 16:03:02 +01:00
Pea Tyczynska
5b256fa64e Migrate all orgs and services onto new organisation types
Remove all mentions of generic 'nhs' organisation type.
2019-07-22 14:58:41 +01:00
Pea Tyczynska
edda816ffa Temporarily add generic 'nhs' 2019-07-19 15:13:24 +01:00
Pea Tyczynska
d89ef0594f nhs_central is crown org and also we do not update org type while
updating service anymore.
2019-07-18 17:05:24 +01:00
Pea Tyczynska
9dfc550f46 Add org types table 2019-07-18 17:05:22 +01:00
Leo Hemsted
7db2b031a2 add free_sms_fragment_limit to platform admin billing report
a little complicated because the free_sms_fragment_limit comes from
the annual_billing table. This relies on there always being at least
one row for every service on annual billing - I checked on prod and
that is true.

Join to the annual billing table, then join to a subquery getting the
latest year for that service to extract only the most recent year.
2019-06-04 11:34:10 +01:00
Leo Hemsted
968d94d350 clean up dao_fetch_live_services
a bit of DRY - use the column definitions to determine what goes into
the dict, and use a `next` iterator rather than a while loop to find
the existing service row. Take advantage of dict mutability to avoid
needing to refer to the list by index.

Also change the tests so if there's an error, the diff is slightly
more readable. But not much
2019-06-04 11:33:19 +01:00
Pea Tyczynska
689ff57c32 Add organisation type to live services report 2019-05-03 15:09:54 +01:00
Pea Tyczynska
e7add1c729 Only show live services in live services query 2019-05-02 11:15:53 +01:00
Pea Tyczynska
83f39730d0 Order results by live date ascending order 2019-05-01 15:58:08 +01:00
Pea Tyczynska
382d1de857 Only count_as_live services
Add comments to live services dao test for context
2019-05-01 15:57:59 +01:00
Pea Tyczynska
c15d7878fc Only include ft_billing data for current financial year
Test get_live_services_data endpoint

Expand dao_fetch_live_services_data test with more ft_billing records
2019-05-01 15:57:45 +01:00
Pea Tyczynska
669db0b4ca New db query that returns data about live services
This data includes service and org name, consent to research,
contact details and both intended and factual notifications
volumes by notification type.

This query was created to get data for a csv report for our
platform admins.
2019-05-01 15:57:20 +01:00
Chris Hill-Scott
96bb9e19f9 Merge pull request #2385 from alphagov/raise-if-fail-to-write-history
Raise exception if history can’t be written
2019-04-17 11:17:49 +01:00
Chris Hill-Scott
c6447c111d Don’t let admin specify branding for new service
It doesn’t need to because the API code works it all out now by looking
at the organisation.
2019-04-12 16:42:50 +01:00
Chris Hill-Scott
a39ed098b8 Merge pull request #2442 from alphagov/default-branding-for-nhs-users
Set default branding for NHS services
2019-04-12 15:29:30 +01:00
Chris Hill-Scott
6bfd999de2 Add method to count of live services and orgs
So that we don’t have to update the home page manually any more.
2019-04-11 13:54:43 +01:00
Chris Hill-Scott
5a7de22f55 Set default branding for NHS services
The NHS is a special case because it’s not one organisation, but it does
have one consistent brand. So anyone working for an NHS organisation
should have their default branding set when they create a service, even
if we know nothing about their specific organisation.
2019-04-08 10:27:26 +01:00
Chris Hill-Scott
eeb90bed57 Do all version table writes in one commit
The behaviour of stacking the version decorators does not work as
expected.

What you would expect to happen is that each decorator causes a history
row to be written for its respective model object.

What actually happens is that the first decorator adds history records
to the database session, but then causes the database session to commit.
This means that subsequent uses of this decorator find a clean session,
and therefore no changes to copy to their respective history tables.

This commit changes the intended use of the decorator so that it is only
used once per function, and accepts multiple definitions of what to
record history for. This way it can record everything that needs to go
into the history before doing anything that would risk flushing the
session.
2019-04-05 16:11:46 +01:00
Chris Hill-Scott
c257ec105c Raise exception if history can’t be written
This is fiendishly difficult error to discover on your own.

It’s caused when, during the creation of a row in the database, you run
a query on the same table, or a table that joins to the table you’re
inserting into. What I think is happening is that the database is forced
to flush the session before running the query in order to maintain
consistency.

This means that the session is clean by the time the history stuff comes
to do its work, so there’s nothing for it to copy into the history
table, and it silently fails to record history.

Hopefully raising an exception will:
- prevent this from failing silently
- save whoever comes across this issue in the future a whole load of
  time
2019-04-05 16:11:46 +01:00
Chris Hill-Scott
eb41ce7304 Make service created by platform admin non-counted
If a service has been created by someone on our team, it’s probably a
test service, which shouldn’t be included in the count of live services.
2019-03-25 13:30:13 +00:00
Chris Hill-Scott
ef515400f3 Fix automatic inheritance of org’s branding
When creating a service it should inherit it’s organisation’s branding,
if that organisation has branding.

This wasn’t working because we were referring to the ID of the branding
when making the association, not the branding itself.
2019-03-22 15:57:20 +00:00
Katie Smith
2aa14bc41c Set folder permissions when adding a user to a service
This sets the folder permissions for a user when adding them to a
service. If a user is being added to a service after accepting an
invite, we need to account for the possibility that the folders we are
trying to add them to have been deleted before they accepted the invite.
2019-03-22 09:30:39 +00:00
Alexey Bezhan
6dc93ffd08 Change dao_remove_user_from_service query to avoid IntegrityError
When triggered by an admin request `dao_remove_user_from_service`
raised an IntegrityError since the user_to_service delete query was
issued before the folder permissions one, violating the foreign key
constraint on the folder permissions table.

For some reason this isn't caught by the tests in test_services_dao
that check that folder permissions are removed properly.
2019-03-11 17:30:06 +00:00
Chris Hill-Scott
c0fb9267bd Automatically associate new service with an org
This is the same thing we do in the admin app at the moment with YAML:
2f4e933b65/app/utils.py (L556-L562)
2019-03-08 13:30:42 +00:00
Katie Smith
cd240f9212 Delete user folder permissions when user is removed from a service 2019-02-27 13:04:14 +00:00
Katie Smith
33166f3fb2 Add migration for user_folder_permissions table
Changed the user_to_service mapping table into a model called
ServiceUser. When looking at users who have permission for a folder
we are only interested in users for a particular service, not all users,
so we can use the ServiceUser model to access folder permissions.

Added a user_folder_permissions table which contains the service_id,
user_id and template_folder_id. There are links between
user_folder_permissions and TemplateFolder, and between
user_folder_permissions and ServiceUser.
2019-02-27 11:50:36 +00:00
Rebecca Law
38a599c758 Remove the need for the edit_folders service permission.
We need another PR to remove it from ServicePermissionTypes and remove the data in service_permissions.
2019-02-11 17:26:17 +00:00
Chris Hill-Scott
4b1336b405 Give folders to new services by default
Step 1 of 2 of turning on folders for all services.

We think it’s a feature which will be useful for the majority of
services, and we think we’ve done enough research to know that it’s
mature enough to release to all services.
2019-01-29 12:30:41 +00:00
Rebecca Law
f11aa55e0b Adding new data models for letter branding. 2019-01-22 17:27:00 +00:00
Rebecca Law
6ac1f39fd0 Remove dao_fetch_monthly_historical_stats_by_template, a query using NotificationHistory that is no longer used. 2019-01-17 17:20:21 +00:00
Rebecca Law
efad58edd8 There is no need to have a separate table to store template monthly statistics. It's easy enough to aggregate the stats from ft_notification_status.
This removes the nightly task, and all the dao methods.
The next PR will remove the table.
2019-01-14 16:30:36 +00:00
Rebecca Law
8fbe60bb90 Remove unused query 2019-01-07 15:37:26 +00:00
Rebecca Law
5f73dfdbe9 Added constraints to services.postage: not nullable and can only containt "first" or "second" 2018-09-18 17:41:25 +01:00
Rebecca Law
7200ccb452 Remove print 2018-09-18 16:44:07 +01:00
Rebecca Law
1c0892888f Change the name of letter_class to postage, this will match the domain language used in the documentation.
Updated the tests to answer review comments.
2018-09-18 15:22:08 +01:00
Rebecca Law
79815b4f8a In order to support sending letters by first class we need a way to know how the service wants us to send the letter.
To start with this will be an attribute on the service, at the time the notification is created it will look at Service.letter_class to decide what class to use for the letter.

This PR adds Service.letter class as a nullable column.
Updated the create_service and update_service method to default the value to second.

Subsequent PRs will add the check constraint to ensure we only get first or second in the letter_class column and make that column nullable.
This can't be done all at once because it will cause an error if someone inserts or updates a service during the deploy.
2018-09-17 11:27:43 +01:00