Commit Graph

387 Commits

Author SHA1 Message Date
Leo Hemsted
1cd8000236 remove browsableitem
it was only used by the choose service page, and then only in kludgy
ways (eg: creating a list containing one item called "add service"),
so lets rip it out and make this page bespoke. Especially now that it's
changed so much.
2018-03-14 15:39:55 +00:00
Leo Hemsted
ee665caa7d get orgs and services from user
this endpoint should probably only be used for the choose-service page
also create an OrganisationBrowsableItem to aid rendering of them
in the front-end.
2018-03-14 15:39:55 +00:00
Chris Waszczuk
4b929aaa6c Merge pull request #1934 from alphagov/update-service-name
Update Organisation Name
2018-03-12 10:13:57 +00:00
Leo Hemsted
34d039d85a Merge pull request #1945 from alphagov/org-invite-api-fix
fix org invite api client
2018-03-09 12:18:25 +00:00
Leo Hemsted
09f7de8015 fix org invite api client 2018-03-09 11:45:20 +00:00
Chris Hill-Scott
240f11e715 Fix count of users on request to go live
We were counting users who had the `manage_settings` permission. This
is the old name for it, therefore there would never be any users with
this permission, so the tick would never go green.

The new name for the permission is `manage_service`. This commit fixes
the error, and adds an extra safeguard against something like this
happening again.
2018-03-09 10:52:13 +00:00
Ken Tsang
4628b99445 Refactor to move preview logic to API
* Moved the notifications code to go to admin to get the the template

preview document rather than go to template preview.

This will remove the logic from admin and place it in api so it is
easier to expand on later when there are precompiled PDFs

* Added some error handling if API returns an API error.

Caught the error and displayed an error PNG so it is obvious something
failed. Currently it displayed a thumbnail of a png over the top of the
loading page, and therefore it wasn't obvious of the state.
2018-03-08 12:25:07 +00:00
chrisw
e32cb5df31 update organisation name 2018-03-06 17:28:04 +00:00
Rebecca Law
bc731ec54d Revert "Letter preview use api not template preview" 2018-03-06 13:47:43 +00:00
Leo Hemsted
793d79c242 ensure invited user permissions show up correctly 2018-03-06 13:08:07 +00:00
Leo Hemsted
7f268c0ab3 don't allow us to create permissions decorator without permissions
ie: not for an organisation, and not for a service
2018-03-06 13:08:07 +00:00
Leo Hemsted
d14f33ea70 has_permissions() now checks user's orgs for <org_id> view args
view args are parameters within the route. for example,
`/organisation/<org_id>/users`. If there is an org_id, then check that
the user is part of that organisation (users.organisations is a list of
all orgs that user is a member of).

* platform admins ignore this check if restrict_admin_usage=False
* if an endpoint has both org_id and service_id, org_id takes
  precedence, but we should probably revisit this if we ever need
  to create such an endpoint.
* you now call `@user_has_permissions()` with no arguments for
  organisation endpoints - we can look at this if we decide we want
  more clarity.
* you should never call user_has_permissions without any arguments
  for endpoints that aren't organisation-based. We'll raise
  NotImplementedError if you do.
2018-03-06 13:08:07 +00:00
Leo Hemsted
3d589887ce remove useless properties from user model
we don't need them to mask private variables if we're not doing anything unusual.
2018-03-06 13:08:07 +00:00
Leo Hemsted
3afc193624 remove any_ from has_permissions
we branch on any_ to either say "require ALL these permissions" or
"require ANY of these permissions". But we only ever call the decorator
with one permission, or with any_=True, so it's unnecessary
2018-03-06 13:08:07 +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
3ae815528c add restrict_admin_usage arg to admin_override
rather than allow admins to do everything specifically, we should
only block them from things we conciously don't want them to do.
This is "Don't let platform admins send letters from services they're
not in". Everything else the platform admins can do.

This is step one, adding a restrict_admin_usage flag, and setting that
for those restricted endpoints around creating api keys, uploading CSVs
and sending one-off messages.

Also, this commit separates the two use cases for permissions:
* user.has_permission for access control
* user.has_permission_for_service for user info - this is used for
  showing checkboxes on the manage-users page for example

With this, we can remove the admin_override flag from the permission
decorator.
2018-03-06 13:08:06 +00: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
Leo Hemsted
bd54dbb40c remove unnecessary invocations of has_permissions(..., any_=True)
when added to a service, all users are given the view_activity
permission. So, if that's included in the list, we don't need `any_`,
and we don't need any of the other permissions.
2018-03-06 13:08:06 +00:00
kentsanggds
acf7b331ad Merge pull request #1918 from alphagov/letter_preview_use_api_not_template_preview
Letter preview use api not template preview
2018-03-05 16:21:12 +00:00
Ken Tsang
6279169b18 WIP refactor preview pdf 2018-03-01 15:21:50 +00:00
Richard Chapman
c4f0b4d35d Moved the notifications code to go to admin to get the the template
preview document rather than go to template preview.

