bcms_webdav 1.0.2 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -0
- data/VERSION +1 -1
- data/lib/bcms_webdav/resource.rb +24 -2
- data/test/unit/web_dav_resource_test.rb +27 -0
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -14,6 +14,8 @@ For more information on WebDAV see: http://en.wikipedia.org/wiki/WebDAV
|
|
14
14
|
* Users must have 'Administer CMS' permissions in order to access resources via WebDAV.
|
15
15
|
* Users can use their normal cms username and password.
|
16
16
|
|
17
|
+
Note: Currently this module is tested to work on Passenger and Mongrel. Other rack servers may work, but implementations for file upload differ slightly.
|
18
|
+
|
17
19
|
=== Clients
|
18
20
|
|
19
21
|
In order to take advantage of this module, users will need a WebDAV client. Many FTP clients will support this, including:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.4
|
data/lib/bcms_webdav/resource.rb
CHANGED
@@ -125,13 +125,13 @@ module Bcms
|
|
125
125
|
|
126
126
|
# Handle uploading file.
|
127
127
|
def put(request, response)
|
128
|
+
temp_file = extract_tempfile(request)
|
128
129
|
|
129
|
-
temp_file = request.body
|
130
130
|
add_rails_like_methods(temp_file)
|
131
131
|
|
132
132
|
section = find_section_for(path)
|
133
133
|
|
134
|
-
file_block = FileBlock.new(:name=>path, :attachment_file=>
|
134
|
+
file_block = FileBlock.new(:name=>path, :attachment_file=>temp_file, :attachment_section => section, :attachment_file_path=>path, :publish_on_save=>true)
|
135
135
|
unless file_block.save
|
136
136
|
log "Couldn't save file."
|
137
137
|
file_block.errors.each do |error|
|
@@ -154,6 +154,28 @@ module Bcms
|
|
154
154
|
|
155
155
|
private
|
156
156
|
|
157
|
+
# Different webservers have slightly different behavior for uploaded files.
|
158
|
+
# 1. Webrick/mongrel - body is a TempFile
|
159
|
+
# 2. Passenger - body is a PhusionPassenger::Utils::RewindableInput
|
160
|
+
#
|
161
|
+
# Until Rails 3, which may have a consistent middleware for extracting a Tempfile, we have to do it this way.
|
162
|
+
def extract_tempfile(request)
|
163
|
+
input = request.body
|
164
|
+
if input
|
165
|
+
# Handle Mongrel
|
166
|
+
return input if input.is_a?(Tempfile)
|
167
|
+
|
168
|
+
# Handle Passenger
|
169
|
+
# This is highly brittle and terrible.
|
170
|
+
if input.respond_to?(:make_rewindable, true)
|
171
|
+
input.size # Force creation of Tempfile
|
172
|
+
return input.instance_variable_get(:@rewindable_io)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
end
|
178
|
+
|
157
179
|
def log_exists(type, path)
|
158
180
|
log "Resource of type '#{type}' with path '#{path}' exists."
|
159
181
|
end
|
@@ -15,6 +15,7 @@ class WebDavSectionResourceTest < ActiveSupport::TestCase
|
|
15
15
|
|
16
16
|
end
|
17
17
|
|
18
|
+
|
18
19
|
test 'users with administrate permissions can access resources' do
|
19
20
|
mock_user = mock()
|
20
21
|
User.expects(:authenticate).with("abc", "123").returns(mock_user)
|
@@ -292,9 +293,35 @@ class FileResourceTest < ActiveSupport::TestCase
|
|
292
293
|
test "parse missing slash section" do
|
293
294
|
path = Bcms::WebDAV::Path.new('test.jpg')
|
294
295
|
assert_equal "test.jpg", path.file_name
|
296
|
+
end
|
297
|
+
|
298
|
+
test "extract tempfile from mongrel style requests" do
|
299
|
+
tempfile = Tempfile.new("testing")
|
300
|
+
@request.expects(:body).returns(tempfile)
|
301
|
+
|
302
|
+
assert_equal tempfile, @resource.send(:extract_tempfile, @request)
|
303
|
+
|
304
|
+
end
|
305
|
+
|
306
|
+
test "extract tempfile from passenger style requests" do
|
307
|
+
class FakeRewindable
|
308
|
+
def size
|
309
|
+
@rewindable_io = 'EXPECTED'
|
310
|
+
end
|
311
|
+
private
|
295
312
|
|
313
|
+
# Matches passengers rewindable input signature
|
314
|
+
def make_rewindable
|
315
|
+
'do nothing'
|
316
|
+
end
|
317
|
+
end
|
296
318
|
|
319
|
+
rewindable_input = FakeRewindable.new
|
320
|
+
@request.expects(:body).returns(rewindable_input)
|
321
|
+
|
322
|
+
assert_equal 'EXPECTED', @resource.send(:extract_tempfile, @request)
|
297
323
|
end
|
324
|
+
|
298
325
|
private
|
299
326
|
def resource_for(path)
|
300
327
|
Bcms::WebDAV::Resource.new(path, path, @request, @response, {})
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bcms_webdav
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 4
|
10
|
+
version: 1.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- BrowserMedia
|