mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-07 15:48:24 -04:00
handle if user doesn't provide name/email
also clean up usage of DESKPRO_PERSON_EMAIL and put it in the conf rather than env
This commit is contained in:
@@ -61,7 +61,7 @@ in a separate terminal from the app
|
|||||||
|
|
||||||
```
|
```
|
||||||
echo "
|
echo "
|
||||||
export NOTIFY_ADMIN_ENVIRONMENT='config.Development'
|
export NOTIFY_ENVIRONMENT='development'
|
||||||
export ADMIN_CLIENT_SECRET='dev-notify-secret-key'
|
export ADMIN_CLIENT_SECRET='dev-notify-secret-key'
|
||||||
export ADMIN_CLIENT_USER_NAME='dev-notify-admin'
|
export ADMIN_CLIENT_USER_NAME='dev-notify-admin'
|
||||||
export API_HOST_NAME='http://localhost:6011'
|
export API_HOST_NAME='http://localhost:6011'
|
||||||
@@ -69,7 +69,6 @@ export DANGEROUS_SALT='dev-notify-salt'
|
|||||||
export SECRET_KEY='dev-notify-secret-key'
|
export SECRET_KEY='dev-notify-secret-key'
|
||||||
export DESKPRO_API_HOST=""
|
export DESKPRO_API_HOST=""
|
||||||
export DESKPRO_API_KEY=""
|
export DESKPRO_API_KEY=""
|
||||||
export DESKPRO_PERSON_EMAIL=""
|
|
||||||
export DESKPRO_DEPT_ID=""
|
export DESKPRO_DEPT_ID=""
|
||||||
export DESKPRO_ASSIGNED_AGENT_TEAM_ID=""
|
export DESKPRO_ASSIGNED_AGENT_TEAM_ID=""
|
||||||
"> environment.sh
|
"> environment.sh
|
||||||
|
|||||||
@@ -8,18 +8,19 @@ from app.main.forms import Feedback
|
|||||||
def feedback():
|
def feedback():
|
||||||
form = Feedback()
|
form = Feedback()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
|
user_supplied_email = form.email_address.data != ''
|
||||||
|
feedback_msg = 'Environment: {}\n{}\n{}'.format(
|
||||||
|
url_for('main.index', _external=True),
|
||||||
|
'' if user_supplied_email else '{} (no email address supplied)'.format(form.name.data),
|
||||||
|
form.feedback.data
|
||||||
|
)
|
||||||
data = {
|
data = {
|
||||||
'person_email': form.email_address.data,
|
'person_email': form.email_address.data or current_app.config.get('DESKPRO_PERSON_EMAIL'),
|
||||||
'person_name': form.name.data,
|
'person_name': form.name.data or None,
|
||||||
'department_id': current_app.config.get('DESKPRO_DEPT_ID'),
|
'department_id': current_app.config.get('DESKPRO_DEPT_ID'),
|
||||||
'agent_team_id': current_app.config.get('DESKPRO_ASSIGNED_AGENT_TEAM_ID'),
|
'agent_team_id': current_app.config.get('DESKPRO_ASSIGNED_AGENT_TEAM_ID'),
|
||||||
'subject': 'Notify feedback',
|
'subject': 'Notify feedback',
|
||||||
'message': 'Environment: {}\n\n{}\n{}\n{}'.format(
|
'message': feedback_msg
|
||||||
url_for('main.index', _external=True),
|
|
||||||
form.name.data,
|
|
||||||
form.email_address.data,
|
|
||||||
form.feedback.data
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
headers = {
|
headers = {
|
||||||
"X-DeskPRO-API-Key": current_app.config.get('DESKPRO_API_KEY'),
|
"X-DeskPRO-API-Key": current_app.config.get('DESKPRO_API_KEY'),
|
||||||
|
|||||||
@@ -108,9 +108,7 @@ def service_request_to_go_live(service_id):
|
|||||||
'department_id': current_app.config.get('DESKPRO_DEPT_ID'),
|
'department_id': current_app.config.get('DESKPRO_DEPT_ID'),
|
||||||
'agent_team_id': current_app.config.get('DESKPRO_ASSIGNED_AGENT_TEAM_ID'),
|
'agent_team_id': current_app.config.get('DESKPRO_ASSIGNED_AGENT_TEAM_ID'),
|
||||||
'subject': 'Request to go live',
|
'subject': 'Request to go live',
|
||||||
'message': "From {} <{}> on behalf of {} ({})\n\nUsage estimate\n---\n\n{}".format(
|
'message': "On behalf of {} ({})\n\nUsage estimate\n---\n\n{}".format(
|
||||||
current_user.name,
|
|
||||||
current_user.email_address,
|
|
||||||
current_service['name'],
|
current_service['name'],
|
||||||
url_for('main.service_dashboard', service_id=current_service['id'], _external=True),
|
url_for('main.service_dashboard', service_id=current_service['id'], _external=True),
|
||||||
form.usage.data
|
form.usage.data
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class Config(object):
|
|||||||
CSV_UPLOAD_BUCKET_NAME = 'local-notifications-csv-upload'
|
CSV_UPLOAD_BUCKET_NAME = 'local-notifications-csv-upload'
|
||||||
DESKPRO_API_HOST = os.environ['DESKPRO_API_HOST']
|
DESKPRO_API_HOST = os.environ['DESKPRO_API_HOST']
|
||||||
DESKPRO_API_KEY = os.environ['DESKPRO_API_KEY']
|
DESKPRO_API_KEY = os.environ['DESKPRO_API_KEY']
|
||||||
DESKPRO_PERSON_EMAIL = os.environ['DESKPRO_PERSON_EMAIL']
|
DESKPRO_PERSON_EMAIL = 'donotreply@notifications.service.gov.uk'
|
||||||
DESKPRO_DEPT_ID = os.environ['DESKPRO_DEPT_ID']
|
DESKPRO_DEPT_ID = os.environ['DESKPRO_DEPT_ID']
|
||||||
DESKPRO_ASSIGNED_AGENT_TEAM_ID = os.environ['DESKPRO_ASSIGNED_AGENT_TEAM_ID']
|
DESKPRO_ASSIGNED_AGENT_TEAM_ID = os.environ['DESKPRO_ASSIGNED_AGENT_TEAM_ID']
|
||||||
ACTIVITY_STATS_LIMIT_DAYS = 7
|
ACTIVITY_STATS_LIMIT_DAYS = 7
|
||||||
|
|||||||
@@ -6,6 +6,5 @@ export DANGEROUS_SALT='dev-notify-salt'
|
|||||||
export SECRET_KEY='dev-notify-secret-key'
|
export SECRET_KEY='dev-notify-secret-key'
|
||||||
export DESKPRO_API_HOST=""
|
export DESKPRO_API_HOST=""
|
||||||
export DESKPRO_API_KEY=""
|
export DESKPRO_API_KEY=""
|
||||||
export DESKPRO_PERSON_EMAIL=""
|
|
||||||
export DESKPRO_DEPT_ID=""
|
export DESKPRO_DEPT_ID=""
|
||||||
export DESKPRO_ASSIGNED_AGENT_TEAM_ID=""
|
export DESKPRO_ASSIGNED_AGENT_TEAM_ID=""
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ display_result $? 1 "Code style check"
|
|||||||
npm test
|
npm test
|
||||||
display_result $? 2 "Front end code style check"
|
display_result $? 2 "Front end code style check"
|
||||||
|
|
||||||
export NOTIFY_ADMIN_ENVIRONMENT='config.Test'
|
|
||||||
|
|
||||||
## Code coverage
|
## Code coverage
|
||||||
py.test -n2 --cov=app --cov-report=term-missing tests/
|
py.test -n2 --cov=app --cov-report=term-missing tests/
|
||||||
display_result $? 3 "Code coverage"
|
display_result $? 3 "Code coverage"
|
||||||
|
|||||||
@@ -26,17 +26,27 @@ def test_get_feedback_page(app_):
|
|||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_post_feedback_with_no_name_email(app_, mocker):
|
def test_post_feedback_with_name_but_no_email(app_, mocker):
|
||||||
mock_post = mocker.patch(
|
mock_post = mocker.patch(
|
||||||
'app.main.views.feedback.requests.post',
|
'app.main.views.feedback.requests.post',
|
||||||
return_value=Mock(status_code=201))
|
return_value=Mock(status_code=201))
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
resp = client.post(url_for('main.feedback'), data={'feedback': "blah"})
|
resp = client.post(url_for('main.feedback'), data={'feedback': "blah", 'name': 'Fred'})
|
||||||
assert resp.status_code == 302
|
assert resp.status_code == 302
|
||||||
|
mock_post.assert_called_with(
|
||||||
|
ANY,
|
||||||
|
data={
|
||||||
|
'department_id': ANY,
|
||||||
|
'agent_team_id': ANY,
|
||||||
|
'subject': 'Notify feedback',
|
||||||
|
'message': 'Environment: http://localhost/\nFred (no email address supplied)\nblah',
|
||||||
|
'person_email': app_.config['DESKPRO_PERSON_EMAIL'],
|
||||||
|
'person_name': 'Fred'},
|
||||||
|
headers=ANY)
|
||||||
|
|
||||||
|
|
||||||
def test_post_feedback_with_no_name_email(app_, mocker):
|
def test_post_feedback_with_no_name_or_email(app_, mocker):
|
||||||
mock_post = mocker.patch(
|
mock_post = mocker.patch(
|
||||||
'app.main.views.feedback.requests.post',
|
'app.main.views.feedback.requests.post',
|
||||||
return_value=Mock(status_code=201))
|
return_value=Mock(status_code=201))
|
||||||
@@ -50,8 +60,9 @@ def test_post_feedback_with_no_name_email(app_, mocker):
|
|||||||
'department_id': ANY,
|
'department_id': ANY,
|
||||||
'agent_team_id': ANY,
|
'agent_team_id': ANY,
|
||||||
'subject': 'Notify feedback',
|
'subject': 'Notify feedback',
|
||||||
'message': 'Environment: http://localhost/\n\n\n\nblah',
|
'message': 'Environment: http://localhost/\n (no email address supplied)\nblah',
|
||||||
'person_email': ANY},
|
'person_email': app_.config['DESKPRO_PERSON_EMAIL'],
|
||||||
|
'person_name': None},
|
||||||
headers=ANY)
|
headers=ANY)
|
||||||
|
|
||||||
|
|
||||||
@@ -71,8 +82,9 @@ def test_post_feedback_with_name_email(app_, mocker):
|
|||||||
'subject': 'Notify feedback',
|
'subject': 'Notify feedback',
|
||||||
'department_id': ANY,
|
'department_id': ANY,
|
||||||
'agent_team_id': ANY,
|
'agent_team_id': ANY,
|
||||||
'message': 'Environment: http://localhost/\n\nSteve Irwin\nrip@gmail.com\nblah',
|
'message': 'Environment: http://localhost/\n\nblah',
|
||||||
'person_email': ANY},
|
'person_name': 'Steve Irwin',
|
||||||
|
'person_email': 'rip@gmail.com'},
|
||||||
headers=ANY)
|
headers=ANY)
|
||||||
|
|
||||||
|
|
||||||
@@ -91,14 +103,6 @@ def test_log_error_on_post(app_, mocker):
|
|||||||
resp = client.post(
|
resp = client.post(
|
||||||
url_for('main.feedback'),
|
url_for('main.feedback'),
|
||||||
data={'feedback': "blah", 'name': "Steve Irwin", 'email_address': 'rip@gmail.com'})
|
data={'feedback': "blah", 'name': "Steve Irwin", 'email_address': 'rip@gmail.com'})
|
||||||
mock_post.assert_called_with(
|
assert mock_post.called
|
||||||
ANY,
|
|
||||||
data={
|
|
||||||
'subject': 'Notify feedback',
|
|
||||||
'department_id': ANY,
|
|
||||||
'agent_team_id': ANY,
|
|
||||||
'message': 'Environment: http://localhost/\n\nSteve Irwin\nrip@gmail.com\nblah',
|
|
||||||
'person_email': ANY},
|
|
||||||
headers=ANY)
|
|
||||||
mock_logger.assert_called_with(
|
mock_logger.assert_called_with(
|
||||||
"Deskpro create ticket request failed with {} '{}'".format(mock_post().status_code, mock_post().json()))
|
"Deskpro create ticket request failed with {} '{}'".format(mock_post().status_code, mock_post().json()))
|
||||||
|
|||||||
@@ -241,10 +241,9 @@ def test_should_redirect_after_request_to_go_live(
|
|||||||
'subject': 'Request to go live',
|
'subject': 'Request to go live',
|
||||||
'department_id': ANY,
|
'department_id': ANY,
|
||||||
'agent_team_id': ANY,
|
'agent_team_id': ANY,
|
||||||
'message': 'From Test User <test@user.gov.uk> on behalf of Test Service (http://localhost/services/6ce466d0-fd6a-11e5-82f5-e0accb9d11a6/dashboard)\n\nUsage estimate\n---\n\nOne million messages', # noqa
|
'message': 'On behalf of Test Service (http://localhost/services/6ce466d0-fd6a-11e5-82f5-e0accb9d11a6/dashboard)\n\nUsage estimate\n---\n\nOne million messages', # noqa
|
||||||
# noqa
|
'person_name': api_user_active.name,
|
||||||
# noqa
|
'person_email': api_user_active.email_address
|
||||||
'person_email': ANY
|
|
||||||
},
|
},
|
||||||
headers=ANY
|
headers=ANY
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user