Repository: freedomofpress/securedrop

Issue:
Extra level in zip folders for single sources
## Description

There is an extra unnecessary folder for zipfiles downloaded from the journalist interface for single sources. 

## Steps to Reproduce

0. Submit some files to SecureDrop
1. Load the home page of the journalist interface
2. Select one source using the checkbox
3. Select "Download"
4. Unzip the resulting file

## Expected Behavior

File structure would ideally be: 

`source-name/number_date`

e.g.:

`ecstatic-potato/1_03-20-20`

## Actual Behavior

Instead there is an additional layer:

`ecstatic-potato/ecstatic-potato/1_03-20-20`

## Comment

This additional folder is confusing to users and should be removed.

Note: if you download unread or download all for multiple sources - the outer folder will not be named after the source and will be e.g. `all`:

`all/ecstatic-potato/1_03-20-20`


Discussion:
(this was not discovered doing 0.4.3 release QA, this is in production)
i can verify with the following details.

## Steps to Reproduce

0. Submit some files to SecureDrop
1. Load the home page of the journalist interface
2. Click on one source
3. Select one document from source using the checkbox
4. Select "Download"
5. Unzip the resulting file




## Expected Behavior
File structure would ideally be:
```
source_name/number_date
```
e.g.:

```
ecstatic_potato/1_03-20-20
```
## Actual Behavior

Instead there is an additional layer:

```
ecstatic_potato/ecstatic potato/1_03-20-20
```



Resolving patch:
diff --git a/securedrop/store.py b/securedrop/store.py
--- a/securedrop/store.py
+++ b/securedrop/store.py
@@ -78,6 +78,7 @@ def get_bulk_archive(selected_submissions, zip_directory=''):
     # folder structure per #383
     with zipfile.ZipFile(zip_file, 'w') as zip:
         for source in sources:
+            fname = ""
             submissions = [s for s in selected_submissions
                            if s.source.journalist_designation == source]
             for submission in submissions:
@@ -85,9 +86,12 @@ def get_bulk_archive(selected_submissions, zip_directory=''):
                                 submission.filename)
                 verify(filename)
                 document_number = submission.filename.split('-')[0]
+                if zip_directory == submission.source.journalist_filename:
+                    fname = zip_directory
+                else:
+                    fname = os.path.join(zip_directory, source)
                 zip.write(filename, arcname=os.path.join(
-                    zip_directory,
-                    source,
+                    fname,
                     "%s_%s" % (document_number,
                                submission.source.last_updated.date()),
                     os.path.basename(filename)


Test patch:
diff --git a/securedrop/tests/test_journalist.py b/securedrop/tests/test_journalist.py
--- a/securedrop/tests/test_journalist.py
+++ b/securedrop/tests/test_journalist.py
@@ -774,7 +774,6 @@ def test_download_selected_submissions_from_source(self):
                 zipfile.ZipFile(StringIO(resp.data)).getinfo(
                     os.path.join(
                         source.journalist_filename,
-                        source.journalist_designation,
                         "%s_%s" % (filename.split('-')[0],
                                    source.last_updated.date()),
                         filename