Repository: freedomofpress/securedrop

Issue:
Codename hint link visible in flash message but codename hint not displayed
## Description

In the Source Interface, if a source generates a codename and proceeds to `/lookup` but elects not to submit anything at this time, the next time the source logs in and submits a message or document, the flash message includes the "Forgot your codename?" link but the `codename-hint` element of the page is missing so the link does not work.

## Steps to Reproduce

1. Run `make dev`.
1. Access the Source Interface and click "GET STARTED".
1. Take note of the codename on `/generate` and click "SUBMIT DOCUMENTS".
1. On `/lookup`, click "LOGOUT".
1. On `/index` click "LOG IN".
1. Enter the codename noted in 3 and click "CONTINUE".
1. On `/lookup` enter a message and click "SUBMIT".

## Expected Behavior

The "Success!" flash message for a first submission is displayed, **without the "Forgot your codename" link**.

## Actual Behavior

The "Success!" flash message for a first submission is displayed, **with the "Forgot your codename?" link** but the `codename-hint` element of the page is missing and therefore the link does not trigger anything.

![image](https://user-images.githubusercontent.com/22901938/72857503-cd420c80-3c8b-11ea-87ea-c1ed39b47e61.png)

## Comments

Suggestions to fix: Use the `'new_user'` session key with an `if` statement in the template to determine whether the "Forgot your codename?" link should be displayed.

This could be combined with the solution to #4401 which already involves some refactoring of the submission confirmation flash messages.



Discussion:
@DrGFreeman Belated thanks for the report! I just encountered the same issue and was wondering if we already had a report for it -- and there it was. Do you have bandwidth these days to attempt a fix yourself?
Hi @eloquence. I was actually wanting to get back to contributing here (Hacktoberfest fever? Not sure...) so this will be a good place to start! Just need to refresh my dev environment and get back into it.

Resolving patch:
diff --git a/securedrop/source_app/main.py b/securedrop/source_app/main.py
--- a/securedrop/source_app/main.py
+++ b/securedrop/source_app/main.py
@@ -201,7 +201,10 @@ def submit(logged_in_source: SourceUser) -> werkzeug.Response:
                     fh.stream))
 
         if first_submission:
-            flash_message = render_template('first_submission_flashed_message.html')
+            flash_message = render_template(
+                'first_submission_flashed_message.html',
+                new_user_codename=session.get('new_user_codename', None),
+            )
             flash(Markup(flash_message), "success")
 
         else:


Test patch:
diff --git a/securedrop/tests/functional/source_navigation_steps.py b/securedrop/tests/functional/source_navigation_steps.py
--- a/securedrop/tests/functional/source_navigation_steps.py
+++ b/securedrop/tests/functional/source_navigation_steps.py
@@ -163,7 +163,9 @@ def file_submitted():
             # allow time for reply key to be generated
             time.sleep(self.timeout)
 
-    def _source_submits_a_message(self):
+    def _source_submits_a_message(
+        self, verify_notification=False, first_submission=False, first_login=False
+    ):
         self._source_enters_text_in_message_field()
         self._source_clicks_submit_button_on_submission_page()
 
@@ -172,6 +174,22 @@ def message_submitted():
                 notification = self.driver.find_element_by_css_selector(".success")
                 assert "Thank" in notification.text
 
+                if verify_notification:
+                    first_submission_text = (
+                        "Please check back later for replies." in notification.text
+                    )
+                    first_login_text = "Forgot your codename?" in notification.text
+
+                    if first_submission:
+                        assert first_submission_text
+
+                        if first_login:
+                            assert first_login_text
+                        else:
+                            assert not first_login_text
+                    else:
+                        assert not first_submission_text
+
         self.wait_for(message_submitted)
 
         # allow time for reply key to be generated
diff --git a/securedrop/tests/functional/test_source.py b/securedrop/tests/functional/test_source.py
--- a/securedrop/tests/functional/test_source.py
+++ b/securedrop/tests/functional/test_source.py
@@ -44,6 +44,33 @@ def test_lookup_codename_hint(self):
         self._source_proceeds_to_login()
         self._source_sees_no_codename()
 
+    def test_lookup_submit_notification_first_login(self):
+        """Test that on a first login, the submission notification includes the 'Please check back
+        later' and 'Forgot your codename?' messages. Also verify that those messages are not
+        present on a subsequent submission."""
+        self._source_visits_source_homepage()
+        self._source_chooses_to_submit_documents()
+        self._source_continues_to_submit_page()
+        self._source_submits_a_message(
+            verify_notification=True, first_submission=True, first_login=True
+        )
+        self._source_submits_a_message(verify_notification=True)
+
+    def test_lookup_submit_notification_2nd_login(self):
+        """Test that on a second login, the first submission notification includes the 'Please
+        check back later' message but not the 'Forgot your codename?' message since the codename
+        hint section is not present on a second login (Ref. issue #5101). Also verify that none of
+        those messages are present on a subsequent submission."""
+        self._source_visits_source_homepage()
+        self._source_chooses_to_submit_documents()
+        self._source_continues_to_submit_page()
+        self._source_logs_out()
+        self._source_visits_source_homepage()
+        self._source_chooses_to_login()
+        self._source_proceeds_to_login()
+        self._source_submits_a_message(verify_notification=True, first_submission=True)
+        self._source_submits_a_message(verify_notification=True)
+
 
 class TestDownloadKey(
         functional_test.FunctionalTest,