From 6e418d637e7d7b0ec6638e09172de0dfe53c43d8 Mon Sep 17 00:00:00 2001 From: "vit.jonas@gmail.com" Date: Tue, 31 May 2011 06:53:14 +0000 Subject: [PATCH] Merged devel branch to trunk git-svn-id: http://redmine-dmsf.googlecode.com/svn/trunk/redmine_dmsf@109 5e329b0b-a2ee-ea63-e329-299493fc886d --- app/controllers/dmsf_controller.rb | 195 +++++++++--- app/controllers/dmsf_detail_controller.rb | 289 ------------------ app/controllers/dmsf_files_controller.rb | 231 ++++++++++++++ app/controllers/dmsf_state_controller.rb | 87 +----- app/controllers/dmsf_upload_controller.rb | 2 +- app/models/dmsf_file.rb | 2 +- app/views/dmsf/_multi_upload.html.erb | 5 - app/views/dmsf/_path.html.erb | 4 +- .../edit.html.erb} | 2 +- app/views/dmsf/email_entries.html.erb | 2 +- .../dmsf/{index.html.erb => show.html.erb} | 79 ++--- .../_file_new_revision.html.erb | 2 +- .../show.html.erb} | 34 +-- .../dmsf_mailer/files_deleted.text.html.rhtml | 2 +- .../files_deleted.text.plain.rhtml | 2 +- .../dmsf_mailer/files_updated.text.html.rhtml | 7 +- .../files_updated.text.plain.rhtml | 5 +- config/routes.rb | 10 +- init.rb | 34 +-- 19 files changed, 477 insertions(+), 517 deletions(-) delete mode 100644 app/controllers/dmsf_detail_controller.rb create mode 100644 app/controllers/dmsf_files_controller.rb rename app/views/{dmsf_detail/folder_detail.html.erb => dmsf/edit.html.erb} (93%) rename app/views/dmsf/{index.html.erb => show.html.erb} (66%) rename app/views/{dmsf_detail => dmsf_files}/_file_new_revision.html.erb (97%) rename app/views/{dmsf_detail/file_detail.html.erb => dmsf_files/show.html.erb} (77%) diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index a80c5971..7c34b5a4 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -20,14 +20,14 @@ class DmsfController < ApplicationController unloadable before_filter :find_project - before_filter :authorize - before_filter :find_folder, :only => [:index, :entries_operation, :email_entries_send] - before_filter :find_file, :only => [:download_file] + before_filter :authorize, :except => [:delete_entries] + before_filter :find_folder, :except => [:new, :create] + before_filter :find_parent, :only => [:new, :create] helper :sort include SortHelper - def index + def show sort_init ["title", "asc"] sort_update ["title", "size", "modified", "version", "author"] @@ -63,29 +63,6 @@ class DmsfController < ApplicationController end - def download_file - if @file.deleted - render_404 - else - @revision = @file.last_revision - Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} downloaded #{@project.identifier}://#{@file.dmsf_path_str} revision #{@revision.id}" - send_revision - end - end - - def download_revision - @revision = DmsfFileRevision.find(params[:revision_id]) - if @revision.deleted - render_404 - else - Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} downloaded #{@project.identifier}://#{@revision.file.dmsf_path_str} revision #{@revision.id}" - check_project(@revision.file) - send_revision - end - rescue DmsfAccessError - render_403 - end - def entries_operation selected_folders = params[:subfolders] selected_files = params[:files] @@ -103,15 +80,15 @@ class DmsfController < ApplicationController end rescue ZipMaxFilesError flash[:error] = l(:error_max_files_exceeded, :number => Setting.plugin_redmine_dmsf["dmsf_max_file_download"].to_i.to_s) - redirect_to({:controller => "dmsf", :action => "index", :id => @project, :folder_id => @folder}) + redirect_to({:controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder}) rescue DmsfAccessError render_403 end - def email_entries_send + def entries_email @email_params = params[:email] if @email_params["to"].strip.blank? - flash[:error] = l(:error_email_to_must_be_entered) + flash.now[:error] = l(:error_email_to_must_be_entered) render :action => "email_entries" return end @@ -119,12 +96,150 @@ class DmsfController < ApplicationController @email_params["subject"], @email_params["zipped_content"], @email_params["body"]) File.delete(@email_params["zipped_content"]) flash[:notice] = l(:notice_email_sent) - redirect_to({:controller => "dmsf", :action => "index", :id => @project, :folder_id => @folder}) + redirect_to({:controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder}) end class ZipMaxFilesError < StandardError end + def delete_entries + selected_folders = params[:subfolders] + selected_files = params[:files] + if selected_folders.nil? && selected_files.nil? + flash[:warning] = l(:warning_no_entries_selected) + else + failed_entries = [] + deleted_files = [] + deleted_folders = [] + unless selected_folders.nil? + if User.current.allowed_to?(:folder_manipulation, @project) + selected_folders.each do |subfolderid| + subfolder = DmsfFolder.find(subfolderid) + next if subfolder.nil? + if subfolder.project != @project || !subfolder.delete + failed_entries.push(subfolder) + else + deleted_folders.push(subfolder) + end + end + else + flash[:error] = l(:error_user_has_not_right_delete_folder) + end + end + unless selected_files.nil? + if User.current.allowed_to?(:file_manipulation, @project) + selected_files.each do |fileid| + file = DmsfFile.find(fileid) + next if file.nil? + if file.project != @project || !file.delete + failed_entries.push(file) + else + deleted_files.push(file) + end + end + else + flash[:error] = l(:error_user_has_not_right_delete_file) + end + end + unless deleted_folders.empty? + Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} deleted folders from project #{@project.identifier}:" + deleted_folders.each {|f| Rails.logger.info "\t#{f.dmsf_path_str}:"} + end + unless deleted_files.empty? + Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} deleted files from project #{@project.identifier}:" + deleted_files.each {|f| Rails.logger.info "\t#{f.dmsf_path_str}:"} + DmsfMailer.deliver_files_deleted(User.current, deleted_files) + end + if failed_entries.empty? + flash[:notice] = l(:notice_entries_deleted) + else + flash[:warning] = l(:warning_some_entries_were_not_deleted, :entries => failed_entries.map{|e| e.title}.join(", ")) + end + end + + redirect_to :controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder + end + + # Folder manipulation + + def new + @pathfolder = @parent + render :action => "edit" + end + + def create + @folder = DmsfFolder.new(params[:dmsf_folder]) + @folder.project = @project + @folder.folder = @parent + @folder.user = User.current + if @folder.save + flash[:notice] = l(:notice_folder_created) + Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} created folder #{@project.identifier}://#{@folder.dmsf_path_str}" + redirect_to({:controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder}) + else + @pathfolder = @parent + render :action => "edit" + end + end + + def edit + @parent = @folder.folder + @pathfolder = copy_folder(@folder) + end + + def save + unless params[:dmsf_folder] + redirect_to :controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder + return + end + @pathfolder = copy_folder(@folder) + @folder.attributes = params[:dmsf_folder] + if @folder.save + Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} updated folder #{@project.identifier}://#{@folder.dmsf_path_str}" + flash[:notice] = l(:notice_folder_details_were_saved) + redirect_to :controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder + else + render :action => "edit" + end + end + + def delete + check_project(@delete_folder = DmsfFolder.find(params[:delete_folder_id])) + if !@delete_folder.nil? + if @delete_folder.delete + flash[:notice] = l(:notice_folder_deleted) + Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} deleted folder #{@project.identifier}://#{@delete_folder.dmsf_path_str}" + else + flash[:error] = l(:error_folder_is_not_empty) + end + end + redirect_to :controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder + rescue DmsfAccessError + render_403 + end + + def notify_activate + if @folder.notification + flash[:warning] = l(:warning_folder_notifications_already_activated) + else + @folder.notify_activate + flash[:notice] = l(:notice_folder_notifications_activated) + end + redirect_to params[:current] ? params[:current] : + {:controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder.folder} + end + + def notify_deactivate + if !@folder.notification + flash[:warning] = l(:warning_folder_notifications_already_deactivated) + else + @folder.notify_deactivate + flash[:notice] = l(:notice_folder_notifications_deactivated) + end + redirect_to params[:current] ? params[:current] : + {:controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder.folder} + end + private def email_entries(selected_folders, selected_files) @@ -189,13 +304,6 @@ class DmsfController < ApplicationController zip end - def send_revision - send_file(@revision.disk_file, - :filename => filename_for_content_disposition(@revision.name), - :type => @revision.detect_content_type, - :disposition => "attachment") - end - def find_project @project = Project.find(params[:id]) end @@ -207,8 +315,9 @@ class DmsfController < ApplicationController render_403 end - def find_file - check_project(@file = DmsfFile.find(params[:file_id])) + def find_parent + @parent = DmsfFolder.find(params[:parent_id]) if params.keys.include?("parent_id") + check_project(@parent) rescue DmsfAccessError render_403 end @@ -219,4 +328,10 @@ class DmsfController < ApplicationController end end + def copy_folder(folder) + copy = folder.clone + copy.id = folder.id + copy + end + end diff --git a/app/controllers/dmsf_detail_controller.rb b/app/controllers/dmsf_detail_controller.rb deleted file mode 100644 index a2f11d5c..00000000 --- a/app/controllers/dmsf_detail_controller.rb +++ /dev/null @@ -1,289 +0,0 @@ -# Redmine plugin for Document Management System "Features" -# -# Copyright (C) 2011 Vít Jonáš -# -# 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. - -class DmsfDetailController < ApplicationController - unloadable - - menu_item :dmsf - - before_filter :find_project - before_filter :authorize, :except => [:delete_entries] - before_filter :find_parent, :only => [:folder_new, :create_folder, :save_folder] - before_filter :find_folder, :only => [:delete_folder, :save_folder, :folder_detail, :delete_entries] - before_filter :find_file, :only => [:save_file, :delete_file, :file_detail] - - def delete_entries - selected_folders = params[:subfolders] - selected_files = params[:files] - if selected_folders.nil? && selected_files.nil? - flash[:warning] = l(:warning_no_entries_selected) - else - failed_entries = [] - deleted_files = [] - deleted_folders = [] - unless selected_folders.nil? - if User.current.allowed_to?(:folder_manipulation, @project) - selected_folders.each do |subfolderid| - subfolder = DmsfFolder.find(subfolderid) - next if subfolder.nil? - if subfolder.project != @project || !subfolder.delete - failed_entries.push(subfolder) - else - deleted_folders.push(subfolder) - end - end - else - flash[:error] = l(:error_user_has_not_right_delete_folder) - end - end - unless selected_files.nil? - if User.current.allowed_to?(:file_manipulation, @project) - selected_files.each do |fileid| - file = DmsfFile.find(fileid) - next if file.nil? - if file.project != @project || !file.delete - failed_entries.push(file) - else - deleted_files.push(file) - end - end - else - flash[:error] = l(:error_user_has_not_right_delete_file) - end - end - unless deleted_folders.empty? - Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} deleted folders from project #{@project.identifier}:" - deleted_folders.each {|f| Rails.logger.info "\t#{f.dmsf_path_str}:"} - end - unless deleted_files.empty? - Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} deleted files from project #{@project.identifier}:" - deleted_files.each {|f| Rails.logger.info "\t#{f.dmsf_path_str}:"} - DmsfMailer.deliver_files_deleted(User.current, deleted_files) - end - if failed_entries.empty? - flash[:notice] = l(:notice_entries_deleted) - else - flash[:warning] = l(:warning_some_entries_were_not_deleted, :entries => failed_entries.map{|e| e.title}.join(", ")) - end - end - - redirect_to :controller => "dmsf", :action => "index", :id => @project, :folder_id => @folder - end - - def folder_new - @pathfolder = @parent - render :action => "folder_detail" - end - - def create_folder - @folder = DmsfFolder.new(params[:dmsf_folder]) - @folder.project = @project - @folder.folder = @parent - @folder.user = User.current - if @folder.save - flash[:notice] = l(:notice_folder_created) - Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} created folder #{@project.identifier}://#{@folder.dmsf_path_str}" - redirect_to({:controller => "dmsf", :action => "index", :id => @project, :folder_id => @folder}) - else - @pathfolder = @parent - render :action => "folder_detail" - end - end - - def folder_detail - @parent = @folder.folder - @pathfolder = copy_folder(@folder) - end - - def save_folder - unless params[:dmsf_folder] - redirect_to :controller => "dmsf", :action => "index", :id => @project, :folder_id => @folder - return - end - @pathfolder = copy_folder(@folder) - @folder.attributes = params[:dmsf_folder] - if @folder.save - Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} updated folder #{@project.identifier}://#{@folder.dmsf_path_str}" - flash[:notice] = l(:notice_folder_details_were_saved) - redirect_to :controller => "dmsf", :action => "index", :id => @project, :folder_id => @folder - else - render :action => "folder_detail" - end - end - - def delete_folder - check_project(@delete_folder = DmsfFolder.find(params[:delete_folder_id])) - if !@delete_folder.nil? - if @delete_folder.delete - flash[:notice] = l(:notice_folder_deleted) - Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} deleted folder #{@project.identifier}://#{@delete_folder.dmsf_path_str}" - else - flash[:error] = l(:error_folder_is_not_empty) - end - end - - redirect_to :controller => "dmsf", :action => "index", :id => @project, :folder_id => @folder - rescue DmsfAccessError - render_403 - end - - def file_detail - @revision = @file.last_revision - # TODO: line bellow is to handle old instalations with errors in data handling - @revision.name = @file.name - end - - #TODO: don't create revision if nothing change - def save_file - unless params[:dmsf_file_revision] - redirect_to :action => "file_detail", :id => @project, :file_id => @file - return - end - if @file.locked_for_user? - flash[:error] = l(:error_file_is_locked) - redirect_to :action => "file_detail", :id => @project, :file_id => @file - else - #TODO: validate folder_id - @revision = DmsfFileRevision.new(params[:dmsf_file_revision]) - - @revision.file = @file - last_revision = @file.last_revision - @revision.source_revision = last_revision - @revision.user = User.current - - @revision.major_version = last_revision.major_version - @revision.minor_version = last_revision.minor_version - @revision.workflow = last_revision.workflow - version = params[:version].to_i - file_upload = params[:file_upload] - if file_upload.nil? - @revision.disk_filename = last_revision.disk_filename - @revision.increase_version(version, false) - @revision.mime_type = last_revision.mime_type - @revision.size = last_revision.size - else - @revision.increase_version(version, true) - @revision.size = file_upload.size - @revision.disk_filename = @revision.new_storage_filename - @revision.mime_type = Redmine::MimeType.of(file_upload.original_filename) - end - @revision.set_workflow(params[:workflow]) - - @file.name = @revision.name - @file.folder = @revision.folder - - if @revision.valid? && @file.valid? - @revision.save! - unless file_upload.nil? - @revision.copy_file_content(file_upload) - end - - if @file.locked? - DmsfFileLock.file_lock_state(@file, false) - flash[:notice] = l(:notice_file_unlocked) + ", " - end - @file.save! - @file.reload - - flash[:notice] = (flash[:notice].nil? ? "" : flash[:notice]) + l(:notice_file_revision_created) - Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} created new revision of file #{@project.identifier}://#{@file.dmsf_path_str}" - begin - DmsfMailer.deliver_files_updated(User.current, [@file]) - rescue ActionView::MissingTemplate => e - Rails.logger.error "Could not send email notifications: " + e - end - redirect_to :action => "file_detail", :id => @project, :file_id => @file - else - render :action => "file_detail" - end - end - end - - def delete_file - if !@file.nil? - if @file.delete - flash[:notice] = l(:notice_file_deleted) - Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} deleted file #{@project.identifier}://#{@file.dmsf_path_str}" - DmsfMailer.deliver_files_deleted(User.current, [@file]) - else - flash[:error] = l(:error_file_is_locked) - end - end - redirect_to :controller => "dmsf", :action => "index", :id => @project, :folder_id => @file.folder - end - - def delete_revision - @revision = DmsfFileRevision.find(params[:revision_id]) - check_project(@revision.file) - if @revision.file.locked_for_user? - flash[:error] = l(:error_file_is_locked) - else - if !@revision.nil? && !@revision.deleted - if @revision.file.revisions.size <= 1 - flash[:error] = l(:error_at_least_one_revision_must_be_present) - else - @revision.deleted = true - @revision.deleted_by_user = User.current - @revision.save - flash[:notice] = l(:notice_revision_deleted) - Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} deleted revision #{@project.identifier}://#{@revision.file.dmsf_path_str}/#{@revision.id}" - end - end - end - redirect_to :action => "file_detail", :id => @project, :file_id => @revision.file - end - - private - - def copy_folder(folder) - copy = folder.clone - copy.id = folder.id - copy - end - - def find_project - @project = Project.find(params[:id]) - end - - def find_folder - @folder = DmsfFolder.find(params[:folder_id]) if params.keys.include?("folder_id") - check_project(@folder) - rescue DmsfAccessError - render_403 - end - - def find_parent - @parent = DmsfFolder.find(params[:parent_id]) if params.keys.include?("parent_id") - check_project(@parent) - rescue DmsfAccessError - render_403 - end - - def find_file - check_project(@file = DmsfFile.find(params[:file_id])) - rescue DmsfAccessError - render_403 - end - - def check_project(entry) - if !entry.nil? && entry.project != @project - raise DmsfAccessError, l(:error_entry_project_does_not_match_current_project) - end - end - -end \ No newline at end of file diff --git a/app/controllers/dmsf_files_controller.rb b/app/controllers/dmsf_files_controller.rb new file mode 100644 index 00000000..459345c0 --- /dev/null +++ b/app/controllers/dmsf_files_controller.rb @@ -0,0 +1,231 @@ +# Redmine plugin for Document Management System "Features" +# +# Copyright (C) 2011 Vít Jonáš +# +# 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. + +class DmsfFilesController < ApplicationController + unloadable + + menu_item :dmsf + + before_filter :find_file, :except => [:delete_revision] + before_filter :find_revision, :only => [:delete_revision] + before_filter :authorize + + def show + # download is put here to provide more clear and usable links + if params.has_key?(:download) + if @file.deleted + render_404 + return + end + if params[:download].blank? + @revision = @file.last_revision + else + @revision = DmsfFileRevision.find(params[:download].to_i) + if @revision.file != @file + render_403 + return + end + if @revision.deleted + render_404 + return + end + end + Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} downloaded #{@project.identifier}://#{@file.dmsf_path_str} revision #{@revision.id}" + check_project(@revision.file) + send_revision + return + end + + @revision = @file.last_revision + # TODO: line bellow is to handle old instalations with errors in data handling + @revision.name = @file.name + end + + #TODO: don't create revision if nothing change + def create_revision + unless params[:dmsf_file_revision] + redirect_to :action => "show", :id => @file + return + end + if @file.locked_for_user? + flash[:error] = l(:error_file_is_locked) + redirect_to :action => "show", :id => @file + else + #TODO: validate folder_id + @revision = DmsfFileRevision.new(params[:dmsf_file_revision]) + + @revision.file = @file + last_revision = @file.last_revision + @revision.source_revision = last_revision + @revision.user = User.current + + @revision.major_version = last_revision.major_version + @revision.minor_version = last_revision.minor_version + @revision.workflow = last_revision.workflow + version = params[:version].to_i + file_upload = params[:file_upload] + if file_upload.nil? + @revision.disk_filename = last_revision.disk_filename + @revision.increase_version(version, false) + @revision.mime_type = last_revision.mime_type + @revision.size = last_revision.size + else + @revision.increase_version(version, true) + @revision.size = file_upload.size + @revision.disk_filename = @revision.new_storage_filename + @revision.mime_type = Redmine::MimeType.of(file_upload.original_filename) + end + @revision.set_workflow(params[:workflow]) + + @file.name = @revision.name + @file.folder = @revision.folder + + if @revision.valid? && @file.valid? + @revision.save! + unless file_upload.nil? + @revision.copy_file_content(file_upload) + end + + if @file.locked? + DmsfFileLock.file_lock_state(@file, false) + flash[:notice] = l(:notice_file_unlocked) + ", " + end + @file.save! + @file.reload + + flash[:notice] = (flash[:notice].nil? ? "" : flash[:notice]) + l(:notice_file_revision_created) + Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} created new revision of file #{@project.identifier}://#{@file.dmsf_path_str}" + begin + DmsfMailer.deliver_files_updated(User.current, [@file]) + rescue ActionView::MissingTemplate => e + Rails.logger.error "Could not send email notifications: " + e + end + redirect_to :action => "show", :id => @file + else + render :action => "show" + end + end + end + + def delete + if !@file.nil? + if @file.delete + flash[:notice] = l(:notice_file_deleted) + Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} deleted file #{@project.identifier}://#{@file.dmsf_path_str}" + DmsfMailer.deliver_files_deleted(User.current, [@file]) + else + flash[:error] = l(:error_file_is_locked) + end + end + redirect_to :controller => "dmsf", :action => "show", :id => @project, :folder_id => @file.folder + end + + def delete_revision + if @revision.file.locked_for_user? + flash[:error] = l(:error_file_is_locked) + else + if !@revision.nil? && !@revision.deleted + if @revision.file.revisions.size <= 1 + flash[:error] = l(:error_at_least_one_revision_must_be_present) + else + @revision.deleted = true + @revision.deleted_by_user = User.current + @revision.save + flash[:notice] = l(:notice_revision_deleted) + Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} deleted revision #{@project.identifier}://#{@revision.file.dmsf_path_str}/#{@revision.id}" + end + end + end + redirect_to :action => "show", :id => @file + end + + def lock + if @file.locked? + flash[:warning] = l(:warning_file_already_locked) + else + @file.lock + flash[:notice] = l(:notice_file_locked) + end + redirect_to params[:current] ? params[:current] : + {:controller => "dmsf", :action => "show", :id => @project, :folder_id => @file.folder} + end + + def unlock + if !@file.locked? + flash[:warning] = l(:warning_file_not_locked) + else + if @file.locks[0].user == User.current || User.current.allowed_to?(:force_file_unlock, @file.project) + @file.unlock + flash[:notice] = l(:notice_file_unlocked) + else + flash[:error] = l(:error_only_user_that_locked_file_can_unlock_it) + end + end + redirect_to params[:current] ? params[:current] : + {:controller => "dmsf", :action => "show", :id => @project, :folder_id => @file.folder} + end + + def notify_activate + if @file.notification + flash[:warning] = l(:warning_file_notifications_already_activated) + else + @file.notify_activate + flash[:notice] = l(:notice_file_notifications_activated) + end + redirect_to params[:current] ? params[:current] : + {:controller => "dmsf", :action => "show", :id => @project, :folder_id => @file.folder} + end + + def notify_deactivate + if !@file.notification + flash[:warning] = l(:warning_file_notifications_already_deactivated) + else + @file.notify_deactivate + flash[:notice] = l(:notice_file_notifications_deactivated) + end + redirect_to params[:current] ? params[:current] : + {:controller => "dmsf", :action => "show", :id => @project, :folder_id => @file.folder} + end + + private + + def send_revision + send_file(@revision.disk_file, + :filename => filename_for_content_disposition(@revision.name), + :type => @revision.detect_content_type, + :disposition => "attachment") + end + + def find_file + @file = DmsfFile.find(params[:id]) + @project = @file.project + end + + def find_revision + @revision = DmsfFileRevision.find(params[:id]) + @file = @revision.file + @project = @file.project + end + + def check_project(entry) + if !entry.nil? && entry.project != @project + raise DmsfAccessError, l(:error_entry_project_does_not_match_current_project) + end + end + +end diff --git a/app/controllers/dmsf_state_controller.rb b/app/controllers/dmsf_state_controller.rb index 9779b229..9e7e1502 100644 --- a/app/controllers/dmsf_state_controller.rb +++ b/app/controllers/dmsf_state_controller.rb @@ -23,34 +23,6 @@ class DmsfStateController < ApplicationController before_filter :find_project before_filter :authorize - before_filter :find_folder, :only => [:folder_notify_activate, :folder_notify_deactivate] - before_filter :find_file, :only => [:lock_file, :unlock_file, :file_notify_activate, :file_notify_deactivate] - - def lock_file - if @file.locked? - flash[:warning] = l(:warning_file_already_locked) - else - @file.lock - flash[:notice] = l(:notice_file_locked) - end - redirect_to params[:current] ? params[:current] : - {:controller => "dmsf", :action => "index", :id => @project, :folder_id => @file.folder} - end - - def unlock_file - if !@file.locked? - flash[:warning] = l(:warning_file_not_locked) - else - if @file.locks[0].user == User.current || User.current.allowed_to?(:force_file_unlock, @file.project) - @file.unlock - flash[:notice] = l(:notice_file_unlocked) - else - flash[:error] = l(:error_only_user_that_locked_file_can_unlock_it) - end - end - redirect_to params[:current] ? params[:current] : - {:controller => "dmsf", :action => "index", :id => @project, :folder_id => @file.folder} - end def user_pref_save @user_pref = DmsfUserPref.for(@project, User.current) @@ -59,74 +31,17 @@ class DmsfStateController < ApplicationController flash[:notice] = l(:notice_your_preferences_were_saved) redirect_to :controller => "projects", :action => 'settings', :tab => 'dmsf', :id => @project end - - def folder_notify_activate - if @folder.notification - flash[:warning] = l(:warning_folder_notifications_already_activated) - else - @folder.notify_activate - flash[:notice] = l(:notice_folder_notifications_activated) - end - redirect_to params[:current] ? params[:current] : - {:controller => "dmsf", :action => "index", :id => @project, :folder_id => @folder.folder} - end - def folder_notify_deactivate - if !@folder.notification - flash[:warning] = l(:warning_folder_notifications_already_deactivated) - else - @folder.notify_deactivate - flash[:notice] = l(:notice_folder_notifications_deactivated) - end - redirect_to params[:current] ? params[:current] : - {:controller => "dmsf", :action => "index", :id => @project, :folder_id => @folder.folder} - end - - def file_notify_activate - if @file.notification - flash[:warning] = l(:warning_file_notifications_already_activated) - else - @file.notify_activate - flash[:notice] = l(:notice_file_notifications_activated) - end - redirect_to params[:current] ? params[:current] : - {:controller => "dmsf", :action => "index", :id => @project, :folder_id => @file.folder} - end - - def file_notify_deactivate - if !@file.notification - flash[:warning] = l(:warning_file_notifications_already_deactivated) - else - @file.notify_deactivate - flash[:notice] = l(:notice_file_notifications_deactivated) - end - redirect_to params[:current] ? params[:current] : - {:controller => "dmsf", :action => "index", :id => @project, :folder_id => @file.folder} - end - private def find_project @project = Project.find(params[:id]) end - def find_folder - @folder = DmsfFolder.find(params[:folder_id]) if params.keys.include?("folder_id") - check_project(@folder) - rescue DmsfAccessError - render_403 - end - - def find_file - check_project(@file = DmsfFile.find(params[:file_id])) - rescue DmsfAccessError - render_403 - end - def check_project(entry) if !entry.nil? && entry.project != @project raise DmsfAccessError, l(:error_entry_project_does_not_match_current_project) end end -end \ No newline at end of file +end diff --git a/app/controllers/dmsf_upload_controller.rb b/app/controllers/dmsf_upload_controller.rb index 27491dc4..7f04aea6 100644 --- a/app/controllers/dmsf_upload_controller.rb +++ b/app/controllers/dmsf_upload_controller.rb @@ -144,7 +144,7 @@ class DmsfUploadController < ApplicationController flash[:warning] = l(:warning_some_files_were_not_commited, :files => failed_uploads.map{|u| u["name"]}.join(", ")) end end - redirect_to :controller => "dmsf", :action => "index", :id => @project, :folder_id => @folder + redirect_to :controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder end private diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index d87a9f23..14eff9b1 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -46,7 +46,7 @@ class DmsfFile < ActiveRecord::Base acts_as_event :title => Proc.new {|o| "#{o.name}"}, :description => Proc.new {|o| "#{o.last_revision.title} - #{o.last_revision.description}" }, - :url => Proc.new {|o| {:controller => "dmsf", :action => "download_file", :id => o.project, :file_id => o}}, + :url => Proc.new {|o| {:controller => "dmsf_files", :action => "show", :id => o, :download => ""}}, :datetime => Proc.new {|o| o.updated_at }, :author => Proc.new {|o| o.last_revision.user } diff --git a/app/views/dmsf/_multi_upload.html.erb b/app/views/dmsf/_multi_upload.html.erb index f66ade01..57a811cd 100644 --- a/app/views/dmsf/_multi_upload.html.erb +++ b/app/views/dmsf/_multi_upload.html.erb @@ -65,11 +65,6 @@ <% content_for :header_tags do %> - <%= stylesheet_link_tag "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/themes/base/jquery-ui.css" %> - <%= stylesheet_link_tag "plupload/jquery.ui.plupload.css", :plugin => "redmine_dmsf" %> - <%= stylesheet_link_tag "dmsf", :plugin => "redmine_dmsf" %> - - <%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js" %> <%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js" %> <%= javascript_include_tag "plupload/plupload.js", :plugin => "redmine_dmsf" %> <%= javascript_include_tag "plupload/plupload.flash.js", :plugin => "redmine_dmsf" %> diff --git a/app/views/dmsf/_path.html.erb b/app/views/dmsf/_path.html.erb index d1d8138d..a937bff4 100644 --- a/app/views/dmsf/_path.html.erb +++ b/app/views/dmsf/_path.html.erb @@ -1,7 +1,7 @@ -<%= link_to(l(:link_documents), {:controller => "dmsf", :action => "index", :id=> @project }) %> +<%= link_to(l(:link_documents), {:controller => "dmsf", :action => "show", :id=> @project }) %> <% path.each do |path_element| %> / - <%= link_to(h(path_element.title), {:controller => "dmsf", :action => "index", :id=> @project, :folder_id => path_element}) %> + <%= link_to(h(path_element.title), {:controller => "dmsf", :action => "show", :id=> @project, :folder_id => path_element}) %> <% if path_element.notification %> <%= image_tag("notify.png", :plugin => "redmine_dmsf", :title => l(:title_notifications_active)) %> <% end %> diff --git a/app/views/dmsf_detail/folder_detail.html.erb b/app/views/dmsf/edit.html.erb similarity index 93% rename from app/views/dmsf_detail/folder_detail.html.erb rename to app/views/dmsf/edit.html.erb index d41bfc4d..c0bb4cd0 100644 --- a/app/views/dmsf_detail/folder_detail.html.erb +++ b/app/views/dmsf/edit.html.erb @@ -8,7 +8,7 @@ <%= ("/ " + l(:heading_new_folder)) if create %> -<% form_for(:dmsf_folder, @folder, :url => {:action => create ? "create_folder" : "save_folder", :id => @project, :folder_id => @folder, :parent_id => @parent}, +<% form_for(:dmsf_folder, @folder, :url => {:action => create ? "create" : "save", :id => @project, :folder_id => @folder, :parent_id => @parent}, :html => {:method=>:post}) do |f| %> <%= error_messages_for("folder") %>
diff --git a/app/views/dmsf/email_entries.html.erb b/app/views/dmsf/email_entries.html.erb index bfc0409c..32d55d1c 100644 --- a/app/views/dmsf/email_entries.html.erb +++ b/app/views/dmsf/email_entries.html.erb @@ -10,7 +10,7 @@

