commit
6c7acfe9dc
@ -1,5 +1,5 @@
|
||||
# encoding: utf-8
|
||||
#
|
||||
#
|
||||
# Redmine plugin for Document Management System "Features"
|
||||
#
|
||||
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
|
||||
@ -22,32 +22,32 @@
|
||||
|
||||
class DmsfController < ApplicationController
|
||||
unloadable
|
||||
|
||||
|
||||
class ZipMaxFilesError < StandardError; end
|
||||
class EmailMaxFileSize < StandardError; end
|
||||
class EmailMaxFileSize < StandardError; end
|
||||
class FileNotFound < StandardError; end
|
||||
|
||||
|
||||
before_filter :find_project
|
||||
before_filter :authorize
|
||||
before_filter :find_folder, :except => [:new, :create, :edit_root, :save_root]
|
||||
before_filter :find_parent, :only => [:new, :create]
|
||||
|
||||
|
||||
helper :all
|
||||
|
||||
def show
|
||||
@folder_manipulation_allowed = User.current.allowed_to?(:folder_manipulation, @project)
|
||||
@file_manipulation_allowed = User.current.allowed_to?(:file_manipulation, @project)
|
||||
@file_delete_allowed = User.current.allowed_to?(:file_delete, @project)
|
||||
@file_delete_allowed = User.current.allowed_to?(:file_delete, @project)
|
||||
@file_view_allowed = User.current.allowed_to?(:view_dmsf_files, @project)
|
||||
@force_file_unlock_allowed = User.current.allowed_to?(:force_file_unlock, @project)
|
||||
@force_file_unlock_allowed = User.current.allowed_to?(:force_file_unlock, @project)
|
||||
@workflows_available = DmsfWorkflow.where(['project_id = ? OR project_id IS NULL', @project.id]).count > 0
|
||||
@file_approval_allowed = User.current.allowed_to?(:file_approval, @project)
|
||||
|
||||
|
||||
unless @folder
|
||||
if params[:custom_field_id].present? && params[:custom_value].present?
|
||||
@subfolders = []
|
||||
DmsfFolder.where(:project_id => @project.id).visible.each do |f|
|
||||
f.custom_field_values.each do |v|
|
||||
f.custom_field_values.each do |v|
|
||||
if v.custom_field_id == params[:custom_field_id].to_i
|
||||
if v.custom_field.compare_values?(v.value, params[:custom_value])
|
||||
@subfolders << f
|
||||
@ -60,24 +60,24 @@ class DmsfController < ApplicationController
|
||||
DmsfFile.where(:project_id => @project.id).visible.each do |f|
|
||||
r = f.last_revision
|
||||
if r
|
||||
r.custom_field_values.each do |v|
|
||||
r.custom_field_values.each do |v|
|
||||
if v.custom_field_id == params[:custom_field_id].to_i
|
||||
if v.custom_field.compare_values?(v.value, params[:custom_value])
|
||||
@files << f
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@dir_links = []
|
||||
DmsfLink.where(:project_id => @project.id, :target_type => DmsfFolder.model_name).visible.each do |l|
|
||||
l.target_folder.custom_field_values.each do |v|
|
||||
l.target_folder.custom_field_values.each do |v|
|
||||
if v.custom_field_id == params[:custom_field_id].to_i
|
||||
if v.custom_field.compare_values?(v.value, params[:custom_value])
|
||||
@dir_links << l
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -111,32 +111,32 @@ class DmsfController < ApplicationController
|
||||
end
|
||||
else
|
||||
@subfolders = @project.dmsf_folders.visible
|
||||
@files = @project.dmsf_files.visible
|
||||
@files = @project.dmsf_files.visible
|
||||
@dir_links = @project.folder_links.visible
|
||||
@file_links = @project.file_links.visible
|
||||
@url_links = @project.url_links.visible
|
||||
end
|
||||
@locked_for_user = false
|
||||
else
|
||||
else
|
||||
@subfolders = @folder.subfolders.visible
|
||||
@files = @folder.files.visible
|
||||
@files = @folder.files.visible
|
||||
@dir_links = @folder.folder_links.visible
|
||||
@file_links = @folder.file_links.visible
|
||||
@url_links = @folder.url_links.visible
|
||||
@locked_for_user = @folder.locked_for_user?
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ajax_upload_size = Setting.plugin_redmine_dmsf['dmsf_max_ajax_upload_filesize'].present? ? Setting.plugin_redmine_dmsf['dmsf_max_ajax_upload_filesize'] : 100
|
||||
|
||||
|
||||
# Trash
|
||||
@trash_visible = @folder_manipulation_allowed && @file_manipulation_allowed && @file_delete_allowed && !@locked_for_user && !@folder
|
||||
@trash_visible = @folder_manipulation_allowed && @file_manipulation_allowed && @file_delete_allowed && !@locked_for_user && !@folder
|
||||
@trash_enabled = DmsfFolder.deleted.where(:project_id => @project.id).any? ||
|
||||
DmsfFile.deleted.where(:project_id => @project.id).any? ||
|
||||
DmsfFile.deleted.where(:project_id => @project.id).any? ||
|
||||
DmsfLink.deleted.where(:project_id => @project.id, :target_type => DmsfFolder.model_name).any? ||
|
||||
DmsfLink.deleted.where(:project_id => @project.id, :target_type => DmsfFile.model_name).any? ||
|
||||
DmsfLink.deleted.where(:project_id => @project.id, :target_type => 'DmsfUrl').any?
|
||||
end
|
||||
|
||||
|
||||
def trash
|
||||
@folder_manipulation_allowed = User.current.allowed_to? :folder_manipulation, @project
|
||||
@file_manipulation_allowed = User.current.allowed_to? :file_manipulation, @project
|
||||
@ -147,47 +147,47 @@ class DmsfController < ApplicationController
|
||||
@file_links = DmsfLink.deleted.where(:project_id => @project.id, :target_type => DmsfFile.model_name)
|
||||
@url_links = DmsfLink.deleted.where(:project_id => @project.id, :target_type => 'DmsfUrl')
|
||||
end
|
||||
|
||||
|
||||
def download_email_entries
|
||||
send_file(
|
||||
send_file(
|
||||
params[:path],
|
||||
:filename => 'Documents.zip',
|
||||
:type => 'application/zip',
|
||||
:type => 'application/zip',
|
||||
:disposition => 'attachment')
|
||||
rescue Exception => e
|
||||
flash[:error] = e.message
|
||||
flash[:error] = e.message
|
||||
end
|
||||
|
||||
def entries_operation
|
||||
def entries_operation
|
||||
# Download/Email
|
||||
selected_folders = params[:subfolders] || []
|
||||
selected_files = params[:files] || []
|
||||
selected_dir_links = params[:dir_links] || []
|
||||
selected_file_links = params[:file_links] || []
|
||||
selected_url_links = params[:url_links] || []
|
||||
|
||||
if selected_folders.blank? && selected_files.blank? &&
|
||||
|
||||
if selected_folders.blank? && selected_files.blank? &&
|
||||
selected_dir_links.blank? && selected_file_links.blank? &&
|
||||
selected_url_links.blank?
|
||||
flash[:warning] = l(:warning_no_entries_selected)
|
||||
flash[:warning] = l(:warning_no_entries_selected)
|
||||
redirect_to :back
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
if selected_dir_links.present?
|
||||
selected_dir_links.each do |id|
|
||||
link = DmsfLink.find_by_id id
|
||||
selected_folders << link.target_id if link && !selected_folders.include?(link.target_id.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if selected_file_links.present?
|
||||
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
|
||||
end
|
||||
|
||||
|
||||
if params[:email_entries].present?
|
||||
email_entries(selected_folders, selected_files)
|
||||
elsif params[:restore_entries].present?
|
||||
@ -213,12 +213,12 @@ class DmsfController < ApplicationController
|
||||
rescue DmsfAccessError
|
||||
render_403
|
||||
end
|
||||
|
||||
|
||||
def tag_changed
|
||||
# Tag filter
|
||||
if params[:dmsf_folder] && params[:dmsf_folder][:custom_field_values].present?
|
||||
redirect_to dmsf_folder_path(
|
||||
:id => @project,
|
||||
:id => @project,
|
||||
:custom_field_id => params[:dmsf_folder][:custom_field_values].first[0],
|
||||
:custom_value => params[:dmsf_folder][:custom_field_values].first[1])
|
||||
else
|
||||
@ -227,18 +227,22 @@ class DmsfController < ApplicationController
|
||||
end
|
||||
|
||||
def entries_email
|
||||
@email_params = params[:email]
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
@email_params = e_params
|
||||
else
|
||||
@email_params = params[:email]
|
||||
end
|
||||
if @email_params[:to].strip.blank?
|
||||
flash.now[:error] = l(:error_email_to_must_be_entered)
|
||||
render :action => 'email_entries'
|
||||
return
|
||||
end
|
||||
end
|
||||
DmsfMailer.send_documents(@project, User.current, @email_params).deliver
|
||||
File.delete(@email_params['zipped_content'])
|
||||
flash[:notice] = l(:notice_email_sent, @email_params['to'])
|
||||
|
||||
|
||||
redirect_to dmsf_folder_path(:id => @project, :folder_id => @folder)
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@folder = DmsfFolder.new
|
||||
@ -247,7 +251,12 @@ class DmsfController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
@folder = DmsfFolder.new(params[:dmsf_folder])
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
@folder = DmsfFolder.new(
|
||||
params.require(:dmsf_folder).permit(:title, :description, :dmsf_folder_id))
|
||||
else
|
||||
@folder = DmsfFolder.new(params[:dmsf_folder])
|
||||
end
|
||||
@folder.project = @project
|
||||
@folder.user = User.current
|
||||
if @folder.save
|
||||
@ -279,7 +288,7 @@ class DmsfController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def delete
|
||||
def delete
|
||||
commit = params[:commit] == 'yes'
|
||||
if @folder.delete(commit)
|
||||
flash[:notice] = l(:notice_folder_deleted)
|
||||
@ -289,12 +298,12 @@ class DmsfController < ApplicationController
|
||||
if commit
|
||||
redirect_to :back
|
||||
else
|
||||
redirect_to dmsf_folder_path(:id => @project, :folder_id => @folder.folder)
|
||||
redirect_to dmsf_folder_path(:id => @project, :folder_id => @folder.folder)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def restore
|
||||
if @folder.restore
|
||||
if @folder.restore
|
||||
flash[:notice] = l(:notice_dmsf_folder_restored)
|
||||
else
|
||||
flash[:error] = @folder.errors.full_messages.to_sentence
|
||||
@ -312,7 +321,7 @@ class DmsfController < ApplicationController
|
||||
redirect_to :controller => 'dmsf', :action => 'show', :id => @project
|
||||
end
|
||||
|
||||
def notify_activate
|
||||
def notify_activate
|
||||
if((@folder && @folder.notification) || (@folder.nil? && @project.dmsf_notification))
|
||||
flash[:warning] = l(:warning_folder_notifications_already_activated)
|
||||
else
|
||||
@ -323,10 +332,10 @@ class DmsfController < ApplicationController
|
||||
@project.save
|
||||
end
|
||||
flash[:notice] = l(:notice_folder_notifications_activated)
|
||||
end
|
||||
end
|
||||
redirect_to :back
|
||||
end
|
||||
|
||||
|
||||
def notify_deactivate
|
||||
if((@folder && !@folder.notification) || (@folder.nil? && !@project.dmsf_notification))
|
||||
flash[:warning] = l(:warning_folder_notifications_already_deactivated)
|
||||
@ -338,7 +347,7 @@ class DmsfController < ApplicationController
|
||||
@project.save
|
||||
end
|
||||
flash[:notice] = l(:notice_folder_notifications_deactivated)
|
||||
end
|
||||
end
|
||||
redirect_to :back
|
||||
end
|
||||
|
||||
@ -350,7 +359,7 @@ class DmsfController < ApplicationController
|
||||
else
|
||||
@folder.lock!
|
||||
flash[:notice] = l(:notice_folder_locked)
|
||||
end
|
||||
end
|
||||
redirect_to :back
|
||||
end
|
||||
|
||||
@ -366,10 +375,10 @@ class DmsfController < ApplicationController
|
||||
else
|
||||
flash[:error] = l(:error_only_user_that_locked_folder_can_unlock_it)
|
||||
end
|
||||
end
|
||||
end
|
||||
redirect_to :back
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def log_activity(file, action)
|
||||
@ -395,14 +404,21 @@ class DmsfController < ApplicationController
|
||||
raise EmailMaxFileSize
|
||||
end
|
||||
|
||||
zip.files.each do |f|
|
||||
zip.files.each do |f|
|
||||
log_activity(f, 'emailing zip')
|
||||
audit = DmsfFileRevisionAccess.new(:user_id => User.current.id, :dmsf_file_revision_id => f.last_revision.id,
|
||||
:action => DmsfFileRevisionAccess::EmailAction)
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
audit = DmsfFileRevisionAccess.new
|
||||
audit.user = User.current
|
||||
audit.revision = f.last_revision
|
||||
audit.action = DmsfFileRevisionAccess::EmailAction
|
||||
else
|
||||
audit = DmsfFileRevisionAccess.new(:user_id => User.current.id, :dmsf_file_revision_id => f.last_revision.id,
|
||||
:action => DmsfFileRevisionAccess::EmailAction)
|
||||
end
|
||||
audit.save!
|
||||
end
|
||||
|
||||
@email_params = {
|
||||
@email_params = {
|
||||
:zipped_content => zipped_content,
|
||||
:folders => selected_folders,
|
||||
:files => selected_files
|
||||
@ -420,16 +436,23 @@ class DmsfController < ApplicationController
|
||||
zip = DmsfZip.new
|
||||
zip_entries(zip, selected_folders, selected_files)
|
||||
|
||||
zip.files.each do |f|
|
||||
zip.files.each do |f|
|
||||
log_activity(f, 'download zip')
|
||||
audit = DmsfFileRevisionAccess.new(:user_id => User.current.id, :dmsf_file_revision_id => f.last_revision.id,
|
||||
:action => DmsfFileRevisionAccess::DownloadAction)
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
audit = DmsfFileRevisionAccess.new
|
||||
audit.user = User.current
|
||||
audit.revision = f.last_revision
|
||||
audit.action = DmsfFileRevisionAccess::DownloadAction
|
||||
else
|
||||
audit = DmsfFileRevisionAccess.new(:user_id => User.current.id, :dmsf_file_revision_id => f.last_revision.id,
|
||||
:action => DmsfFileRevisionAccess::DownloadAction)
|
||||
end
|
||||
audit.save!
|
||||
end
|
||||
|
||||
send_file(zip.finish,
|
||||
send_file(zip.finish,
|
||||
:filename => filename_for_content_disposition("#{@project.name}-#{DateTime.now.strftime('%y%m%d%H%M%S')}.zip"),
|
||||
:type => 'application/zip',
|
||||
:type => 'application/zip',
|
||||
:disposition => 'attachment')
|
||||
rescue Exception => e
|
||||
flash[:error] = e.message
|
||||
@ -437,12 +460,12 @@ class DmsfController < ApplicationController
|
||||
zip.close if zip
|
||||
end
|
||||
end
|
||||
|
||||
def zip_entries(zip, selected_folders, selected_files)
|
||||
|
||||
def zip_entries(zip, selected_folders, selected_files)
|
||||
if selected_folders && selected_folders.is_a?(Array)
|
||||
selected_folders.each do |selected_folder_id|
|
||||
selected_folders.each do |selected_folder_id|
|
||||
folder = DmsfFolder.visible.find_by_id selected_folder_id
|
||||
if folder
|
||||
if folder
|
||||
zip.add_folder(folder, (folder.folder.dmsf_path_str if folder.folder))
|
||||
else
|
||||
raise FileNotFound
|
||||
@ -450,22 +473,22 @@ class DmsfController < ApplicationController
|
||||
end
|
||||
end
|
||||
if selected_files && selected_files.is_a?(Array)
|
||||
selected_files.each do |selected_file_id|
|
||||
selected_files.each do |selected_file_id|
|
||||
file = DmsfFile.visible.find_by_id selected_file_id
|
||||
if file && file.last_revision && File.exists?(file.last_revision.disk_file)
|
||||
zip.add_file(file, (file.folder.dmsf_path_str if file.folder)) if file
|
||||
if file && file.last_revision && File.exists?(file.last_revision.disk_file)
|
||||
zip.add_file(file, (file.folder.dmsf_path_str if file.folder)) if file
|
||||
else
|
||||
raise FileNotFound
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
max_files = Setting.plugin_redmine_dmsf['dmsf_max_file_download'].to_i
|
||||
if max_files > 0 && zip.files.length > max_files
|
||||
raise ZipMaxFilesError, zip.files.length
|
||||
end
|
||||
end
|
||||
zip
|
||||
end
|
||||
|
||||
|
||||
def restore_entries(selected_folders, selected_files, selected_dir_links, selected_file_links, selected_url_links)
|
||||
# Folders
|
||||
selected_folders.each do |id|
|
||||
@ -501,7 +524,7 @@ class DmsfController < ApplicationController
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def delete_entries(selected_folders, selected_files, selected_dir_links, selected_file_links, selected_url_links, commit)
|
||||
# Folders
|
||||
selected_folders.each do |id|
|
||||
@ -530,8 +553,8 @@ class DmsfController < ApplicationController
|
||||
end
|
||||
end
|
||||
# Activities
|
||||
if !deleted_files.empty?
|
||||
deleted_files.each do |f|
|
||||
if !deleted_files.empty?
|
||||
deleted_files.each do |f|
|
||||
log_activity(f, 'deleted')
|
||||
end
|
||||
begin
|
||||
@ -542,19 +565,19 @@ class DmsfController < ApplicationController
|
||||
Rails.logger.error "Could not send email notifications: #{e.message}"
|
||||
end
|
||||
end
|
||||
unless not_deleted_files.empty?
|
||||
unless not_deleted_files.empty?
|
||||
flash[:warning] = l(:warning_some_entries_were_not_deleted, :entries => not_deleted_files.map{|e| e.title}.join(', '))
|
||||
end
|
||||
# Links
|
||||
(selected_dir_links + selected_file_links + selected_url_links).each do |id|
|
||||
link = DmsfLink.find_by_id id
|
||||
link.delete commit if link
|
||||
link = DmsfLink.find_by_id id
|
||||
link.delete commit if link
|
||||
end
|
||||
if flash[:error].blank? && flash[:warning].blank?
|
||||
flash[:notice] = l(:notice_entries_deleted)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def find_folder
|
||||
@folder = DmsfFolder.find params[:folder_id] if params[:folder_id].present?
|
||||
rescue DmsfAccessError
|
||||
@ -573,4 +596,14 @@ class DmsfController < ApplicationController
|
||||
copy
|
||||
end
|
||||
|
||||
end
|
||||
private
|
||||
|
||||
def e_params
|
||||
params.fetch(:email, {}).permit(
|
||||
:to, :zipped_content, :email,
|
||||
:cc, :subject, :zipped_content => [], :files => [])
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
# encoding: utf-8
|
||||
#
|
||||
#
|
||||
# Redmine plugin for Document Management System "Features"
|
||||
#
|
||||
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
|
||||
@ -21,13 +21,13 @@
|
||||
|
||||
class DmsfFilesController < ApplicationController
|
||||
unloadable
|
||||
|
||||
|
||||
menu_item :dmsf
|
||||
|
||||
|
||||
before_filter :find_file, :except => [:delete_revision]
|
||||
before_filter :find_revision, :only => [:delete_revision]
|
||||
before_filter :authorize
|
||||
|
||||
|
||||
accept_api_auth :show
|
||||
|
||||
helper :all
|
||||
@ -35,12 +35,20 @@ class DmsfFilesController < ApplicationController
|
||||
|
||||
def view
|
||||
@revision = @file.last_revision
|
||||
check_project(@revision.file)
|
||||
check_project(@revision.file)
|
||||
begin
|
||||
log_activity('downloaded')
|
||||
access = DmsfFileRevisionAccess.new(:user_id => User.current.id,
|
||||
:dmsf_file_revision_id => @revision.id,
|
||||
:action => DmsfFileRevisionAccess::DownloadAction)
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
access = DmsfFileRevisionAccess.new
|
||||
access.user = User.current
|
||||
access.revision = @revision
|
||||
access.action = DmsfFileRevisionAccess::DownloadAction
|
||||
else
|
||||
access = DmsfFileRevisionAccess.new(
|
||||
:user_id => User.current.id,
|
||||
:dmsf_file_revision_id => @revision.id,
|
||||
:action => DmsfFileRevisionAccess::DownloadAction)
|
||||
end
|
||||
access.save!
|
||||
send_file(@revision.disk_file,
|
||||
:filename => filename_for_content_disposition(@revision.name),
|
||||
@ -49,9 +57,9 @@ class DmsfFilesController < ApplicationController
|
||||
rescue ActionController::MissingFile => e
|
||||
logger.error e.message
|
||||
render_404
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
# The download is put here to provide more clear and usable links
|
||||
if params.has_key?(:download)
|
||||
@ -62,17 +70,25 @@ class DmsfFilesController < ApplicationController
|
||||
if @revision.file != @file
|
||||
render_403
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
check_project(@revision.file)
|
||||
begin
|
||||
log_activity('downloaded')
|
||||
access = DmsfFileRevisionAccess.new(:user_id => User.current.id, :dmsf_file_revision_id => @revision.id,
|
||||
:action => DmsfFileRevisionAccess::DownloadAction)
|
||||
access.save!
|
||||
send_file(@revision.disk_file,
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
access = DmsfFileRevisionAccess.new
|
||||
access.user = User.current
|
||||
access.revision = @revision
|
||||
access.action = DmsfFileRevisionAccess::DownloadAction
|
||||
else
|
||||
access = DmsfFileRevisionAccess.new(
|
||||
:user_id => User.current.id,
|
||||
:dmsf_file_revision_id => @revision.id,
|
||||
:action => DmsfFileRevisionAccess::DownloadAction)
|
||||
end
|
||||
send_file(@revision.disk_file,
|
||||
:filename => filename_for_content_disposition(@revision.name),
|
||||
:type => @revision.detect_content_type,
|
||||
:type => @revision.detect_content_type,
|
||||
:disposition => 'attachment')
|
||||
rescue ActionController::MissingFile => e
|
||||
logger.error e.message
|
||||
@ -80,35 +96,40 @@ class DmsfFilesController < ApplicationController
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
@revision = @file.last_revision
|
||||
@file_delete_allowed = User.current.allowed_to?(:file_delete, @project)
|
||||
|
||||
@revision = @file.last_revision
|
||||
@file_delete_allowed = User.current.allowed_to?(:file_delete, @project)
|
||||
@revision_pages = Paginator.new @file.revisions.visible.count, params['per_page'] ? params['per_page'].to_i : 25, params['page']
|
||||
|
||||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
render :layout => !request.xhr?
|
||||
}
|
||||
format.api
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def create_revision
|
||||
if params[:dmsf_file_revision]
|
||||
if @file.locked_for_user?
|
||||
flash[:error] = l(:error_file_is_locked)
|
||||
else
|
||||
revision = DmsfFileRevision.new(params[:dmsf_file_revision])
|
||||
flash[:error] = l(:error_file_is_locked)
|
||||
else
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
aparams = frev_params
|
||||
else
|
||||
aparams = params
|
||||
end
|
||||
revision = DmsfFileRevision.new(aparams)
|
||||
|
||||
revision.file = @file
|
||||
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.minor_version = last_revision.minor_version
|
||||
version = params[:version].to_i
|
||||
file_upload = params[:file_upload]
|
||||
file_upload = params[:file_upload]
|
||||
unless file_upload
|
||||
revision.disk_filename = last_revision.disk_filename
|
||||
if version == 3
|
||||
@ -129,9 +150,9 @@ class DmsfFilesController < ApplicationController
|
||||
revision.size = file_upload.size
|
||||
revision.disk_filename = revision.new_storage_filename
|
||||
revision.mime_type = Redmine::MimeType.of(file_upload.original_filename)
|
||||
end
|
||||
end
|
||||
|
||||
@file.name = revision.name
|
||||
@file.name = revision.name
|
||||
|
||||
if revision.valid? && @file.valid?
|
||||
revision.save!
|
||||
@ -153,11 +174,11 @@ class DmsfFilesController < ApplicationController
|
||||
|
||||
flash[:notice] = (flash[:notice].nil? ? '' : flash[:notice]) + l(:notice_file_revision_created)
|
||||
log_activity('new revision')
|
||||
begin
|
||||
begin
|
||||
recipients = DmsfMailer.get_notify_users(@project, [@file])
|
||||
recipients.each do |u|
|
||||
DmsfMailer.files_updated(u, @project, [@file]).deliver
|
||||
end
|
||||
end
|
||||
if Setting.plugin_redmine_dmsf[:dmsf_display_notified_recipients] == '1'
|
||||
unless recipients.empty?
|
||||
to = recipients.collect{ |r| r.name }.first(DMSF_MAX_NOTIFICATION_RECEIVERS_INFO).join(', ')
|
||||
@ -167,14 +188,14 @@ class DmsfFilesController < ApplicationController
|
||||
end
|
||||
rescue Exception => e
|
||||
logger.error "Could not send email notifications: #{e.message}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
redirect_to :back
|
||||
end
|
||||
|
||||
def delete
|
||||
def delete
|
||||
if @file
|
||||
commit = params[:commit] == 'yes'
|
||||
if @file.delete(commit)
|
||||
@ -189,26 +210,26 @@ class DmsfFilesController < ApplicationController
|
||||
Rails.logger.error "Could not send email notifications: #{e.message}"
|
||||
end
|
||||
end
|
||||
else
|
||||
@file.errors.each do |e, msg|
|
||||
flash[:error] = msg
|
||||
else
|
||||
@file.errors.each do |e, msg|
|
||||
flash[:error] = msg
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if commit
|
||||
redirect_to :back
|
||||
else
|
||||
redirect_to dmsf_folder_path(:id => @project, :folder_id => @file.folder)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def delete_revision
|
||||
def delete_revision
|
||||
if @revision # && !@revision.deleted
|
||||
if @revision.delete(true)
|
||||
flash[:notice] = l(:notice_revision_deleted)
|
||||
log_activity('deleted')
|
||||
else
|
||||
@revision.errors.each do |e, msg|
|
||||
else
|
||||
@revision.errors.each do |e, msg|
|
||||
flash[:error] = msg
|
||||
end
|
||||
end
|
||||
@ -222,10 +243,10 @@ class DmsfFilesController < ApplicationController
|
||||
else
|
||||
@file.lock!
|
||||
flash[:notice] = l(:notice_file_locked)
|
||||
end
|
||||
end
|
||||
redirect_to :back
|
||||
end
|
||||
|
||||
|
||||
def unlock
|
||||
unless @file.locked?
|
||||
flash[:warning] = l(:warning_file_not_locked)
|
||||
@ -236,7 +257,7 @@ class DmsfFilesController < ApplicationController
|
||||
else
|
||||
flash[:error] = l(:error_only_user_that_locked_file_can_unlock_it)
|
||||
end
|
||||
end
|
||||
end
|
||||
redirect_to :back
|
||||
end
|
||||
|
||||
@ -246,20 +267,20 @@ class DmsfFilesController < ApplicationController
|
||||
else
|
||||
@file.notify_activate
|
||||
flash[:notice] = l(:notice_file_notifications_activated)
|
||||
end
|
||||
end
|
||||
redirect_to :back
|
||||
end
|
||||
|
||||
|
||||
def notify_deactivate
|
||||
unless @file.notification
|
||||
flash[:warning] = l(:warning_file_notifications_already_deactivated)
|
||||
else
|
||||
@file.notify_deactivate
|
||||
flash[:notice] = l(:notice_file_notifications_deactivated)
|
||||
end
|
||||
end
|
||||
redirect_to :back
|
||||
end
|
||||
|
||||
|
||||
def restore
|
||||
if @file.restore
|
||||
log_activity('restored')
|
||||
@ -272,11 +293,16 @@ class DmsfFilesController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def frev_params
|
||||
params.require(:dmsf_file_revision).permit(
|
||||
:title, :name, :description, :comment)
|
||||
end
|
||||
|
||||
def log_activity(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}/#{@revision.id if @revision}"
|
||||
end
|
||||
|
||||
def find_file
|
||||
end
|
||||
|
||||
def find_file
|
||||
@file = DmsfFile.find params[:id]
|
||||
@project = @file.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
@ -285,7 +311,7 @@ class DmsfFilesController < ApplicationController
|
||||
|
||||
def find_revision
|
||||
@revision = DmsfFileRevision.visible.find(params[:id])
|
||||
@file = @revision.file
|
||||
@file = @revision.file
|
||||
@project = @file.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
@ -293,8 +319,8 @@ class DmsfFilesController < ApplicationController
|
||||
|
||||
def check_project(entry)
|
||||
if entry && entry.project != @project
|
||||
raise DmsfAccessError, l(:error_entry_project_does_not_match_current_project)
|
||||
raise DmsfAccessError, l(:error_entry_project_does_not_match_current_project)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -18,23 +18,27 @@
|
||||
|
||||
class DmsfLinksController < ApplicationController
|
||||
unloadable
|
||||
|
||||
|
||||
model_object DmsfLink
|
||||
before_filter :find_model_object, :only => [:destroy, :restore]
|
||||
before_filter :find_link_project
|
||||
before_filter :authorize
|
||||
before_filter :authorize
|
||||
|
||||
def new
|
||||
@dmsf_link = DmsfLink.new(:project_id => params[:project_id])
|
||||
|
||||
if params[:dmsf_link].present?
|
||||
def new
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
@dmsf_link = DmsfLink.new(l_params)
|
||||
else
|
||||
@dmsf_link = DmsfLink.new(:project_id => params[:project_id])
|
||||
end
|
||||
|
||||
if params[:dmsf_link].present?
|
||||
# Reload
|
||||
@dmsf_link.dmsf_folder_id = params[:dmsf_link][:dmsf_folder_id] # TODO: Add stuff in here for external links so that if error occurs, repopulate the same
|
||||
@dmsf_file_id = params[:dmsf_link][:dmsf_file_id]
|
||||
@type = params[:dmsf_link][:type]
|
||||
@link_external = (params[:external_link] == 'true')
|
||||
@dmsf_link.target_project_id = params[:dmsf_link][:target_project_id]
|
||||
@target_folder_id = params[:dmsf_link][:target_folder_id].to_i if params[:reload].blank? && DmsfLinksHelper.is_a_number?(params[:dmsf_link][:target_folder_id])
|
||||
@dmsf_link.target_project_id = params[:dmsf_link][:target_project_id]
|
||||
@target_folder_id = params[:dmsf_link][:target_folder_id].to_i if params[:reload].blank? && DmsfLinksHelper.is_a_number?(params[:dmsf_link][:target_folder_id])
|
||||
if @type == 'link_to'
|
||||
if params[:dmsf_link][:dmsf_file_id].present?
|
||||
file = DmsfFile.find_by_id params[:dmsf_link][:dmsf_file_id]
|
||||
@ -43,7 +47,7 @@ class DmsfLinksController < ApplicationController
|
||||
folder = DmsfFolder.find_by_id params[:dmsf_link][:dmsf_folder_id]
|
||||
@dmsf_link.name = folder.title if folder
|
||||
end
|
||||
else
|
||||
else
|
||||
if params[:dmsf_link][:target_file_id].present?
|
||||
@target_file_id = params[:dmsf_link][:target_file_id]
|
||||
file = DmsfFile.find_by_id @target_file_id
|
||||
@ -53,7 +57,7 @@ class DmsfLinksController < ApplicationController
|
||||
if (folder && (folder.project_id == @dmsf_link.target_project_id) && folder.files.include?(file)) || folder.nil?
|
||||
@dmsf_link.name = file.title
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
folder = DmsfFolder.find_by_id params[:dmsf_link][:target_folder_id]
|
||||
|
||||
@ -61,9 +65,9 @@ class DmsfLinksController < ApplicationController
|
||||
if folder.project_id == @dmsf_link.target_project_id
|
||||
@dmsf_link.name = folder.title if folder
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
# Link from/to
|
||||
@dmsf_link.dmsf_folder_id = params[:dmsf_folder_id]
|
||||
@ -71,6 +75,7 @@ class DmsfLinksController < ApplicationController
|
||||
@type = params[:type]
|
||||
@link_external = false
|
||||
@dmsf_link.target_project_id = params[:project_id]
|
||||
@dmsf_link.project_id = params[:project_id]
|
||||
@target_folder_id = params[:dmsf_folder_id].to_i if params[:dmsf_folder_id].present?
|
||||
if @type == 'link_to'
|
||||
if @dmsf_file_id
|
||||
@ -81,15 +86,15 @@ class DmsfLinksController < ApplicationController
|
||||
@dmsf_link.name = folder.title if folder
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
render :layout => !request.xhr?
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@dmsf_link = DmsfLink.new
|
||||
@dmsf_link.user = User.current
|
||||
|
||||
|
||||
if params[:dmsf_link][:type] == 'link_from'
|
||||
# Link from
|
||||
@dmsf_link.project_id = params[:dmsf_link][:project_id]
|
||||
@ -105,21 +110,21 @@ class DmsfLinksController < ApplicationController
|
||||
else
|
||||
@dmsf_link.target_id = DmsfLinksHelper.is_a_number?(params[:dmsf_link][:target_folder_id]) ? params[:dmsf_link][:target_folder_id].to_i : nil
|
||||
@dmsf_link.target_type = DmsfFolder.model_name
|
||||
end
|
||||
@dmsf_link.name = params[:dmsf_link][:name]
|
||||
|
||||
end
|
||||
@dmsf_link.name = params[:dmsf_link][:name]
|
||||
|
||||
if @dmsf_link.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to dmsf_folder_path(:id => @project.id, :folder_id => @dmsf_link.dmsf_folder_id)
|
||||
else
|
||||
else
|
||||
@dmsf_file_id = params[:dmsf_link][:dmsf_file_id]
|
||||
@type = params[:dmsf_link][:type]
|
||||
@target_folder_id = params[:dmsf_link][:target_folder_id].to_i if DmsfLinksHelper.is_a_number?(params[:dmsf_link][:target_folder_id])
|
||||
@type = params[:dmsf_link][:type]
|
||||
@target_folder_id = params[:dmsf_link][:target_folder_id].to_i if DmsfLinksHelper.is_a_number?(params[:dmsf_link][:target_folder_id])
|
||||
@target_file_id = @dmsf_link.target_id if @dmsf_link.target_type == DmsfFile.model_name
|
||||
render :action => 'new'
|
||||
end
|
||||
else
|
||||
# Link to
|
||||
# Link to
|
||||
@dmsf_link.project_id = params[:dmsf_link][:target_project_id]
|
||||
@dmsf_link.dmsf_folder_id = DmsfLinksHelper.is_a_number?(params[:dmsf_link][:target_folder_id]) ? params[:dmsf_link][:target_folder_id].to_i : nil
|
||||
@dmsf_link.target_project_id = params[:dmsf_link][:project_id]
|
||||
@ -130,29 +135,29 @@ class DmsfLinksController < ApplicationController
|
||||
elsif params[:dmsf_link][:dmsf_file_id].present?
|
||||
@dmsf_link.target_id = params[:dmsf_link][:dmsf_file_id]
|
||||
@dmsf_link.target_type = DmsfFile.model_name
|
||||
else
|
||||
else
|
||||
@dmsf_link.target_id = params[:dmsf_link][:dmsf_folder_id]
|
||||
@dmsf_link.target_type = DmsfFolder.model_name
|
||||
end
|
||||
@dmsf_link.name = params[:dmsf_link][:name]
|
||||
|
||||
if @dmsf_link.save
|
||||
@dmsf_link.name = params[:dmsf_link][:name]
|
||||
|
||||
if @dmsf_link.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
if params[:dmsf_link][:dmsf_file_id].present?
|
||||
redirect_to dmsf_file_path(@dmsf_link.target_file)
|
||||
else
|
||||
redirect_to edit_dmsf_path(:id => params[:dmsf_link][:project_id], :folder_id => params[:dmsf_link][:dmsf_folder_id])
|
||||
else
|
||||
redirect_to edit_dmsf_path(:id => params[:dmsf_link][:project_id], :folder_id => params[:dmsf_link][:dmsf_folder_id])
|
||||
end
|
||||
else
|
||||
@dmsf_file_id = params[:dmsf_link][:dmsf_file_id]
|
||||
@type = params[:dmsf_link][:type]
|
||||
@target_folder_id = @dmsf_link.dmsf_folder_id
|
||||
@type = params[:dmsf_link][:type]
|
||||
@target_folder_id = @dmsf_link.dmsf_folder_id
|
||||
@dmsf_link.target_project_id = @dmsf_link.project.id
|
||||
@dmsf_link.project_id = params[:dmsf_link][:project_id]
|
||||
@dmsf_link.dmsf_folder_id = params[:dmsf_link][:dmsf_folder_id]
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@ -174,25 +179,39 @@ class DmsfLinksController < ApplicationController
|
||||
|
||||
redirect_to :back
|
||||
end
|
||||
|
||||
|
||||
def restore
|
||||
if @dmsf_link.restore
|
||||
flash[:notice] = l(:notice_dmsf_link_restored)
|
||||
end
|
||||
|
||||
|
||||
redirect_to :back
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
def l_params
|
||||
params.fetch(:dmsf_link, {}).permit(:project_id)
|
||||
end
|
||||
|
||||
def find_link_project
|
||||
if @dmsf_link
|
||||
@project = @dmsf_link.project
|
||||
else
|
||||
@project = Project.find(params[:dmsf_link].present? ? params[:dmsf_link][:project_id] : params[:project_id])
|
||||
if params[:dmsf_link].present?
|
||||
if params[:dmsf_link].fetch(:project_id, nil).blank?
|
||||
pid = params[:dmsf_link].fetch(:target_project_id, nil)
|
||||
else
|
||||
pid = params[:dmsf_link][:project_id]
|
||||
end
|
||||
else
|
||||
pid = params[:project_id]
|
||||
end
|
||||
Rails.logger.error("pid #{pid}")
|
||||
@project = Project.find(pid)
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -52,7 +52,11 @@ class DmsfUploadController < ApplicationController
|
||||
|
||||
# async single file upload handling
|
||||
def upload_file
|
||||
@tempfile = params[:file]
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
@tempfile = params.require(:file)
|
||||
else
|
||||
@tempfile = params[:file]
|
||||
end
|
||||
unless @tempfile.original_filename
|
||||
render_404
|
||||
return
|
||||
@ -82,7 +86,11 @@ class DmsfUploadController < ApplicationController
|
||||
end
|
||||
|
||||
def commit_files
|
||||
commited_files = params[:commited_files]
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
commited_files = params.require(:commited_files)
|
||||
else
|
||||
commited_files = params[:commited_files]
|
||||
end
|
||||
if commited_files && commited_files.is_a?(Hash)
|
||||
files = []
|
||||
failed_uploads = []
|
||||
@ -220,4 +228,4 @@ class DmsfUploadController < ApplicationController
|
||||
render_403
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@ -29,38 +29,58 @@ class DmsfFile < ActiveRecord::Base
|
||||
unloadable
|
||||
|
||||
include RedmineDmsf::Lockable
|
||||
|
||||
|
||||
attr_accessor :event_description
|
||||
|
||||
|
||||
belongs_to :project
|
||||
belongs_to :folder, :class_name => 'DmsfFolder', :foreign_key => 'dmsf_folder_id'
|
||||
belongs_to :deleted_by_user, :class_name => 'User', :foreign_key => 'deleted_by_user_id'
|
||||
|
||||
has_many :revisions, :class_name => 'DmsfFileRevision', :foreign_key => 'dmsf_file_id',
|
||||
:order => "#{DmsfFileRevision.table_name}.major_version DESC, #{DmsfFileRevision.table_name}.minor_version DESC, #{DmsfFileRevision.table_name}.updated_at DESC",
|
||||
:dependent => :destroy
|
||||
has_many :locks, :class_name => 'DmsfLock', :foreign_key => 'entity_id',
|
||||
:order => "#{DmsfLock.table_name}.updated_at DESC",
|
||||
:conditions => {:entity_type => 0},
|
||||
:dependent => :destroy
|
||||
has_many :referenced_links, :class_name => 'DmsfLink', :foreign_key => 'target_id',
|
||||
:conditions => {:target_type => DmsfFile.model_name}, :dependent => :destroy
|
||||
|
||||
scope :visible, where(:deleted => false)
|
||||
scope :deleted, where(:deleted => true)
|
||||
|
||||
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
has_many :revisions, -> { order("#{DmsfFileRevision.table_name}.major_version DESC, #{DmsfFileRevision.table_name}.minor_version DESC, #{DmsfFileRevision.table_name}.updated_at DESC") },
|
||||
:class_name => 'DmsfFileRevision', :foreign_key => 'dmsf_file_id',
|
||||
:dependent => :destroy
|
||||
has_many :locks, -> { where(entity_type: 0).order("#{DmsfLock.table_name}.updated_at DESC") },
|
||||
:class_name => 'DmsfLock', :foreign_key => 'entity_id', :dependent => :destroy
|
||||
has_many :referenced_links, -> { where target_type: DmsfFile.model_name},
|
||||
:class_name => 'DmsfLink', :foreign_key => 'target_id', :dependent => :destroy
|
||||
accepts_nested_attributes_for :revisions, :locks, :referenced_links, :project
|
||||
else
|
||||
has_many :revisions, :class_name => 'DmsfFileRevision', :foreign_key => 'dmsf_file_id',
|
||||
:order => "#{DmsfFileRevision.table_name}.major_version DESC, #{DmsfFileRevision.table_name}.minor_version DESC, #{DmsfFileRevision.table_name}.updated_at DESC",
|
||||
:dependent => :destroy
|
||||
has_many :locks, :class_name => 'DmsfLock', :foreign_key => 'entity_id',
|
||||
:order => "#{DmsfLock.table_name}.updated_at DESC",
|
||||
:conditions => {:entity_type => 0},
|
||||
:dependent => :destroy
|
||||
has_many :referenced_links, :class_name => 'DmsfLink', :foreign_key => 'target_id',
|
||||
:conditions => {:target_type => DmsfFile.model_name}, :dependent => :destroy
|
||||
end
|
||||
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
accepts_nested_attributes_for :revisions, :locks, :referenced_links
|
||||
end
|
||||
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
scope :visible, -> { where(deleted: false) }
|
||||
scope :deleted, -> { where(deleted: true) }
|
||||
else
|
||||
scope :visible, where(:deleted => false)
|
||||
scope :deleted, where(:deleted => true)
|
||||
end
|
||||
|
||||
validates :name, :presence => true
|
||||
validates_format_of :name, :with => DmsfFolder.invalid_characters,
|
||||
:message => l(:error_contains_invalid_character)
|
||||
|
||||
validate :validates_name_uniqueness
|
||||
|
||||
|
||||
validate :validates_name_uniqueness
|
||||
|
||||
def validates_name_uniqueness
|
||||
existing_file = DmsfFile.visible.find_file_by_name(self.project, self.folder, self.name)
|
||||
errors.add(:name, l('activerecord.errors.messages.taken')) unless
|
||||
existing_file.nil? || existing_file.id == self.id
|
||||
end
|
||||
|
||||
|
||||
acts_as_event :title => Proc.new {|o| "#{o.title} - #{o.name}"},
|
||||
:description => Proc.new {|o| o.description },
|
||||
:url => Proc.new {|o| {:controller => 'dmsf_files', :action => 'show', :id => o}},
|
||||
@ -83,32 +103,32 @@ class DmsfFile < ActiveRecord::Base
|
||||
unless @@storage_path.present?
|
||||
@@storage_path = Setting.plugin_redmine_dmsf['dmsf_storage_directory'].strip
|
||||
@@storage_path = Pathname(Redmine::Configuration['attachments_storage_path']).join('dmsf') if @@storage_path.blank? && Redmine::Configuration['attachments_storage_path'].present?
|
||||
@@storage_path = Rails.root.join('files/dmsf').to_s if @@storage_path.blank?
|
||||
Dir.mkdir(@@storage_path) unless File.exists?(@@storage_path)
|
||||
end
|
||||
@@storage_path = Rails.root.join('files/dmsf').to_s if @@storage_path.blank?
|
||||
Dir.mkdir(@@storage_path) unless File.exists?(@@storage_path)
|
||||
end
|
||||
@@storage_path
|
||||
end
|
||||
|
||||
# Lets introduce a write for storage path, that way we can also
|
||||
# Lets introduce a write for storage path, that way we can also
|
||||
# better interact from test-cases etc
|
||||
def self.storage_path=(obj)
|
||||
@@storage_path = obj
|
||||
end
|
||||
|
||||
def self.find_file_by_name(project, folder, name)
|
||||
|
||||
def self.find_file_by_name(project, folder, name)
|
||||
where(
|
||||
:project_id => project,
|
||||
:dmsf_folder_id => folder ? folder.id : nil,
|
||||
:project_id => project,
|
||||
:dmsf_folder_id => folder ? folder.id : nil,
|
||||
:name => name).visible.first
|
||||
end
|
||||
|
||||
def last_revision
|
||||
unless @last_revision
|
||||
@last_revision = deleted ? self.revisions.first : self.revisions.visible.first
|
||||
@last_revision = deleted ? self.revisions.first : self.revisions.visible.first
|
||||
end
|
||||
@last_revision
|
||||
end
|
||||
|
||||
|
||||
def set_last_revision(new_revision)
|
||||
@last_revision = new_revision
|
||||
end
|
||||
@ -117,7 +137,7 @@ class DmsfFile < ActiveRecord::Base
|
||||
if locked_for_user?
|
||||
Rails.logger.info l(:error_file_is_locked)
|
||||
errors[:base] << l(:error_file_is_locked)
|
||||
return false
|
||||
return false
|
||||
end
|
||||
begin
|
||||
# Revisions and links of a deleted file SHOULD be deleted too
|
||||
@ -135,7 +155,7 @@ class DmsfFile < ActiveRecord::Base
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def restore
|
||||
if self.dmsf_folder_id && (self.folder.nil? || self.folder.deleted)
|
||||
errors[:base] << l(:error_parent_folder)
|
||||
@ -147,54 +167,54 @@ class DmsfFile < ActiveRecord::Base
|
||||
self.deleted_by_user = nil
|
||||
save
|
||||
end
|
||||
|
||||
|
||||
def title
|
||||
self.last_revision ? self.last_revision.title : self.name
|
||||
end
|
||||
|
||||
|
||||
def description
|
||||
self.last_revision ? self.last_revision.description : ''
|
||||
end
|
||||
|
||||
|
||||
def version
|
||||
self.last_revision ? self.last_revision.version : '0'
|
||||
end
|
||||
|
||||
|
||||
def workflow
|
||||
self.last_revision ? self.last_revision.workflow : nil
|
||||
end
|
||||
|
||||
|
||||
def size
|
||||
self.last_revision ? self.last_revision.size : 0
|
||||
end
|
||||
|
||||
|
||||
def dmsf_path
|
||||
path = self.folder.nil? ? [] : self.folder.dmsf_path
|
||||
path.push(self)
|
||||
path
|
||||
end
|
||||
|
||||
def dmsf_path_str
|
||||
self.dmsf_path.map { |element| element.title }.join('/')
|
||||
|
||||
def dmsf_path_str
|
||||
self.dmsf_path.map { |element| element.title }.join('/')
|
||||
end
|
||||
|
||||
|
||||
def notify?
|
||||
return true if self.notification
|
||||
return true if folder && folder.notify?
|
||||
return true if !folder && self.project.dmsf_notification
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
def notify_deactivate
|
||||
self.notification = nil
|
||||
self.save!
|
||||
end
|
||||
|
||||
|
||||
def notify_activate
|
||||
self.notification = true
|
||||
self.save!
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Returns an array of projects that current user can copy file to
|
||||
def self.allowed_target_projects_on_copy
|
||||
projects = []
|
||||
@ -205,47 +225,47 @@ class DmsfFile < ActiveRecord::Base
|
||||
end
|
||||
projects
|
||||
end
|
||||
|
||||
|
||||
def move_to(project, folder)
|
||||
if self.locked_for_user?
|
||||
errors[:base] << l(:error_file_is_locked)
|
||||
return false
|
||||
return false
|
||||
end
|
||||
|
||||
# If the target project differs from the source project we must physically move the disk files
|
||||
if self.project != project
|
||||
self.revisions.all.each do |rev|
|
||||
|
||||
# If the target project differs from the source project we must physically move the disk files
|
||||
if self.project != project
|
||||
self.revisions.all.each do |rev|
|
||||
if File.exist? rev.disk_file(self.project)
|
||||
FileUtils.mv rev.disk_file(self.project), rev.disk_file(project)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
self.project = project
|
||||
self.folder = folder
|
||||
new_revision = self.last_revision.clone
|
||||
new_revision.file = self
|
||||
self.folder = folder
|
||||
new_revision = self.last_revision.clone
|
||||
new_revision.file = self
|
||||
new_revision.comment = l(:comment_moved_from, :source => "#{self.project.identifier}:#{self.dmsf_path_str}")
|
||||
new_revision.custom_values = []
|
||||
|
||||
self.last_revision.custom_values.each do |cv|
|
||||
new_revision.custom_values << CustomValue.new({:custom_field => cv.custom_field, :value => cv.value})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
self.save && new_revision.save
|
||||
end
|
||||
|
||||
|
||||
def copy_to(project, folder)
|
||||
|
||||
# If the target project differs from the source project we must physically move the disk files
|
||||
if self.project != project
|
||||
self.revisions.all.each do |rev|
|
||||
|
||||
# If the target project differs from the source project we must physically move the disk files
|
||||
if self.project != project
|
||||
self.revisions.all.each do |rev|
|
||||
if File.exist? rev.disk_file(self.project)
|
||||
FileUtils.cp rev.disk_file(self.project), rev.disk_file(project)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
file = DmsfFile.new
|
||||
file.folder = folder
|
||||
file.project = project
|
||||
@ -254,63 +274,63 @@ class DmsfFile < ActiveRecord::Base
|
||||
|
||||
if file.save && self.last_revision
|
||||
new_revision = self.last_revision.clone
|
||||
new_revision.file = file
|
||||
new_revision.file = file
|
||||
new_revision.comment = l(:comment_copied_from, :source => "#{self.project.identifier}: #{self.dmsf_path_str}")
|
||||
|
||||
|
||||
new_revision.custom_values = []
|
||||
self.last_revision.custom_values.each do |cv|
|
||||
new_revision.custom_values << CustomValue.new({:custom_field => cv.custom_field, :value => cv.value})
|
||||
end
|
||||
|
||||
file.delete(true) unless new_revision.save
|
||||
file.delete(true) unless new_revision.save
|
||||
end
|
||||
|
||||
|
||||
return file
|
||||
end
|
||||
|
||||
|
||||
# To fulfill searchable module expectations
|
||||
def self.search(tokens, projects = nil, options = {})
|
||||
tokens = [] << tokens unless tokens.is_a?(Array)
|
||||
projects = [] << projects unless projects.nil? || projects.is_a?(Array)
|
||||
|
||||
|
||||
find_options = {:include => [:project,:revisions]}
|
||||
find_options[:order] = 'dmsf_files.updated_at ' + (options[:before] ? 'DESC' : 'ASC')
|
||||
|
||||
|
||||
limit_options = {}
|
||||
limit_options[:limit] = options[:limit] if options[:limit]
|
||||
if options[:offset]
|
||||
limit_options[:conditions] = '(dmsf_files.updated_at ' + (options[:before] ? '<' : '>') + "'#{connection.quoted_date(options[:offset])}')"
|
||||
end
|
||||
|
||||
|
||||
columns = %w(dmsf_files.name dmsf_file_revisions.title dmsf_file_revisions.description)
|
||||
columns = ['dmsf_file_revisions.title'] if options[:titles_only]
|
||||
|
||||
|
||||
token_clauses = columns.collect {|column| "(LOWER(#{column}) LIKE ?)"}
|
||||
|
||||
|
||||
sql = (['(' + token_clauses.join(' OR ') + ')'] * tokens.size).join(options[:all_words] ? ' AND ' : ' OR ')
|
||||
find_options[:conditions] = [sql, * (tokens.collect {|w| "%#{w.downcase}%"} * token_clauses.size).sort]
|
||||
|
||||
|
||||
project_conditions = []
|
||||
project_conditions << (Project.allowed_to_condition(User.current, :view_dmsf_files))
|
||||
project_conditions << "#{DmsfFile.table_name}.project_id IN (#{projects.collect(&:id).join(',')})" unless projects.nil?
|
||||
|
||||
|
||||
results = []
|
||||
results_count = 0
|
||||
|
||||
|
||||
with_scope(:find => {:conditions => [project_conditions.join(' AND ') + " AND #{DmsfFile.table_name}.deleted = :false", {:false => false}]}) do
|
||||
with_scope(:find => find_options) do
|
||||
results_count = count(:all)
|
||||
results = find(:all, limit_options)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if !options[:titles_only] && $xapian_bindings_available
|
||||
database = nil
|
||||
begin
|
||||
database = nil
|
||||
begin
|
||||
lang = Setting.plugin_redmine_dmsf['dmsf_stemming_lang'].strip
|
||||
databasepath = File.join(
|
||||
Setting.plugin_redmine_dmsf['dmsf_index_database'].strip, lang)
|
||||
database = Xapian::Database.new(databasepath)
|
||||
database = Xapian::Database.new(databasepath)
|
||||
rescue Exception => e
|
||||
Rails.logger.warn 'REDMAIN_XAPIAN ERROR: Xapian database is not properly set or initiated or is corrupted.'
|
||||
Rails.logger.warn e.message
|
||||
@ -318,33 +338,33 @@ class DmsfFile < ActiveRecord::Base
|
||||
|
||||
if database
|
||||
enquire = Xapian::Enquire.new(database)
|
||||
|
||||
|
||||
query_string = tokens.join(' ')
|
||||
qp = Xapian::QueryParser.new()
|
||||
stemmer = Xapian::Stem.new(lang)
|
||||
qp.stemmer = stemmer
|
||||
qp.database = database
|
||||
|
||||
|
||||
case Setting.plugin_redmine_dmsf['dmsf_stemming_strategy'].strip
|
||||
when 'STEM_NONE'
|
||||
when 'STEM_NONE'
|
||||
qp.stemming_strategy = Xapian::QueryParser::STEM_NONE
|
||||
when 'STEM_SOME'
|
||||
qp.stemming_strategy = Xapian::QueryParser::STEM_SOME
|
||||
when 'STEM_ALL'
|
||||
qp.stemming_strategy = Xapian::QueryParser::STEM_ALL
|
||||
end
|
||||
|
||||
|
||||
if options[:all_words]
|
||||
qp.default_op = Xapian::Query::OP_AND
|
||||
else
|
||||
else
|
||||
qp.default_op = Xapian::Query::OP_OR
|
||||
end
|
||||
|
||||
|
||||
query = qp.parse_query(query_string)
|
||||
|
||||
|
||||
enquire.query = query
|
||||
matchset = enquire.mset(0, 1000)
|
||||
|
||||
|
||||
if matchset
|
||||
matchset.matches.each {|m|
|
||||
docdata = m.document.data{url}
|
||||
@ -356,9 +376,9 @@ class DmsfFile < ActiveRecord::Base
|
||||
id_attribute = dmsf_attrs[0][1] if dmsf_attrs.length > 0
|
||||
next if dmsf_attrs.length == 0 || id_attribute == 0
|
||||
next unless results.select{|f| f.id.to_s == id_attribute}.empty?
|
||||
|
||||
|
||||
dmsf_file = DmsfFile.where(limit_options[:conditions]).where(:id => id_attribute, :deleted => false).first
|
||||
|
||||
|
||||
if dmsf_file
|
||||
if options[:offset]
|
||||
if options[:before]
|
||||
@ -367,14 +387,14 @@ class DmsfFile < ActiveRecord::Base
|
||||
next if dmsf_file.updated_at > options[:offset]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
allowed = User.current.allowed_to?(:view_dmsf_files, dmsf_file.project)
|
||||
project_included = false
|
||||
project_included = true unless projects
|
||||
unless project_included
|
||||
projects.each do |x|
|
||||
unless project_included
|
||||
projects.each do |x|
|
||||
if x.is_a?(ActiveRecord::Relation)
|
||||
project_included = x.first.id == dmsf_file.project.id
|
||||
project_included = x.first.id == dmsf_file.project.id
|
||||
else
|
||||
if dmsf_file.project
|
||||
project_included = x[:id] == dmsf_file.project.id
|
||||
@ -384,7 +404,7 @@ class DmsfFile < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if (allowed && project_included)
|
||||
dmsf_file.event_description = dochash['sample'].force_encoding('UTF-8') if dochash['sample']
|
||||
results.push(dmsf_file)
|
||||
@ -394,17 +414,17 @@ class DmsfFile < ActiveRecord::Base
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
[results, results_count]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def display_name
|
||||
if self.name.length > 50
|
||||
return "#{self.name[0, 25]}...#{self.name[-25, 25]}"
|
||||
end
|
||||
self.name
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -23,62 +23,83 @@ class DmsfFileRevision < ActiveRecord::Base
|
||||
belongs_to :source_revision, :class_name => 'DmsfFileRevision', :foreign_key => 'source_dmsf_file_revision_id'
|
||||
belongs_to :user
|
||||
belongs_to :folder, :class_name => 'DmsfFolder', :foreign_key => 'dmsf_folder_id'
|
||||
belongs_to :deleted_by_user, :class_name => 'User', :foreign_key => 'deleted_by_user_id'
|
||||
belongs_to :deleted_by_user, :class_name => 'User', :foreign_key => 'deleted_by_user_id'
|
||||
has_many :access, :class_name => 'DmsfFileRevisionAccess', :foreign_key => 'dmsf_file_revision_id', :dependent => :destroy
|
||||
has_many :dmsf_workflow_step_assignment, :dependent => :destroy
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
accepts_nested_attributes_for :access, :dmsf_workflow_step_assignment, :file, :user
|
||||
end
|
||||
|
||||
# Returns a list of revisions that are not deleted here, or deleted at parent level either
|
||||
scope :visible, where(:deleted => false)
|
||||
scope :deleted, where(:deleted => true)
|
||||
|
||||
# Returns a list of revisions that are not deleted here, or deleted at parent level either
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
scope :visible, -> { where(deleted: false) }
|
||||
scope :deleted, -> { where(deleted: true) }
|
||||
else
|
||||
scope :visible, where(:deleted => false)
|
||||
scope :deleted, where(:deleted => true)
|
||||
end
|
||||
|
||||
acts_as_customizable
|
||||
acts_as_event :title => Proc.new {|o| "#{l(:label_dmsf_updated)}: #{o.file.dmsf_path_str}"},
|
||||
:url => Proc.new {|o| {:controller => 'dmsf_files', :action => 'show', :id => o.file}},
|
||||
:datetime => Proc.new {|o| o.updated_at },
|
||||
:description => Proc.new {|o| o.comment },
|
||||
:author => Proc.new {|o| o.user }
|
||||
acts_as_activity_provider :type => 'dmsf_file_revisions',
|
||||
:timestamp => "#{DmsfFileRevision.table_name}.updated_at",
|
||||
:author_key => "#{DmsfFileRevision.table_name}.user_id",
|
||||
:permission => :view_dmsf_file_revisions,
|
||||
:find_options => {:select => "#{DmsfFileRevision.table_name}.*",
|
||||
:joins =>
|
||||
"INNER JOIN #{DmsfFile.table_name} ON #{DmsfFileRevision.table_name}.dmsf_file_id = #{DmsfFile.table_name}.id " +
|
||||
"INNER JOIN #{Project.table_name} ON #{DmsfFile.table_name}.project_id = #{Project.table_name}.id",
|
||||
:conditions => ["#{DmsfFile.table_name}.deleted = :false", {:false => false}]
|
||||
}
|
||||
|
||||
:author => Proc.new {|o| o.user }
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
acts_as_activity_provider :type => 'dmsf_file_revisions',
|
||||
:timestamp => "#{DmsfFileRevision.table_name}.updated_at",
|
||||
:author_key => "#{DmsfFileRevision.table_name}.user_id",
|
||||
:permission => :view_dmsf_file_revisions,
|
||||
:scope => select("#{DmsfFileRevision.table_name}.*").
|
||||
joins(
|
||||
"INNER JOIN #{DmsfFile.table_name} ON #{DmsfFileRevision.table_name}.dmsf_file_id = #{DmsfFile.table_name}.id " +
|
||||
"INNER JOIN #{Project.table_name} ON #{DmsfFile.table_name}.project_id = #{Project.table_name}.id").
|
||||
where("#{DmsfFile.table_name}.deleted = :false", {:false => false})
|
||||
else
|
||||
acts_as_activity_provider :type => 'dmsf_file_revisions',
|
||||
:timestamp => "#{DmsfFileRevision.table_name}.updated_at",
|
||||
:author_key => "#{DmsfFileRevision.table_name}.user_id",
|
||||
:permission => :view_dmsf_file_revisions,
|
||||
:find_options => {:select => "#{DmsfFileRevision.table_name}.*",
|
||||
:joins =>
|
||||
"INNER JOIN #{DmsfFile.table_name} ON #{DmsfFileRevision.table_name}.dmsf_file_id = #{DmsfFile.table_name}.id " +
|
||||
"INNER JOIN #{Project.table_name} ON #{DmsfFile.table_name}.project_id = #{Project.table_name}.id",
|
||||
:conditions => ["#{DmsfFile.table_name}.deleted = :false", {:false => false}]
|
||||
}
|
||||
end
|
||||
|
||||
validates :title, :name, :presence => true
|
||||
validates_format_of :name, :with => DmsfFolder.invalid_characters,
|
||||
:message => l(:error_contains_invalid_character)
|
||||
|
||||
|
||||
def project
|
||||
self.file.project if self.file
|
||||
end
|
||||
|
||||
|
||||
def folder
|
||||
self.file.folder if self.file
|
||||
end
|
||||
|
||||
|
||||
def self.remove_extension(filename)
|
||||
filename[0, (filename.length - File.extname(filename).length)]
|
||||
end
|
||||
|
||||
|
||||
def self.filename_to_title(filename)
|
||||
remove_extension(filename).gsub(/_+/, ' ');
|
||||
end
|
||||
|
||||
|
||||
def delete(commit = false, force = true)
|
||||
if self.file.locked_for_user?
|
||||
errors[:base] << l(:error_file_is_locked)
|
||||
return false
|
||||
end
|
||||
return false
|
||||
end
|
||||
if !commit && (!force && (self.file.revisions.length <= 1))
|
||||
errors[:base] << l(:error_at_least_one_revision_must_be_present)
|
||||
return false
|
||||
end
|
||||
dependent = DmsfFileRevision.where(:source_dmsf_file_revision_id => self.id).all
|
||||
dependent.each do |d|
|
||||
dependent.each do |d|
|
||||
d.source_revision = self.source_revision
|
||||
d.save!
|
||||
end
|
||||
@ -90,13 +111,13 @@ class DmsfFileRevision < ActiveRecord::Base
|
||||
save
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def restore
|
||||
self.deleted = false
|
||||
self.deleted_by_user = nil
|
||||
save
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
if Setting.plugin_redmine_dmsf['dmsf_really_delete_files']
|
||||
dependencies = DmsfFileRevision.where(:disk_filename => self.disk_filename).all.count
|
||||
@ -104,47 +125,47 @@ class DmsfFileRevision < ActiveRecord::Base
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
|
||||
# In a static call, we find the first matched record on base object type and
|
||||
# then run the access_grouped call against it
|
||||
def self.access_grouped(revision_id)
|
||||
DmsfFileRevision.find(revision_id).first.access_grouped
|
||||
end
|
||||
|
||||
|
||||
# Get grouped data from dmsf_file_revision_access about file interactions
|
||||
# - 22-06-2012 - Rather than calling a static, we should use the access
|
||||
# (has_many) to re-run a query - it makes more sense then executing
|
||||
# - 22-06-2012 - Rather than calling a static, we should use the access
|
||||
# (has_many) to re-run a query - it makes more sense then executing
|
||||
# custom SQL into a temporary object
|
||||
#
|
||||
def access_grouped
|
||||
access.select('user_id, COUNT(*) AS count, MIN(created_at) AS first_at, MAX(created_at) AS last_at').group('user_id')
|
||||
end
|
||||
|
||||
|
||||
def version
|
||||
"#{self.major_version}.#{self.minor_version}"
|
||||
end
|
||||
|
||||
def disk_file(project = nil)
|
||||
project = self.file.project unless project
|
||||
project = self.file.project unless project
|
||||
storage_base = DmsfFile.storage_path.dup
|
||||
if self.file && project
|
||||
if self.file && project
|
||||
project_base = project.identifier.gsub(/[^\w\.\-]/,'_')
|
||||
storage_base << "/p_#{project_base}"
|
||||
end
|
||||
Dir.mkdir(storage_base) unless File.exists?(storage_base)
|
||||
"#{storage_base}/#{self.disk_filename}"
|
||||
end
|
||||
|
||||
|
||||
def detect_content_type
|
||||
content_type = self.mime_type
|
||||
content_type = Redmine::MimeType.of(self.disk_filename) if content_type.blank?
|
||||
content_type = 'application/octet-stream' if content_type.blank?
|
||||
content_type.to_s
|
||||
end
|
||||
|
||||
|
||||
def clone
|
||||
new_revision = DmsfFileRevision.new
|
||||
new_revision.file = self.file
|
||||
new_revision.file = self.file
|
||||
new_revision.disk_filename = self.disk_filename
|
||||
new_revision.size = self.size
|
||||
new_revision.mime_type = self.mime_type
|
||||
@ -152,18 +173,18 @@ class DmsfFileRevision < ActiveRecord::Base
|
||||
new_revision.description = self.description
|
||||
new_revision.workflow = self.workflow
|
||||
new_revision.major_version = self.major_version
|
||||
new_revision.minor_version = self.minor_version
|
||||
new_revision.minor_version = self.minor_version
|
||||
new_revision.source_revision = self
|
||||
new_revision.user = User.current
|
||||
new_revision.name = self.name
|
||||
new_revision.user = User.current
|
||||
new_revision.name = self.name
|
||||
new_revision
|
||||
end
|
||||
|
||||
|
||||
def workflow_str(name)
|
||||
str = ''
|
||||
if name && dmsf_workflow_id
|
||||
wf = DmsfWorkflow.find_by_id(dmsf_workflow_id)
|
||||
str = "#{wf.name} - " if wf
|
||||
str = "#{wf.name} - " if wf
|
||||
end
|
||||
case workflow
|
||||
when DmsfWorkflow::STATE_WAITING_FOR_APPROVAL
|
||||
@ -178,9 +199,9 @@ class DmsfFileRevision < ActiveRecord::Base
|
||||
str + l(:title_none)
|
||||
end
|
||||
end
|
||||
|
||||
def set_workflow(dmsf_workflow_id, commit)
|
||||
self.dmsf_workflow_id = dmsf_workflow_id
|
||||
|
||||
def set_workflow(dmsf_workflow_id, commit)
|
||||
self.dmsf_workflow_id = dmsf_workflow_id
|
||||
if commit == 'start'
|
||||
self.workflow = DmsfWorkflow::STATE_WAITING_FOR_APPROVAL
|
||||
self.dmsf_workflow_started_by = User.current.id if User.current
|
||||
@ -189,34 +210,34 @@ class DmsfFileRevision < ActiveRecord::Base
|
||||
self.workflow = DmsfWorkflow::STATE_ASSIGNED
|
||||
self.dmsf_workflow_assigned_by = User.current.id if User.current
|
||||
self.dmsf_workflow_assigned_at = DateTime.now
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assign_workflow(dmsf_workflow_id)
|
||||
|
||||
def assign_workflow(dmsf_workflow_id)
|
||||
wf = DmsfWorkflow.find_by_id(dmsf_workflow_id)
|
||||
wf.assign(self.id) if wf && self.id
|
||||
wf.assign(self.id) if wf && self.id
|
||||
end
|
||||
|
||||
|
||||
def increase_version(version_to_increase, new_content)
|
||||
if new_content
|
||||
self.minor_version = case version_to_increase
|
||||
self.minor_version = case version_to_increase
|
||||
when 2 then 0
|
||||
else self.minor_version + 1
|
||||
end
|
||||
else
|
||||
self.minor_version = case version_to_increase
|
||||
self.minor_version = case version_to_increase
|
||||
when 1 then self.minor_version + 1
|
||||
when 2 then 0
|
||||
else self.minor_version
|
||||
end
|
||||
end
|
||||
|
||||
self.major_version = case version_to_increase
|
||||
self.major_version = case version_to_increase
|
||||
when 2 then self.major_version + 1
|
||||
else self.major_version
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def new_storage_filename
|
||||
raise DmsfAccessError, 'File id is not set' unless self.file.id
|
||||
filename = DmsfHelper.sanitize_filename(self.name)
|
||||
@ -226,9 +247,9 @@ class DmsfFileRevision < ActiveRecord::Base
|
||||
end
|
||||
"#{timestamp}_#{self.file.id}_#{filename}"
|
||||
end
|
||||
|
||||
|
||||
def copy_file_content(open_file)
|
||||
File.open(self.disk_file, 'wb') do |f|
|
||||
File.open(self.disk_file, 'wb') do |f|
|
||||
while (buffer = open_file.read(8192))
|
||||
f.write(buffer)
|
||||
end
|
||||
@ -236,13 +257,13 @@ class DmsfFileRevision < ActiveRecord::Base
|
||||
end
|
||||
|
||||
# Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields
|
||||
def available_custom_fields
|
||||
def available_custom_fields
|
||||
DmsfFileRevisionCustomField.all
|
||||
end
|
||||
|
||||
|
||||
def iversion
|
||||
parts = self.version.split '.'
|
||||
parts.size == 2 ? parts[0].to_i * 1000 + parts[1].to_i : 0
|
||||
parts.size == 2 ? parts[0].to_i * 1000 + parts[1].to_i : 0
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@ -22,6 +22,9 @@ class DmsfFileRevisionAccess < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
delegate :project, :to => :revision, :allow_nil => false
|
||||
delegate :file, :to => :revision, :allow_nil => false
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
accepts_nested_attributes_for :user, :revision
|
||||
end
|
||||
|
||||
DownloadAction = 0
|
||||
EmailAction = 1
|
||||
@ -31,16 +34,29 @@ class DmsfFileRevisionAccess < ActiveRecord::Base
|
||||
:datetime => Proc.new {|o| o.updated_at },
|
||||
:description => Proc.new {|o| o.revision.comment },
|
||||
:author => Proc.new {|o| o.user }
|
||||
acts_as_activity_provider :type => 'dmsf_file_revision_accesses',
|
||||
:timestamp => "#{DmsfFileRevisionAccess.table_name}.updated_at",
|
||||
:author_key => "#{DmsfFileRevisionAccess.table_name}.user_id",
|
||||
:permission => :view_dmsf_file_revision_accesses,
|
||||
:find_options => {:select => "#{DmsfFileRevisionAccess.table_name}.*",
|
||||
:joins =>
|
||||
"INNER JOIN #{DmsfFileRevision.table_name} ON #{DmsfFileRevisionAccess.table_name}.dmsf_file_revision_id = #{DmsfFileRevision.table_name}.id " +
|
||||
"INNER JOIN #{DmsfFile.table_name} ON #{DmsfFileRevision.table_name}.dmsf_file_id = #{DmsfFile.table_name}.id " +
|
||||
"INNER JOIN #{Project.table_name} ON #{DmsfFile.table_name}.project_id = #{Project.table_name}.id",
|
||||
:conditions => ["#{DmsfFile.table_name}.deleted = :false", {:false => false}]
|
||||
}
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
acts_as_activity_provider :type => 'dmsf_file_revision_accesses',
|
||||
:timestamp => "#{DmsfFileRevisionAccess.table_name}.updated_at",
|
||||
:author_key => "#{DmsfFileRevisionAccess.table_name}.user_id",
|
||||
:permission => :view_dmsf_file_revision_accesses,
|
||||
:scope => select("#{DmsfFileRevisionAccess.table_name}.*").
|
||||
joins(
|
||||
"INNER JOIN #{DmsfFileRevision.table_name} ON #{DmsfFileRevisionAccess.table_name}.dmsf_file_revision_id = #{DmsfFileRevision.table_name}.id " +
|
||||
"INNER JOIN #{DmsfFile.table_name} ON #{DmsfFileRevision.table_name}.dmsf_file_id = #{DmsfFile.table_name}.id " +
|
||||
"INNER JOIN #{Project.table_name} ON #{DmsfFile.table_name}.project_id = #{Project.table_name}.id").
|
||||
where("#{DmsfFile.table_name}.deleted = :false", {:false => false})
|
||||
else
|
||||
acts_as_activity_provider :type => 'dmsf_file_revision_accesses',
|
||||
:timestamp => "#{DmsfFileRevisionAccess.table_name}.updated_at",
|
||||
:author_key => "#{DmsfFileRevisionAccess.table_name}.user_id",
|
||||
:permission => :view_dmsf_file_revision_accesses,
|
||||
:find_options => {:select => "#{DmsfFileRevisionAccess.table_name}.*",
|
||||
:joins =>
|
||||
"INNER JOIN #{DmsfFileRevision.table_name} ON #{DmsfFileRevisionAccess.table_name}.dmsf_file_revision_id = #{DmsfFileRevision.table_name}.id " +
|
||||
"INNER JOIN #{DmsfFile.table_name} ON #{DmsfFileRevision.table_name}.dmsf_file_id = #{DmsfFile.table_name}.id " +
|
||||
"INNER JOIN #{Project.table_name} ON #{DmsfFile.table_name}.project_id = #{Project.table_name}.id",
|
||||
:conditions => ["#{DmsfFile.table_name}.deleted = :false", {:false => false}]
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@ -21,45 +21,64 @@ class DmsfFolder < ActiveRecord::Base
|
||||
unloadable
|
||||
|
||||
include RedmineDmsf::Lockable
|
||||
|
||||
|
||||
cattr_reader :invalid_characters
|
||||
@@invalid_characters = /\A[^\/\\\?":<>]*\z/
|
||||
|
||||
|
||||
belongs_to :project
|
||||
belongs_to :folder, :class_name => 'DmsfFolder', :foreign_key => 'dmsf_folder_id'
|
||||
belongs_to :deleted_by_user, :class_name => 'User', :foreign_key => 'deleted_by_user_id'
|
||||
belongs_to :user
|
||||
|
||||
has_many :subfolders, :class_name => 'DmsfFolder', :foreign_key => 'dmsf_folder_id',
|
||||
:dependent => :destroy
|
||||
has_many :files, :class_name => 'DmsfFile', :foreign_key => 'dmsf_folder_id',
|
||||
:dependent => :destroy
|
||||
has_many :folder_links, :class_name => 'DmsfLink', :foreign_key => 'dmsf_folder_id',
|
||||
:conditions => {:target_type => DmsfFolder.model_name}, :dependent => :destroy
|
||||
has_many :file_links, :class_name => 'DmsfLink', :foreign_key => 'dmsf_folder_id',
|
||||
:conditions => {:target_type => DmsfFile.model_name}, :dependent => :destroy
|
||||
has_many :url_links, :class_name => 'DmsfLink', :foreign_key => 'dmsf_folder_id',
|
||||
:conditions => {:target_type => 'DmsfUrl'}, :dependent => :destroy
|
||||
has_many :referenced_links, :class_name => 'DmsfLink', :foreign_key => 'target_id',
|
||||
:conditions => {:target_type => DmsfFolder.model_name}, :dependent => :destroy
|
||||
has_many :locks, :class_name => 'DmsfLock', :foreign_key => 'entity_id',
|
||||
:order => "#{DmsfLock.table_name}.updated_at DESC",
|
||||
:conditions => {:entity_type => 1},
|
||||
|
||||
has_many :subfolders, :class_name => 'DmsfFolder', :foreign_key => 'dmsf_folder_id',
|
||||
:dependent => :destroy
|
||||
|
||||
scope :visible, where(:deleted => false)
|
||||
scope :deleted, where(:deleted => true)
|
||||
has_many :files, :class_name => 'DmsfFile', :foreign_key => 'dmsf_folder_id',
|
||||
:dependent => :destroy
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
has_many :folder_links, -> { where target_type: DmsfFolder.model_name },
|
||||
:class_name => 'DmsfLink', :foreign_key => 'dmsf_folder_id', :dependent => :destroy
|
||||
has_many :file_links, -> { where target_type: DmsfFile.model_name },
|
||||
:class_name => 'DmsfLink', :foreign_key => 'dmsf_folder_id', :dependent => :destroy
|
||||
has_many :url_links, -> { where target_type: 'DmsfUrl' },
|
||||
:class_name => 'DmsfLink', :foreign_key => 'dmsf_folder_id', :dependent => :destroy
|
||||
has_many :referenced_links, -> { where target_type: DmsfFolder.model_name },
|
||||
:class_name => 'DmsfLink', :foreign_key => 'target_id', :dependent => :destroy
|
||||
has_many :locks, -> { where(entity_type: 1).order("#{DmsfLock.table_name}.updated_at DESC") },
|
||||
:class_name => 'DmsfLock', :foreign_key => 'entity_id', :dependent => :destroy
|
||||
accepts_nested_attributes_for :user, :project, :folder, :subfolders, :files, :folder_links, :file_links, :url_links, :referenced_links, :locks
|
||||
else
|
||||
has_many :folder_links, :class_name => 'DmsfLink', :foreign_key => 'dmsf_folder_id',
|
||||
:conditions => {:target_type => DmsfFolder.model_name}, :dependent => :destroy
|
||||
has_many :file_links, :class_name => 'DmsfLink', :foreign_key => 'dmsf_folder_id',
|
||||
:conditions => {:target_type => DmsfFile.model_name}, :dependent => :destroy
|
||||
has_many :url_links, :class_name => 'DmsfLink', :foreign_key => 'dmsf_folder_id',
|
||||
:conditions => {:target_type => 'DmsfUrl'}, :dependent => :destroy
|
||||
has_many :referenced_links, :class_name => 'DmsfLink', :foreign_key => 'target_id',
|
||||
:conditions => {:target_type => DmsfFolder.model_name}, :dependent => :destroy
|
||||
has_many :locks, :class_name => 'DmsfLock', :foreign_key => 'entity_id',
|
||||
:order => "#{DmsfLock.table_name}.updated_at DESC",
|
||||
:conditions => {:entity_type => 1},
|
||||
:dependent => :destroy
|
||||
end
|
||||
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
scope :visible, -> { where(deleted: false) }
|
||||
scope :deleted, -> { where(deleted: true) }
|
||||
else
|
||||
scope :visible, where(:deleted => false)
|
||||
scope :deleted, where(:deleted => true)
|
||||
end
|
||||
|
||||
acts_as_customizable
|
||||
|
||||
validate :title, :presence => true
|
||||
|
||||
validates :title, :presence => true
|
||||
validates_uniqueness_of :title, :scope => [:dmsf_folder_id, :project_id, :deleted]
|
||||
|
||||
|
||||
validates_format_of :title, :with => @@invalid_characters,
|
||||
:message => l(:error_contains_invalid_character)
|
||||
|
||||
|
||||
validate :check_cycle
|
||||
|
||||
|
||||
acts_as_event :title => Proc.new {|o| o.title},
|
||||
:description => Proc.new {|o| o.description },
|
||||
:url => Proc.new {|o| {:controller => 'dmsf', :action => 'show', :id => o.project, :folder_id => o}},
|
||||
@ -88,15 +107,15 @@ class DmsfFolder < ActiveRecord::Base
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
def self.find_by_title(project, folder, title)
|
||||
|
||||
def self.find_by_title(project, folder, title)
|
||||
if folder
|
||||
visible.where(:project_id => project.id, :dmsf_folder_id => nil, :title => title).first
|
||||
else
|
||||
visible.where(:project_id => project.id, :dmsf_folder_id => folder.id, :title => title).first
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def delete(commit)
|
||||
if self.locked?
|
||||
errors[:base] << l(:error_folder_is_locked)
|
||||
@ -104,7 +123,7 @@ class DmsfFolder < ActiveRecord::Base
|
||||
elsif !self.subfolders.visible.empty? || !self.files.visible.empty?
|
||||
errors[:base] << l(:error_folder_is_not_empty)
|
||||
return false
|
||||
end
|
||||
end
|
||||
self.referenced_links.each { |l| l.delete(commit) }
|
||||
if commit
|
||||
self.destroy
|
||||
@ -114,7 +133,7 @@ class DmsfFolder < ActiveRecord::Base
|
||||
self.save
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def restore
|
||||
if self.dmsf_folder_id && (self.folder.nil? || self.folder.deleted)
|
||||
errors[:base] << l(:error_parent_folder)
|
||||
@ -125,40 +144,40 @@ class DmsfFolder < ActiveRecord::Base
|
||||
self.deleted_by_user = nil
|
||||
self.save
|
||||
end
|
||||
|
||||
|
||||
def dmsf_path
|
||||
folder = self
|
||||
path = []
|
||||
while folder
|
||||
path.unshift(folder)
|
||||
folder = folder.folder
|
||||
end
|
||||
end
|
||||
path
|
||||
end
|
||||
|
||||
|
||||
def dmsf_path_str
|
||||
path = self.dmsf_path
|
||||
string_path = path.map { |element| element.title }
|
||||
string_path.join('/')
|
||||
end
|
||||
|
||||
|
||||
def notify?
|
||||
return true if self.notification
|
||||
return true if folder && folder.notify?
|
||||
return true if !folder && self.project.dmsf_notification
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
def notify_deactivate
|
||||
self.notification = nil
|
||||
self.save!
|
||||
end
|
||||
|
||||
|
||||
def notify_activate
|
||||
self.notification = true
|
||||
self.save!
|
||||
end
|
||||
|
||||
|
||||
def self.directory_tree(project, current_folder = nil)
|
||||
tree = [[l(:link_documents), nil]]
|
||||
project.dmsf_folders.visible.each do |folder|
|
||||
@ -168,14 +187,14 @@ class DmsfFolder < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
return tree
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def folder_tree
|
||||
tree = [[self.title, self.id]]
|
||||
DmsfFolder.directory_subtree(tree, self, 2, nil)
|
||||
DmsfFolder.directory_subtree(tree, self, 2, nil)
|
||||
return tree
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def self.file_list(files)
|
||||
options = Array.new
|
||||
options.push ['', nil]
|
||||
@ -184,19 +203,19 @@ class DmsfFolder < ActiveRecord::Base
|
||||
end
|
||||
options
|
||||
end
|
||||
|
||||
|
||||
def deep_file_count
|
||||
file_count = self.files.visible.count
|
||||
self.subfolders.visible.each {|subfolder| file_count += subfolder.deep_file_count}
|
||||
file_count + self.file_links.visible.count
|
||||
end
|
||||
end
|
||||
|
||||
def deep_folder_count
|
||||
folder_count = self.subfolders.visible.count
|
||||
self.subfolders.visible.each {|subfolder| folder_count += subfolder.deep_folder_count}
|
||||
folder_count + self.folder_links.visible.count
|
||||
end
|
||||
|
||||
|
||||
def deep_size
|
||||
size = 0
|
||||
self.files.visible.each {|file| size += file.size}
|
||||
@ -221,27 +240,27 @@ class DmsfFolder < ActiveRecord::Base
|
||||
new_folder.project = folder ? folder.project : project
|
||||
new_folder.title = self.title
|
||||
new_folder.description = self.description
|
||||
new_folder.user = User.current
|
||||
|
||||
new_folder.user = User.current
|
||||
|
||||
new_folder.custom_values = []
|
||||
self.custom_values.each do |cv|
|
||||
new_folder.custom_values << CustomValue.new({:custom_field => cv.custom_field, :value => cv.value})
|
||||
end
|
||||
end
|
||||
|
||||
return new_folder unless new_folder.save
|
||||
|
||||
|
||||
self.files.visible.each do |f|
|
||||
f.copy_to project, new_folder
|
||||
end
|
||||
|
||||
|
||||
self.subfolders.visible.each do |s|
|
||||
s.copy_to project, new_folder
|
||||
end
|
||||
|
||||
|
||||
self.folder_links.visible.each do |l|
|
||||
l.copy_to project, new_folder
|
||||
end
|
||||
|
||||
|
||||
self.file_links.visible.each do |l|
|
||||
l.copy_to project, new_folder
|
||||
end
|
||||
@ -249,7 +268,7 @@ class DmsfFolder < ActiveRecord::Base
|
||||
self.url_links.visible.each do |l|
|
||||
l.copy_to project, new_folder
|
||||
end
|
||||
|
||||
|
||||
return new_folder
|
||||
end
|
||||
|
||||
@ -262,40 +281,40 @@ class DmsfFolder < ActiveRecord::Base
|
||||
def self.search(tokens, projects=nil, options={})
|
||||
tokens = [] << tokens unless tokens.is_a?(Array)
|
||||
projects = [] << projects unless projects.nil? || projects.is_a?(Array)
|
||||
|
||||
|
||||
find_options = {:include => [:project]}
|
||||
find_options[:order] = 'dmsf_folders.updated_at ' + (options[:before] ? 'DESC' : 'ASC')
|
||||
|
||||
|
||||
limit_options = {}
|
||||
limit_options[:limit] = options[:limit] if options[:limit]
|
||||
if options[:offset]
|
||||
limit_options[:conditions] = '(dmsf_folders.updated_at ' + (options[:before] ? '<' : '>') + "'#{connection.quoted_date(options[:offset])}')"
|
||||
end
|
||||
|
||||
|
||||
columns = options[:titles_only] ? ["dmsf_folders.title"] : ["dmsf_folders.title", "dmsf_folders.description"]
|
||||
|
||||
|
||||
token_clauses = columns.collect {|column| "(LOWER(#{column}) LIKE ?)"}
|
||||
|
||||
|
||||
sql = (['(' + token_clauses.join(' OR ') + ')'] * tokens.size).join(options[:all_words] ? ' AND ' : ' OR ')
|
||||
find_options[:conditions] = [sql, * (tokens.collect {|w| "%#{w.downcase}%"} * token_clauses.size).sort]
|
||||
|
||||
|
||||
project_conditions = []
|
||||
project_conditions << (Project.allowed_to_condition(User.current, :view_dmsf_files))
|
||||
project_conditions << "project_id IN (#{projects.collect(&:id).join(',')})" unless projects.nil?
|
||||
|
||||
|
||||
results = []
|
||||
results_count = 0
|
||||
|
||||
|
||||
with_scope(:find => {:conditions => [project_conditions.join(' AND ')]}) do
|
||||
with_scope(:find => find_options) do
|
||||
results_count = count(:all)
|
||||
results = find(:all, limit_options)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
[results, results_count]
|
||||
end
|
||||
|
||||
|
||||
def modified
|
||||
last_update = updated_at
|
||||
subfolders.each do |subfolder|
|
||||
@ -317,7 +336,7 @@ class DmsfFolder < ActiveRecord::Base
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
def self.directory_subtree(tree, folder, level, current_folder)
|
||||
folder.subfolders.visible.each do |subfolder|
|
||||
unless subfolder == current_folder
|
||||
@ -326,5 +345,5 @@ class DmsfFolder < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -18,18 +18,23 @@
|
||||
|
||||
class DmsfLink < ActiveRecord::Base
|
||||
unloadable
|
||||
|
||||
|
||||
belongs_to :project
|
||||
belongs_to :dmsf_folder
|
||||
belongs_to :deleted_by_user, :class_name => 'User', :foreign_key => 'deleted_by_user_id'
|
||||
belongs_to :user
|
||||
|
||||
|
||||
validates :name, :presence => true
|
||||
validates_length_of :name, :maximum => 255
|
||||
|
||||
scope :visible, where(:deleted => false)
|
||||
scope :deleted, where(:deleted => true)
|
||||
|
||||
validates_length_of :name, :maximum => 255
|
||||
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
scope :visible, -> { where(deleted: false) }
|
||||
scope :deleted, -> { where(deleted: true) }
|
||||
else
|
||||
scope :visible, where(:deleted => false)
|
||||
scope :deleted, where(:deleted => true)
|
||||
end
|
||||
|
||||
def target_folder_id
|
||||
if self.target_type == DmsfFolder.model_name
|
||||
self.target_id
|
||||
@ -38,49 +43,49 @@ class DmsfLink < ActiveRecord::Base
|
||||
f.dmsf_folder_id if f
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def target_folder
|
||||
DmsfFolder.find_by_id self.target_folder_id if self.target_folder_id
|
||||
end
|
||||
|
||||
|
||||
def target_file_id
|
||||
self.target_id if self.target_type == DmsfFile.model_name
|
||||
end
|
||||
|
||||
|
||||
def target_file
|
||||
DmsfFile.find_by_id self.target_file_id if self.target_file_id
|
||||
end
|
||||
|
||||
|
||||
def target_project
|
||||
Project.find_by_id self.target_project_id
|
||||
Project.find_by_id self.target_project_id
|
||||
end
|
||||
|
||||
|
||||
def folder
|
||||
DmsfFolder.find_by_id self.dmsf_folder_id
|
||||
end
|
||||
|
||||
|
||||
def title
|
||||
self.name
|
||||
end
|
||||
|
||||
|
||||
def self.find_link_by_file_name(project, folder, filename)
|
||||
links = DmsfLink.where(
|
||||
:project_id => project.id,
|
||||
:dmsf_folder_id => folder ? folder.id : nil,
|
||||
:target_type => DmsfFile.model_name).visible.all
|
||||
links.each do |link|
|
||||
return link if link.target_file.name == filename
|
||||
links.each do |link|
|
||||
return link if link.target_file.name == filename
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
|
||||
def path
|
||||
if self.target_type == DmsfFile.model_name
|
||||
file = self.target_file
|
||||
path = file.dmsf_path.map { |element| element.is_a?(DmsfFile) ? element.name : element.title }.join('/') if file
|
||||
file = self.target_file
|
||||
path = file.dmsf_path.map { |element| element.is_a?(DmsfFile) ? element.name : element.title }.join('/') if file
|
||||
else
|
||||
folder = self.target_folder
|
||||
path = folder.dmsf_path_str if folder
|
||||
folder = self.target_folder
|
||||
path = folder.dmsf_path_str if folder
|
||||
end
|
||||
path.insert(0, "#{self.target_project.name}:") if self.project_id != self.target_project_id && path
|
||||
if path.length > 50
|
||||
@ -88,7 +93,7 @@ class DmsfLink < ActiveRecord::Base
|
||||
end
|
||||
path
|
||||
end
|
||||
|
||||
|
||||
def copy_to(project, folder)
|
||||
link = DmsfLink.new(
|
||||
:target_project_id => self.target_project_id,
|
||||
@ -101,7 +106,7 @@ class DmsfLink < ActiveRecord::Base
|
||||
link.save
|
||||
link
|
||||
end
|
||||
|
||||
|
||||
def delete(commit = false)
|
||||
if commit
|
||||
self.destroy
|
||||
@ -111,7 +116,7 @@ class DmsfLink < ActiveRecord::Base
|
||||
save
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def restore
|
||||
if self.dmsf_folder_id && (self.folder.nil? || self.folder.deleted)
|
||||
errors[:base] << l(:error_parent_folder)
|
||||
@ -121,5 +126,5 @@ class DmsfLink < ActiveRecord::Base
|
||||
self.deleted_by_user = nil
|
||||
save
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class DmsfWorkflow < ActiveRecord::Base
|
||||
has_many :dmsf_workflow_steps, :dependent => :destroy, :order => 'step ASC, operator DESC'
|
||||
has_many :dmsf_workflow_steps, -> { order 'step ASC, operator DESC' }, :dependent => :destroy
|
||||
|
||||
scope :sorted, lambda { order('name ASC') }
|
||||
scope :global, lambda { where('project_id IS NULL') }
|
||||
@ -244,4 +244,4 @@ class DmsfWorkflow < ActiveRecord::Base
|
||||
end
|
||||
return new_wf
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -101,4 +101,4 @@
|
||||
$("#link_internal").toggle();
|
||||
$("#link_external").toggle();
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
||||
@ -22,13 +22,16 @@ require_dependency 'custom_fields_helper'
|
||||
|
||||
module RedmineDmsf
|
||||
module Patches
|
||||
module CustomFieldsHelperPatch
|
||||
module CustomFieldsHelperPatch
|
||||
def self.included(base)
|
||||
base.extend(ClassMethods)
|
||||
base.send(:include, InstanceMethods)
|
||||
base.class_eval do
|
||||
unloadable
|
||||
if Redmine::VERSION::MAJOR >= 2 && Redmine::VERSION::MINOR >= 5
|
||||
if (
|
||||
(Redmine::VERSION::MAJOR >= 3) ||
|
||||
(Redmine::VERSION::MAJOR >= 2 && Redmine::VERSION::MINOR >= 5)
|
||||
)
|
||||
alias_method_chain :render_custom_fields_tabs, :render_custom_tab
|
||||
alias_method_chain :custom_field_type_options, :custom_tab_options
|
||||
else
|
||||
@ -37,39 +40,42 @@ module RedmineDmsf
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
module ClassMethods
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def custom_fields_tabs_with_custom_tab
|
||||
|
||||
def custom_fields_tabs_with_custom_tab
|
||||
add_cf
|
||||
custom_fields_tabs_without_custom_tab
|
||||
custom_fields_tabs_without_custom_tab
|
||||
end
|
||||
|
||||
def render_custom_fields_tabs_with_render_custom_tab(types)
|
||||
|
||||
def render_custom_fields_tabs_with_render_custom_tab(types)
|
||||
add_cf
|
||||
render_custom_fields_tabs_without_render_custom_tab(types)
|
||||
end
|
||||
|
||||
def custom_field_type_options_with_custom_tab_options
|
||||
def custom_field_type_options_with_custom_tab_options
|
||||
add_cf
|
||||
custom_field_type_options_without_custom_tab_options
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
def add_cf
|
||||
cf = {:name => 'DmsfFileRevisionCustomField', :partial => 'custom_fields/index', :label => :dmsf}
|
||||
if Redmine::VERSION::MAJOR <= 2 && Redmine::VERSION::MINOR < 4
|
||||
unless CustomField::CUSTOM_FIELDS_TABS.index { |f| f[:name] == cf[:name] }
|
||||
CustomField::CUSTOM_FIELDS_TABS << cf
|
||||
end
|
||||
else
|
||||
if (
|
||||
(Redmine::VERSION::MAJOR >= 3) ||
|
||||
(Redmine::VERSION::MAJOR >= 2 && Redmine::VERSION::MINOR >= 5)
|
||||
)
|
||||
unless CustomFieldsHelper::CUSTOM_FIELDS_TABS.index { |f| f[:name] == cf[:name] }
|
||||
CustomFieldsHelper::CUSTOM_FIELDS_TABS << cf
|
||||
end
|
||||
end
|
||||
CustomFieldsHelper::CUSTOM_FIELDS_TABS << cf
|
||||
else
|
||||
unless CustomField::CUSTOM_FIELDS_TABS.index { |f| f[:name] == cf[:name] }
|
||||
CustomField::CUSTOM_FIELDS_TABS << cf
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
# encoding: utf-8
|
||||
#
|
||||
#
|
||||
# Redmine plugin for Document Management System "Features"
|
||||
#
|
||||
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
|
||||
@ -27,30 +27,45 @@ module RedmineDmsf
|
||||
module ProjectPatch
|
||||
|
||||
def self.included(base) # :nodoc:
|
||||
base.send(:include, InstanceMethods)
|
||||
base.send(:include, InstanceMethods)
|
||||
base.class_eval do
|
||||
unloadable
|
||||
alias_method_chain :copy, :dmsf
|
||||
|
||||
has_many :dmsf_files, :class_name => 'DmsfFile', :foreign_key => 'project_id',
|
||||
:conditions => { :dmsf_folder_id => nil }, :dependent => :destroy
|
||||
has_many :dmsf_folders, :class_name => 'DmsfFolder', :foreign_key => 'project_id',
|
||||
:conditions => {:dmsf_folder_id => nil}, :dependent => :destroy
|
||||
has_many :dmsf_workflows, :dependent => :destroy
|
||||
has_many :folder_links, :class_name => 'DmsfLink', :foreign_key => 'project_id',
|
||||
:conditions => { :dmsf_folder_id => nil, :target_type => 'DmsfFolder' },
|
||||
:dependent => :destroy
|
||||
has_many :file_links, :class_name => 'DmsfLink', :foreign_key => 'project_id',
|
||||
:conditions => { :dmsf_folder_id => nil, :target_type => 'DmsfFile' },
|
||||
:dependent => :destroy
|
||||
has_many :url_links, :class_name => 'DmsfLink', :foreign_key => 'project_id',
|
||||
:conditions => { :dmsf_folder_id => nil, :target_type => 'DmsfUrl' },
|
||||
:dependent => :destroy
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
has_many :dmsf_files, -> { where dmsf_folder_id: nil},
|
||||
:class_name => 'DmsfFile', :foreign_key => 'project_id', :dependent => :destroy
|
||||
has_many :dmsf_folders, -> {where dmsf_folder_id: nil},
|
||||
:class_name => 'DmsfFolder', :foreign_key => 'project_id',
|
||||
:dependent => :destroy
|
||||
has_many :dmsf_workflows, :dependent => :destroy
|
||||
has_many :folder_links, -> { where dmsf_folder_id: nil, target_type: 'DmsfFolder' },
|
||||
:class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy
|
||||
has_many :file_links, -> { where dmsf_folder_id: nil, target_type: 'DmsfFile' },
|
||||
:class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy
|
||||
has_many :url_links, -> { where dmsf_folder_id: nil, target_type: 'DmsfUrl' },
|
||||
:class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy
|
||||
else
|
||||
has_many :dmsf_files, :class_name => 'DmsfFile', :foreign_key => 'project_id',
|
||||
:conditions => { :dmsf_folder_id => nil }, :dependent => :destroy
|
||||
has_many :dmsf_folders, :class_name => 'DmsfFolder', :foreign_key => 'project_id',
|
||||
:conditions => {:dmsf_folder_id => nil}, :dependent => :destroy
|
||||
has_many :dmsf_workflows, :dependent => :destroy
|
||||
has_many :folder_links, :class_name => 'DmsfLink', :foreign_key => 'project_id',
|
||||
:conditions => { :dmsf_folder_id => nil, :target_type => 'DmsfFolder' },
|
||||
:dependent => :destroy
|
||||
has_many :file_links, :class_name => 'DmsfLink', :foreign_key => 'project_id',
|
||||
:conditions => { :dmsf_folder_id => nil, :target_type => 'DmsfFile' },
|
||||
:dependent => :destroy
|
||||
has_many :url_links, :class_name => 'DmsfLink', :foreign_key => 'project_id',
|
||||
:conditions => { :dmsf_folder_id => nil, :target_type => 'DmsfUrl' },
|
||||
:dependent => :destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
|
||||
def dmsf_count
|
||||
file_count = self.dmsf_files.visible.count + self.file_links.count
|
||||
folder_count = self.dmsf_folders.visible.count + self.folder_links.count
|
||||
@ -87,23 +102,23 @@ module RedmineDmsf
|
||||
f.copy_to(self, nil)
|
||||
end
|
||||
project.folder_links.visible.each do |l|
|
||||
l.copy_to(self, nil)
|
||||
l.copy_to(self, nil)
|
||||
end
|
||||
project.file_links.visible.each do |l|
|
||||
l.copy_to(self, nil)
|
||||
l.copy_to(self, nil)
|
||||
end
|
||||
project.url_links.visible.each do |l|
|
||||
l.copy_to(self, nil)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def copy_approval_workflows(project)
|
||||
project.dmsf_workflows.each do |wf|
|
||||
wf.copy_to self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -113,4 +128,4 @@ Rails.configuration.to_prepare do
|
||||
unless Project.included_modules.include?(RedmineDmsf::Patches::ProjectPatch)
|
||||
Project.send(:include, RedmineDmsf::Patches::ProjectPatch)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -577,8 +577,15 @@ module RedmineDmsf
|
||||
# If there is no range (start of ranged download, or direct download) then we log the
|
||||
# file access, so we can properly keep logged information
|
||||
if @request.env['HTTP_RANGE'].nil?
|
||||
access = DmsfFileRevisionAccess.new(:user_id => User.current.id, :dmsf_file_revision_id => file.last_revision.id,
|
||||
:action => DmsfFileRevisionAccess::DownloadAction)
|
||||
if (Redmine::VERSION::MAJOR >= 3)
|
||||
access = DmsfFileRevisionAccess.new
|
||||
access.user = User.current
|
||||
access.revision = file.revision
|
||||
access.action = DmsfFileRevisionAccess::DownloadAction
|
||||
else
|
||||
access = DmsfFileRevisionAccess.new(:user_id => User.current.id, :dmsf_file_revision_id => file.last_revision.id,
|
||||
:action => DmsfFileRevisionAccess::DownloadAction)
|
||||
end
|
||||
access.save!
|
||||
end
|
||||
Download.new(file.last_revision.disk_file)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user