* finished Issue 134: Create possibility to copy file even to different project
git-svn-id: http://redmine-dmsf.googlecode.com/svn/trunk/redmine_dmsf@220 5e329b0b-a2ee-ea63-e329-299493fc886d
This commit is contained in:
parent
a6389a4a74
commit
a33340c4fc
@ -219,6 +219,7 @@ class DmsfFilesController < ApplicationController
|
||||
def find_file
|
||||
@file = DmsfFile.find(params[:id])
|
||||
@project = @file.project
|
||||
rescue
|
||||
end
|
||||
|
||||
def find_revision
|
||||
|
||||
129
app/controllers/dmsf_files_copy_controller.rb
Normal file
129
app/controllers/dmsf_files_copy_controller.rb
Normal file
@ -0,0 +1,129 @@
|
||||
# Redmine plugin for Document Management System "Features"
|
||||
#
|
||||
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
|
||||
#
|
||||
# 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 DmsfFilesCopyController < ApplicationController
|
||||
unloadable
|
||||
|
||||
menu_item :dmsf
|
||||
|
||||
before_filter :find_file
|
||||
before_filter :authorize
|
||||
|
||||
def new
|
||||
@target_project = DmsfFile.allowed_target_projects_on_copy.detect {|p| p.id.to_s == params[:target_project_id]} if params[:target_project_id]
|
||||
@target_project ||= @project if User.current.allowed_to?(:file_manipulation, @project)
|
||||
if DmsfFile.allowed_target_projects_on_copy.blank?
|
||||
flash.now[:warning] = l(:warning_no_project_to_copy_file_to)
|
||||
else
|
||||
@target_project ||= DmsfFile.allowed_target_projects_on_copy[0]
|
||||
end
|
||||
|
||||
@target_folder = DmsfFolder.find(params[:target_folder_id]) unless params[:target_folder_id].blank?
|
||||
@target_folder ||= @file.folder if @target_project == @project
|
||||
|
||||
render :layout => !request.xhr?
|
||||
end
|
||||
|
||||
def create
|
||||
if request.post?
|
||||
@target_project = DmsfFile.allowed_target_projects_on_copy.detect {|p| p.id.to_s == params[:target_project_id]} if params[:target_project_id]
|
||||
unless @target_project
|
||||
render_403
|
||||
return
|
||||
end
|
||||
@target_folder = DmsfFolder.find(params[:target_folder_id]) unless params[:target_folder_id].blank?
|
||||
if !@target_folder.nil? && @target_folder.project != @target_project
|
||||
raise DmsfAccessError, l(:error_entry_project_does_not_match_current_project)
|
||||
end
|
||||
|
||||
name = @file.name
|
||||
|
||||
file = DmsfFile.find_file_by_name(@target_project, @target_folder, name)
|
||||
if file.nil?
|
||||
file = DmsfFile.new
|
||||
file.project = @target_project
|
||||
file.name = name
|
||||
file.folder = @target_folder
|
||||
file.notification = !Setting.plugin_redmine_dmsf["dmsf_default_notifications"].blank?
|
||||
else
|
||||
if file.locked_for_user?
|
||||
flash[:error] = l(:error_file_is_locked)
|
||||
redirect_to :action => "new", :id => @file, :target_project_id => @target_project, :target_folder_id => @target_folder
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
last_revision = @file.last_revision
|
||||
|
||||
new_revision = DmsfFileRevision.new
|
||||
new_revision.folder = @target_folder
|
||||
new_revision.file = file
|
||||
new_revision.user = User.current
|
||||
new_revision.name = name
|
||||
new_revision.title = @file.title
|
||||
new_revision.description = @file.description
|
||||
new_revision.comment = l(:comment_copied_from, :source => "#{@project.identifier}:#{@file.dmsf_path_str}")
|
||||
new_revision.source_revision = last_revision
|
||||
new_revision.major_version = last_revision.major_version
|
||||
new_revision.minor_version = last_revision.minor_version
|
||||
new_revision.workflow = last_revision.workflow
|
||||
new_revision.mime_type = last_revision.mime_type
|
||||
new_revision.size = last_revision.size
|
||||
new_revision.disk_filename = last_revision.disk_filename
|
||||
|
||||
if file.save && new_revision.save
|
||||
file.reload
|
||||
else
|
||||
flash[:error] = error_messages_for(file)
|
||||
redirect_to :action => "new", :id => @file, :target_project_id => @target_project, :target_folder_id => @target_folder
|
||||
return
|
||||
end
|
||||
|
||||
flash[:notice] = l(:notice_file_copied)
|
||||
log_activity(file, "was copied (is copy)")
|
||||
|
||||
if params[:move]
|
||||
if User.current.allowed_to?(:file_manipulation, @project)
|
||||
if @file.delete
|
||||
flash[:notice] = l(:notice_file_moved)
|
||||
log_activity(@file, "was deleted")
|
||||
DmsfMailer.deliver_files_deleted(User.current, [@file])
|
||||
else
|
||||
flash[:error] = l(:error_file_is_locked)
|
||||
end
|
||||
else
|
||||
flash[:error] = l(:error_user_has_not_right_delete_file)
|
||||
end
|
||||
end
|
||||
|
||||
redirect_to :controller => "dmsf_files", :action => "show", :id => file
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def log_activity(file, action)
|
||||
Rails.logger.info "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} #{User.current.login}@#{request.remote_ip}/#{request.env['HTTP_X_FORWARDED_FOR']}: #{action} dmsf://#{file.project.identifier}/#{file.id}/#{file.last_revision.id}"
|
||||
end
|
||||
|
||||
def find_file
|
||||
@file = DmsfFile.find(params[:id])
|
||||
@project = @file.project
|
||||
end
|
||||
|
||||
end
|
||||
@ -184,6 +184,17 @@ class DmsfFile < ActiveRecord::Base
|
||||
#end
|
||||
end
|
||||
|
||||
# Returns an array of projects that current user can copy file to
|
||||
def self.allowed_target_projects_on_copy
|
||||
projects = []
|
||||
if User.current.admin?
|
||||
projects = Project.visible.all
|
||||
elsif User.current.logged?
|
||||
User.current.memberships.each {|m| projects << m.project if m.roles.detect {|r| r.allowed_to?(:file_manipulation)}}
|
||||
end
|
||||
projects
|
||||
end
|
||||
|
||||
# To fullfill searchable module expectations
|
||||
def self.search(tokens, projects=nil, options={})
|
||||
tokens = [] << tokens unless tokens.is_a?(Array)
|
||||
|
||||
@ -31,6 +31,8 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= link_to(image_tag("copy.png"), {:controller => :dmsf_files_copy, :action => "new", :id => @file }, :title => l(:title_copy_or_move)) %>
|
||||
</div>
|
||||
|
||||
<% path = @file.folder.nil? ? [] : @file.folder.dmsf_path %>
|
||||
@ -172,5 +174,15 @@ sUrl = "jquery.dataTables/#{I18n.locale.to_s.downcase}.json" if I18n.locale && !
|
||||
<%= javascript_include_tag "jquery.dataTables/jquery.dataTables.min.js", :plugin => "redmine_dmsf" %>
|
||||
<script type="text/javascript">
|
||||
jQuery.noConflict();
|
||||
|
||||
function copyFile() {
|
||||
var $copyDialog = jQuery('#copyDialog');
|
||||
$copyDialog.dialog({
|
||||
autoOpen: false,
|
||||
title: "Copy file"
|
||||
});
|
||||
$copyDialog.dialog('open')
|
||||
}
|
||||
|
||||
</script>
|
||||
<% end %>
|
||||
47
app/views/dmsf_files_copy/new.html.erb
Normal file
47
app/views/dmsf_files_copy/new.html.erb
Normal file
@ -0,0 +1,47 @@
|
||||
<% html_title(l(:dmsf)) %>
|
||||
|
||||
<div class="contextual">
|
||||
</div>
|
||||
|
||||
<% path = @file.folder.nil? ? [] : @file.folder.dmsf_path %>
|
||||
<h2>
|
||||
<%= render(:partial => "/dmsf/path", :locals => {:path => path}) %>
|
||||
/
|
||||
<%= link_to(h(@file.title), {:controller => "dmsf_files", :action => "show", :id=> @file}) %>
|
||||
<%= image_tag("notify.png", :plugin => "redmine_dmsf", :title => l(:title_notifications_active)) if @file.notification %>
|
||||
</h2>
|
||||
|
||||
<% unless DmsfFile.allowed_target_projects_on_copy.blank?
|
||||
form_tag({:action => "create", :id => @file}, :id => "copyForm") do |f| %>
|
||||
<div class="box dmsf_detail">
|
||||
<%= error_messages_for("file") %>
|
||||
<p>
|
||||
<label for="target_project_id"><%=l(:label_target_project)%>:</label>
|
||||
<%= select_tag("target_project_id",
|
||||
project_tree_options_for_select(DmsfFile.allowed_target_projects_on_copy, :selected => @target_project),
|
||||
:onchange => remote_function(:url => { :action => 'new' },
|
||||
:method => :get,
|
||||
:update => 'content',
|
||||
:with => "Form.serialize('copyForm')")) %>
|
||||
</p>
|
||||
<p>
|
||||
<%= label_tag("target_folder_id", l(:label_target_folder) + ":") %>
|
||||
<%= select_tag("target_folder_id",
|
||||
options_for_select(DmsfFolder.directory_tree(@target_project),
|
||||
:selected => (@target_folder.id unless @target_folder.nil?))) %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<%= submit_tag(l(:button_copy)) %>
|
||||
<%= submit_tag(l(:button_move), :name => 'move') if User.current.allowed_to?(:file_manipulation, @project) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% content_for :header_tags do %>
|
||||
<%= stylesheet_link_tag "dmsf", :plugin => "redmine_dmsf" %>
|
||||
<%= robot_exclusion_tag %>
|
||||
<%= javascript_include_tag "jquery-1.6.1.min.js", :plugin => "redmine_dmsf" %>
|
||||
<script type="text/javascript">
|
||||
jQuery.noConflict();
|
||||
</script>
|
||||
<% end %>
|
||||
@ -165,4 +165,12 @@ cs:
|
||||
:heading_access_last: "Poslední"
|
||||
:label_dmsf_updated: "DMSF změněno"
|
||||
:title_total_size_of_all_files: "Celková velikost všech souborů v adresáři"
|
||||
:project_module_dmsf: "DMSF"
|
||||
:project_module_dmsf: "DMSF"
|
||||
:warning_no_project_to_copy_file_to: "Neexistuje projekt, do kterého můžete kopírovat"
|
||||
:comment_copied_from: "Zkopírováno z %{source}"
|
||||
:notice_file_copied: "Soubor zkopírován"
|
||||
:notice_file_moved: "Soubor přesunut"
|
||||
:label_target_project: "Cílový projekt"
|
||||
:label_target_folder: "Cílový adresář"
|
||||
:title_copy_or_move: "Kopírovat/Přesunout"
|
||||
|
||||
@ -167,4 +167,11 @@ de:
|
||||
#Not translated
|
||||
:title_total_size_of_all_files: "Total size of all files under this folder"
|
||||
:project_module_dmsf: "DMSF"
|
||||
|
||||
:warning_no_project_to_copy_file_to: "No project to copy file to"
|
||||
:comment_copied_from: "Copied from %{source}"
|
||||
:notice_file_copied: "File copied"
|
||||
:notice_file_moved: "File moved"
|
||||
:label_target_project: "Target project"
|
||||
:label_target_folder: "Target folder"
|
||||
:title_copy_or_move: "Copy/Move"
|
||||
|
||||
@ -162,4 +162,11 @@ en-GB:
|
||||
:label_dmsf_updated: "DMSF updated"
|
||||
:title_total_size_of_all_files: "Total size of all files under this folder"
|
||||
:project_module_dmsf: "DMSF"
|
||||
:warning_no_project_to_copy_file_to: "No project to copy file to"
|
||||
:comment_copied_from: "Copied from %{source}"
|
||||
:notice_file_copied: "File copied"
|
||||
:notice_file_moved: "File moved"
|
||||
:label_target_project: "Target project"
|
||||
:label_target_folder: "Target folder"
|
||||
:title_copy_or_move: "Copy/Move"
|
||||
|
||||
@ -162,4 +162,11 @@ en-GB:
|
||||
:label_dmsf_updated: "DMSF updated"
|
||||
:title_total_size_of_all_files: "Total size of all files under this folder"
|
||||
:project_module_dmsf: "DMSF"
|
||||
:warning_no_project_to_copy_file_to: "No project to copy file to"
|
||||
:comment_copied_from: "Copied from %{source}"
|
||||
:notice_file_copied: "File copied"
|
||||
:notice_file_moved: "File moved"
|
||||
:label_target_project: "Target project"
|
||||
:label_target_folder: "Target folder"
|
||||
:title_copy_or_move: "Copy/Move"
|
||||
|
||||
@ -166,4 +166,11 @@ en:
|
||||
:label_dmsf_updated: "DMSF updated"
|
||||
:title_total_size_of_all_files: "Total size of all files under this folder"
|
||||
:project_module_dmsf: "DMSF"
|
||||
:warning_no_project_to_copy_file_to: "No project to copy file to"
|
||||
:comment_copied_from: "Copied from %{source}"
|
||||
:notice_file_copied: "File copied"
|
||||
:notice_file_moved: "File moved"
|
||||
:label_target_project: "Target project"
|
||||
:label_target_folder: "Target folder"
|
||||
:title_copy_or_move: "Copy/Move"
|
||||
|
||||
@ -164,4 +164,11 @@ es:
|
||||
:label_dmsf_updated: "DMSF updated"
|
||||
:title_total_size_of_all_files: "Total size of all files under this folder"
|
||||
:project_module_dmsf: "DMSF"
|
||||
:warning_no_project_to_copy_file_to: "No project to copy file to"
|
||||
:comment_copied_from: "Copied from %{source}"
|
||||
:notice_file_copied: "File copied"
|
||||
:notice_file_moved: "File moved"
|
||||
:label_target_project: "Target project"
|
||||
:label_target_folder: "Target folder"
|
||||
:title_copy_or_move: "Copy/Move"
|
||||
|
||||
@ -162,4 +162,11 @@ fr:
|
||||
:label_dmsf_updated: "DMSF updated"
|
||||
:title_total_size_of_all_files: "Total size of all files under this folder"
|
||||
:project_module_dmsf: "DMSF"
|
||||
:warning_no_project_to_copy_file_to: "No project to copy file to"
|
||||
:comment_copied_from: "Copied from %{source}"
|
||||
:notice_file_copied: "File copied"
|
||||
:notice_file_moved: "File moved"
|
||||
:label_target_project: "Target project"
|
||||
:label_target_folder: "Target folder"
|
||||
:title_copy_or_move: "Copy/Move"
|
||||
|
||||
@ -165,4 +165,13 @@ ja:
|
||||
:heading_access_last: "最終アクセス"
|
||||
:title_total_size_of_all_files: "このフォルダにある全ファイルの合計サイズ"
|
||||
:project_module_dmsf: "DMSF"
|
||||
|
||||
# Not translated
|
||||
:warning_no_project_to_copy_file_to: "No project to copy file to"
|
||||
:comment_copied_from: "Copied from %{source}"
|
||||
:notice_file_copied: "File copied"
|
||||
:notice_file_moved: "File moved"
|
||||
:label_target_project: "Target project"
|
||||
:label_target_folder: "Target folder"
|
||||
:title_copy_or_move: "Copy/Move"
|
||||
|
||||
@ -166,4 +166,13 @@ ru:
|
||||
:label_dmsf_updated: "Модуль Документооборота обновлен"
|
||||
:title_total_size_of_all_files: "Суммарный объем файлов в каталоге"
|
||||
:project_module_dmsf: "Документооборот"
|
||||
|
||||
|
||||
# Not translated
|
||||
:warning_no_project_to_copy_file_to: "No project to copy file to"
|
||||
:comment_copied_from: "Copied from %{source}"
|
||||
:notice_file_copied: "File copied"
|
||||
:notice_file_moved: "File moved"
|
||||
:label_target_project: "Target project"
|
||||
:label_target_folder: "Target folder"
|
||||
:title_copy_or_move: "Copy/Move"
|
||||
|
||||
@ -167,4 +167,13 @@ zh:
|
||||
:label_dmsf_updated: "DMSF updated"
|
||||
:title_total_size_of_all_files: "文件夹所有文件总大小"
|
||||
:project_module_dmsf: "文档管家"
|
||||
|
||||
# Not translated
|
||||
:warning_no_project_to_copy_file_to: "No project to copy file to"
|
||||
:comment_copied_from: "Copied from %{source}"
|
||||
:notice_file_copied: "File copied"
|
||||
:notice_file_moved: "File moved"
|
||||
:label_target_project: "Target project"
|
||||
:label_target_folder: "Target folder"
|
||||
:title_copy_or_move: "Copy/Move"
|
||||
|
||||
4
init.rb
4
init.rb
@ -29,7 +29,7 @@ Redmine::Plugin.register :redmine_dmsf do
|
||||
name "DMSF"
|
||||
author "Vít Jonáš"
|
||||
description "Document Management System Features"
|
||||
version "1.0.0"
|
||||
version "1.1.0 devel"
|
||||
url "http://code.google.com/p/redmine-dmsf/"
|
||||
author_url "mailto:vit.jonas@gmail.com"
|
||||
|
||||
@ -55,7 +55,7 @@ Redmine::Plugin.register :redmine_dmsf do
|
||||
permission :view_dmsf_folders, {:dmsf => [:show]}
|
||||
permission :user_preferences, {:dmsf_state => [:user_pref_save]}
|
||||
permission :view_dmsf_files, {:dmsf => [:entries_operation, :entries_email],
|
||||
:dmsf_files => [:show]}
|
||||
:dmsf_files => [:show], :dmsf_files_copy => [:new, :create]}
|
||||
permission :folder_manipulation, {:dmsf => [:new, :create, :delete, :edit, :save, :edit_root, :save_root]}
|
||||
permission :file_manipulation, {:dmsf_files => [:create_revision, :delete, :lock, :unlock],
|
||||
:dmsf_upload => [:upload_files, :upload_file, :commit_files]}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user