Commit Graph

245 Commits

Author SHA1 Message Date
Pea Tyczynska
e6e363ba3f Add antivirus scan to letter validation preview view 2018-10-05 16:27:57 +01:00
Chris Hill-Scott
c2ef522986 Make task list read better for screen readers
This duplicates how the task list pattern is coded in the GOV.UK
Prototype kit[1]. It adds ARIA attributes and the use of a
semantically-meaningful element (`<strong>`) to give more information to
screen reader users.

1. https://govuk-prototype-kit.herokuapp.com/docs/templates/task-list
2018-09-25 10:31:40 +01:00
Chris Hill-Scott
c59142b871 Map ‘pending’ status to ‘sending’
For some reason we are getting pending back as a status from one of
our text message providers.

Because this is unrecognised by the admin app it shows up in the list of
messages as the raw status, styled like an error.

This commit maps it to sending instead, because the user doesn’t need to
know or care about the difference.
2018-09-11 13:46:33 +01:00
Alexey Bezhan
b75681dfbc Add a platform admin page to submit returned letter references
A platform admin form accepts a list of references (one per line)
received from DVLA and sends them to the API to update notification
statuses.

References we get from DVLA start with `NOTIFY00\d`, which isn't
part of the reference we store in the database, so we remove them
before sending the data to the API.

The new `returned-letter` status should be treated as `delivered`
for now until we decide a way to display returned letters to users.
2018-09-07 11:13:01 +01:00
Tom Byers
7b955ffad2 Add 'self' to 'frame-src' header
Allows iframes to contain pages from the same
domain as the parent page.
2018-08-07 16:56:36 +01:00
Rebecca Law
ae1f1c95d6 Merge branch 'master' into flexible-data-retention 2018-08-06 15:37:11 +01:00
Chris Hill-Scott
036923c382 Make a service model and use for permissions
Having the service floating about as JSON is a bit flakey. Could easily
introduce a mistake where you mistype the name of a key and silently
get `None`.

Also means doing awkward things like `if 'permission' in
current_service['permissions']`, whereas for users we can do the
much cleaner `user.has_permission()`.

So this commit:
- introduces a model
- adds a `.has_permission` method similar to the one we have for users
2018-07-30 14:56:36 +01:00
Rebecca Law
4b8b571a87 Adding views to view, add and edit service data retention policies.
Only visible to a platform admin.
A service can have a custom number of days to retain the notification data for each notification type.
2018-07-17 14:39:04 +01:00
Chris Hill-Scott
84de1c5625 Let caseworkers send one off messages
The main task that we think ‘caseworker’ users do is send one off
messages.

So this commit:
- makes sure users who don’t have the `view_activity` permission (ie
  not ‘admin’ users) can still send messages
- adds navigation so that these users have a place to go from which to
  start the process of sending a one off message
2018-07-05 11:53:42 +01:00
Katie Smith
ca16bef7f7 Add PlatformStatsAPIClient
In API, the endpoint for the new platform admin stats page has been
moved to a platform stats blueprint. This means we now need a platform
stats client.
2018-06-29 15:31:41 +01:00
Leo Hemsted
e81f302084 handle 405 METHOD NOT ALLOWEDs
(show the "something went wrong" error page).

also catch any other werkzeug http exceptions and show an appropriate
template, if it exists
2018-06-22 18:07:18 +01:00
Chris Hill-Scott
81dc9a0092 Merge pull request #2063 from alphagov/pyup-update-flask-0.12.2-to-1.0.2
Update flask to 1.0.2
2018-06-18 13:51:14 +01:00
Rebecca Law
84445d154d When someone complains about an email from the platform we get a callback from SES.
A new platform admin page Email complaints has been added to surface those complaints.
Eventually the complaints will be visible to the services so they can remove the email address from their mailing list.

Next thing to implement is "x email complaints" warning on the platform admin summary page.
2018-06-06 15:22:48 +01:00
Rebecca Law
886ed01638 Flask has change how it handles werkzeug.routing.RequestRedirect, we need to add an errorhandler so that the request does the right thing.
Refer to: https://github.com/pallets/flask/issues/671#issuecomment-305394901
2018-05-30 14:54:25 +01:00
Rebecca Law
869e5cd766 Added a 400 error handler 2018-05-30 14:01:19 +01:00
Katie Smith
58cc1604a7 Bump utils and sanitise header values
Updated notifications-utils. This brings in
- the renamed character sanitization classes
- the change to allow unicode in letter addresses (this lets us delete
a test that is no longer relevant)