<%= l(:heading_send_documents_by_email) %>

-<% form_tag({:action => "email_entries_send", :id => @project, :folder_id => @folder}, +<% form_tag({:action => "entries_email", :id => @project, :folder_id => @folder}, { :method=>:post, :class => "tabular"}) do %>

diff --git a/app/views/dmsf/index.html.erb b/app/views/dmsf/show.html.erb similarity index 66% rename from app/views/dmsf/index.html.erb rename to app/views/dmsf/show.html.erb index 89eca50f..b4192ef8 100644 --- a/app/views/dmsf/index.html.erb +++ b/app/views/dmsf/show.html.erb @@ -4,11 +4,11 @@ <% if User.current.allowed_to?(:folder_manipulation, @project) %> <% unless @folder.nil? %> <%= link_to(image_tag("edit.png", :style => "vertical-align: text-top;"), - {:controller => "dmsf_detail", :action => "folder_detail", :id => @project, :folder_id => @folder }, - :title => l(:link_edit, :title => h(@folder.title))) %>   + {:action => "edit", :id => @project, :folder_id => @folder }, + :title => l(:link_edit, :title => h(@folder.title))) %>   <% end %> <%= link_to(image_tag("add.png", :style => "vertical-align: text-top;"), - {:controller => "dmsf_detail", :action => "folder_new", :id => @project, :parent_id => @folder }, + {:action => "new", :id => @project, :parent_id => @folder }, :title => l(:link_create_folder)) %> <% end %>

