Files
notifications-admin/app/main/validators.py
Chris Hill-Scott 1df3c11ae9 Split support into two pages
The kind of communications we’re getting at the moment can broadly be
broken down into:
- problems
- questions and feedback

We will need to triage problems differently, because they could
potentially be urgent/severe/emergency/P1/whatever language we use.
Questions or feedback will never be P1.

Two reasons for making the user categorise their tickets themselves:

- Outside of hours we can’t get someone out of bed in order to decide if
  a ticket is a problem or just feedback

- We can tailor the subsequent pages to whether it’s a problem or
  feedback (eg showing a link to the status page if the user is having
  a problem)

This commit let’s users make the choice with a pair of radio buttons.

It also cleans up a bunch of the tests and parameterizes them so we’re
testing the flow for both ticket types.
2017-02-02 15:18:40 +00:00

51 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from wtforms import ValidationError
from notifications_utils.template import Template
from app.utils import (
Spreadsheet,
is_gov_user
)
from ._blacklisted_passwords import blacklisted_passwords
class Blacklist(object):
def __init__(self, message=None):
if not message:
message = 'Password is blacklisted.'
self.message = message
def __call__(self, form, field):
if field.data in blacklisted_passwords:
raise ValidationError(self.message)
class CsvFileValidator(object):
def __init__(self, message='Not a csv file'):
self.message = message
def __call__(self, form, field):
if not Spreadsheet.can_handle(field.data.filename):
raise ValidationError("{} isnt a spreadsheet that Notify can read".format(field.data.filename))
class ValidGovEmail(object):
def __call__(self, form, field):
from flask import url_for
message = (
'Enter a central government email address.'
' If you think you should have access'
' <a href="{}">contact us</a>').format(url_for('main.support'))
if not is_gov_user(field.data.lower()):
raise ValidationError(message)
class NoCommasInPlaceHolders():
def __init__(self, message='You cant have commas in your fields'):
self.message = message
def __call__(self, form, field):
if ',' in ''.join(Template({'content': field.data}).placeholders):
raise ValidationError(self.message)