问题
I would like to enable WebDav for Rails 3.1 application, where I use Devise for authentication and CanCan for authorization.
So far I turned on WebDav and works fine. Is it possible to use Devise logins/users with dav4rack to enable/restrict access to certain files/directories on WebDav? Maybe there is already a howto or wiki page about that? Any help will be appreciated.
PS. is this the right way of solving this kind of problem? maybe i should switch back to apache mod_dav and synchronise apache's dav users/groups with users/groups defined in my Rails application?
回答1:
I found an example of Devise w/ a Dav4Rack resource here https://github.com/bryanrite/dav4rack-example-devise-subdirectories/blob/master/app/models/my_resource.rb
class MyResource < DAV4Rack::FileResource
def root
File.join(options[:root].to_s, user.id.to_s)
end
private
def authenticate(username, password)
self.user = User.find_by_username(username)
user.try(:valid_password?, password)
end
end
In my case, I used email instead of username.
来源:https://stackoverflow.com/questions/8034384/rails-3-1-app-with-integrated-webdav-and-authentication