@@ -47,7 +47,7 @@ form_tag({:action => "entries_operation", :id => @project, :folder_id => @folder <%= check_box_tag("subfolders[]", subfolder.id, false, :title => l(:title_check_for_zip_download_or_email)) %> <%= link_to(h(subfolder.title), - {:action => "index", :folder_id => subfolder}, + {:action => "show", :id => @project, :folder_id => subfolder}, :class => "icon icon-folder") %> - @@ -59,12 +59,12 @@ form_tag({:action => "entries_operation", :id => @project, :folder_id => @folder
<% if subfolder.notification %> <%= link_to(image_tag("notify.png", :plugin => "redmine_dmsf"), - {:controller => "dmsf_state", :action => "folder_notify_deactivate", :id => @project, - :folder_id => subfolder}, :title => l(:title_notifications_active_deactivate)) %> + {:action => "notify_deactivate", :id => @project, + :folder_id => subfolder}, :title => l(:title_notifications_active_deactivate)) %> <% else %> <%= link_to(image_tag("notifynot.png", :plugin => "redmine_dmsf"), - {:controller => "dmsf_state", :action => "folder_notify_activate", :id => @project, - :folder_id => subfolder}, :title => l(:title_notifications_not_active_activate)) %> + {:action => "notify_activate", :id => @project, + :folder_id => subfolder}, :title => l(:title_notifications_not_active_activate)) %> <% end %>
<% end %> @@ -72,15 +72,15 @@ form_tag({:action => "entries_operation", :id => @project, :folder_id => @folder <% if User.current.allowed_to?(:folder_manipulation, @project) %>
<%= link_to(image_tag("edit.png", :class =>"detail_icon"), - {:controller => "dmsf_detail", :action => "folder_detail", :id => @project, :folder_id => subfolder }, - :title => l(:link_edit, :title => h(subfolder.title))) %> + {:action => "edit", :id => @project, :folder_id => subfolder }, + :title => l(:link_edit, :title => h(subfolder.title))) %>
<% end %>
<%= link_to(image_tag("delete.png", :plugin => "redmine_dmsf"), - {:controller => "dmsf_detail", :action => "delete_folder", :id => @project, - :folder_id => @folder, :delete_folder_id => subfolder}, :class => "delete-link", - :title => l(:title_delete)) if User.current.allowed_to?(:folder_manipulation, @project) %> + {:action => "delete", :id => @project, + :folder_id => @folder, :delete_folder_id => subfolder}, :class => "delete-link", + :title => l(:title_delete)) if User.current.allowed_to?(:folder_manipulation, @project) %>

@@ -92,9 +92,9 @@ form_tag({:action => "entries_operation", :id => @project, :folder_id => @folder <%= check_box_tag("files[]", file.id, false, :title => l(:title_check_for_zip_download_or_email)) %> <%= link_to(h(file.last_revision.display_title), - {:action => "download_file", :id => @project, :file_id => file}, - :class => "icon icon-file #{DmsfHelper.filetype_css(file.name)}", - :title => l(:title_title_version_version_download, :title => h(file.title), :version => file.version)) %> + {:controller => :dmsf_files, :action => "show", :id => file, :download => ""}, + :class => "icon icon-file #{DmsfHelper.filetype_css(file.name)}", + :title => l(:title_title_version_version_download, :title => h(file.title), :version => file.version)) %>
<%= h(file.display_name) %>
<%= number_to_human_size(file.last_revision.size) unless file.last_revision.nil? %> @@ -102,12 +102,11 @@ form_tag({:action => "entries_operation", :id => @project, :folder_id => @folder <%= file.last_revision.updated_at.strftime("%Y-%m-%d %H:%M") unless file.last_revision.nil? %> <% if file.locked_for_user? %> <%= link_to(image_tag("locked.png", :plugin => "redmine_dmsf"), - {:controller => "users", :action => "show", :id => file.locks[0].user }, - :title => l(:title_locked_by_user, :user => file.locks[0].user.to_s)) %> + {:controller => "users", :action => "show", :id => file.locks[0].user }, + :title => l(:title_locked_by_user, :user => file.locks[0].user.to_s)) %> <% else if file.locked? %> - <%= image_tag("lockedbycurrent.png", :title => l(:title_locked_by_you), - :plugin => "redmine_dmsf") %> + <%= image_tag("lockedbycurrent.png", :title => l(:title_locked_by_you), :plugin => "redmine_dmsf") %> <% end %> <% end %> @@ -126,38 +125,38 @@ form_tag({:action => "entries_operation", :id => @project, :folder_id => @folder
<% if file.notification %> <%= link_to(image_tag("notify.png", :plugin => "redmine_dmsf"), - {:controller => "dmsf_state", :action => "file_notify_deactivate", :id => @project, - :file_id => file}, :title => l(:title_notifications_active_deactivate)) %> + {:controller => "dmsf_files", :action => "notify_deactivate", :id => file}, + :title => l(:title_notifications_active_deactivate)) %> <% else %> <%= link_to(image_tag("notifynot.png", :plugin => "redmine_dmsf"), - {:controller => "dmsf_state", :action => "file_notify_activate", :id => @project, - :file_id => file}, :title => l(:title_notifications_not_active_activate)) %> + {:controller => "dmsf_files", :action => "notify_activate", :id => file}, + :title => l(:title_notifications_not_active_activate)) %> <% end %>
<% end %>
<%= link_to(image_tag("filedetails.png", :plugin => "redmine_dmsf", :class =>"detail_icon"), - {:controller => "dmsf_detail", :action => "file_detail", :id => @project, :file_id => file }, - :title => l(:link_details, :title =>h(file.last_revision.title))) %> + {:controller => "dmsf_files", :action => :show, :id => file }, + :title => l(:link_details, :title =>h(file.last_revision.title))) %>
<% unless file.locked_for_user? && !User.current.allowed_to?(:force_file_unlock, @project)%> <% if file.locked? %> <%= link_to(image_tag("unlock.png", :plugin => "redmine_dmsf"), - {:controller => "dmsf_state", :action => "unlock_file", :id => @project, :file_id => file }, - :title => l(:title_unlock_file)) %> + {:controller => "dmsf_files", :action => "unlock", :id => file }, + :title => l(:title_unlock_file)) %> <% else %> <%= link_to(image_tag("lock.png", :plugin => "redmine_dmsf"), - {:controller => "dmsf_state", :action => "lock_file", :id => @project, :file_id => file }, - :title => l(:title_lock_file)) %> + {:controller => "dmsf_files", :action => "lock", :id => file }, + :title => l(:title_lock_file)) %> <% end %>   <% end %> <% if User.current.allowed_to?(:file_manipulation, @project) && !file.locked_for_user? %> <%= link_to(image_tag("delete.png", :plugin => "redmine_dmsf"), - {:controller => "dmsf_detail", :action => "delete_file", :id => @project, - :file_id => file}, :class => "delete-link", :title => l(:title_delete)) %> + {:controller => "dmsf_files", :action => "delete", :id => file}, + :class => "delete-link", :title => l(:title_delete)) %> <% end %>
@@ -170,12 +169,22 @@ form_tag({:action => "entries_operation", :id => @project, :folder_id => @folder
<%= submit_tag(l(:submit_download), :title => l(:title_download_checked), :name => "download_entries") %> <%= submit_tag(l(:submit_email), :title => l(:title_send_checked_by_email), :name => "email_entries") %> - + <% if User.current.allowed_to?(:file_manipulation, @project) %> + + <% end %>

<% end %> -<%= render(:partial => "multi_upload") %> +<% content_for :header_tags do %> + <%= stylesheet_link_tag "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/themes/base/jquery-ui.css" %> + <%= stylesheet_link_tag "plupload/jquery.ui.plupload.css", :plugin => "redmine_dmsf" %> + <%= stylesheet_link_tag "dmsf", :plugin => "redmine_dmsf" %> + + <%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js" %> +<% end %> + +<%= render(:partial => "multi_upload") if User.current.allowed_to?(:file_manipulation, @project) %>
<% content_for :header_tags do %> @@ -189,7 +198,7 @@ form_tag({:action => "entries_operation", :id => @project, :folder_id => @folder jQuery("#entries_delete_button").click(function(event) { if(window.confirm("<%= l(:question_do_you_really_want_to_delete_entries) %>")) { - jQuery("#entries_form").attr("action", "<%= url_for(:controller => 'dmsf_detail', :action => 'delete_entries', :id => @project, :folder_id => @folder) %>"); + jQuery("#entries_form").attr("action", "<%= url_for(:action => 'delete_entries', :id => @project, :folder_id => @folder) %>"); jQuery("#entries_form").submit(); } }) diff --git a/app/views/dmsf_detail/_file_new_revision.html.erb b/app/views/dmsf_files/_file_new_revision.html.erb similarity index 97% rename from app/views/dmsf_detail/_file_new_revision.html.erb rename to app/views/dmsf_files/_file_new_revision.html.erb index 5cd9aaa7..dc889937 100644 --- a/app/views/dmsf_detail/_file_new_revision.html.erb +++ b/app/views/dmsf_files/_file_new_revision.html.erb @@ -18,7 +18,7 @@ else selected_workflow = @file.last_revision.workflow end -form_for(:dmsf_file_revision, @revision, :url => {:action => "save_file", :id => @project, :file_id => @file}, +form_for(:dmsf_file_revision, @revision, :url => {:action => "create_revision", :id => @file}, :html => {:method=>:post, :multipart => true}) do |f| %>
diff --git a/app/views/dmsf_detail/file_detail.html.erb b/app/views/dmsf_files/show.html.erb similarity index 77% rename from app/views/dmsf_detail/file_detail.html.erb rename to app/views/dmsf_files/show.html.erb index 7fb85708..3db8ce13 100644 --- a/app/views/dmsf_detail/file_detail.html.erb +++ b/app/views/dmsf_files/show.html.erb @@ -5,32 +5,29 @@ <% unless @file.locked_for_user? && !User.current.allowed_to?(:force_file_unlock, @project)%> <% if @file.locked? %> <%= link_to(image_tag("unlock.png", :plugin => "redmine_dmsf"), - {:controller => "dmsf_state", :action => "unlock_file", :id => @project, :file_id => @file, - :current => request.url }, - :title => l(:title_unlock_file)) %> + {:action => "unlock", :id => @file, :current => request.url }, + :title => l(:title_unlock_file)) %> <% else %> <%= link_to(image_tag("lock.png", :plugin => "redmine_dmsf"), - {:controller => "dmsf_state", :action => "lock_file", :id => @project, :file_id => @file, - :current => request.url }, - :title => l(:title_lock_file)) %> + {:action => "lock", :id => @file, :current => request.url }, + :title => l(:title_lock_file)) %> <% end %> <% end %> <% if User.current.allowed_to?(:file_manipulation, @project) && !@file.locked_for_user? %>   <%= link_to(image_tag("delete.png", :plugin => "redmine_dmsf"), - {:controller => "dmsf_detail", :action => "delete_file", :id => @project, - :file_id => @file}, :class => "delete-entry", :title => l(:title_delete)) %> + {:action => "delete", :id => @file}, :class => "delete-entry", :title => l(:title_delete)) %> <% end %> <% if User.current.allowed_to?(:file_approval, @project) %>   <% if @file.notification %> <%= link_to(image_tag("notify.png", :plugin => "redmine_dmsf"), - {:controller => "dmsf_state", :action => "file_notify_deactivate", :id => @project, - :file_id => @file, :current => request.url }, :title => l(:title_notifications_active_deactivate)) %> + {:action => "notify_deactivate", :id => @file, :current => request.url }, + :title => l(:title_notifications_active_deactivate)) %> <% else %> <%= link_to(image_tag("notifynot.png", :plugin => "redmine_dmsf"), - {:controller => "dmsf_state", :action => "file_notify_activate", :id => @project, - :file_id => @file, :current => request.url}, :title => l(:title_notifications_not_active_activate)) %> + {:action => "notify_activate", :id => @file, :current => request.url}, + :title => l(:title_notifications_not_active_activate)) %> <% end %> <% end %> <% end %> @@ -41,30 +38,25 @@ <%= render(:partial => "/dmsf/path", :locals => {:path => path}) %> / <%= h(@file.last_revision.title) %> -<% if @file.notification %> - <%= image_tag("notify.png", :plugin => "redmine_dmsf", - :title => l(:title_notifications_active)) %> -<% end %> +<%= image_tag("notify.png", :plugin => "redmine_dmsf", :title => l(:title_notifications_active)) if @file.notification %> <%= error_messages_for("file") %> <%= error_messages_for("revision") %> -<% if User.current.allowed_to?(:file_manipulation, @file.project) %> - <%= render(:partial => 'file_new_revision') %> -<% end %> +<%= render(:partial => "file_new_revision") if User.current.allowed_to?(:file_manipulation, @file.project) %>