Also replaced non-ascii characters in headers. This fixes a bug where
non-ascii characters in a CSV filename were causing errors since the
filename is also used in the header.
2018-05-25 10:34:47 +01:00
Chris Hill-Scott
872d9ea62b Merge pull request #2033 from alphagov/selected-nav
Highlight selected navigation item
2018-04-27 16:38:27 +01:00
Chris Hill-Scott
9f5d42a788 Add selected navigation for organisations page
To match how the navigation works for a single service.
2018-04-25 13:17:47 +01:00
Chris Hill-Scott
8a7525a809 Highlight selected item in proposition navigation
It is standard practice when using GOV.UK template to highlight the
selected navigation item in the propositional navigation (black bar) by
colouring it blue.

This commit adds a new subclass of `Navigation` with the mapping needed
to decide which pages belong to which item in the navigation (or none
at all).
2018-04-25 11:30:39 +01:00
Chris Hill-Scott
e1fd63e184 Rewrite navigation as a class
Because we have multiple navigations, which will share the same methods
(by subclassing) but different mappings of navigation items to endpoints
by overriding the `.mapping` and `.exclude` attributes.
2018-04-25 11:15:13 +01:00
Chris Hill-Scott
1fba5d186d Highlight selected navigation item
In research I’ve sometimes seen people click the wrong nav item. I
reckon that people’s concept of which pages live behind which navigation
items isn’t very strong.

We can reinforce this relationship by showing, for every page, which is
the corresponding nav item. The conventional way of doing this is either
with some kind of emphasis, typically colour or bold. I’ve gone for bold
because colour would be weird.

---

The implementation of this is quite loosely coupled to our application
code because:
- our application code is not well structured (eg we don’t make any use
  of blueprints)
- spreading this change across lots of files in our application would
  make it harder to test without actually hitting each endpoints; such
  tests would be slow and verbose

So I’ve gone for more of a meta approach. Rather than testing that each
endpoint has a specific navigation item selected, I’ve gone for
validating that:
- all endpoints being mapped to are real
- all endpoints have _a_ selected navigation item (or are specifically
  excluded)

This means that it’s impossible to add, change or remove an endpoint
without also updating which navigation item should be selected. And the
actual mapping is so declarative that it testing it would be redundant.
2018-04-25 09:37:35 +01:00
Leo Hemsted
d675ceb5c2 send zendesk rather than deskpro tickets 2018-04-24 17:37:15 +01:00
Leo Hemsted
df30562216 fix relative datetime function to handle dates correctly
Previously, we were looking at the day of the week - so messages sent
six days ago would show up as "tomorrow". We now look at the actual
date, so that won't happen again.

We were also subtracting an hour to make 00:00 this evening show up as
"midnight today", despite it technically being tomorrow. However, this
means that 00:59 tomorrow morning would show up as "00:59 today", a
full day out. So reduce that to just a minute, so it doesn't affect
other times of day.
2018-03-21 16:08:09 +00:00
Katie Smith
4db75f6a58 Display the two new virus states for letters
Precompiled letters can now have two additional states:
* pending-virus-check
* virus-scan-failed

Both new states should show in the notifications dashboard, and
virus-scan-failed should appear as an error state, with a descriptive
message. You should not be able to preview a letter in one of the two
new states, so the preview link has been removed for precompiled letters
in these states.
2018-03-20 14:54:29 +00:00
Leo Hemsted
29ae0118f3 log as exception if the api returns 5xx
if it returns 400 only log warning, as they're much less urgent. it's
probably someone clicking an old invite or something.
2018-03-14 15:39:55 +00:00
Leo Hemsted
04bfc362a2 save the organisation to the session after the user visits an org page
also remove the service/org from the session if the user is on a diff
type page, to make sure the redirects from /services-or-dashboard plays
nicely
2018-03-14 15:39:55 +00:00
Athanasios Voutsadakis
1764499a25 Merge branch 'master' into error-handling 2018-03-09 10:17:17 +00:00
Athanasios Voutsadakis
249ae41c24 Add error handling
This adds an /error/XXX endpoint that triggers the corresponding XXX
error code and its handling.

Related: https://github.com/alphagov/notifications-aws/pull/331
2018-03-08 17:49:08 +00:00
Chris Hill-Scott
d90cdc1f81 Don’t change colour of sent date for letters
For text messages/emails it makes sense for ‘sending’ to be gray and
‘delivered’ to be black. But since we don’t show sending/delivered for
letters it doesn’t make sense for the text to change colour.
2018-03-06 13:51:50 +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
chrisw
22bbc0d6d8 invite-team-members 2018-02-23 11:43:13 +00:00
chrisw
dd2231056d organisation dashboard page 2018-02-19 16:56:16 +00:00
Ken Tsang
c1e3658a8f Add load org before request to allow current_org to be accessible from request context 2018-02-19 16:56:16 +00:00
chrisw
96b66829a1 organisation-dashboard 2018-02-19 16:56:16 +00:00
Leo Hemsted
08fb149b5f don't log 404s as ERROR 2018-02-12 16:02:33 +00:00
Ken Tsang
b11bfd49e3 Add Organisations API Client 2018-02-12 12:27:06 +00:00
chrisw
5d26d4457f manage api keys permission should be able to see senders 2018-02-08 11:25:49 +00:00
chrisw
9ad4435d94 Change organisations to email branding 2018-02-07 17:41:23 +00:00
Alexey Bezhan
a23efc9a93 Replace Deskpro ad-hoc requests with a client from utils
Moves the duplicated calls to Deskpro to notification_utils and
rewrites feedback and service go-live requests to use the shared
client.
2018-01-17 14:31:27 +00:00
Leo Hemsted
b9f7fa1f6f Replace cookie implementation with flask builtin secure cookie.
However, by default, session cookies don't expire (only cleared out by
the end user's browser).

