Commit Graph

450 Commits

Author SHA1 Message Date
Ryan Ahearn
4fce69f0ac Merge branch 'main' into cleanup-config
* main:
  lingering merge repair
  remove alerts from env
  remove broadcast-related code
2022-10-26 13:23:01 +00:00
stvnrlly
218eb3559f Merge branch 'main' into stvnrlly-remove-broadcasts 2022-10-26 01:27:44 +00:00
Ryan Ahearn
921c872bd1 Refactor method of retrieving credentials out of VCAP_SERVICES 2022-10-20 08:36:30 -04:00
Steven Reilly
345516606f Merge pull request #59 from GSA/stvnrlly-update-form-flow
Update services for post-sign-up tour
2022-10-17 09:43:32 -04:00
stvnrlly
f16b5dd1c4 remove broadcast-related code 2022-10-04 03:04:13 +00:00
Ryan Ahearn
5f1a1f083a Proactively specify aws region for s3 operations 2022-09-26 10:25:03 -04:00
Ryan Ahearn
a90dcc918b Provide s3 credentials for each individual bucket 2022-09-23 12:59:55 -04:00
stvnrlly
3e7b5b4370 update tests based on updated orgs 2022-09-15 18:47:04 +00:00
stvnrlly
7b51d1e7a6 remove nhs and gpo forms 2022-09-13 13:20:54 +00:00
Ben Thorner
5db2581669 Simplify tests for TemplateList class
In response to: [^1][^2][^3].

Originally there were three tests:

- One was testing the "get_user_template_folders" method directly.

- The other two were testing "get_template_folders", which calls
the "_user_" method if a user is passed - this is what the tests
were primarily checking, by passing or not passing a User object.

The two tests of "get_template_folders" also implicitly checked
that it filtered folders based on a "parent_folder_id". I wanted
to emulate the tests but it makes more sense to simplify them, as
the methods are now only used by TemplateList internally.

To simplify, we just keep just two tests to check that the overall
set of folders is filtered based on the presence of a User. We do
lose the implicit check of filtering by "parent_folder_id", but:

- We are still checking this implicitly in the sense that the loop
to generate the overall set of folders terminates. If the method
didn't do any filtering, the loop would be infinite.

- We need to acknowledge that these tests were incomplete to begin
with. There is also lots of coverage in higher level tests [^4],
although it's harder to reason exactly what is covered.

[^1]: https://github.com/alphagov/notifications-admin/pull/4258#discussion_r890144076
[^2]: https://github.com/alphagov/notifications-admin/pull/4258#discussion_r890151220
[^3]: https://github.com/alphagov/notifications-admin/pull/4258#discussion_r890147506
[^4]: 1787f9f42f/tests/app/main/views/test_template_folders.py
2022-06-07 11:31:09 +01:00
Ben Thorner
1c4a2b4790 Cache templates and folders in TemplateList
This gives us the performance gains identified in [^1] for the test
service described in the spike:

- user_template_folders - from 10s to a little above 3s on its own

- get_templates_and_folders - from 10s to below 6s on its own

In combination, these two uses of caching reduce the test page load
time from 10s to a little above 3s. This is slightly higher than in
the spike PR due to all the extra work we're doing to generate the
"move to" list of folders, as described in a previous commit.

The render time is unchanged for services with few folders. We start
to see the benefit of this change at around 200 templates + folders,
with no evidence that any service will experience worse render times,
despite the extra work we're doing from previous commits.

[^1]: https://github.com/alphagov/notifications-admin/pull/4251
2022-06-07 11:05:36 +01:00
Ben Thorner
2771ae1274 Remove redundant user param from template methods
This will finally make it possible to cache some of the methods.
2022-06-07 11:05:35 +01:00
Ben Thorner
9126c8ca5e Move _template_ methods to TemplateList class
This is a straight move with a few minor tweaks:

- Some references to self.X in the code from Service now need to
become self.service.X.

- Some reference to self.service.Y in TemplateList can now become
self.Y for the methods that were migrated.

