Commit Graph

65 Commits

Author SHA1 Message Date
Cliff Hill
6e3a569a0a Resend invites works.
Signed-off-by: Cliff Hill <clifford.hill@gsa.gov>
2024-11-07 09:56:18 -05:00
Cliff Hill
14bbabcab7 Invites are now working.
Signed-off-by: Cliff Hill <clifford.hill@gsa.gov>
2024-11-07 08:37:45 -05:00
Cliff Hill
95a39cfd31 Trying to get invites to flow correctly.
Signed-off-by: Cliff Hill <clifford.hill@gsa.gov>
2024-11-06 16:04:18 -05:00
Cliff Hill
f363a8e184 Getting all the needed data in place.
Signed-off-by: Cliff Hill <clifford.hill@gsa.gov>
2024-11-06 14:30:28 -05:00
Cliff Hill
d798d3695e More little fixes.
Signed-off-by: Cliff Hill <clifford.hill@gsa.gov>
2024-11-06 10:48:28 -05:00
Cliff Hill
c8ed66cbfe Storing user data in redis.
Signed-off-by: Cliff Hill <clifford.hill@gsa.gov>
2024-11-06 10:41:20 -05:00
Cliff Hill
b532ce8959 Fixing tests, and resend invites endpoint.
Signed-off-by: Cliff Hill <clifford.hill@gsa.gov>
2024-11-06 08:20:11 -05:00
Cliff Hill
a39c844c30 Properly handling and validating the state for login.gov
Signed-off-by: Cliff Hill <clifford.hill@gsa.gov>
2024-11-06 08:20:10 -05:00
Cliff Hill
579a65c92d Removed defunct imports.
Signed-off-by: Cliff Hill <clifford.hill@gsa.gov>
2024-10-21 16:41:49 -04:00
Cliff Hill
7275dac6a0 black, isort, and flake8.
Signed-off-by: Cliff Hill <clifford.hill@gsa.gov>
2024-10-21 16:41:49 -04:00
Cliff Hill
8c40538334 Nonce is working now for invites.
Signed-off-by: Cliff Hill <clifford.hill@gsa.gov>
2024-10-21 16:41:49 -04:00
Cliff Hill
da6882774b Getting the redis stuff configured correctly.
Signed-off-by: Cliff Hill <clifford.hill@gsa.gov>
2024-10-21 16:41:49 -04:00
Cliff Hill
d0cda995cf Standardising nonce storage/retrieval through redis for both login and
invite.

Signed-off-by: Cliff Hill <clifford.hill@gsa.gov>
2024-10-21 16:41:49 -04:00
Cliff Hill
82cef7dbd3 Nonce stuff added.
Signed-off-by: Cliff Hill <clifford.hill@gsa.gov>
2024-10-21 16:41:33 -04:00
Cliff Hill
09e011fc9f black, isort, flake8
Signed-off-by: Cliff Hill <clifford.hill@gsa.gov>
2023-12-20 14:53:02 -05:00
Cliff Hill
0e7b371f90 Got tests in place.
Signed-off-by: Cliff Hill <clifford.hill@gsa.gov>
2023-12-20 14:53:02 -05:00
Cliff Hill
6f43be69ba Wired up admin to send resend invite request to api.
Signed-off-by: Cliff Hill <clifford.hill@gsa.gov>
2023-12-20 14:53:02 -05:00
Cliff Hill
f308b85715 Cleaning up string formatting in invite_api_client.py.
Signed-off-by: Cliff Hill <clifford.hill@gsa.gov>
2023-12-20 14:53:02 -05:00
Kenneth Kehl
8c9721d8e2 notify-api-412 use black to enforce python coding style 2023-08-25 09:12:23 -07:00
jimmoffet
69abec0bb3 change dashboard test to reflect demo changes to uploads view 2022-09-09 17:02:48 -07:00
jimmoffet
dad051a662 2767 passing 2022-08-05 00:25:03 -07:00
James Moffet
f1d9aef9cd comment cache decorator 2022-07-19 18:31:01 -07:00
Ben Thorner
dcfff87cc0 Continue to remove "roles" terminology
This renames the two functions we have to translate between UI and
DB permissions, as well as some of their associated variables to
make it clearer which kind of permission they contain.
2021-07-28 12:37:17 +01:00
Ben Thorner
ba9865e62e Start to remove use of the term "roles"
We don't use this term consistently and it's not defined anywhere.
Since most of the Admin app deals with user-facing permssions, it's
OK to just use the term "permissions". Where both types of permission
are present in the same file, we can more clearly distinguish them
as "UI permissions" and "DB permissions".
2021-07-28 12:37:16 +01:00
Ben Thorner
1127a03c32 Move and rename roles_and_permissions.py
This file does not represent a model, but rather a set of utilities
that are specific to user permissions (vs. service permissions).
2021-07-28 12:36:40 +01:00
Leo Hemsted
bf979128ab use new check api endpoints for validating invite tokens
added in https://github.com/alphagov/notifications-api/pull/3171
2021-03-15 12:22:00 +00:00
Leo Hemsted
45297eae43 store invited user ids in session
same as the invited org user ids in the previous commit
2021-03-15 12:21:58 +00:00
Leo Hemsted
c89be0079a rename get_invited_user funcs
make it clear they're expecting a service/org id
2021-03-12 15:59:32 +00:00
Katie Smith
895a9df55a Add confirmation banner when cancelling user invites
This shows the green banner with a tick when cancelling a user's
invitation to a service or organisation. The accessibility audit noted
that 'When cancelling an invite a new page loads, however, there is no
immediate indication that the invite has been cancelled.'

