Commit Graph

37 Commits

Author SHA1 Message Date
Carlo Costino
9a83ba7475 Localize notification_utils to the admin
This changeset pulls in all of the notification_utils code directly into the admin and removes it as an external dependency. We are doing this to cut down on operational maintenance of the project and will begin removing parts of it no longer needed for the admin.

Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
2024-05-16 10:37:37 -04:00
Kenneth Kehl
8c9721d8e2 notify-api-412 use black to enforce python coding style 2023-08-25 09:12:23 -07:00
Katie Smith
b5fa270cd2 Bump all test dependencies
This results in some new errors from flake8-bugbear:
```
B020: Loop control variable overrides iterable it iterates
```
I can't see an issue with the places that we do this, so have ignored
these warnings. If we keep getting these and they look fine, we can
create a global rule to ignore B020.
2022-04-06 12:17:09 +01:00
Ben Thorner
7c27646d6a Extract user utility code into own module
This provides more room for expansion, and reduces the amount of
arbitrary code in the __init__.py file for the new package.
2021-06-09 13:19:05 +01:00
Chris Hill-Scott
88734bb74f Bump utils to bring in recent changes to Template classes
The main things we have to account for are:
- `WithSubjectTemplate` has gone
- every template dictionary must have `template_type` set
2020-04-15 17:58:57 +01:00
Chris Hill-Scott
ef335e7601 Require IDs to be UUIDs in URLS
We mostly rely on the API returning a 404 to generate 404s for trying
to get things with non-UUID IDs. This is fine, except our tests often
mock these API calls. So it could look like everything is working fine,
except the thing your passing in might never be a valid UUID, and thus
would 404 in a non-test environment.

So this commit:
1. uses the `uuid` URL converter everywhere there’s something that looks
   like an ID in a URL parameter
2.  adds a test which automates checking for 1.
2019-11-07 13:46:25 +00:00
Chris Hill-Scott
b620b677d3 Have permissions decorators check user signed in
Rather than force us to write the decorators in a specific order let’s
just have one decorator call the other. This should make fewer lines of
code, and fewer annoying test failures. It also means that the same way
of raising a `401` (through the `current_app` method) is used
everywhere.
2019-07-03 09:54:35 +01:00
Chris Hill-Scott
3da9e84ece Enforce order of permissions decorators
At the moment we mostly have `user_has_permissions` execute first. It
shouldn’t matter, but it feels right for us to check that a user is
logged in before we check their permissions to a service. Otherwise a
malicious user could (maybe) check if a service ID belongs to a real
service, and go on to do something malicious with that information.

This commit adds some extra test code to enforce that the order is
always the same.

N.B. decorators in Python execute from closest to furthest (from the
line on which the function is defined).
2019-07-03 09:54:17 +01:00
Katie Smith
5be6b41195 Allow Welsh characters in SMS
- This brings in the latest version of notifications-utils which
allows Welsh characters in SMS templates.
- Updated the pricing page to show the new prices for SMS with certain
Welsh characters
2019-05-15 14:20:49 +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
Pea Tyczynska
0743a68e09 Reflect template folder structure on inbound conversation reply page 2019-03-21 16:06:47 +00:00
Pea Tyczynska
3fc4f6866c When replying to inbound sms show templates in all user's folders 2019-03-21 16:06:47 +00:00
Leo Hemsted
f83910599c remove option for branding to sometimes not show search
it wouldn't show search if there were under a certain amount of letter
or email branding options - however we know there will always be more
than that amount so lets remove some complexity.

Also, rename the SearchTemplatesForm because it can search anything -
it just prompts you to search by name is all.
2019-02-07 11:39:23 +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
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
Leo Hemsted
236339435c conversations only looks for 404 errors from inbound sms
stops masking some 503s in tests
2018-05-03 16:33:37 +01:00
chrisw
f5c467e4ff add pagination to inbox page 2018-04-04 15:41:17 +01:00
Chris Waszczuk
6153389e01 Revert "add pagination to inbox page" 2018-04-04 14:18:03 +01:00
chrisw
50661faac0 add pagination to inbox page 2018-04-03 12:12:30 +01:00
Rebecca Law
58de759ef4 Fix bug with inbound message page
The get notifications endpoint needs the template_type for search. The inbox page for inbound sms messages was not passing that through, which caused a 400 response.
This resolves that by passing the template_type to the api.
2018-03-12 12:44:32 +00: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
6325f26081 Revert "Stop escaping special characters in inbound messages" 2017-11-07 17:22:57 +00:00
Chris Hill-Scott
f329e138cd Factor out string escaping code
So that it only lives in one place.
2017-11-06 13:24:16 +00:00
Chris Hill-Scott
f6950ae987 Stop escaping special characters in inbound
At least one of our providers gives us messages with special characters
escaped, ie a newline comes through as `\n`, not a literal newline. We
shouldn’t be showing these backslashes to any of our users.

