File move (within) project now supported; overwrite on both folder and file is still unspported at this time
This commit is contained in:
parent
24c2646d8e
commit
c8441bc4bb
2
Gemfile
2
Gemfile
@ -7,3 +7,5 @@ gem "dav4rack"
|
|||||||
group :xapian do
|
group :xapian do
|
||||||
gem "xapian-full", :require => false
|
gem "xapian-full", :require => false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
gem "ruby-debug19"
|
||||||
|
|||||||
@ -79,16 +79,18 @@ table { width:100%%; }
|
|||||||
def dirname
|
def dirname
|
||||||
File.dirname(path)
|
File.dirname(path)
|
||||||
end
|
end
|
||||||
def Project
|
def project
|
||||||
return @Project unless @Project.nil?
|
return @Project unless @Project.nil?
|
||||||
pinfo = @path.split('/').drop(1)
|
pinfo = @path.split('/').drop(1)
|
||||||
if pinfo.length > 0
|
if pinfo.length > 0
|
||||||
begin
|
begin
|
||||||
@project = Project.find(pinfo.first)
|
@Project = Project.find(pinfo.first)
|
||||||
rescue
|
rescue
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#Make it easy to find the path without project in it.
|
||||||
def projectless_path
|
def projectless_path
|
||||||
'/'+path.split('/').drop(2).join('/')
|
'/'+path.split('/').drop(2).join('/')
|
||||||
end
|
end
|
||||||
|
|||||||
@ -27,7 +27,7 @@ module RedmineDmsf
|
|||||||
def folder?
|
def folder?
|
||||||
return @_folder unless @_folder.nil?
|
return @_folder unless @_folder.nil?
|
||||||
@_folder = false
|
@_folder = false
|
||||||
folders = DmsfFolder.find(:all, :conditions => ["project_id = :project_id AND title = :title", {:project_id => self.Project.id, :title => basename}], :order => "title ASC")
|
folders = DmsfFolder.find(:all, :conditions => ["project_id = :project_id AND title = :title", {:project_id => project.id, :title => basename}], :order => "title ASC")
|
||||||
return false unless folders.length > 0
|
return false unless folders.length > 0
|
||||||
if (folders.length > 1) then
|
if (folders.length > 1) then
|
||||||
folders.delete_if {|x| '/'+x.dmsf_path_str != projectless_path}
|
folders.delete_if {|x| '/'+x.dmsf_path_str != projectless_path}
|
||||||
@ -48,13 +48,35 @@ module RedmineDmsf
|
|||||||
def file?
|
def file?
|
||||||
return @_file unless @_file.nil?
|
return @_file unless @_file.nil?
|
||||||
@_file = false
|
@_file = false
|
||||||
files = DmsfFile.find(:all, :conditions => ["project_id = :project_id AND name = :file_name AND deleted = :deleted", {:project_id => self.Project.id, :file_name => basename, :deleted => false}], :order => "name ASC")
|
|
||||||
|
#
|
||||||
|
# Hunt for files parent path
|
||||||
|
f = false
|
||||||
|
if (parent.projectless_path != "/")
|
||||||
|
if parent.folder?
|
||||||
|
f = parent.folder
|
||||||
|
end
|
||||||
|
else
|
||||||
|
f = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if f || f.nil? then
|
||||||
|
# f has a value other than false? - lets use traditional
|
||||||
|
# DMSF file search by name.
|
||||||
|
@_filedata = DmsfFile.find_file_by_name(project, f, basename)
|
||||||
|
@_file = !@_filedata.nil?
|
||||||
|
else
|
||||||
|
# If folder is false, means it couldn't pick up parent,
|
||||||
|
# as such its probably fine to bail out, however we'll
|
||||||
|
# perform a search in this scenario
|
||||||
|
files = DmsfFile.find(:all, :conditions => ["project_id = :project_id AND name = :file_name AND deleted = :deleted", {:project_id => project.id, :file_name => basename, :deleted => false}], :order => "name ASC")
|
||||||
files.delete_if {|x| File.dirname('/'+x.dmsf_path_str) != File.dirname(projectless_path)}
|
files.delete_if {|x| File.dirname('/'+x.dmsf_path_str) != File.dirname(projectless_path)}
|
||||||
if files.length > 0
|
if files.length > 0
|
||||||
@_filedata = files[0]
|
@_filedata = files[0]
|
||||||
@_file = true
|
@_file = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def content_type
|
def content_type
|
||||||
if folder? then
|
if folder? then
|
||||||
@ -115,27 +137,17 @@ module RedmineDmsf
|
|||||||
if (request.body.read.to_s == '')
|
if (request.body.read.to_s == '')
|
||||||
|
|
||||||
_folder = false
|
_folder = false
|
||||||
if (File.basename(File.dirname(projectless_path)) != "/")
|
_folderid = nil
|
||||||
folders = DmsfFolder.find(:all, :conditions => ["project_id = :project_id AND title = :title", {:project_id => self.Project.id, :title => File.basename(File.dirname(path))}], :order => "title ASC")
|
if (parent.projectless_path != "/")
|
||||||
if (folders.length > 1) then
|
if parent.folder? then
|
||||||
folders.delete_if {|x| x.dmsf_path_str != File.dirname(projectless_path)}
|
_folderdata = parent.folder
|
||||||
return false unless folders.length > 0
|
_folder = true
|
||||||
_folder=true
|
|
||||||
_folderdata = folders[0]
|
|
||||||
elsif (folders.length == 1)
|
|
||||||
if ('/'+folders[0].dmsf_path_str == File.dirname(projectless_path)) then
|
|
||||||
_folder=true
|
|
||||||
_folderdata = folders[0]
|
|
||||||
else
|
|
||||||
_folder= false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return MethodNotAllowed unless _folder
|
return MethodNotAllowed unless _folder
|
||||||
f = DmsfFolder.new({:title => basename, :dmsf_folder_id => _folderdata.id, :description => 'Folder created from WebDav'})
|
_folderid = _folderdata.id
|
||||||
else
|
|
||||||
f = DmsfFolder.new({:title => basename, :dmsf_folder_id => nil, :description => 'Folder created from WebDav'})
|
|
||||||
end
|
end
|
||||||
f.project = self.Project
|
f = DmsfFolder.new({:title => basename, :dmsf_folder_id => _folderid, :description => 'Folder created from WebDav'})
|
||||||
|
f.project = project
|
||||||
f.user = User.current
|
f.user = User.current
|
||||||
f.save ? OK : MethodNotAllowed
|
f.save ? OK : MethodNotAllowed
|
||||||
else
|
else
|
||||||
@ -154,27 +166,51 @@ module RedmineDmsf
|
|||||||
end
|
end
|
||||||
|
|
||||||
def move(dest, overwrite)
|
def move(dest, overwrite)
|
||||||
return PreconditionFailed if !dest.Resource.is_a?(DmsfResource) || dest.Resource.Project.nil? || dest.Resource.Project.id == 0
|
return PreconditionFailed if !dest.Resource.is_a?(DmsfResource) || dest.Resource.project.nil? || dest.Resource.project.id == 0
|
||||||
|
|
||||||
|
#At the moment we don't support cross project destinations
|
||||||
|
return MethodNotImplemented unless project.id == dest.Resource.project.id
|
||||||
|
|
||||||
|
parent = dest.Resource.parent
|
||||||
if (collection?)
|
if (collection?)
|
||||||
#Current object is a folder, so now we need to figure out information about Destination
|
#Current object is a folder, so now we need to figure out information about Destination
|
||||||
if(dest.exist?) then
|
if(dest.exist?) then
|
||||||
STDOUT.puts "Exist?"
|
STDOUT.puts "Exist?"
|
||||||
else
|
else
|
||||||
if(File.basename(File.dirname(dest.Resource.projectless_path)) == "/") #Project root
|
|
||||||
if(self.Project.id != dest.Resource.Project.id) then
|
if(parent.projectless_path == "/") #Project root
|
||||||
return MethodNotImplemented
|
|
||||||
end
|
|
||||||
folder.dmsf_folder_id = nil
|
folder.dmsf_folder_id = nil
|
||||||
else
|
else
|
||||||
parent = dest.Resource.parent #Grab parent Resource
|
|
||||||
return PreconditionFailed unless parent.exist? && parent.folder?
|
return PreconditionFailed unless parent.exist? && parent.folder?
|
||||||
folder.dmsf_folder_id = parent.folder.id
|
folder.dmsf_folder_id = parent.folder.id
|
||||||
end
|
end
|
||||||
folder.title = dest.Resource.basename
|
folder.title = dest.Resource.basename
|
||||||
folder.save ? Created : PreconditionFailed
|
folder.save ? Created : PreconditionFailed
|
||||||
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
STDOUT.puts "Not a col"
|
if(dest.exist?) then
|
||||||
|
STDOUT.puts "Exist?"
|
||||||
|
else
|
||||||
|
|
||||||
|
if(parent.projectless_path == "/") #Project root
|
||||||
|
f = nil
|
||||||
|
else
|
||||||
|
return PreconditionFailed unless parent.exist? && parent.folder?
|
||||||
|
f = parent.folder
|
||||||
|
end
|
||||||
|
return PreconditionFailed unless exist? && file?
|
||||||
|
return InternalServerError unless file.move_to(project, f)
|
||||||
|
|
||||||
|
#Update Revision and names of file [We can link to old physical resource, as it's not changed]
|
||||||
|
rev = file.last_revision
|
||||||
|
rev.name = dest.Resource.basename
|
||||||
|
file.name = dest.Resource.basename
|
||||||
|
|
||||||
|
#Save Changes
|
||||||
|
(rev.save! && file.save!) ? Created : PreconditionFailed
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -10,17 +10,17 @@ module RedmineDmsf
|
|||||||
#caching for repeat usage
|
#caching for repeat usage
|
||||||
return @children unless @children.nil?
|
return @children unless @children.nil?
|
||||||
@children = []
|
@children = []
|
||||||
DmsfFolder.project_root_folders(self.Project).map do |p|
|
DmsfFolder.project_root_folders(project).map do |p|
|
||||||
@children.push child(p.title, p)
|
@children.push child(p.title, p)
|
||||||
end
|
end
|
||||||
DmsfFile.project_root_files(self.Project).map do |p|
|
DmsfFile.project_root_files(project).map do |p|
|
||||||
@children.push child(p.name, p)
|
@children.push child(p.name, p)
|
||||||
end
|
end
|
||||||
@children
|
@children
|
||||||
end
|
end
|
||||||
|
|
||||||
def exist?
|
def exist?
|
||||||
!(self.Project.nil? || User.current.anonymous?)
|
!(project.nil? || User.current.anonymous?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def collection?
|
def collection?
|
||||||
@ -28,11 +28,11 @@ module RedmineDmsf
|
|||||||
end
|
end
|
||||||
|
|
||||||
def creation_date
|
def creation_date
|
||||||
self.Project.created_on unless self.Project.nil?
|
project.created_on unless project.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_modified
|
def last_modified
|
||||||
self.Project.updated_on unless self.Project.nil?
|
project.updated_on unless project.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def etag
|
def etag
|
||||||
@ -40,11 +40,11 @@ module RedmineDmsf
|
|||||||
end
|
end
|
||||||
|
|
||||||
def name
|
def name
|
||||||
self.Project.identifier unless self.Project.nil?
|
project.identifier unless project.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def long_name
|
def long_name
|
||||||
self.Project.name unless self.Project.nil?
|
project.name unless project.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def content_type
|
def content_type
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user