Skip to content

Commit

Permalink
MDL-68758 core_repository: Allow ability to download files on all views.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Dias committed May 27, 2020
1 parent d851183 commit 31788c8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 0 additions & 2 deletions lang/en/repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@
$string['download'] = 'Download';
$string['downloadallfiles'] = 'Download all files';
$string['downloadfolder'] = 'Download all';
$string['downloadselected'] = 'Download selected files';
$string['deleteselected'] = 'Delete selected';
$string['downloadsucc'] = 'The file has been downloaded successfully';
$string['draftareanofiles'] = 'Cannot be downloaded because there is no files attached';
$string['editrepositoryinstance'] = 'Edit repository instance';
Expand Down
4 changes: 2 additions & 2 deletions lib/templates/filemanager_page_generallayout.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
</a>
</div>
<div class="fp-btn-download">
<a role="button" title="{{#str}}downloadselected, repository{{/str}}" class="btn btn-secondary btn-sm" href="#">
<a role="button" title="{{#str}}download, repository{{/str}}" class="btn btn-secondary btn-sm" href="#">
{{#pix}}a/download_all{{/pix}}
</a>
</div>
<div class="fp-btn-delete">
<a role="button" title="{{#str}}deleteselected, repository{{/str}}" class="btn btn-secondary btn-sm" href="#">
<a role="button" title="{{#str}}delete{{/str}}" class="btn btn-secondary btn-sm" href="#">
{{#pix}}i/trash{{/pix}}
</a>
</div>
Expand Down
7 changes: 7 additions & 0 deletions repository/draftfiles_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@
case 'downloadselected':
$selected = required_param('selected', PARAM_RAW);
$selectedfiles = json_decode($selected);
if (!count($selectedfiles)) {
$filepath = required_param('filepath', PARAM_PATH);
$selectedfiles = [(object)[
'filename' => '',
'filepath' => $filepath
]];
}
$return = repository_download_selected_files($usercontext, 'user', 'draft', $draftid, $selectedfiles);
echo (json_encode($return));
die;
Expand Down
6 changes: 4 additions & 2 deletions repository/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3272,7 +3272,7 @@ function repository_download_selected_files($context, string $component, string
$filestoarchive = [];

foreach ($files as $selectedfile) {
$filename = clean_filename($selectedfile->filename); // Default to '.' for root.
$filename = $selectedfile->filename ? clean_filename($selectedfile->filename) : '.'; // Default to '.' for root.
$filepath = clean_param($selectedfile->filepath, PARAM_PATH); // Default to '/' for downloadall.
$filepath = file_correct_filepath($filepath);
$area = file_get_draft_area_info($itemid, $filepath);
Expand All @@ -3284,7 +3284,9 @@ function repository_download_selected_files($context, string $component, string
// If it is empty we are downloading a directory.
$archivefile = $storedfile->get_filename();
if (!$filename || $filename == '.' ) {
$archivefile = $filepath;
$foldername = explode('/', trim($filepath, '/'));
$folder = trim(array_pop($foldername), '/');
$archivefile = $folder ?? '/';
}

$filestoarchive[$archivefile] = $storedfile;
Expand Down
8 changes: 4 additions & 4 deletions repository/tests/behat/delete_files.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Feature: Delete files and folders from the file manager
And I follow "Manage private files"
And I click on "Display folder with file details" "link"
And I set the field "Select file 'empty.txt'" to "1"
When I click on "Delete selected" "link"
When I click on "Delete" "link"
Then I should see "Are you sure you want to delete the selected 1 file(s)?"
When I click on "OK" "button" in the "Confirm" "dialogue"
Then I should not see "empty.txt"
Expand All @@ -40,7 +40,7 @@ Feature: Delete files and folders from the file manager
Then I should not see "empty.txt"
But I should see "Delete me later"
And I set the field "Select file 'Delete me later'" to "1"
And I click on "Delete selected" "link"
And I click on "Delete" "link"
And I click on "OK" "button" in the "Confirm" "dialogue"
Then I should not see "Delete me later"
When I press "Save changes"
Expand All @@ -58,7 +58,7 @@ Feature: Delete files and folders from the file manager
And I click on "Display folder with file details" "link"
And I set the field "Select file 'empty.txt'" to "1"
And I set the field "Select file 'Delete me'" to "1"
When I click on "Delete selected" "link"
When I click on "Delete" "link"
Then I should see "Are you sure you want to delete the selected 2 file(s)?"
When I click on "OK" "button" in the "Confirm" "dialogue"
Then I should not see "Delete me"
Expand All @@ -84,7 +84,7 @@ Feature: Delete files and folders from the file manager
| Select file 'empty.txt' | 1 |
| Select file 'Delete me' | 1 |
| Select file 'Delete me too' | 1 |
When I click on "Delete selected" "link"
When I click on "Delete" "link"
Then I should see "Are you sure you want to delete the selected 3 file(s)?"
When I click on "OK" "button" in the "Confirm" "dialogue"
Then I should not see "Delete me"
Expand Down

0 comments on commit 31788c8

Please sign in to comment.