This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

install DAV4Rack and custom resource

  • Loading branch information...
bryanrite committed Jan 28, 2012
1 parent 2bdde8d commit c00655675b6d4c2688919c8c6e0a89a8c56ec5c9
Showing with 50 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 Gemfile
  3. +7 −0 Gemfile.lock
  4. +14 −0 app/models/my_resource.rb
  5. +1 −1 app/models/user.rb
  6. +1 −0 config/initializers/webdav.rb
  7. +17 −3 config/routes.rb
  8. +8 −0 lib/subdomain.rb
View
@@ -13,3 +13,4 @@
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
/public/system/userfiles/*
View
@@ -7,6 +7,7 @@ gem 'rails', '3.1.3'
gem 'sqlite3'
gem 'devise'
gem 'dav4rack'
# Gems used only for assets and not required
# in production environments by default.
View
@@ -39,6 +39,10 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.2.0)
dav4rack (0.2.10)
nokogiri (>= 1.4.2)
rack (>= 1.1.0)
uuidtools (~> 2.1.1)
devise (1.5.3)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
@@ -58,6 +62,7 @@ GEM
treetop (~> 1.4.8)
mime-types (1.17.2)
multi_json (1.0.4)
nokogiri (1.5.0)
orm_adapter (0.0.5)
polyglot (0.3.3)
rack (1.3.6)
@@ -107,6 +112,7 @@ GEM
uglifier (1.2.2)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
uuidtools (2.1.2)
warden (1.1.0)
rack (>= 1.0)
@@ -115,6 +121,7 @@ PLATFORMS
DEPENDENCIES
coffee-rails (~> 3.1.1)
dav4rack
devise
jquery-rails
rails (= 3.1.3)
View
@@ -0,0 +1,14 @@
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
View
@@ -9,7 +9,7 @@ class User < ActiveRecord::Base
after_create :create_userfile_directory
validates :username, presence: true
validates :username, presence: true, uniqueness: true
def create_userfile_directory
FileUtils.mkdir(File.join(Rails.root, 'public', 'system', 'userfiles', id.to_s))
@@ -0,0 +1 @@
require 'dav4rack/file_resource'
View
@@ -1,5 +1,19 @@
require 'subdomain'
Example::Application.routes.draw do
get "home/index"
devise_for :users
root :to => "home#index"
constraints(NotDav) do
get "home/index"
devise_for :users
root :to => "home#index"
end
constraints :subdomain => 'webdav' do
mount DAV4Rack::Handler.new(
:root => File.join(Rails.root, 'public', 'system', 'userfiles'),
:root_uri_path => '/',
:resource_class => Example::MyResource
), :at => '/'
end
end
View
@@ -0,0 +1,8 @@
# lib/sub_domain.rb
class NotDav
def self.matches?(request)
request.subdomain != 'webdav'
end
end

0 comments on commit c006556

Please sign in to comment.