Python has built in codecs for dealing with encoding/decoding of
strings – see
https://docs.python.org/3/library/codecs.html#text-encodings
for details. Using these builtins is safer than trying to do anything
regex or parsing-based.
2017-11-06 13:24:16 +00:00
Chris Hill-Scott
fed4275403 Factor out code that gets message content
The nesting is getting pretty deep here. Let’s make it into its own
method so it doesn’t get out of hand when we add more functionality to
it.
2017-11-06 13:10:02 +00:00
Chris Hill-Scott
91cdc9ffcb Auto populate the phone number when replying
Currently the only way of ‘replying’ to an inbound message is by
copy/pasting the phone number from the inbound page into the send one
off page. Rather than making people copy/paste, this commit puts the
phone number in the session, if the user is going through the new reply
flow.
2017-10-16 09:34:19 +01:00
Chris Hill-Scott
88f169d970 Add a page to pick a template to reply with
If your service is receiving inbound messages, you might want to reply
to them. Without an API integration, the only way to do this is by doing
the send one off flow. But currently there is no direct link from the
page which shows the inbound messages.

So this commit:
- adds a link to a new page…
- …which shows the available (ie only text message) templates with which
  you can reply
2017-10-16 09:33:59 +01:00
Leo Hemsted
57b4971ac1 update conftest and tests to contain accurate test data
specifically, we identify inbound vs outbound by presence of
"notify_number", so ensure that test content actually contains that
field
2017-09-29 10:15:17 +01:00
Leo Hemsted
b1e809e82a make sure inbound sms page doesn't break if you receive a blank inbound message 2017-09-28 15:37:18 +01:00
Chris Hill-Scott
dc3f26a646 Make conversation page update using AJAX
Fairly self-explanatory. Uses the same pattern of breaking things up
into functions as the jobs page.
2017-07-12 17:09:33 +01:00
Chris Hill-Scott
61fd27c4f6 Fix 500 on two-way conversation page
We changed the schema used by the endpoint that searches for
notifications by recipient. So the admin app was looking for the wrong
thing in the JSON.

This is hard to catch in tests because it relies on our fixtures
matching what the API really returns.

This commit fixes the code to use the correct key to lookup the template
content from the JSON.

This also exposed the fact that we weren’t passing in the
personalisation any more (perhaps got lost in the re-reverts somehow)
so users were only seeing the template in the inbound view, not the
full message content.
2017-07-07 10:16:33 +01:00
Chris Hill-Scott
7e8471f21f Look at body, not template in outbound texts
As of this PR we don’t return the template content any more:
https://github.com/alphagov/notifications-api/pull/1015
2017-06-14 17:44:50 +01:00
Chris Hill-Scott
eabd3f551a Add tests for getting a user’s phone number
Also makes the code a bit more specific by not squashing any exception,
only `HTTPError`s.
2017-06-14 15:37:57 +01:00
Chris Hill-Scott
bff9365d1b Let users send inbound emoji
Implements:
- [ ] https://github.com/alphagov/notifications-utils/pull/167

Required some refactoring to be able to defined the `is_inbound`
variable.
2017-06-10 12:03:37 +01:00
Chris Hill-Scott
f6d8e55579 Add two-way messaging view
> Once an inbound message has been received, there should be a way to
> see the other messages in the system from the same service to the same
> number. Both in and outbound. Nice inbox/whatsapp stylee view or some
> such. This way the context of the reply is understood.
>
> Initially will only see the outbound template, not the actual message,
> but we’re going to change this for the rest (soon), so that you can
> always see the full message for all outbound.
2017-06-10 12:03:10 +01:00