The remaining _template_ methods in Service are still called from
multiple places and there's no performance gain to motivate moving
them out of the Service class, which is now a more manageable size.
2022-06-07 11:05:34 +01:00
Ben Thorner
487dc1b488 Test _template_folders functions via TemplateList
This is part of the overall migration of the "_template_folders"
methods to the TemplateList class. Moving the existing tests now
will make the actual migration easier to follow.

To emulate the second and third tests, we need to grab a specific
folder from the TemplateList and then look at its folders - these
are set based on "get_template_folders" as before.
2022-06-07 11:05:30 +01:00
Ben Thorner
b97bf19b45 Make creating TemplateListServices consistent
TemplateListServices are used when we want to show the service
as an additional layer of hierarchy when a user copies a template,
potentially across services [^1].

Normally a TemplateFolder is given "folders" and "templates" by
TemplateList [^2]; TemplateListService was doing it the other
way round and getting its own instead.

Using a subclass of TemplateList means we can make the approach
consistent, which will support the caching approach later on, as
well as simplifying how we work with templates and folders.

[^1]: 2e637f801f/app/main/views/templates.py (L356)
[^2]: bef0382cca/app/models/template_list.py (L31-L36)
2022-06-07 10:43:30 +01:00
Ben Thorner
a87138b9f9 Refactor loop over TemplateList items
This is a technique we'll use in later commits.
2022-06-06 10:36:49 +01:00
Ben Thorner
ad4ef12251 Reuse TemplateList to display move-to options
This is slightly less efficient than getting the folder dicts from
"get_user_template_folders" directly, since:

- TemplateList returns both templates and folders.
- TemplateList encapsulates the dicts in model classes.

We'll compensate for this later on:

- We'll introduce a new caching approach to make the call fast.
- We'll expose a property to avoid the "if" in the comprehension.
2022-06-06 10:36:48 +01:00
Ben Thorner
f500db44f1 Reuse TemplateList class when deleting a folder
Part of moving "get_template_folders" et al. into TemplateList so we
can cache it more effectively. This is slightly less efficient as
iterating a TemplateList will instantiate an object for each item
in the folder; but the difference is minimal.

Note that:

- The default template_type for TemplateList is "all".
- We need to pass realistic template "JSON" in the test now.
2022-06-06 10:36:47 +01:00
Ben Thorner
32efb9a03d Fix go-live checks ignoring nested templates
This is a very low impact bug since a user can always create such
templates after their service is live and not be subject to checks
we do before that point. Still, we may as well fix it.

The main benefit of this change is actually to contribute towards
moving methods like "get_templates" out of the Service class so
we can simplify and cache their results more effectively.

Note: I wanted to simplify the Service class further as the two
"has_" properties are only used once in the app code. Unfortunately
they are tightly coupled in one of the tests as well [^1].

[^1]: bef0382cca/tests/app/main/views/service_settings/test_service_settings.py (L1961-L1962)
2022-05-27 12:46:37 +01:00
Chris Hill-Scott
80854ab2cc Force xlsm files to open with pyexcel-xlsx
`.xlsm` files are like `.xlxs` files but with macros enabled. They store
data in the same XML-based format as `.xlsx` files.

Pyexcel will try to use the xlrd package to parse `.xlsm` files. This
used to work because xlrd used to support reading `.xlsx` files. xlrd
has dropped support for `.xlsx` files in version 2 because of security
concerns. This means that when pyexcel asks xlrd to parse a `.xlsm` file
it causes an error.

This commit adds some branching to force `.xlsm` files to be opened
with pyexcel-xlsx instead, which does support `.xlsx` files.
2022-05-13 13:17:55 +01:00
Chris Hill-Scott
c6dc0d513e Allow editing of pending users
At the moment if a user is pending we don’t show the ‘change’ link.

This is unhelpful because:
- there’s no way to remove this user
- there’s no way to change their phone number, if the reason that
  they are still pending is because they’ve been unable to receive
  the two factor code at the number they first provided
2022-05-05 09:42:14 +01:00
Chris Hill-Scott
c5d4bfd8ef Refactor to avoid direct string comparison
Direct string comparison in multiple places is prone to typos. It
also means that a consumer of the class needs to know that whether
a user is pending or active is held in the `state` property, which
is an implementation detail.
2022-05-05 09:39:32 +01:00
Chris Hill-Scott
5ac6efc580 Refactor logic out of Jinja before making more complicated
To keep the conditionals in the Jinja template more readable, this
commit moves the logic into a method on the model, where it can
be split over multiple statements and lines.
2022-05-05 09:38:40 +01:00
Ben Thorner
6030e9e5bb Decouple the set of org types from their labels
In response to: [^1].

