This commit is contained in:
karel.picman@lbcfree.net 2021-02-03 13:24:00 +01:00
parent 7a1548868e
commit 884be7220b
22 changed files with 60 additions and 11 deletions

View File

@ -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, {}

View File

@ -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

View File

@ -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 @@
<div class="dmsf-header">
<div class="wiki">
<%= textilizable(@folder ? @folder.description : @project.dmsf_description) %>
<%= textilizable @folder ? @folder.description : @project.dmsf_description %>
</div>
</div>

View File

@ -22,14 +22,14 @@
<% html_title l(:dmsf) %>
<h2><%= l(:link_trash_bin) %></h2>
<div class="dmsf-header">
<div class="wiki">
<%= textilizable @project.dmsf_description %>
</div>
<div class="contextual">
<% if @file_delete_allowed %>
<%= link_to l(:label_empty_trash_bin), empty_trash_path(id: @project), class: 'icon icon-del' %>
<% end %>
</div>
<h2><%= l(:link_trash_bin) %></h2>
<%= form_tag(trash_dmsf_path(id: @project), method: :get, id: 'query_form', class: 'dmsf-query-form') do %>
<%= render partial: 'queries/query_form' %>
<% end %>

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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]

View File

@ -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