Fixing FileController#import; sort of works, but fails on some interesting tests

This commit is contained in:
Alexey Verkhovsky 2006-03-23 07:14:51 +00:00
parent cb869abf0d
commit 64313ca208
5 changed files with 32 additions and 14 deletions

View file

@ -2,7 +2,7 @@
# Likewise will all the methods added be available for all controllers.
class ApplicationController < ActionController::Base
before_filter :connect_to_model, :check_authorization, :setup_url_generator, :set_content_type_header, :set_robots_metatag
before_filter :fetch_model_data, :check_authorization, :setup_url_generator, :set_content_type_header, :set_robots_metatag
after_filter :remember_location, :teardown_url_generator
# For injecting a different wiki model implementation. Intended for use in tests
@ -19,7 +19,7 @@ class ApplicationController < ActionController::Base
end
protected
def check_authorization
if in_a_web? and authorization_needed? and not authorized?
redirect_to :controller => 'wiki', :action => 'login', :web => @web_name
@ -27,18 +27,18 @@ class ApplicationController < ActionController::Base
end
end
def connect_to_model
def fetch_model_data
@action_name = @params['action'] || 'index'
@web_name = @params['web']
@wiki = wiki
@author = cookies['author'] || 'AnonymousCoward'
if @web_name
@web = @wiki.webs[@web_name]
if @web.nil?
render :status => 404, :text => "Unknown web '#{@web_name}'"
return false
render(:status => 404, :text => "Unknown web '#{@web_name}'")
return false
end
end
@author = cookies['author'] || 'AnonymousCoward'
end
FILE_TYPES = {

View file

@ -1,5 +1,7 @@
# Controller responsible for serving files and pictures.
require 'zip/zip'
class FileController < ApplicationController
layout 'default'
@ -19,7 +21,6 @@ class FileController < ApplicationController
render
end
else
render(:status => 404, :text => 'Unspecified file name') and return unless @file_name
# no form supplied, this is a request to download the file
file = WikiFile.find_by_file_name(@file_name)
if file
@ -39,8 +40,7 @@ class FileController < ApplicationController
if @params['file']
@problems = []
import_file_name = "#{@web.address}-import-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.zip"
file_yard.upload_file(import_file_name, @params['file'])
import_from_archive(file_yard.file_path(import_file_name))
import_from_archive(@params['file'].path)
if @problems.empty?
flash[:info] = 'Import successfully finished'
else
@ -56,6 +56,7 @@ class FileController < ApplicationController
protected
def check_allow_uploads
render(:status => 404, :text => "Web #{@params['web'].inspect} not found") and return false unless @web
if @web.allow_uploads?
return true
else
@ -65,8 +66,7 @@ class FileController < ApplicationController
end
def connect_to_model
super
@file_name = @params['id']
super and @file_name = @params['id']
end
private
@ -87,10 +87,10 @@ class FileController < ApplicationController
next
else
logger.info "Page '#{page_name}' already exists. Adding a new revision to it."
wiki.revise_page(@web.address, page_name, page_content, Time.now, @author)
wiki.revise_page(@web.address, page_name, page_content, Time.now, @author, PageRenderer.new)
end
else
wiki.write_page(@web.address, page_name, page_content, Time.now, @author)
wiki.write_page(@web.address, page_name, page_content, Time.now, @author, PageRenderer.new)
end
rescue => e
logger.error(e)