diff --git a/lib/redmine_dmsf/webdav/base_resource.rb b/lib/redmine_dmsf/webdav/base_resource.rb index a5a28651..9b07f9e9 100644 --- a/lib/redmine_dmsf/webdav/base_resource.rb +++ b/lib/redmine_dmsf/webdav/base_resource.rb @@ -3,7 +3,7 @@ # Redmine plugin for Document Management System "Features" # # Copyright (C) 2012 Daniel Munn -# Copyright (C) 2011-15 Karel Pičman +# Copyright (C) 2011-16 Karel Pičman # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -39,12 +39,12 @@ module RedmineDmsf @__proxy = klass end - #Overridable function to provide better listing for GET requests + # Overridable function to provide better listing for GET requests def long_name nil end - #Overridable function to provide better listing for GET requests + # Overridable function to provide better listing for GET requests def special_type nil end @@ -59,15 +59,15 @@ module RedmineDmsf @public_path.force_encoding('utf-8') end - #Generate HTML for Get requests + # Generate HTML for Get requests def html_display @response.body = '' - Confict unless collection? + Confict unless collection? entities = children.map{|child| DIR_FILE % [ child.public_path, child.long_name || child.name, - child.collection? ? '-' : number_to_human_size(child.content_length), + child.collection? ? '' : number_to_human_size(child.content_length), child.special_type || child.content_type, child.last_modified ] @@ -75,11 +75,11 @@ module RedmineDmsf entities = DIR_FILE % [ parent.public_path, l(:parent_directory), - '-', '', '', - ] + entities if parent - @response.body << index_page % [ path.empty? ? '/' : path, path.empty? ? '/' : path , entities ] + '', + ] + entities if parent + @response.body << index_page % [ path.empty? ? '/' : path, path.empty? ? '/' : path, entities ] end # Run method through proxy class - ensuring always compatible child is generated @@ -99,37 +99,43 @@ module RedmineDmsf return p.resource.nil? ? p : p.resource end - #Override index_page from DAV4Rack::Resource + # Override index_page from DAV4Rack::Resource def index_page return <<-PAGE - - %s + + + + Index of %s - -

%s

-
- - - - - - - -%s -
NameSizeTypeLast Modified
-
- + + +

Index of %s

+
+ + + + + + + + %s +
NameSizeTypeLast Modified
+
+ + PAGE end - protected + protected + def basename File.basename(path) end @@ -163,4 +169,4 @@ table { width:100%%; } end end end -end +end \ No newline at end of file diff --git a/lib/redmine_dmsf/webdav/dmsf_resource.rb b/lib/redmine_dmsf/webdav/dmsf_resource.rb index cdf130d9..66ff3f6f 100644 --- a/lib/redmine_dmsf/webdav/dmsf_resource.rb +++ b/lib/redmine_dmsf/webdav/dmsf_resource.rb @@ -46,14 +46,16 @@ module RedmineDmsf # Our already quite heavy usage of DB would just get silly every time we called # this method. def children - return @children if @children - @children = [] - return [] unless collection? - folder.subfolders.visible.map do |p| - @children.push child(p.title) - end - folder.files.visible.map do |p| - @children.push child(p.name) + unless @childern + @children = [] + if collection? + folder.subfolders.visible.map do |p| + @children.push child(p.title) + end + folder.files.visible.map do |p| + @children.push child(p.name) + end + end end @children end @@ -97,7 +99,7 @@ module RedmineDmsf # Check if current entity exists as a file (DmsfFile), and returns corresponding object if found (nil otherwise) # Currently has a dual search approach (depending on if parent can be determined) - def file + def file unless @file return nil unless project # Again if entity project is nil, it cannot exist in context of this object # Hunt for files parent path diff --git a/lib/redmine_dmsf/webdav/download.rb b/lib/redmine_dmsf/webdav/download.rb index 18765334..f7e2698d 100644 --- a/lib/redmine_dmsf/webdav/download.rb +++ b/lib/redmine_dmsf/webdav/download.rb @@ -50,4 +50,4 @@ module RedmineDmsf end end end -end +end \ No newline at end of file diff --git a/lib/redmine_dmsf/webdav/index_resource.rb b/lib/redmine_dmsf/webdav/index_resource.rb index 621f43f3..bc622ef3 100644 --- a/lib/redmine_dmsf/webdav/index_resource.rb +++ b/lib/redmine_dmsf/webdav/index_resource.rb @@ -3,7 +3,7 @@ # Redmine plugin for Document Management System "Features" # # Copyright (C) 2012 Daniel Munn -# Copyright (C) 2011-15 Karel Pičman +# Copyright (C) 2011-16 Karel Pičman # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -22,25 +22,16 @@ module RedmineDmsf module Webdav class IndexResource < BaseResource - - def initialize(public_path, path, request, response, options) - super(public_path, path, request, response, options) - end - + def children - if @projects.blank? + unless @projects @projects = [] - if User.current.admin? - @projects = Project.visible.order('lft').to_a - elsif User.current.logged? # If user is not admin, we should only show memberships relevant - User.current.memberships.each{ |m| @projects << m.project if m.roles.detect{ |r| r.allowed_to?(:view_dmsf_folders) } } + Project.has_module(:dmsf).where(Project.allowed_to_condition( + User.current, :view_dmsf_folders)).order('lft').all.each do |p| + @projects << child(p.identifier) end - end - @projects.delete_if { |node| !node.module_enabled?('dmsf') } if @projects - return [] if @projects.blank? - @projects.map do |p| - child p.identifier end + @projects end def collection? diff --git a/lib/redmine_dmsf/webdav/project_resource.rb b/lib/redmine_dmsf/webdav/project_resource.rb index 3704dfb7..73d19be4 100644 --- a/lib/redmine_dmsf/webdav/project_resource.rb +++ b/lib/redmine_dmsf/webdav/project_resource.rb @@ -22,24 +22,21 @@ module RedmineDmsf module Webdav class ProjectResource < BaseResource - - def initialize(public_path, path, request, response, options) - super(public_path, path, request, response, options) - end - - def children - #caching for repeat usage - return @children unless @children.nil? - return [] if project.nil? || project.id.nil? - @children = [] - project.dmsf_folders.visible.map do |p| - @children.push child(p.title) - end - project.dmsf_files.visible.map do |p| - @children.push child(p.name) + + def children + unless @children + @children = [] + if project + project.dmsf_folders.visible.map do |p| + @children.push child(p.title) + end + project.dmsf_files.visible.map do |p| + @children.push child(p.name) + end + end end @children - end + end def exist? return false if (project.nil? || User.current.anonymous?)