This is dumb. You'd think, given that there's
`config['PERMANENT_SESSION_LIFETIME']`, that you'd enable permanent
sessions in the config too - but no, you have to declare it for each
request. session.permanent is also, helpfully, a way of saying that the
session isn't permanent - in that, it will expire on its own, as
opposed to being controlled by the browser's session. Because session
is a proxy, it's only accessible from within a request context, so we
need to set this before every request 🙄

http://flask.pocoo.org/docs/0.12/api/#flask.session
https://stackoverflow.com/questions/34118093/flask-permanent-session-where-to-define-them
2018-01-09 16:45:48 +00:00
Leo Hemsted
18b50ddfde error handlers should not raise. Not even abort(400)s.
Refactor csrf handler into the normal error handler area, and then add
some tests to make sure it does the right thing. Also, change it back
to a 400, because the 403 err page talks about being in the wrong
place, but this is about sending the wrong data through, even though
it's technically a 403. Will need to think about wording but this is a
fine first pass
2017-11-28 12:28:16 +00:00
Athanasios Voutsadakis
c38d10d773 Change the CSRF error from 400 to 403
All 400s are handled by a generic errorhandler which logs them and
converts them to 500.

We don't need to be alerted for CSRF problems.
2017-11-28 11:44:59 +00:00
Athanasios Voutsadakis
f8b8cdece7 No need to put the before_request down there 2017-11-16 16:25:40 +00:00
Athanasios Voutsadakis
fce8129f3e Merge branch 'master' into add_proxy_header_check 2017-11-16 11:09:32 +00:00
Leo Hemsted
b8c8372f77 Merge pull request #1617 from alphagov/remove-flask-script
remove flask-script
2017-11-15 17:47:30 +00:00
Athanasios Voutsadakis
5f0e6beb79 Add before_request to check header 2017-11-14 14:40:32 +00:00
Athanasios Voutsadakis
a7dbde39e9 Rename utils module 2017-11-14 14:38:26 +00:00
Leo Hemsted
ca373e9d88 add templates in a loop 2017-11-09 15:54:49 +00:00
Leo Hemsted
4aeb57567a remove flask-script
flask-script has been deprecated by the internal flask.cli module, but
making this carries a few changes with it

* you should add FLASK_APP=application.py and FLASK_DEBUG=1 to your
  environment.sh.
* instead of using `python app.py runserver`, now you must run
  `flask run -p 6012`. The -p command is important - the port must be
  set before the config is loaded, so that it can live reload nicely.
  (https://github.com/pallets/flask/issues/2113#issuecomment-268014481)
* find available commands by just running `flask`.
* run them using flask. eg `flask list_routes`
* define new tasks by giving them the decorator
  `@app.cli.command('task-name')`. Task name isn't needed if it's just
  the same as the function name. Alternatively, if app isn't available
  in the current scope, you can invoke the decorator directly, as seen
  in app/commands.py
2017-11-06 17:33:04 +00:00
Chris Hill-Scott
1d10ad2247 Stop content security policy blocking GA
In https://github.com/alphagov/notifications-admin/pull/1583 we changed
our Google Analytics settings to use newer browsers’ `sendBeacon`
feature. The advantage of this is that it

> [ensures] that the data has been sent during the unloading of a
> document [which] is something that has traditionally been difficult
> for developers

– https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon

To transmit this data it uses a AJAX request (`XMLHttpRequest`)
underneath. AJAX requests are governed by the `connect-src` content
security policy (or the `default-src` if one is not present).
`connect-src`:

> Applies to XMLHttpRequest (AJAX), WebSocket or EventSource. If not
> allowed the browser emulates a 400 HTTP status code.

– https://content-security-policy.com/

Because we didn’t have one in place, `sendBeacon` requests to GA were
getting blocked in browsers that support content security policy (pretty
much everything better than IE11[1]).

1. https://caniuse.com/#feat=beacon
2017-11-06 10:25:30 +00:00