In order to display the invited user's email address as part of the
flash message, this adds new methods to the api clients for invites to get
a single invite.
2020-08-19 09:05:41 +01:00
Chris Hill-Scott
554a852e2d Don’t return UUID objects from the UUID convertor
Because it means you often have to cast to string in your application
code just to get your tests passing.

The method being monkey patched is originally defined here: b81aa0f18c/src/werkzeug/routing.py (L1272)
2019-11-07 13:46:24 +00:00
Chris Hill-Scott
628e344b36 Make user API client return JSON, not a model
The data flow of other bits of our application looks like this:
```
                         API (returns JSON)
                                  ⬇
          API client (returns a built in type, usually `dict`)
                                  ⬇
          Model (returns an instance, eg of type `Service`)
                                  ⬇
                         View (returns HTML)
```
The user API client was architected weirdly, in that it returned a model
directly, like this:

```
                         API (returns JSON)
                                  ⬇
    API client (returns a model, of type `User`, `InvitedUser`, etc)
                                  ⬇
                         View (returns HTML)
```

This mixing of different layers of the application is bad because it
makes it hard to write model code that doesn’t have circular
dependencies. As our application gets more complicated we will be
relying more on models to manage this complexity, so we should make it
easy, not hard to write them.

It also means that most of our mocking was of the User model, not just
the underlying JSON. So it would have been easy to introduce subtle bugs
to the user model, because it wasn’t being comprehensively tested. A lot
of the changed lines of code in this commit mean changing the tests to
mock only the JSON, which means that the model layer gets implicitly
tested.

For those reasons this commit changes the user API client to return
JSON, not an instance of `User` or other models.
2019-06-05 11:13:41 +01:00
Chris Hill-Scott
116f36192f Let inviting a user complete the go live checklist
At the moment you have to wait for whoever you’ve invited to accept the
invitation before you can go live. Since this check is mainly for the
benefit of the service, not us, we should trust that people’s intentions
are good when they invite someone.

So this commit also checks the invited users when counting how many team
members a service has.
2019-04-12 22:45:48 +01:00
Katie Smith
c39f6d49ea Set folder permissions when creating and accepting invites to services
Added a folder permissions form to the page to invite users to services.
This only shows if the service has 'edit_folder_permissions' enabled,
and all folder checkboxes are checked by default. This change means that
InviteApiClient.create_invite now sends folder_permissions through to
notifications_api (so invites get created with folder permissions).

Started passing the folder_permissions through to notifications-api when
accepting an invite. This changes UserApiClient.add_user_to_service to
send folder_permissions to notifications_api so that new users get folder
permissions when they are added to the service.
2019-03-21 10:17:05 +00:00
Chris Hill-Scott
1d3a4e5043 Inherit don’t duplicate API client constructor
This removes some code which is duplicative and obscure (ie it’s not
very clear why we do `"a" * 73` even though there is a Very Good Reason
for doing so).
2019-01-29 12:11:27 +00:00
Chris Hill-Scott
538a06c0bf Refactor filtering out accepted invites to client
None of our model or view layer code should need to know about accepted
invites. We don’t use them anywhere because once an invite is accepted
that person is now a user.

Putting this logic in the client means that:
- none of the code calling the client needs to care about accepted
  invites
- it’s easier to (if we want) update the API code to not return accepted
  invites
2018-12-03 11:06:03 +00:00
Chris Hill-Scott
e04b2b5631 Split models to prevent circular imports
This commit is the first step to disentangling the models from the API
clients. With the models in the same folder as the API clients it makes
it hard to import the API clients within the model without getting a
circular import.

