From 884be7220ba55850cc55386c4aa7c5677479e8f7 Mon Sep 17 00:00:00 2001 From: "karel.picman@lbcfree.net" Date: Wed, 3 Feb 2021 13:24:00 +0100 Subject: [PATCH] #1204 Empty trash --- after_init.rb | 2 +- app/controllers/dmsf_controller.rb | 20 +++++++++++++++++++- app/views/dmsf/show.html.erb | 5 ++--- app/views/dmsf/trash.html.erb | 12 ++++++------ config/locales/cs.yml | 1 + config/locales/de.yml | 1 + config/locales/en.yml | 1 + config/locales/es.yml | 1 + config/locales/fr.yml | 1 + config/locales/hu.yml | 1 + config/locales/it.yml | 1 + config/locales/ja.yml | 1 + config/locales/ko.yml | 1 + config/locales/nl.yml | 1 + config/locales/pl.yml | 1 + config/locales/pt-BR.yml | 1 + config/locales/ru.yml | 1 + config/locales/sl.yml | 1 + config/locales/zh-TW.yml | 1 + config/locales/zh.yml | 1 + config/routes.rb | 1 + test/functional/dmsf_controller_test.rb | 15 +++++++++++++++ 22 files changed, 60 insertions(+), 11 deletions(-) diff --git a/after_init.rb b/after_init.rb index 3149d462..2d19cff7 100644 --- a/after_init.rb +++ b/after_init.rb @@ -74,7 +74,7 @@ def dmsf_init dmsf_files_copy: [:new, :copy, :move], dmsf_context_menus: [:dmsf]} pmap.permission :file_delete, - { dmsf: [:trash, :delete_entries], + { dmsf: [:trash, :delete_entries, :empty_trash], dmsf_files: [:delete], dmsf_trash_context_menus: [:trash] } pmap.permission :force_file_unlock, {} diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index 8f19dc29..5bfa63d8 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -32,7 +32,7 @@ class DmsfController < ApplicationController before_action :permissions # Also try to lookup folder by title if this is an API call before_action :find_folder_by_title, only: [:show] - before_action :get_query, only: [:expand_folder, :show, :trash] + before_action :get_query, only: [:expand_folder, :show, :trash, :empty_trash] before_action :get_project_roles, only: [:new, :edit] accept_api_auth :show, :create, :save, :delete @@ -436,6 +436,24 @@ class DmsfController < ApplicationController end end + def empty_trash + @query.deleted = true + @query.dmsf_nodes.each do |node| + case node.type + when 'folder' + folder = DmsfFolder.find_by(id: node.id) + folder.delete true + when 'file' + file = DmsfFile.find_by(id: node.id) + file.delete true + when /link$/ + link = DmsfLink.find_by(id: node.id) + link.delete true + end + end + redirect_back_or_default trash_dmsf_path(id: @project.id) + end + private def users_for_new_users diff --git a/app/views/dmsf/show.html.erb b/app/views/dmsf/show.html.erb index 1110c8f5..efa7bbd9 100644 --- a/app/views/dmsf/show.html.erb +++ b/app/views/dmsf/show.html.erb @@ -30,8 +30,7 @@ class: 'icon icon-add' %> <% end %> <% if @folder_manipulation_allowed %> - <%= link_to l(:link_create_folder), new_dmsf_path(id: @project, parent_id: @folder), - title: l(:link_create_folder), class: 'icon icon-add' %> + <%= link_to l(:link_create_folder), new_dmsf_path(id: @project, parent_id: @folder), class: 'icon icon-add' %> <% end %> <% end %> <% if defined?(EasyExtensions) %> @@ -61,7 +60,7 @@
- <%= textilizable(@folder ? @folder.description : @project.dmsf_description) %> + <%= textilizable @folder ? @folder.description : @project.dmsf_description %>
diff --git a/app/views/dmsf/trash.html.erb b/app/views/dmsf/trash.html.erb index 9bcd75ef..dd69e185 100644 --- a/app/views/dmsf/trash.html.erb +++ b/app/views/dmsf/trash.html.erb @@ -22,14 +22,14 @@ <% html_title l(:dmsf) %> -