[^1]: https://github.com/alphagov/notifications-admin/pull/4196#discussion_r838383086
2022-03-30 17:46:53 +01:00
Ben Thorner
21eea0189d DRY-up listing NHS organisation types
The model should be the source of truth for this.
2022-03-30 17:46:40 +01:00
Chris Hill-Scott
82b3a96a83 Use SortByName mixin where possible
Implementing `__lt__` makes objects sortable.

Rather than reimplementing `__lt__` each time we want to make an object
sortable by name, we can inherit from the extant `SortByNameMixin`.
2022-02-01 14:29:50 +00:00
Pea Tyczynska
78681eb452 Display if broadcast was cancelled via API
If broadcast_message has no value under cancelled_by_id, display
in the view that it was cancelled by an API call.
2022-01-19 11:01:03 +00:00
Leo Hemsted
a602ffceb9 fix bug where job reports showed before jobs finished
for a job to be finished there are two requirements:

* the status to be "finished"
* the percentage complete to be 100%

The job status is set to finished when the process_job task finishes
(even though not all process_row may have finished). The
percentage_complete is calculated by comparing the number of
notifications in the database with the number of rows in the
spreadsheet.

This was inadvertently changed from an "and" to an "or" clause two years
ago. This meant that people could download a report when the status was
finished but not all notifications were present in the database. Lets
change it back.

7d52ac97f1 (diff-44b012cad205379c481bed244ddb2294bae5ee85dcd01f4aee932a2bd85b67b2L86-R100)
2022-01-14 15:48:04 +00:00
Ben Thorner
1a4204fed1 Merge pull request #4086 from alphagov/small-spreadsheet-refactor-177535141
Small refactoring to the Spreadsheet class
2021-12-07 16:59:46 +00:00
Chris Hill-Scott
99a8a4fd48 Don’t combine polygons with different projections
When we combine simplified polygons from different areas we try to use
the polygons that are defined in metres as a speed optimisation.

This doesn’t work when those polygons are in several different
projections because the distance in metres is relative to the edge of
the projection. Just naively choosing one projection means that some
of the polygons will shift position on the earth by 100s of kilometers
once they are converted back to degrees.

To avoid this we need to:
- check for situations where we have polygons in multiple different
  projections
- transforms these polygons back into degrees and let `Polygons` pick a
  common projection for all of them before doing any
  merging/smoothing/etc.
2021-12-07 14:16:54 +00:00
Ben Thorner
3c79675ba2 Remove unused properties in Spreadsheet class
These are no longer used anywhere. Note that pyexcel-xlsx is still
a necessary dependency: it acts as an implicit plugin to pyexcel
that, surprisingly, allows pyexcel to...read excel files [1].

[1]: https://github.com/pyexcel/pyexcel-xlsx#as-a-pyexcel-plugin
2021-12-03 17:25:17 +00:00
Chris Hill-Scott
6a3aba3bc5 Store CRS to avoid costly lookup
Looking up the coordinate reference system for a given polygon’s bounds
is surprisingly expensive.

We can make things run faster by precomputing it at the time of
generating the simplified polygons, then storing it in the SQLite
database alongside the polygon data.
2021-12-01 14:10:55 +00:00
Chris Hill-Scott
0cf443e9a6 Use already-transformed polygons wherever possible
Transforming full resolution polygons to linear coordinates is somewhat
expensive. We can make things run faster by:
- looking at `simple_polygons` which have fewer points and are therefore
  faster to transform.
- reusing polygons that have already been transformed where possible
2021-12-01 14:10:55 +00:00
Chris Hill-Scott
6cb326f153 Update utils to do linear transformation of polygons
Brings in https://github.com/alphagov/notifications-utils/pull/889/files

At the moment, we are not doing any transformation of features before
applying geometric algorithms to them. This is, in effect, assuming that
the earth is flat.