<%= l(:heading_revisions) %>

<% @file.revisions.each do |revision| %>
<%= link_to(image_tag("download.png", :plugin => "redmine_dmsf"), - {:controller=>"dmsf", :action => "download_revision", :id => @project, :revision_id => revision}, + {:action => "show", :id => @file, :download => revision}, :title => l(:title_title_version_version_download, :title => h(revision.title), :version => revision.version)) %> <% if User.current.allowed_to?(:file_approval, @project) %>   <%= link_to(image_tag("delete.png", :plugin => "redmine_dmsf"), - {:action => "delete_revision", :id => @project, :revision_id => revision}, + {:action => "delete_revision", :id => revision}, :class => "delete-revision", :title => l(:title_delete_revision)) %> <% end %>
diff --git a/app/views/dmsf_mailer/files_deleted.text.html.rhtml b/app/views/dmsf_mailer/files_deleted.text.html.rhtml index 4439430f..6c930a4e 100644 --- a/app/views/dmsf_mailer/files_deleted.text.html.rhtml +++ b/app/views/dmsf_mailer/files_deleted.text.html.rhtml @@ -8,7 +8,7 @@ deleted DMSF files in project <%= @project.name %>: <% @files.each do |file| %>

- <%= h(file.dmsf_path_str) %>, + <%= h(file.dmsf_path_str) %> (<%= file.name %>), <%= number_to_human_size(file.last_revision.size) %>, version: <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %>

