diff --git a/CHANGELOG.md b/CHANGELOG.md index 9716bda4..b632abd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,11 @@ Changelog for Redmine DMSF 1.6.1 *2018-??-??* ------------------ - Javascript on pages is loaded asynchronously. - Obsolete Dav4Rack gem replaced with an up to date fork by Planio (Consequently WebDAV caching has been removed, sorry...). - Project members can be chosen as recipients when sending documents by email. + Javascript on pages is loaded asynchronously + Obsolete Dav4Rack gem replaced with an up to date fork by Planio (Consequently WebDAV caching has been removed, sorry...) + Project members can be chosen as recipients when sending documents by email + Responsive view + Direct editing of document in MS Office 1.6.0 *2017-09-12* ------------------ diff --git a/after_init.rb b/after_init.rb index e9d3f472..5f6042a8 100644 --- a/after_init.rb +++ b/after_init.rb @@ -49,8 +49,9 @@ def init :dmsf_files_copy => [:new, :copy, :move], :dmsf_context_menus => [:dmsf]} pmap.permission :file_delete, - { :dmsf => [:trash, :delete_entries], - :dmsf_files => [:delete]} + {:dmsf => [:trash, :delete_entries], + :dmsf_files => [:delete], + :dmsf_trash_context_menus => [:trash]} pmap.permission :force_file_unlock, {} pmap.permission :file_approval, {:dmsf_workflows => [:action, :new_action, :autocomplete_for_user, :start, :assign, :assignment]} diff --git a/app/controllers/dmsf_context_menus_controller.rb b/app/controllers/dmsf_context_menus_controller.rb index cfa9c146..74021608 100644 --- a/app/controllers/dmsf_context_menus_controller.rb +++ b/app/controllers/dmsf_context_menus_controller.rb @@ -22,19 +22,45 @@ class DmsfContextMenusController < ApplicationController helper :context_menus + before_action :find_project + before_action :find_folder + before_action :find_file, :except => [:trash] + def dmsf - selected_files = params[:ids].select{ |x| x =~ /file-\d+/ }.map{ |x| $1.to_i if x =~ /file-(\d+)/ } - selected_file_links = params[:ids].select{ |x| x =~ /file-link-\d+/ }.map{ |x| $1.to_i if x =~ /file-link-(\d+)/ } - selected_file_links.each do |id| - link = DmsfLink.find_by_id id - selected_files << link.target_id if link && !selected_files.include?(link.target_id.to_s) - end - if (selected_files.size == 1) && (params[:ids].size == 1) - @file = DmsfFile.find selected_files[0] - end + @disabled = params[:ids].blank? render :layout => false rescue ActiveRecord::RecordNotFound render_404 end + def trash + render :layout => false + rescue ActiveRecord::RecordNotFound + render_404 + end + + private + + def find_folder + @folder = DmsfFolder.find params[:folder_id] if params[:folder_id].present? + rescue DmsfAccessError + render_403 + rescue ActiveRecord::RecordNotFound + render_404 + end + + def find_file + if params[:ids].present? + selected_files = params[:ids].select{ |x| x =~ /file-\d+/ }.map{ |x| $1.to_i if x =~ /file-(\d+)/ } + selected_file_links = params[:ids].select{ |x| x =~ /file-link-\d+/ }.map{ |x| $1.to_i if x =~ /file-link-(\d+)/ } + selected_file_links.each do |id| + link = DmsfLink.find_by_id id + selected_files << link.target_id if link && !selected_files.include?(link.target_id.to_s) + end + if (selected_files.size == 1) && (params[:ids].size == 1) + @file = DmsfFile.find selected_files[0] + end + end + end + end \ No newline at end of file diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index 8a94b339..f0cf2037 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -100,11 +100,19 @@ class DmsfController < ApplicationController def entries_operation # Download/Email - selected_folders = params[:ids].select{ |x| x =~ /folder-\d+/ }.map{ |x| $1.to_i if x =~ /folder-(\d+)/ } - selected_files = params[:ids].select{ |x| x =~ /file-\d+/ }.map{ |x| $1.to_i if x =~ /file-(\d+)/ } - selected_dir_links = params[:ids].select{ |x| x =~ /folder-link-\d+/ }.map{ |x| $1.to_i if x =~ /folder-link-(\d+)/ } - selected_file_links = params[:ids].select{ |x| x =~ /file-link-\d+/ }.map{ |x| $1.to_i if x =~ /file-link-(\d+)/ } - selected_url_links = params[:ids].select{ |x| x =~ /url-link-\d+/ }.map{ |x| $1.to_i if x =~ /url-link-(\d+)/ } + if params[:ids].present? + selected_folders = params[:ids].select{ |x| x =~ /folder-\d+/ }.map{ |x| $1.to_i if x =~ /folder-(\d+)/ } + selected_files = params[:ids].select{ |x| x =~ /file-\d+/ }.map{ |x| $1.to_i if x =~ /file-(\d+)/ } + selected_dir_links = params[:ids].select{ |x| x =~ /folder-link-\d+/ }.map{ |x| $1.to_i if x =~ /folder-link-(\d+)/ } + selected_file_links = params[:ids].select{ |x| x =~ /file-link-\d+/ }.map{ |x| $1.to_i if x =~ /file-link-(\d+)/ } + selected_url_links = params[:ids].select{ |x| x =~ /url-link-\d+/ }.map{ |x| $1.to_i if x =~ /url-link-(\d+)/ } + else + selected_folders = [] + selected_files = [] + selected_dir_links = [] + selected_file_links = [] + selected_url_links = [] + end if selected_folders.blank? && selected_files.blank? && selected_dir_links.blank? && selected_file_links.blank? && @@ -143,6 +151,7 @@ class DmsfController < ApplicationController redirect_to :back else download_entries(selected_folders, selected_files) + redirect_to :back end rescue FileNotFound render_404 @@ -359,47 +368,45 @@ class DmsfController < ApplicationController end def email_entries(selected_folders, selected_files) - begin - zip = DmsfZip.new - zip_entries(zip, selected_folders, selected_files) + zip = DmsfZip.new + zip_entries(zip, selected_folders, selected_files) - zipped_content = DmsfHelper.temp_dir.join(DmsfHelper.temp_filename('dmsf_email_sent_documents.zip')) + zipped_content = DmsfHelper.temp_dir.join(DmsfHelper.temp_filename('dmsf_email_sent_documents.zip')) - File.open(zipped_content, 'wb') do |f| - zip_file = File.open(zip.finish, 'rb') - while (buffer = zip_file.read(8192)) - f.write(buffer) - end + File.open(zipped_content, 'wb') do |f| + zip_file = File.open(zip.finish, 'rb') + while (buffer = zip_file.read(8192)) + f.write(buffer) end - - max_filesize = Setting.plugin_redmine_dmsf['dmsf_max_email_filesize'].to_f - if max_filesize > 0 && File.size(zipped_content) > max_filesize * 1048576 - raise EmailMaxFileSize - end - - zip.files.each do |f| - audit = DmsfFileRevisionAccess.new - audit.user = User.current - audit.dmsf_file_revision = f.last_revision - audit.action = DmsfFileRevisionAccess::EmailAction - audit.save! - end - - @email_params = { - :zipped_content => zipped_content, - :folders => selected_folders, - :files => selected_files, - :subject => "#{@project.name} #{l(:label_dmsf_file_plural).downcase}", - :from => Setting.plugin_redmine_dmsf['dmsf_documents_email_from'].blank? ? - "#{User.current.name} <#{User.current.mail}>" : Setting.plugin_redmine_dmsf['dmsf_documents_email_from'], - :reply_to => Setting.plugin_redmine_dmsf['dmsf_documents_email_reply_to'] - } - render :action => 'email_entries' - rescue Exception - raise - ensure - zip.close if zip end + + max_filesize = Setting.plugin_redmine_dmsf['dmsf_max_email_filesize'].to_f + if max_filesize > 0 && File.size(zipped_content) > max_filesize * 1048576 + raise EmailMaxFileSize + end + + zip.files.each do |f| + audit = DmsfFileRevisionAccess.new + audit.user = User.current + audit.dmsf_file_revision = f.last_revision + audit.action = DmsfFileRevisionAccess::EmailAction + audit.save! + end + + @email_params = { + :zipped_content => zipped_content, + :folders => selected_folders, + :files => selected_files, + :subject => "#{@project.name} #{l(:label_dmsf_file_plural).downcase}", + :from => Setting.plugin_redmine_dmsf['dmsf_documents_email_from'].blank? ? + "#{User.current.name} <#{User.current.mail}>" : Setting.plugin_redmine_dmsf['dmsf_documents_email_from'], + :reply_to => Setting.plugin_redmine_dmsf['dmsf_documents_email_reply_to'] + } + render :action => 'email_entries' + rescue Exception + raise + ensure + zip.close if zip end def download_entries(selected_folders, selected_files) diff --git a/app/models/dmsf_file_revision.rb b/app/models/dmsf_file_revision.rb index c6edb64f..2e5dc5eb 100644 --- a/app/models/dmsf_file_revision.rb +++ b/app/models/dmsf_file_revision.rb @@ -36,12 +36,16 @@ class DmsfFileRevision < ActiveRecord::Base PROTOCOLS = { 'application/msword' => 'ms-word', + 'application/excel' => 'ms-excel', 'application/vnd.ms-excel' => 'ms-excel', 'application/vnd.ms-powerpoint' => 'ms-powerpoint', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'ms-word', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'ms-excel', 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'ms-powerpoint', - 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'ms-powerpoint' + 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'ms-powerpoint', + 'application/vnd.oasis.opendocument.spreadsheet' => 'ms-excel', + 'application/vnd.oasis.opendocument.text' => 'ms-word', + 'application/vnd.oasis.opendocument.presentation' => 'ms-powerpoint', }.freeze scope :visible, -> { where(:deleted => STATUS_ACTIVE) } diff --git a/app/views/dmsf/_list_view.erb b/app/views/dmsf/_list_view.erb index 2914684e..ba66d5c8 100644 --- a/app/views/dmsf/_list_view.erb +++ b/app/views/dmsf/_list_view.erb @@ -24,7 +24,9 @@ - + <% if !@system_folder %> + + <% end %> <% if DmsfFolder.is_column_on?('id') %> # diff --git a/app/views/dmsf/_tree_view.erb b/app/views/dmsf/_tree_view.erb index 5114301d..57300710 100644 --- a/app/views/dmsf/_tree_view.erb +++ b/app/views/dmsf/_tree_view.erb @@ -24,8 +24,10 @@ - <%= check_box_tag 'check_all', '', false, :class => 'toggle-selection', + <% if !@system_folder %> + <%= check_box_tag 'check_all', '', false, :class => 'toggle-selection', :title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}" %> + <% end %> <% if DmsfFolder.is_column_on?('id') %> # diff --git a/app/views/dmsf/_url.html.erb b/app/views/dmsf/_url.html.erb index 80d67d4e..cc6247be 100644 --- a/app/views/dmsf/_url.html.erb +++ b/app/views/dmsf/_url.html.erb @@ -20,7 +20,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. %> - +<%= check_box_tag('ids[]', "#{name}-#{id}", false) %> <% if DmsfFolder.is_column_on?('id') %> <% end %> diff --git a/app/views/dmsf/show.html.erb b/app/views/dmsf/show.html.erb index d17e7be8..a78e04c1 100644 --- a/app/views/dmsf/show.html.erb +++ b/app/views/dmsf/show.html.erb @@ -86,16 +86,18 @@ <%= form_tag(entries_operations_dmsf_path(:id => @project, :folder_id => @folder), :method => :post, :class => 'dmsf_entries', :id => 'entries_form', :data => {:cm_url => dmsf_context_menu_path}) do %> <%= hidden_field_tag('action') %> -
- <%= submit_tag(l(:button_download), :title => l(:title_download_checked), :name => 'download_entries', - :class => 'toggle-selection') if @file_view_allowed %> - <%= submit_tag(l(:field_mail), :title => l(:title_send_checked_by_email), :name => 'email_entries', - :class => 'toggle-selection') if (@file_view_allowed && User.current.allowed_to?(:email_documents, @project)) %> - <% if @file_delete_allowed %> - <%= submit_tag(l(:button_delete), :title => l(:title_delete_checked), :name => 'delete_entries', - :class => 'toggle-selection') if @file_delete_allowed %> - <% end %> -
+ <% if !@system_folder %> +
+ <%= submit_tag(l(:button_download), :title => l(:title_download_checked), :name => 'download_entries', + :class => 'toggle-selection') if @file_view_allowed %> + <%= submit_tag(l(:field_mail), :title => l(:title_send_checked_by_email), :name => 'email_entries', + :class => 'toggle-selection') if (@file_view_allowed && User.current.allowed_to?(:email_documents, @project)) %> + <% if @file_delete_allowed %> + <%= submit_tag(l(:button_delete), :title => l(:title_delete_checked), :name => 'delete_entries', + :class => 'toggle-selection') if @file_delete_allowed %> + <% end %> +
+ <% end %> <% unless @system_folder %> <% values = @folder ? @folder.custom_field_values : DmsfFolder.new.custom_field_values %> <% unless values.empty? %> diff --git a/app/views/dmsf/trash.html.erb b/app/views/dmsf/trash.html.erb index e27d9f18..71d866cd 100644 --- a/app/views/dmsf/trash.html.erb +++ b/app/views/dmsf/trash.html.erb @@ -33,7 +33,7 @@ <%= error_messages_for('dmsf_workflow') %> <%= form_tag(entries_operations_dmsf_path(:id => @project, :folder_id => @folder), :method => :post, - :class => 'dmsf_entries', :id => 'entries_form', :data => {:cm_url => dmsf_context_menu_path}) do %> + :class => 'dmsf_entries', :id => 'entries_form', :data => {:cm_url => dmsf_trash_context_menu_path}) do %> <%= hidden_field_tag('action') %>
<% if @file_manipulation_allowed && @folder_manipulation_allowed %> @@ -99,7 +99,7 @@ :subfolder => subfolder, :link => nil, :id => subfolder.id, - :name => 'subfolders[]', + :name => 'folder', :title => subfolder.title }) %> <% end %> @@ -112,7 +112,7 @@ :subfolder => link.target_folder, :link => link, :id => link.id, - :name => 'dir_links[]', + :name => 'folder-link', :title => link.name }) %> <% end %> @@ -128,7 +128,7 @@ :file => file, :link => nil, :id => file.id, - :name => 'files[]', + :name => 'file', :title => file.title }) %> <% end %> @@ -148,7 +148,7 @@ :file => link.target_file, :link => link, :id => link.id, - :name => 'file_links[]', + :name => 'file-link', :title => link.name }) %> <% end %> diff --git a/app/views/dmsf_context_menus/dmsf.html.erb b/app/views/dmsf_context_menus/dmsf.html.erb index 8c582b0e..f6d03f17 100644 --- a/app/views/dmsf_context_menus/dmsf.html.erb +++ b/app/views/dmsf_context_menus/dmsf.html.erb @@ -21,8 +21,24 @@ %> diff --git a/app/views/dmsf_context_menus/trash.html.erb b/app/views/dmsf_context_menus/trash.html.erb new file mode 100644 index 00000000..d9bb9067 --- /dev/null +++ b/app/views/dmsf_context_menus/trash.html.erb @@ -0,0 +1,32 @@ +<% + # encoding: utf-8 + # + # Redmine plugin for Document Management System "Features" + # + # Copyright © 2011-18 Karel Pičman + # + # This program is free software; you can redistribute it and/or + # modify it under the terms of the GNU General Public License + # as published by the Free Software Foundation; either version 2 + # of the License, or (at your option) any later version. + # + # This program is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with this program; if not, write to the Free Software + # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +%> + + diff --git a/config/routes.rb b/config/routes.rb index 2b354526..b62f861c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -55,6 +55,7 @@ if Redmine::Plugin.installed? :redmine_dmsf # dmsf_context_menu_controller match '/projects/:id/dmsf/context_menu', :to => 'dmsf_context_menus#dmsf', :as => 'dmsf_context_menu', :via => [:get, :post] + match '/projects/:id/dmsf/trash/context_menu', :to => 'dmsf_context_menus#trash', :as => 'dmsf_trash_context_menu', :via => [:get, :post] # # dmsf_state controller diff --git a/test/functional/dmsf_context_menus_controller_test.rb b/test/functional/dmsf_context_menus_controller_test.rb new file mode 100644 index 00000000..288fbe0e --- /dev/null +++ b/test/functional/dmsf_context_menus_controller_test.rb @@ -0,0 +1,72 @@ +# encoding: utf-8 +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-18 Karel Pičman +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.expand_path('../../test_helper', __FILE__) + +class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase + include Redmine::I18n + + fixtures :users, :email_addresses, :projects, :members, :roles, :member_roles, :dmsf_folders, + :dmsf_files, :dmsf_file_revisions + + def setup + @user_member = User.find_by_id 2 # John Smith - manager + @project1 = Project.find_by_id 1 + assert_not_nil @project1 + @project1.enable_module! :dmsf + @file1 = DmsfFile.find_by_id 1 + @folder1 = DmsfFolder.find_by_id 1 + User.current = nil + @request.session[:user_id] = @user_member.id + end + + def test_truth + assert_kind_of User, @user_member + assert_kind_of Project, @project1 + assert_kind_of DmsfFile, @file1 + assert_kind_of DmsfFolder, @folder1 + end + + def test_dmsf + get :dmsf, :id => @project1.id, :ids => ["file-#{@file1.id}"] + assert_response :success + assert_select 'a.icon-edit', :text => l(:button_edit) + assert_select 'a.icon-del', :text => l(:button_delete) + assert_select 'a.icon-download', :text => l(:button_download) + assert_select 'a.icon-email', :text => l(:field_mail) + end + + def test_dmsf_no_edit + get :dmsf, :id => @project1.id, :ids => ["folder-#{@folder1.id}"] + assert_response :success + assert_select 'a.icon-edit', :text => l(:button_edit), :count => 0 + assert_select 'a.icon-del', :text => l(:button_delete) + assert_select 'a.icon-download', :text => l(:button_download) + assert_select 'a.icon-email', :text => l(:field_mail) + end + + def test_trash + get :trash, :id => @project1.id, :ids => ["file-#{@file1.id}"] + assert_response :success + assert_select 'a.icon-cancel', :text => l(:title_restore) + assert_select 'a.icon-del', :text => l(:button_delete) + end + +end \ No newline at end of file diff --git a/test/functional/dmsf_controller_test.rb b/test/functional/dmsf_controller_test.rb index 05671fbc..a75a9bb1 100644 --- a/test/functional/dmsf_controller_test.rb +++ b/test/functional/dmsf_controller_test.rb @@ -140,8 +140,7 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase def test_delete_restore_entries_forbidden # Missing permissions get :entries_operation, :id => @project, :delete_entries => 'Delete', - :subfolders => [@folder1.id.to_s], :files => [@file1.id.to_s], - :dir_links => [@folder_link1.id.to_s], :file_links => [@file_link2.id.to_s] + :ids => ["folder-#{@folder1.id}", "file-#{@file1.id}", "folder-link-#{@folder_link1.id}", "file-link-#{@file_link2.id}"] assert_response :forbidden end @@ -150,8 +149,7 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase @request.env['HTTP_REFERER'] = dmsf_folder_path(:id => @project.id) @role.add_permission! :view_dmsf_files get :entries_operation, :id => @project, :delete_entries => 'Delete', - :subfolders => [@folder1.id.to_s], :files => [@file1.id.to_s], - :dir_links => [@folder_link1.id.to_s], :file_links => [@file_link2.id.to_s] + :ids => ["folder-#{@folder1.id}", "file-#{@file1.id}", "folder-link-#{@folder_link1.id}", "file-link-#{@file_link2.id}"] assert_response :redirect assert_equal flash[:error].to_s, l(:error_folder_is_not_empty) end @@ -162,8 +160,7 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase @role.add_permission! :view_dmsf_files flash[:error] = nil get :entries_operation, :id => @project, :delete_entries => 'Delete', - :subfolders => [], :files => [@file1.id.to_s], - :dir_links => [], :file_links => [@file_link2.id.to_s] + :ids => ["file-#{@file1.id}", "file-link-#{@file_link2.id}"] assert_response :redirect assert_nil flash[:error] end @@ -173,8 +170,7 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase @role.add_permission! :view_dmsf_files @request.env['HTTP_REFERER'] = trash_dmsf_path(:id => @project.id) get :entries_operation, :id => @project, :restore_entries => 'Restore', - :subfolders => [], :files => [@file1.id.to_s], - :dir_links => [], :file_links => [@file_link2.id.to_s] + :ids => ["file-#{@file1.id}", "file-link-#{@file_link2.id}"] assert_response :redirect assert_nil flash[:error] end @@ -229,7 +225,7 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase Setting.plugin_redmine_dmsf['dmsf_documents_email_from'] = 'karel.picman@kontron.com' Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.expand_path '../../fixtures/files', __FILE__ @role.add_permission! :view_dmsf_files - get :entries_operation, :id => @project, :email_entries => 'Email', :files => [@file1.id] + get :entries_operation, :id => @project, :email_entries => 'Email', :ids => ["file-#{@file1.id}"] assert_response :success assert_select "input:match('value', ?)", Setting.plugin_redmine_dmsf['dmsf_documents_email_from'] end @@ -238,7 +234,7 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase Setting.plugin_redmine_dmsf['dmsf_documents_email_reply_to'] = 'karel.picman@kontron.com' Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.expand_path '../../fixtures/files', __FILE__ @role.add_permission! :view_dmsf_files - get :entries_operation, :id => @project, :email_entries => 'Email', :files => [@file1.id] + get :entries_operation, :id => @project, :email_entries => 'Email', :ids => ["file-#{@file1.id}"] assert_response :success assert_select "input:match('value', ?)", Setting.plugin_redmine_dmsf['dmsf_documents_email_reply_to'] end @@ -247,7 +243,7 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase Setting.plugin_redmine_dmsf['dmsf_documents_email_links_only'] = '1' Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.expand_path '../../fixtures/files', __FILE__ @role.add_permission! :view_dmsf_files - get :entries_operation, :id => @project, :email_entries => 'Email', :files => [@file1.id] + get :entries_operation, :id => @project, :email_entries => 'Email', :ids => ["file-#{@file1.id}"] assert_response :success assert_select "input:match('value', ?)", Setting.plugin_redmine_dmsf['dmsf_documents_email_links_only'] end diff --git a/test/unit/dmsf_file_revision_test.rb b/test/unit/dmsf_file_revision_test.rb index 89b75fa7..9f6ffe2c 100644 --- a/test/unit/dmsf_file_revision_test.rb +++ b/test/unit/dmsf_file_revision_test.rb @@ -41,19 +41,19 @@ class DmsfFileRevisionTest < RedmineDmsf::Test::UnitTest assert_kind_of DmsfFileRevision, @revision8 assert_kind_of DmsfWorkflow, @wf1 end - - def test_delete_restore - @revision5.delete false - assert @revision5.deleted?, + + def test_delete_restore + @revision5.delete false + assert @revision5.deleted?, "File revision #{@revision5.name} hasn't been deleted" - @revision5.restore - assert !@revision5.deleted?, + @revision5.restore + assert !@revision5.deleted?, "File revision #{@revision5.name} hasn't been restored" - end - - def test_destroy + end + + def test_destroy @revision5.delete true - assert_nil DmsfFileRevision.find_by_id @revision5.id + assert_nil DmsfFileRevision.find_by_id @revision5.id end def test_create_digest @@ -69,7 +69,7 @@ class DmsfFileRevisionTest < RedmineDmsf::Test::UnitTest @revision1.create_digest assert_equal 'SHA256', @revision1.digest_type end - + def test_new_storage_filename # Create a file. f = DmsfFile.new @@ -78,7 +78,7 @@ class DmsfFileRevisionTest < RedmineDmsf::Test::UnitTest f.dmsf_folder = nil f.notification = !Setting.plugin_redmine_dmsf['dmsf_default_notifications'].blank? f.save - + # Create two new revisions, r1 and r2 r1 = DmsfFileRevision.new r1.minor_version = 0 @@ -91,13 +91,13 @@ class DmsfFileRevisionTest < RedmineDmsf::Test::UnitTest r1.comment = nil r1.mime_type = nil r1.size = 4 - + r2 = r1.clone r2.minor_version = 1 - + assert r1.valid? assert r2.valid? - + # This is a very stupid since the generation and storing of files below must be done during the # same second, so wait until the microsecond part of the DateTime is less than 10 ms, should be # plenty of time to do the rest then. @@ -109,7 +109,7 @@ class DmsfFileRevisionTest < RedmineDmsf::Test::UnitTest end sleep 0.01 end - + # First, generate the r1 storage filename and save the file r1.disk_filename = r1.new_storage_filename assert r1.save @@ -117,12 +117,12 @@ class DmsfFileRevisionTest < RedmineDmsf::Test::UnitTest File.open(r1.disk_file, 'wb') do |f| f.write('1234') end - + # Directly after the file has been stored generate the r2 storage filename. # Hopefully the seconds part of the DateTime.now has not changed and the generated filename will # be on the same second but it should then be increased by 1. r2.disk_filename = r2.new_storage_filename - + assert_not_equal r1.disk_filename, r2.disk_filename, "The disk filename should not be equal for two revisions." end @@ -182,11 +182,45 @@ class DmsfFileRevisionTest < RedmineDmsf::Test::UnitTest assert_equal -(' '.ord), @revision1.minor_version end - def description_max_length - @revision1.description = 2.megabytes * 'a' + def test_description_max_length + @revision1.description = 'a' * 2.megabytes assert !@revision1.save - @revision1.description = 1.megabyte * 'a' + @revision1.description = 'a' * 1.megabyte assert @revision1.save end + def test_protocol_txt + assert !@revision1.protocol + end + + def test_protocol_doc + @revision1.mime_type = Redmine::MimeType.of('test.doc') + assert_equal 'ms-word', @revision1.protocol + end + + def test_protocol_docx + @revision1.mime_type = Redmine::MimeType.of('test.docx') + assert_equal 'ms-word', @revision1.protocol + end + + def test_protocol_odt + @revision1.mime_type = Redmine::MimeType.of('test.odt') + assert_equal 'ms-word', @revision1.protocol + end + + def test_protocol_xls + @revision1.mime_type = Redmine::MimeType.of('test.xls') + assert_equal 'ms-excel', @revision1.protocol + end + + def test_protocol_xlsx + @revision1.mime_type = Redmine::MimeType.of('test.xlsx') + assert_equal 'ms-excel', @revision1.protocol + end + + def test_protocol_ods + @revision1.mime_type = Redmine::MimeType.of('test.ods') + assert_equal 'ms-excel', @revision1.protocol + end + end \ No newline at end of file