#1179 sub-project X sub-folder

This commit is contained in:
karel.picman@lbcfree.net 2020-10-06 09:31:12 +02:00
parent edaf8be0e8
commit 25dc88c5e2
2 changed files with 14 additions and 12 deletions

View File

@ -150,21 +150,21 @@ module RedmineDmsf
def project
unless @project
i = 1
project_names = Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names']
while true
prj = nil
pinfo = @path.split('/').drop(i)
#break if (pinfo.length == 1) && @project
prj = nil
if pinfo.length > 0
if project_names
if Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names']
if pinfo.first =~ / (\d+)$/
prj = Project.visible.find_by(id: $1)
prj = Project.visible.find_by(id: $1, parent_id: @project&.id)
if prj
# Check again whether it's really the project and not a folder with a number as a suffix
prj = nil unless pinfo.first.start_with?(DmsfFolder::get_valid_title(prj.name))
end
end
else
prj = Project.visible.find_by(identifier: pinfo.first)
prj = Project.visible.find_by(identifier: pinfo.first, parent_id: @project&.id)
end
end
break unless prj
@ -178,21 +178,22 @@ module RedmineDmsf
# Make it easy to find the path without project in it.
def projectless_path
i = 1
project_names = Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names']
project = nil
while true
prj = nil
pinfo = @path.split('/').drop(i)
if pinfo.length > 0
if project_names
if Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names']
if pinfo.first =~ / (\d+)$/
prj = Project.visible.find_by(id: $1)
prj = Project.visible.find_by(id: $1, parent_id: project&.id)
if prj
# Check again whether it's really the project and not a folder with a number as a suffix
prj = nil unless pinfo.first.start_with?(DmsfFolder::get_valid_title(prj.name))
end
end
else
prj = Project.visible.find_by(identifier: pinfo.first)
prj = Project.visible.find_by(identifier: pinfo.first, parent_id: project&.id)
project = prj
end
end
return '/' + @path.split('/').drop(i).join('/') unless prj

View File

@ -224,14 +224,14 @@ module RedmineDmsf
raise Forbidden unless User.current.admin? || User.current.allowed_to?(:folder_manipulation, project)
raise Forbidden unless (!parent.exist? || !parent.folder || DmsfFolder.permissions?(parent.folder, false))
return MethodNotAllowed if exist? # If we already exist, why waste the time trying to save?
parent_folder = nil
parent_folder_id = nil
if parent.projectless_path != '/'
return Conflict unless parent.folder
parent_folder = parent.folder.id
parent_folder_id = parent.folder.id
end
f = DmsfFolder.new
f.title = basename
f.dmsf_folder_id = parent_folder
f.dmsf_folder_id = parent_folder_id
f.project = project
f.user = User.current
f.save ? Created : Conflict
@ -287,6 +287,7 @@ module RedmineDmsf
resource = dest.is_a?(ResourceProxy) ? dest.resource : dest
return PreconditionFailed if !resource.is_a?(DmsfResource) || resource.project.nil?
parent = resource.parent
raise Forbidden unless resource.project.module_enabled?(:dmsf)
if !parent.exist? || (!User.current.admin? && (!DmsfFolder.permissions?(folder, false) ||
!DmsfFolder.permissions?(parent.folder, false)))
raise Forbidden