Resolves pull request #84

This commit is contained in:
Daniel Munn 2013-01-09 23:55:20 +00:00
parent 1987a6a0b8
commit 076f840eee
5 changed files with 67 additions and 10 deletions

View File

@ -354,7 +354,7 @@ class DmsfFile < ActiveRecord::Base
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
dmsf_file = DmsfFile.where(limit_options[:conditions]).where(:id => dmsf_attrs[2], :deleted => false).first
if !dmsf_file.nil?
if options[:offset]
@ -368,10 +368,14 @@ class DmsfFile < ActiveRecord::Base
allowed = User.current.allowed_to?(:view_dmsf_files, dmsf_file.project)
project_included = false
project_included = true if projects.nil?
if !project_included
projects.each {|x|
project_included = true if x[:id] == dmsf_file.project.id
}
unless project_included
projects.each do |x|
if x.is_a?(ActiveRecord::Relation)
project_included = x.first.id == dmsf_file.project.id
else
project_included = x[:id] == dmsf_file.project.id
end
end
end
if (allowed && project_included)

View File

@ -144,6 +144,25 @@ class DmsfFolder < ActiveRecord::Base
self.subfolders.visible.each {|subfolder| file_count += subfolder.deep_file_count}
file_count
end
def deep_folder_count
folder_count = self.subfolders.length
self.subfolders.each {|subfolder| folder_count += subfolder.deep_folder_count}
folder_count
end
def self.project_deep_folder_count(project)
subfolders = self.project_root_folders(project)
folder_count = subfolders.length
subfolders.each{|subfolder| folder_count += subfolder.deep_folder_count}
folder_count
end
def self.project_deep_file_count(project)
file_count = DmsfFile.project_root_files(project).length
self.project_root_folders(project).each{|subfolder| file_count += subfolder.deep_file_count}
file_count
end
def deep_folder_count
folder_count = self.subfolders.length

View File

@ -70,6 +70,8 @@ RedmineApp::Application.routes.draw do
get '/dmsf/files/:id/download', :controller => 'dmsf_files', :action => 'show', :download => '' #Otherwise will not route nil download param
get '/dmsf/files/:id/download/:download', :controller => 'dmsf_files', :action => 'show'
get '/dmsf/files/:id', :controller => 'dmsf_files', :action => 'show'
# Just to keep backward compatibility of external url links
get '/dmsf_files/:id', :controller => 'dmsf_files', :action => 'show'
#
# files_copy controller

View File

@ -72,7 +72,7 @@ Redmine::Plugin.register :redmine_dmsf do
unless entry.nil? || entry.deleted
title = args[1] ? args[1] : entry.title
revision = args[2] ? args[2] : ""
return link_to "#{title}", :controller => "dmsf_files", :action => "show", :id => entry, :download => revision
return link_to "#{title}", :controller => "dmsf_files", :action => "show", :id => entry, :download => revision, :only_path => false
end
nil
end
@ -85,13 +85,13 @@ Redmine::Plugin.register :redmine_dmsf do
macro :dmsff do |obj, args|
if args.length < 1
return link_to l(:link_documents), :controller => "dmsf", :action => "show", :id => @project
return link_to l(:link_documents), :controller => "dmsf", :action => "show", :id => @project, :only_path => false
else
entry_id = args[0].strip
entry = DmsfFolder.find(entry_id)
unless entry.nil?
title = args[1] ? args[1] : entry.title
return link_to "#{title}", :controller => "dmsf", :action => "show", :id => entry.project, :folder_id => entry
return link_to "#{title}", :controller => "dmsf", :action => "show", :id => entry.project, :folder_id => entry, :only_path => false
end
end
nil
@ -109,7 +109,7 @@ Redmine::Plugin.register :redmine_dmsf do
entry = DmsfFile.find(entry_id)
unless entry.nil? || entry.deleted
title = args[1] ? args[1] : entry.title
return link_to "#{title}", :controller => "dmsf_files", :action => "show", :id => entry
return link_to "#{title}", :controller => "dmsf_files", :action => "show", :id => entry, :only_path => false
end
nil
end

View File

@ -1,6 +1,6 @@
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2011 V<EFBFBD>t Jon<6F> <vit.jonas@gmail.com>
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
#
# This program is free software; you can redistribute it and/or
@ -28,6 +28,7 @@ module RedmineDmsf
base.extend(ClassMethods)
base.class_eval do
unloadable
<<<<<<< HEAD
alias_method_chain :copy, :dmsf
has_many :dmsf_files, :class_name => "DmsfFile", :foreign_key => "project_id", :conditions => { :dmsf_folder_id => nil }
@ -36,6 +37,10 @@ module RedmineDmsf
end
=======
alias_method_chain :copy, :dmsf_copy
end
>>>>>>> d4e19db3410db4cae44a55b0e8c022a6fd82e9fa
end
module ClassMethods
@ -45,6 +50,7 @@ module RedmineDmsf
def all_dmsf_custom_fields
@all_dmsf_custom_fields ||= (DmsfFileRevisionCustomField.for_all).uniq.sort # + dmsf_file_revision_custom_fields).uniq.sort
end
<<<<<<< HEAD
def dmsf_count
file_count = DmsfFile.visible.project_root_files(self).count
@ -79,6 +85,32 @@ module RedmineDmsf
f.copy_to(self, nil)
}
end
=======
def copy_with_dmsf_copy(project, options={})
project = project.is_a?(Project) ? project : Project.find(project)
to_be_copied = %w(wiki versions issue_categories issues members queries boards dmsf)
to_be_copied = to_be_copied & options[:only].to_a unless options[:only].nil?
Project.transaction do
if save
reload
to_be_copied.each do |name|
send "copy_#{name}", project
end
Redmine::Hook.call_hook(:model_project_copy_before_save, :source_project => project, :destination_project => self)
save
end
end
end
# Copies DMSF from +project+
def copy_dmsf(project)
DmsfFolder.project_root_folders(project).each{|subfolder| subfolder.copy_to(self, nil)}
DmsfFile.project_root_files(project).each{|file| file.copy_to(self, nil)}
end
>>>>>>> d4e19db3410db4cae44a55b0e8c022a6fd82e9fa
end
end
end