After this commit the user API clients still has this problem, but at
least the service API client doesn’t.
2018-10-30 15:01:36 +00:00
Chris Hill-Scott
9e798506c5 Initialise clients outside the app
This avoids the annoying problem where you can’t import a client unless
the app has already been initialised.
2018-10-30 14:59:24 +00:00
Chris Hill-Scott
06de94f1c5 Rewrite cache decorator to use format string
This is easier to read than having to understand the arguments 1…n of
the cache decorator are ‘magic’, and gives us more flexibility about
how the cache keys are formatted, eg being able to add words in the
middle of them.

Also changes the key format for all templates to be
`service-{service_id}-templates` instead of `templates-{service_id}`
because then it’s clearer what the ID represents.
2018-04-20 16:32:02 +01:00
Chris Hill-Scott
6101e5da43 Rewrite cache decorator to reference args by name
`@cache.delete('user', 'user_id')` is easier to read and understand than
`@cache.delete('user', key_from_args=[1])`. This will become even more
apparent if we have to start doing stuff like `key_from_args=[1, 5]`,
which is a lot more opaque than just saying
`'service_id', 'template_id'`.

It does make the implementation a bit more complex, but I’m not too
worried about that because:
- the tests are solid
- it’s nicely encapsulated
2018-04-19 13:58:40 +01:00
Chris Hill-Scott
9a3f9b7273 Delete caches when user accepts invite
Accepting an invite changes:
- the `user_to_service` list of users returned by `GET /service/<id>`
- the `services` list return by `GET /user/<id>`

The latter change is causing the functional tests to fail.
2018-04-19 13:15:52 +01:00
Leo Hemsted
17061e0d06 map roles and db permissions
in the db, we have several rows for single permissions - we separate
`send_messages` into `send_texts`, `send_emails` and `send_letters`,
and also `manage_service` into `manage_users` and `manage_settings`.

But on the front end we don't do anything with this distinction. It's
unhelpful for us to have to think about permissions as groups of things
when we can never split them up at all. So we should combine them. This
commit makes sure:
* when user models are read  (from JSON direct from the API), we
  should transform them from db permissions into roles.
* when permissions are persisted (editing permissions, and creating
  invites), we should send db permissions to the API.

All other interaction with permissions (should just be the endpoint
decorator and checks in html templates generally) should use admin
roles.
2018-03-06 13:08:06 +00:00
Alexey Bezhan
acfe8092fc Add route secret key header to the API requests
Currently requests to the API made from the admin app are going from
PaaS admin app to the nginx router ELB, which then routes them back
to the api app on PaaS.

This makes sense for external requests, but for requests made from
the admin app we could skip nginx and go directly to the api PaaS
host, which should reduce load on the nginx instances and
potentially reduce latency of the api requests.

API apps on PaaS are checking the X-Custom-Forwarder header (which
is set by nginx on proxy_pass requests) to only allow requests going
through the proxy.

This adds the custom header to the API client requests, so that they
can pass that header check without going through nginx.
2018-02-28 11:28:46 +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
Rebecca Law
298eb77b54 Refactor the check token endpoint to use the newly merged api endpoints. 2018-02-26 11:50:40 +00:00
Chris Hill-Scott
86d76baa0d Have admin specify host to use for invite links
When we’re doing user research we often:
- start the task by inviting the participant to a service on Notify
- have them use a prototype version of the admin app, hosted on a
  different domain

Currently we can’t do both of these things together, because the invite
emails always send people to notifications.service.gov.uk (because it’s
the API that sends the emails, and the prototype admin app points at the
production API).

This commit changes the admin app to tell the API which host to use when
creating the invite links.

Depends on:
- [ ] https://github.com/alphagov/notifications-api/pull/1515
2018-01-03 10:37:29 +00:00
chrisw
c6ea90a7d8 Email auth for inviting members and editing permissions 2017-11-02 12:38:01 +00:00
Chris Hill-Scott
415e1a401a Don’t set combined API on Notify python client
Because we’re setting the API key and service ID after calling the
`__init__` method of the client it wasn’t doing the thing where it
splits the combined key into the two individual UUIDs. So we still need
to set them directly, individually on the client.
2017-07-26 12:08:10 +01:00
Chris Hill-Scott
5ddbe80ea9 Fix calls to API client which now takes fewer args
The Notify API client changed in version 4 to take two arguments, not
three (service ID was removed in favour of the combined API key).

This gets a bit gnarly because the API key has to be at least a certain
length so it can be substringed internally.
2017-07-26 11:10:37 +01:00
Martyn Inglis
08dc8fb13d Use the local APIClient rather than the one from the python-api-client
- ensures that all API calls set the request ID when talking to the API.
2016-11-30 17:01:44 +00:00
Chris Hill-Scott
92aacc1a54 Remove extraneous arguments to super
> dont need self.__class__, self in super - that's a python 2.x crutch.
> super() is equivalent
2016-09-12 14:59:53 +01:00