<%= l(:link_trash_bin) %>

- -
-
- <%= textilizable @project.dmsf_description %> -
+
+ <% if @file_delete_allowed %> + <%= link_to l(:label_empty_trash_bin), empty_trash_path(id: @project), class: 'icon icon-del' %> + <% end %>
+

<%= l(:link_trash_bin) %>

+ <%= form_tag(trash_dmsf_path(id: @project), method: :get, id: 'query_form', class: 'dmsf-query-form') do %> <%= render partial: 'queries/query_form' %> <% end %> diff --git a/config/locales/cs.yml b/config/locales/cs.yml index 443b3075..ec8b33dd 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -417,6 +417,7 @@ cs: note_webdav_disabled: WebDAV je zablokovaný. Kontaktujte administrátora. dmsf_copy: "Kopie (%{n})" + label_empty_trash_bin: Vysypat koš easy_pages: modules: diff --git a/config/locales/de.yml b/config/locales/de.yml index 0c6ff060..6127c166 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -416,6 +416,7 @@ de: note_webdav_disabled: WebDAV is disabled. Contact the administrator. dmsf_copy: "Kopie (%{n})" + label_empty_trash_bin: Empty Trash easy_pages: modules: diff --git a/config/locales/en.yml b/config/locales/en.yml index 8f459e83..bf0218e5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -417,6 +417,7 @@ en: note_webdav_disabled: WebDAV is disabled. Contact the administrator. dmsf_copy: "Copy (%{n})" + label_empty_trash_bin: Empty Trash easy_pages: modules: diff --git a/config/locales/es.yml b/config/locales/es.yml index 73ee3978..6e1b5904 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -417,6 +417,7 @@ es: note_webdav_disabled: WebDAV is disabled. Contact the administrator. dmsf_copy: "Copy (%{n})" + label_empty_trash_bin: Empty Trash easy_pages: modules: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 3045c14f..d270201f 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -417,6 +417,7 @@ fr: note_webdav_disabled: WebDAV is disabled. Contact the administrator. dmsf_copy: "Copy (%{n})" + label_empty_trash_bin: Empty Trash easy_pages: modules: diff --git a/config/locales/hu.yml b/config/locales/hu.yml index ce95ffc9..11eedee1 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -416,6 +416,7 @@ hu: note_webdav_disabled: WebDAV is disabled. Contact the administrator. dmsf_copy: "Copy (%{n})" + label_empty_trash_bin: Empty Trash easy_pages: modules: diff --git a/config/locales/it.yml b/config/locales/it.yml index eabed390..412ecf12 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -417,6 +417,7 @@ it: # Italian strings thx 2 Matteo Arceci! note_webdav_disabled: WebDAV is disabled. Contact the administrator. dmsf_copy: "Copy (%{n})" + label_empty_trash_bin: Empty Trash easy_pages: modules: diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 75e4e5b2..a137ceb8 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -417,6 +417,7 @@ ja: note_webdav_disabled: WebDAV is disabled. Contact the administrator. dmsf_copy: "Copy (%{n})" + label_empty_trash_bin: Empty Trash easy_pages: modules: diff --git a/config/locales/ko.yml b/config/locales/ko.yml index 913f8f89..ca24790a 100644 --- a/config/locales/ko.yml +++ b/config/locales/ko.yml @@ -416,6 +416,7 @@ ko: note_webdav_disabled: WebDAV is disabled. Contact the administrator. dmsf_copy: "Copy (%{n})" + label_empty_trash_bin: Empty Trash easy_pages: modules: diff --git a/config/locales/nl.yml b/config/locales/nl.yml index d421e2a0..454237f1 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -417,6 +417,7 @@ nl: note_webdav_disabled: WebDAV is disabled. Contact the administrator. dmsf_copy: "Copy (%{n})" + label_empty_trash_bin: Empty Trash easy_pages: modules: diff --git a/config/locales/pl.yml b/config/locales/pl.yml index 8f9849f6..af6b2702 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -417,6 +417,7 @@ pl: note_webdav_disabled: WebDAV is disabled. Contact the administrator. dmsf_copy: "Copy (%{n})" + label_empty_trash_bin: Empty Trash easy_pages: modules: diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 26aefa1e..6bce6e3d 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -417,6 +417,7 @@ pt-BR: note_webdav_disabled: WebDAV is disabled. Contact the administrator. dmsf_copy: "Copy (%{n})" + label_empty_trash_bin: Empty Trash easy_pages: modules: diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 7a782bc7..c6f8ddc9 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -417,6 +417,7 @@ ru: note_webdav_disabled: WebDAV is disabled. Contact the administrator. dmsf_copy: "Copy (%{n})" + label_empty_trash_bin: Empty Trash easy_pages: modules: diff --git a/config/locales/sl.yml b/config/locales/sl.yml index 24d629f1..5dfe9340 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -417,6 +417,7 @@ sl: note_webdav_disabled: WebDAV is disabled. Contact the administrator. dmsf_copy: "Copy (%{n})" + label_empty_trash_bin: Empty Trash easy_pages: modules: diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index b6aa3b88..f446897c 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -416,6 +416,7 @@ zh-TW: note_webdav_disabled: WebDAV is disabled. Contact the administrator. dmsf_copy: "Copy (%{n})" + label_empty_trash_bin: Empty Trash easy_pages: modules: diff --git a/config/locales/zh.yml b/config/locales/zh.yml index cc917957..7cff2360 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -417,6 +417,7 @@ zh: note_webdav_disabled: WebDAV is disabled. Contact the administrator. dmsf_copy: "Copy (%{n})" + label_empty_trash_bin: Empty Trash easy_pages: modules: diff --git a/config/routes.rb b/config/routes.rb index 5c6a6054..a0467028 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -54,6 +54,7 @@ if Redmine::Plugin.installed? :redmine_dmsf post '/projects/:id/dmsf/append_email', controller: 'dmsf', action: 'append_email', as: 'append_email_dmsf' get '/projects/:id/dmsf/autocomplete_for_user', controller: 'dmsf', action: 'autocomplete_for_user' put '/projects/:id/dmsf', controller: 'dmsf', action: 'drop' + get '/projects/:id/dmsf/empty_trash', to: 'dmsf#empty_trash', as: 'empty_trash' # dmsf_context_menu_controller match '/projects/:id/dmsf/context_menu', to: 'dmsf_context_menus#dmsf', as: 'dmsf_context_menu', via: [:get, :post] diff --git a/test/functional/dmsf_controller_test.rb b/test/functional/dmsf_controller_test.rb index dc208f14..3227e63f 100644 --- a/test/functional/dmsf_controller_test.rb +++ b/test/functional/dmsf_controller_test.rb @@ -100,6 +100,21 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase assert_select 'a', href: url_for(controller: :dmsf_files, action: 'view', id: @link2.target_id, only_path: true) end + def test_empty_trash + get :empty_trash, params: { id: @project1.id } + assert_equal 0, DmsfFolder.deleted.where(project_id: @project1.id).all.size + assert_equal 0, DmsfFile.deleted.where(project_id: @project1.id).all.size + assert_equal 0, DmsfLink.deleted.where(project_id: @project1.id).all.size + assert_redirected_to trash_dmsf_path(id: @project1.id) + end + + def test_empty_trash_forbidden + # Missing permissions + @role_manager.remove_permission! :file_delete + get :empty_trash, params: { id: @project1.id } + assert_response :forbidden + end + def test_delete_forbidden # Missing permissions @role_manager.remove_permission! :folder_manipulation