RailsDAV update, dynamic base_dir
January 13th, 2007
I’ve added a couple of features to the RailsDAV act_as_filewebdav. Dynamic base directories and absolute base directories.
act_as_filewebdav takes two parameters:
base_dir can take either a String for the base directory or a Symbol which will use a method in the controller to return the base directory to use on each request.
absolute allows for either true or false (defaults to false) to determine to use either an absolute filesystem directory or relative to the RAILS_ROOT
So a common example usecase to allow users to upload/download to their own directories after they have logged on using basic HTTP authentication.
class FileDavController < ApplicationController
act_as_filewebdav :base_dir => :user_web_dir, :absolute => true
before_filter :user_auth
def user_auth
basic_auth_required {|username, password| session[:user] = User.authenticate(username,password) }
end
def user_web_dir
"/var/user/#{session[:user].username}"
end
end
January 23rd, 2007 at 03:09 PM
Rails 1.2 has broken railsdav. :(
January 25th, 2007 at 11:22 PM
Yep there is definately an issue here somewhere on Rails 1.2
January 29th, 2007 at 03:16 PM
Great Work! I just try it and … incredible – it works ;-)
But may be i make something bad (actually, i just “svn co ..” in vendor/plugins/railsdav and copypase exaple from site), but nobody can see files and directories with spaces in name (say “untitled folder” appears on disk, but throught webdav i can see it)
Its my mistake or bug?
January 29th, 2007 at 03:17 PM
ups. so many mistypes ;-) s/exaple/example/ s/i can see/i cant see/
January 29th, 2007 at 10:41 PM
ill check this one as the directories in spaces used to work but the url encoding of spaces may not be working
February 24th, 2007 at 11:13 AM
I’ve made a trivial patch to get this working with Rails 1.2.x located here http://svn.shiftnetwork.com/plugins/railsdav
February 25th, 2007 at 10:57 PM
Thanks shift i’ve added your patch and does seem testing and it looks ok so i’ve merged into the HEAD for anyone having problems with 1.2.x
February 25th, 2007 at 11:26 PM
Stuart, I just updated my version and I am revision 15, is this what you just posted? For a controller called “file_controller”, should I mount it in OS X finder as http://localhost:3000/file/? or is there something else I should use? I can’t seem to get it to respond. I am on Rails 1.2.2 as well.
Eric
February 27th, 2007 at 01:51 PM
It depends how you have set up the routes.rb.
The webdav controller must have a map.connect ‘file/*path_info’, :controller => ‘file’, :action => ‘webdav’
to mount as http://localhost:3000/file/
February 27th, 2007 at 08:00 PM
Stuart: No problem. On a side note, while testing I noticed it doesn’t like receiving biggish file uploads (350mb test file), the dispatcher ran out of memory to allocate. I was wondering if there was anyway this could be worked around but I haven’t had time to look into this yet (my application will need to deal with files of any size).
In my patch I also commented out the line that removes the first / as I’m using the path /home (webdav home directory’s), just incase you had over looked it as I notice it was committed too.
March 7th, 2007 at 09:49 AM
I whipped up a small patch:
https://blarf.homeip.net/~alex/railsdav-r15.patch
Three proposed changes would be accomplished here:
1.) Properly handle the no user agent string case
2.) Allow the ‘Allow’ and ‘DAV’ headers to be appended so that things like CalDAV can be implemented (since CalDAV provides two new methods (REPORT and MKCALENDAR) and requires that it be advertised in the DAV header). There’s probably a more Ruby like way to do this (right now it’s simply instance variables in the controller). But, you know, to get the ball rolling I figured this was worth a shot.
3.) Rework read_params so that other methods (such as REPORT) can acquire data that’s been sent. My thinking here was that PUT and POST will have parameters in the request body, but that those parameters will be of mime type ‘application/x-www-form-urlencoded’. With that in mind, Rails will now read the request body anytime there is one (so that it’s accessible), and it will try to parse the query string. Unless the request body is of type ‘application/x-www-form-urlencoded’ it will use the query string to populate the paramaters ‘hash’.
March 19th, 2007 at 10:34 PM
Thanks Alex, that looks like some good additions and the iCal stuff is something I was going to look at.
I’ll integrate these type of changes when I get back (although I may change the implementation slightly.)
thanks again Stuart