Project folder names in WebDav can be the project name instead of identifier.

This commit is contained in:
COLA@Redmine.local 2017-02-12 19:55:15 +01:00
parent 2bbd259ff2
commit 12a7a45e59
3 changed files with 49 additions and 9 deletions

View File

@ -94,6 +94,22 @@ module RedmineDmsf
@__proxy.class.new("#{new_public}#{name}", "#{new_path}#{name}", request, response, options.merge(:user => @user))
end
def child_project(p)
project_display_name = ProjectResource.create_display_name(p)
new_public = public_path.dup
new_public = new_public + '/' unless new_public[-1,1] == '/'
new_public = '/' + new_public unless new_public[0,1] == '/'
new_public += project_display_name
new_path = path.dup
new_path = new_path + '/' unless new_path[-1,1] == '/'
new_path = '/' + new_path unless new_path[0,1] == '/'
new_path += project_display_name
@__proxy.class.new("#{new_public}", "#{new_path}", request, response, options.merge(:user => @user))
end
def parent
p = @__proxy.parent
return nil if p.nil?
@ -148,8 +164,22 @@ module RedmineDmsf
# Return instance of Project based on the path
def project
unless @project
use_project_names = Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names']
pinfo = @path.split('/').drop(1)
if pinfo.length > 0
if use_project_names
unless pinfo.first.match('(\[([0-9]+)\])$').nil?
pid = $2
begin
@project = Project.find_by_id(pid)
rescue Exception => e
Rails.logger.error e.message
end
end
if @project.nil?
Rails.logger.warn {"WebDAV ERROR: No project found on path '#{@path}'"}
end
else
begin
@project = Project.find(pinfo.first)
rescue Exception => e
@ -157,6 +187,7 @@ module RedmineDmsf
end
end
end
end
@project
end

View File

@ -31,10 +31,10 @@ module RedmineDmsf
def children
unless @projects
@projects = []
Project.select(:identifier).has_module(:dmsf).where(
Project.select(:id, :identifier, :name).has_module(:dmsf).where(
Project.allowed_to_condition(
User.current, :view_dmsf_folders)).order('lft').all.each do |p|
@projects << child(p.identifier)
@projects << child_project(p)
end
end
@projects

View File

@ -72,7 +72,7 @@ module RedmineDmsf
end
def name
project.identifier unless project.nil?
ProjectResource.create_display_name(project)
end
def long_name
@ -109,6 +109,15 @@ module RedmineDmsf
self.project.id if self.project
end
def self.create_display_name(p)
use_project_names = Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names']
if use_project_names
"#{p.name.gsub(/\W/, "_")} [#{p.id}]" unless p.nil?
else
p.identifier unless p.nil?
end
end
end
end
end