Webs that Don't Allow File Uploads

... should still allow you to manually upload files
and have them render.

Fixed.
This commit is contained in:
Jacques Distler 2009-01-26 01:39:04 -06:00
parent 5d15e3f39d
commit 34fd7b425f
2 changed files with 15 additions and 13 deletions

View file

@ -7,12 +7,13 @@ class FileController < ApplicationController
layout 'default' layout 'default'
before_filter :dnsbl_check, :check_allow_uploads before_filter :dnsbl_check
before_filter :check_allow_uploads, :except => :file
def file def file
@file_name = params['id'] @file_name = params['id']
if params['file'] if params['file']
return unless is_post return unless is_post and check_allow_uploads
# form supplied # form supplied
new_file = @web.wiki_files.create(params['file']) new_file = @web.wiki_files.create(params['file'])
if new_file.valid? if new_file.valid?
@ -25,10 +26,11 @@ class FileController < ApplicationController
end end
else else
# no form supplied, this is a request to download the file # no form supplied, this is a request to download the file
file = WikiFile.find_by_file_name(@file_name) file = @web.files_path + '/' + @file_name
if file if File.exists?(file)
send_data(file.content, determine_file_options_for(@file_name, :filename => @file_name)) send_file(file)
else else
return unless check_allow_uploads
@file = WikiFile.new(:file_name => @file_name) @file = WikiFile.new(:file_name => @file_name)
render render
end end

View file

@ -117,6 +117,14 @@ class Web < ActiveRecord::Base
end end
end end
def files_path
if default_web?
"#{RAILS_ROOT}/webs/files"
else
"#{RAILS_ROOT}/webs/#{self.address}/files"
end
end
private private
# Returns an array of all the wiki words in any current revision # Returns an array of all the wiki words in any current revision
@ -150,12 +158,4 @@ class Web < ActiveRecord::Base
def default_web? def default_web?
defined? DEFAULT_WEB and self.address == DEFAULT_WEB defined? DEFAULT_WEB and self.address == DEFAULT_WEB
end end
def files_path
if default_web?
"#{RAILS_ROOT}/webs/files"
else
"#{RAILS_ROOT}/webs/#{self.address}/files"
end
end
end end