From 34fd7b425fa0d3cdb622d0c0e8bb79265024924b Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Mon, 26 Jan 2009 01:39:04 -0600 Subject: [PATCH] Webs that Don't Allow File Uploads ... should still allow you to manually upload files and have them render. Fixed. --- app/controllers/file_controller.rb | 12 +++++++----- app/models/web.rb | 16 ++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/controllers/file_controller.rb b/app/controllers/file_controller.rb index 2364abc1..9123a6a4 100644 --- a/app/controllers/file_controller.rb +++ b/app/controllers/file_controller.rb @@ -7,12 +7,13 @@ class FileController < ApplicationController layout 'default' - before_filter :dnsbl_check, :check_allow_uploads + before_filter :dnsbl_check + before_filter :check_allow_uploads, :except => :file def file @file_name = params['id'] if params['file'] - return unless is_post + return unless is_post and check_allow_uploads # form supplied new_file = @web.wiki_files.create(params['file']) if new_file.valid? @@ -25,10 +26,11 @@ class FileController < ApplicationController end else # no form supplied, this is a request to download the file - file = WikiFile.find_by_file_name(@file_name) - if file - send_data(file.content, determine_file_options_for(@file_name, :filename => @file_name)) + file = @web.files_path + '/' + @file_name + if File.exists?(file) + send_file(file) else + return unless check_allow_uploads @file = WikiFile.new(:file_name => @file_name) render end diff --git a/app/models/web.rb b/app/models/web.rb index 50d15347..3f6c8042 100644 --- a/app/models/web.rb +++ b/app/models/web.rb @@ -117,6 +117,14 @@ class Web < ActiveRecord::Base end end + def files_path + if default_web? + "#{RAILS_ROOT}/webs/files" + else + "#{RAILS_ROOT}/webs/#{self.address}/files" + end + end + private # Returns an array of all the wiki words in any current revision @@ -150,12 +158,4 @@ class Web < ActiveRecord::Base def default_web? defined? DEFAULT_WEB and self.address == DEFAULT_WEB end - - def files_path - if default_web? - "#{RAILS_ROOT}/webs/files" - else - "#{RAILS_ROOT}/webs/#{self.address}/files" - end - end end