Skip to content

Commit

Permalink
Merge pull request #5046 from petevdp/submission-preferences-confirma…
Browse files Browse the repository at this point in the history
…tion-flash

Added confirmation flash when submission preferences are saved.
  • Loading branch information
zenmonkeykstop authored Dec 18, 2019
2 parents 2bd6679 + 91903f8 commit 4324582
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions securedrop/journalist_app/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def update_submission_preferences():
form = SubmissionPreferencesForm()
if form.validate_on_submit():
# The UI prompt ("prevent") is the opposite of the setting ("allow"):
flash(gettext("Preferences saved."), "submission-preferences-success")
value = not bool(request.form.get('prevent_document_uploads'))
InstanceConfig.set('allow_document_uploads', value)
return redirect(url_for('admin.manage_config'))
Expand Down
1 change: 1 addition & 0 deletions securedrop/journalist_templates/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ <h2>{{ gettext('Submission Preferences') }}</h2>
<button type="submit" id="submit-submission-preferences">
<i class="fas fa-pencil-alt"></i> {{ gettext('UPDATE SUBMISSION PREFERENCES') }}
</button>
{% include 'submission_preferences_saved_flash.html' %}
</form>

{% endblock %}
2 changes: 1 addition & 1 deletion securedrop/journalist_templates/logo_upload_flashed.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{# these are flashed messages for the logo upload file verifiaction #}
{# these are flashed messages for the logo upload file verification #}
{% with messages = get_flashed_messages(with_categories=True, category_filter=["logo-success", "logo-error"]) %}
{% for category, message in messages %}
{% set category_status = category[5:] %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% with messages = get_flashed_messages(with_categories=True, category_filter=["submission-preferences-success"]) %}
{% for category, message in messages %}
{# Get the end of the of the category message which
contains the category status.(success/error)#}
{% set category_status = category[23:] %}
<div class="flash {{ category_status }}">
<img src="{{ url_for('static', filename='i/success_checkmark.png') }}" height="17" width="20">
{{ message }}
</div>
{% endfor %}
{% endwith %}
10 changes: 10 additions & 0 deletions securedrop/tests/functional/journalist_navigation_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,21 @@ def _admin_disallows_document_uploads(self):
self.safe_click_by_id("prevent_document_uploads")
self.safe_click_by_id("submit-submission-preferences")

def preferences_saved():
flash_msg = self.driver.find_element_by_css_selector(".flash")
assert "Preferences saved." in flash_msg.text
self.wait_for(preferences_saved, timeout=self.timeout * 6)

def _admin_allows_document_uploads(self):
if self.driver.find_element_by_id("prevent_document_uploads").is_selected():
self.safe_click_by_id("prevent_document_uploads")
self.safe_click_by_id("submit-submission-preferences")

def preferences_saved():
flash_msg = self.driver.find_element_by_css_selector(".flash")
assert "Preferences saved." in flash_msg.text
self.wait_for(preferences_saved, timeout=self.timeout * 6)

def _add_user(self, username, first_name="", last_name="", is_admin=False, hotp=None):
self.safe_send_keys_by_css_selector('input[name="username"]', username)

Expand Down
9 changes: 9 additions & 0 deletions securedrop/tests/test_journalist.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,11 @@ def test_prevent_document_uploads(journalist_app, test_admin):
data=form.data,
follow_redirects=True)
assert InstanceConfig.get_current().allow_document_uploads is False
with InstrumentedApp(journalist_app) as ins:
app.post(url_for('admin.update_submission_preferences'),
data=form.data,
follow_redirects=True)
ins.assert_message_flashed('Preferences saved.', 'submission-preferences-success')


def test_no_prevent_document_uploads(journalist_app, test_admin):
Expand All @@ -1306,6 +1311,10 @@ def test_no_prevent_document_uploads(journalist_app, test_admin):
app.post(url_for('admin.update_submission_preferences'),
follow_redirects=True)
assert InstanceConfig.get_current().allow_document_uploads is True
with InstrumentedApp(journalist_app) as ins:
app.post(url_for('admin.update_submission_preferences'),
follow_redirects=True)
ins.assert_message_flashed('Preferences saved.', 'submission-preferences-success')


def test_logo_upload_with_valid_image_succeeds(journalist_app, test_admin):
Expand Down

0 comments on commit 4324582

Please sign in to comment.