This will remove the logic from admin and place it in api so it is
easier to expand on later when there are precompiled PDFs
2018-03-01 15:21:50 +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
d638b446f5 Merge branch 'master' into becca-invite-users 2018-02-27 10:13:40 +00:00
Rebecca Law
41309721bd - Remove organisation setter for the user model.
- Revert the change to the log level for admin.
2018-02-26 22:18:46 +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
96aac519cc Extend user client to count users with permission
One of the things we need to know for a service to go live is whether
they have at least two users with the ‘manage service’ permission.

So this commit adds a method to the client to count how many users have
a given permission. We can do logic on this count later. But having the
counting done in the client feels like a cleaner separation of concerns.

Meant some refactoring of the way `service_id` is extracted from the
request, in order to make it easier to mock.
2018-02-26 08:53:45 +00:00
Chris Hill-Scott
51f0320aec Add API client method to count templates
When users request to go live we check stuff like:
- if they’ve added templates
- if they have email templates (then we can check their reply to
  address)

This commit adds a method to do this programatically rather than
manually.

We _could_ do this in SQL, but for page that’s used intermittently it
doesn’t feel worth the work/optimisation (and the client method is at
least in place now if we do ever need to lean on this code more
heavily).
2018-02-26 08:53:45 +00:00
chrisw
22bbc0d6d8 invite-team-members 2018-02-23 11:43:13 +00:00
chrisw
96b66829a1 organisation-dashboard 2018-02-19 16:56:16 +00:00
Chris Waszczuk
34f1b40dbc Merge pull request #1858 from gov-cjwaszczuk/link-service-to-organisation
Link services to organisations (Admin)
2018-02-14 12:30:15 +00:00
Katie Smith
84d810b981 Pass service_id through to API '/service/unique' endpoint
Notifications-api now needs the service_id to check the uniqueness of
the service name when trying to change it. This is to allow a user to
successfully change the pluralization or the case of their service name.
2018-02-13 15:57:19 +00:00
chrisw
1450138b9c link-services-to-organisations 2018-02-13 12:49:57 +00:00
Ken Tsang
b11bfd49e3 Add Organisations API Client 2018-02-12 12:27:06 +00:00
Chris Hill-Scott
1908e7b091 Tell API what URL to use for email auth links
So that we can keep people on the prototype URL when doing user
research.

Depends on:
- [ ] https://github.com/alphagov/notifications-api/pull/1645
2018-02-09 15:01:20 +00:00
chrisw
9ad4435d94 Change organisations to email branding 2018-02-07 17:41:23 +00:00
Chris Hill-Scott
2221a8ca48 Change display of cancelled users, fix edit link
It’s confusing showing green ticks for cancelled invites. This commit
changes the appearance so that only pending or active users (ie those
that could actually do some damage) get green ticks.

Also fixes missing edit links caused by instances of `User` having
`.state` but instances of `InvitedUser` having `.status`.

Right now these are two separate lists. Which makes it harder to add
improvements that will make large numbers of users easier to manage.
2018-01-29 15:23:54 +00:00
Chris Hill-Scott
e573f492db Check for unknown permissions
This guards against anyone mispelling or using the wrong words for a
permission, which could introduce unexpected or hard to catch errors.
2018-01-16 11:24:37 +00:00
Chris Hill-Scott
f2418c171c Move roles to models file
Any time we can keep code out of the view files is good. This user stuff
seems like a sensible place to put it, since we’re going to use it
there.
2018-01-16 11:23:48 +00:00
Chris Hill-Scott
d9a63c07a9 Refactor user permissions to use args, not list
This makes the interface a bit cleaner and less verbose.
2018-01-16 11:22:57 +00:00
chrisw
7271d4fbde Allow letter templates to select the default contact block from the list 2018-01-10 11:20: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
Leo Hemsted
99db15d975 fix notifications-python-client version import 2017-12-28 10:05:54 +00:00
chrisw
43c14fb756 Allow service to set callback url for notifications 2017-12-08 10:52:50 +00:00
Leo Hemsted
2a28278cb8 make sure service api client doesnt expect free sms fragment 2017-12-04 16:57:00 +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
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
Venus Bailey
f039e64a6d Merge pull request #1594 from alphagov/vb-free-sms-history
Use annual_billing tables at backend for getting and updating free_sm…
2017-11-15 14:57:46 +00:00
Leo Hemsted
65ba7e88c8 refactor RegisterFromInvite to make auth_type required, and update test fixtures 2017-11-14 15:18:14 +00:00
venusbb
581759931f Merge branch 'master' of https://github.com/alphagov/notifications-admin into vb-free-sms-history 2017-11-14 09:40:05 +00:00