This new version of utils implements the transformation of our polygons
to a Cartesian plane. In other words, it converts them from being
defined in spherical degrees to metres.

For the admin app this means we need to convert places where the code
expects things to be measured in degrees to work in metres instead.
2021-12-01 14:10:54 +00:00
Chris Hill-Scott
223b275507 Merge pull request #4010 from alphagov/refactor-duplicate-method
Refactor `get_simple_polygons` method for reuse
2021-11-15 11:21:50 +00:00
Chris Hill-Scott
0c2b586e40 Make organisations natively sortable 2021-11-11 14:59:06 +00:00
Chris Hill-Scott
8934e402e8 Make a model collection for organisations
This makes returning a user’s organisations consistent with how we
return their services.
2021-11-09 15:05:43 +00:00
Chris Hill-Scott
029682d561 Rename model to AllOrganisations
This makes it clearer that this model collection isn’t the organisations
for a user or a service or some other entity, like most model
collections are.

It will also lets us make a separate Organisations model, without the
name conflicting.
2021-11-09 15:05:42 +00:00
Chris Hill-Scott
cbbc58e649 Make a model collection for services
This is tidier than having a manual loop.
2021-11-09 15:05:42 +00:00
Chris Hill-Scott
9281ca7d50 Sort services and orgs in presentation layer
The model layer shouldn’t need to be concerned with sorting. For
services this means we can make a `SerialisedModelCollection` rather
than writing a manual loop.
2021-11-09 15:05:42 +00:00
Chris Hill-Scott
4d4c9c0db2 Make services natively sortable 2021-11-09 15:05:42 +00:00
Chris Hill-Scott
18d14a06fa Refactor get_simple_polygons method for reuse
This means we:
- don’t need to pass the areas around as an argument
- keep all the complexity of combining polygons from different areas in
  one method
2021-11-09 15:05:27 +00:00
David McDonald
c6b884dcef Upgrade utils to 48.0.0
Fixes a bug with non breaking spaces being removed from templates
2021-11-01 10:22:58 +00:00
Chris Hill-Scott
1334538cad Prefer cap_event to reference when referring to an alert
`reference` isn’t very human-friendly – the Environment Agency just
supply a UUID in this field.

The Environment Agency also populate the `<event>`` field with some
human readable text, for example:

> 013 Issue Severe Flood Warning EA

(013 is an ‘area code’ which will be meaningful to the Flood Warning Service team)

This commit changes the frontend to display the value of the `cap_event`
field, if it’s present, which is where the API stores the value of the
`<event>` field from the original CAP XML.

***

Depends on:
- [x] https://github.com/alphagov/notifications-api/pull/3344/files
2021-10-28 10:24:32 +01:00
Chris Hill-Scott
e675500ac2 Move branding info from model
This was an awkward property to have in a model class because
- it’s presentation not data about the object
- it munged together data from a different object, so it wasn’t well
  encapsulated

This commit moves the logic to the template, where it can reference the
`Organisation` and `User` models directly.
2021-10-26 18:14:09 +01:00
Chris Hill-Scott
72742cf477 Move unknown organisation logic into Jinja
Human readable content like this doesn’t really belong in the model
layer, it’s more natural to have it in the presentation layer.
2021-10-15 09:23:31 +01:00
Chris Hill-Scott
eefc903b25 Move ‘can’t tell’ message to Jinja
Human readable content like this doesn’t really belong in the model
layer, it’s more natural to have it in the presentation layer.
2021-10-15 09:23:31 +01:00
Chris Hill-Scott
d76dacc41e Move ‘agreement signed’ message into Jinja
Human readable content like this doesn’t really belong in the model
layer, it’s more natural to have it in the presentation layer.
2021-10-15 09:23:31 +01:00
Chris Hill-Scott
1ab83c48e3 Move request to go live notes into template
We can make the `as_agreement_statement_for_go_live_request` method less
complex by offloading some of the content it returns to the presentation
layer.
2021-10-15 09:23:31 +01:00
Chris Hill-Scott
ec703c5998 Add details of MOU signatory to go live ticket
This will help us monitor organisations that have signed our MOU using a
shared inbox and prevent it happening in future.

https://www.pivotaltracker.com/story/show/179782040
2021-10-15 09:23:30 +01:00