diff --git a/app/views/dmsf_mailer/files_deleted.text.plain.rhtml b/app/views/dmsf_mailer/files_deleted.text.plain.rhtml index a06527cd..52905590 100644 --- a/app/views/dmsf_mailer/files_deleted.text.plain.rhtml +++ b/app/views/dmsf_mailer/files_deleted.text.plain.rhtml @@ -1,5 +1,5 @@ User <%= @user %> deleted DMSF files in project <%= @project.name %>: <% @files.each do |file| %> - <%= file.dmsf_path_str %>, <%= number_to_human_size(file.last_revision.size) %>, version: <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %> + <%= file.dmsf_path_str %> (<%= file.name %>), <%= number_to_human_size(file.last_revision.size) %>, version: <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %> <% end %> \ No newline at end of file diff --git a/app/views/dmsf_mailer/files_updated.text.html.rhtml b/app/views/dmsf_mailer/files_updated.text.html.rhtml index cc505212..545256e2 100644 --- a/app/views/dmsf_mailer/files_updated.text.html.rhtml +++ b/app/views/dmsf_mailer/files_updated.text.html.rhtml @@ -9,14 +9,13 @@ <% @files.each do |file| %>

<%= link_to(h(file.dmsf_path_str), - {:only_path => false, :controller => "dmsf", :action => "download_file", :id => file.project, - :file_id => file}) %>, + {:only_path => false, :controller => "dmsf_files", :action => "show", :id => file, + :download => ""}) %> (<%= file.name %>), <%= number_to_human_size(file.last_revision.size) %>, version: <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %>, <%= "#{file.last_revision.workflow_str}," unless file.last_revision.workflow_str.blank? %> <%= link_to("Details", - {:only_path => false, :controller => "dmsf_detail", :action => "file_detail", :id => file.project, - :file_id => file }) %> + {:only_path => false, :controller => "dmsf_files", :action => "show", :id => file}) %> <% unless file.last_revision.comment.blank? %>
    <%= h(file.last_revision.comment) %> <% end %> diff --git a/app/views/dmsf_mailer/files_updated.text.plain.rhtml b/app/views/dmsf_mailer/files_updated.text.plain.rhtml index 766afdb7..b78bd7c2 100644 --- a/app/views/dmsf_mailer/files_updated.text.plain.rhtml +++ b/app/views/dmsf_mailer/files_updated.text.plain.rhtml @@ -1,7 +1,6 @@ User <%= @user %> actualized DMSF files in project <%= @project.name %>: <% @files.each do |file| %> - <%= file.dmsf_path_str %>, <%= number_to_human_size(file.last_revision.size) %>, version: <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %><%= ", #{file.last_revision.workflow_str}" unless file.last_revision.workflow_str.blank? %> - <%= url_for({:only_path => false, :controller => "dmsf_detail", :action => "file_detail", :id => file.project, - :file_id => file }) %> + <%= file.dmsf_path_str %> (<%= file.name %>), <%= number_to_human_size(file.last_revision.size) %>, version: <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %><%= ", #{file.last_revision.workflow_str}" unless file.last_revision.workflow_str.blank? %> + <%= url_for({:only_path => false, :controller => "dmsf_files", :action => "show", :id => file}) %> <% unless file.last_revision.comment.blank? %> comment: <%= file.last_revision.comment %><% end %> <% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1b9f41d0..9afd3f5c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,9 +16,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -#ActionController::Routing::Routes.draw do |map| -# map.resource :dmsf, :member => {:sync => :put} do |dmsf| -# dmsf.resource :dmsf_detail, :as => 'detail' -# dmsf.resource :dmsf_state, :as => 'state' -# end -#end +ActionController::Routing::Routes.draw do |map| + map.resources :dmsf + map.resources :dmsf_files +end diff --git a/init.rb b/init.rb index fd8ea83a..78b63bbf 100644 --- a/init.rb +++ b/init.rb @@ -28,8 +28,8 @@ end Redmine::Plugin.register :redmine_dmsf do name "DMSF" author "Vít Jonáš" - description "Document Management System Features for Redmine" - version "0.8.0" + description "Document Management System Features" + version "0.8.0 beta" url "https://code.google.com/p/redmine-dmsf/" author_url "mailto:vit.jonas@gmail.com" @@ -45,22 +45,22 @@ Redmine::Plugin.register :redmine_dmsf do "dmsf_stemming_strategy" => "STEM_NONE" } - menu :project_menu, :dmsf, { :controller => "dmsf", :action => "index" }, :caption => :dmsf, :after => :activity, :param => :id + menu :project_menu, :dmsf, { :controller => "dmsf", :action => "show" }, :caption => :dmsf, :after => :activity, :param => :id #delete_menu_item :project_menu, :documents activity_provider :dmsf_files, :class_name => "DmsfFileRevision", :default => true project_module :dmsf do - permission :browse_documents, {:dmsf => [:index]} + permission :browse_documents, {:dmsf => [:show]} permission :user_preferences, {:dmsf_state => [:user_pref_save]} - permission :view_dmsf_files, {:dmsf => [:download_file, :download_revision, :entries_operation, :email_entries_send], - :dmsf_detail => [:file_detail]} - permission :folder_manipulation, {:dmsf_detail => [:folder_new, :create_folder, :delete_folder, :folder_detail, :save_folder]} - permission :file_manipulation, {:dmsf_detail => [:save_file, :delete_file], - :dmsf_state => [:lock_file, :unlock_file], :dmsf_upload => [:upload_files, :upload_file, :commit_files]} - permission :file_approval, {:dmsf_detail => [:approve_file, :delete_revision], - :dmsf_state => [:file_notify_activate, :file_notify_deactivate, :folder_notify_activate, :folder_notify_deactivate]} - permission :force_file_unlock, {:dmsf_state => [:force_file_unlock]} + permission :view_dmsf_files, {:dmsf => [:entries_operation, :entries_email], + :dmsf_files => [:show]} + permission :folder_manipulation, {:dmsf => [:new, :create, :delete, :edit, :save]} + permission :file_manipulation, {:dmsf_files => [:create_revision, :delete, :lock, :unlock], + :dmsf_upload => [:upload_files, :upload_file, :commit_files]} + permission :file_approval, {:dmsf_files => [:delete_revision, :notify_activate, :notify_deactivate], + :dmsf => [:notify_activate, :notify_deactivate]} + permission :force_file_unlock, {} end Redmine::WikiFormatting::Macros.register do @@ -70,12 +70,10 @@ Redmine::Plugin.register :redmine_dmsf do macro :dmsf do |obj, args| return nil if args.length < 1 # require file id - return nil if @project == nil entry_id = args[0].strip entry = DmsfFile.find(entry_id) unless entry.nil? || entry.deleted - return nil if entry.project != @project - return link_to "#{entry.title}", :controller => "dmsf", :action => "download_file", :id => @project, :file_id => entry + return link_to "#{entry.title}", :controller => "dmsf_files", :action => "show", :id => entry, :download => "" end nil end @@ -87,15 +85,13 @@ Redmine::Plugin.register :redmine_dmsf do "_folder_id_ may be missing. _folder_id_ can be found in link for folder opening." macro :dmsff do |obj, args| - return nil if @project == nil if args.length < 1 - return link_to l(:link_documents), :controller => "dmsf", :action => "index", :id => @project + return link_to l(:link_documents), :controller => "dmsf", :action => "show", :id => @project else entry_id = args[0].strip entry = DmsfFolder.find(entry_id) unless entry.nil? - return nil if entry.project != @project - return link_to "#{entry.title}", :controller => "dmsf", :action => "index", :id => @project, :folder_id => entry + return link_to "#{entry.title}", :controller => "dmsf", :action => "show", :id => @project, :folder_id => entry end end nil