Extracted AdminController from WikiController

This commit is contained in:
Alexey Verkhovsky 2005-01-28 01:24:31 +00:00
parent 9bc9a29789
commit 88e52ab5a9
10 changed files with 223 additions and 191 deletions

View file

@ -0,0 +1,54 @@
require 'application'
class AdminController < ApplicationController
layout 'default'
def create_system
@wiki.setup(@params['password'], @params['web_name'], @params['web_address']) unless @wiki.setup?
redirect_show('HomePage', @params['web_address'])
end
def create_web
if @wiki.authenticate(@params['system_password'])
@wiki.create_web(@params['name'], @params['address'])
redirect_show('HomePage', @params['address'])
else
redirect_to :action => 'index'
end
end
def edit_web
# to template
end
def new_system
redirect_to(:action => 'index') if wiki.setup?
# otherwise, to template
end
def new_web
redirect_to :action => 'index' if wiki.system['password'].nil?
# otherwise, to template
end
def update_web
if wiki.authenticate(@params['system_password'])
wiki.update_web(
@web.address, @params['address'], @params['name'],
@params['markup'].intern,
@params['color'], @params['additional_style'],
@params['safe_mode'] ? true : false,
@params['password'].empty? ? nil : @params['password'],
@params['published'] ? true : false,
@params['brackets_only'] ? true : false,
@params['count_pages'] ? true : false,
@params['allow_uploads'] ? true : false
)
redirect_show('HomePage', @params['address'])
else
redirect_show('HomePage')
end
end
end

View file

@ -71,6 +71,11 @@ class ApplicationController < ActionController::Base
not @web_name.nil?
end
def redirect_show(page_name = @page_name, web = @web_name)
redirect_to :web => web, :controller => 'wiki', :action => 'show',
:id => CGI.escape(page_name || 'HomePage')
end
@@REMEMBER_NOT = ['locked', 'save', 'back', 'file', 'pic', 'import']
def remember_location
if @response.headers['Status'] == '200 OK'

View file

@ -18,37 +18,6 @@ class WikiController < ApplicationController
end
end
# Administrating the Instiki setup --------------------------------------------
def create_system
@wiki.setup(@params['password'], @params['web_name'], @params['web_address']) unless @wiki.setup?
redirect_show('HomePage', @params['web_address'])
end
def create_web
if @wiki.authenticate(@params['system_password'])
@wiki.create_web(@params['name'], @params['address'])
redirect_show('HomePage', @params['address'])
else
redirect_to :action => 'index'
end
end
def edit_web
# to template
end
def new_system
redirect_to(:action => 'index') if wiki.setup?
# otherwise, to template
end
def new_web
redirect_to :action => 'index' if wiki.system['password'].nil?
# otherwise, to template
end
# Outside a single web --------------------------------------------------------
def authenticate
@ -138,26 +107,6 @@ class WikiController < ApplicationController
redirect_show(@results.first.name) if @results.length == 1
end
def update_web
if wiki.authenticate(@params['system_password'])
wiki.update_web(
@web.address, @params['address'], @params['name'],
@params['markup'].intern,
@params['color'], @params['additional_style'],
@params['safe_mode'] ? true : false,
@params['password'].empty? ? nil : @params['password'],
@params['published'] ? true : false,
@params['brackets_only'] ? true : false,
@params['count_pages'] ? true : false,
@params['allow_uploads'] ? true : false
)
redirect_show('HomePage', @params['address'])
else
redirect_show('HomePage')
end
end
# Within a single page --------------------------------------------------------
def cancel_edit
@ -345,10 +294,6 @@ class WikiController < ApplicationController
end
end
def redirect_show(page_name = @page_name, web = @web_name)
redirect_to :web => web, :action => 'show', :id => CGI.escape(page_name)
end
def remote_ip
ip = @request.remote_ip
logger.info(ip)

View file

@ -3,6 +3,6 @@
<p>You can subscribe to this wiki by RSS and get either just the headlines of the pages that change or the entire page.</p>
<ul id="feedsList">
<li><a href="../rss_with_content<%= "?password=#{web.password}" if @web.password %>">Full content (RSS 2.0)</a>
<li><a href="../rss_with_headlines<%= "?password=#{web.password}" if @web.password %>">Headlines (RSS 2.0)</a>
<li><a href="../rss_with_content<%= "?password=#{@web.password}" if @web.password %>">Full content (RSS 2.0)</a>
<li><a href="../rss_with_headlines<%= "?password=#{@web.password}" if @web.password %>">Headlines (RSS 2.0)</a>
</ul>

View file

@ -62,9 +62,15 @@ class DispatchServlet
class ActionMapper
@@action_to_controller_map = {
'create_system' => 'admin',
'create_web' => 'admin',
'edit_web' => 'admin',
'file' => 'file',
'import' => 'file',
'new_system' => 'admin',
'new_web' => 'admin',
'pic' => 'file',
'import' => 'file'
'update_web' => 'admin'
}
def self.map_to_controller(action)

View file

@ -0,0 +1,155 @@
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'admin_controller'
# Raise errors beyond the default web-based presentation
class AdminController; def rescue_action(e) logger.error(e); raise e end; end
class AdminControllerTest < Test::Unit::TestCase
def setup
setup_test_wiki
setup_controller_test
end
def tear_down
tear_down_wiki
end
def test_create_system
ApplicationController.wiki = WikiServiceWithNoPersistence.new
assert !@controller.wiki.setup?
process('create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
'web_address' => 'my_wiki')
assert_redirected_to :web => 'my_wiki', :action => 'show', :id => 'HomePage'
assert @controller.wiki.setup?
assert_equal 'a_password', @controller.wiki.system[:password]
assert_equal 1, @controller.wiki.webs.size
new_web = @controller.wiki.webs['my_wiki']
assert_equal 'My Wiki', new_web.name
assert_equal 'my_wiki', new_web.address
end
def test_create_system_already_setup
wiki_before = @controller.wiki
assert @controller.wiki.setup?
process 'create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
'web_address' => 'my_wiki'
assert_redirected_to :web => 'my_wiki', :action => 'show', :id => 'HomePage'
assert_equal wiki_before, @controller.wiki
# and no new wikis shuld be created either
assert_equal 1, @controller.wiki.webs.size
end
def test_create_web
@wiki.system[:password] = 'pswd'
process 'create_web', 'system_password' => 'pswd', 'name' => 'Wiki Two', 'address' => 'wiki2'
assert_redirected_to :web => 'wiki2', :action => 'show', :id => 'HomePage'
wiki2 = @wiki.webs['wiki2']
assert wiki2
assert_equal 'Wiki Two', wiki2.name
assert_equal 'wiki2', wiki2.address
end
def test_create_web_default_password
@wiki.system[:password] = nil
process 'create_web', 'system_password' => 'instiki', 'name' => 'Wiki Two', 'address' => 'wiki2'
assert_redirected_to :web => 'wiki2', :action => 'show', :id => 'HomePage'
end
def test_create_web_failed_authentication
@wiki.system[:password] = 'pswd'
process 'create_web', 'system_password' => 'wrong', 'name' => 'Wiki Two', 'address' => 'wiki2'
assert_redirected_to :web => nil, :action => 'index'
assert_nil @wiki.webs['wiki2']
end
def test_edit_web
process 'edit_web', 'web' => 'wiki1'
# this action simply renders a form
assert_success
end
def test_new_system
ApplicationController.wiki = WikiServiceWithNoPersistence.new
process('new_system')
assert_success
end
def test_new_system_system_already_initialized
assert @wiki.setup?
process('new_system')
assert_redirected_to :action => 'index'
end
def test_new_web
@wiki.system['password'] = 'pswd'
process 'new_web'
assert_success
end
def test_new_web_no_password_set
@wiki.system['password'] = nil
process 'new_web'
assert_redirected_to :action => 'index'
end
def test_update_web
@wiki.system[:password] = 'pswd'
process('update_web', 'system_password' => 'pswd',
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever',
'safe_mode' => 'on', 'password' => 'new_password', 'published' => 'on',
'brackets_only' => 'on', 'count_pages' => 'on', 'allow_uploads' => 'on')
assert_redirected_to :web => 'renamed_wiki1', :action => 'show', :id => 'HomePage'
assert_equal 'renamed_wiki1', @web.address
assert_equal 'Renamed Wiki1', @web.name
assert_equal :markdown, @web.markup
assert_equal 'blue', @web.color
assert @web.safe_mode
assert_equal 'new_password', @web.password
assert @web.published
assert @web.brackets_only
assert @web.count_pages
assert @web.allow_uploads
end
def test_update_web_opposite_values
@wiki.system[:password] = 'pswd'
process('update_web', 'system_password' => 'pswd',
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever',
'password' => 'new_password')
# safe_mode, published, brackets_only, count_pages, allow_uploads not set
# and should become false
assert_redirected_to :web => 'renamed_wiki1', :action => 'show', :id => 'HomePage'
assert !@web.safe_mode
assert !@web.published
assert !@web.brackets_only
assert !@web.count_pages
assert !@web.allow_uploads
end
end

View file

@ -66,66 +66,6 @@ class WikiControllerTest < Test::Unit::TestCase
end
def test_create_system
ApplicationController.wiki = WikiServiceWithNoPersistence.new
assert !@controller.wiki.setup?
process('create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
'web_address' => 'my_wiki')
assert_redirected_to :web => 'my_wiki', :action => 'show', :id => 'HomePage'
assert @controller.wiki.setup?
assert_equal 'a_password', @controller.wiki.system[:password]
assert_equal 1, @controller.wiki.webs.size
new_web = @controller.wiki.webs['my_wiki']
assert_equal 'My Wiki', new_web.name
assert_equal 'my_wiki', new_web.address
end
def test_create_system_already_setup
wiki_before = @controller.wiki
assert @controller.wiki.setup?
process 'create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
'web_address' => 'my_wiki'
assert_redirected_to :web => 'my_wiki', :action => 'show', :id => 'HomePage'
assert_equal wiki_before, @controller.wiki
# and no new wikis shuld be created either
assert_equal 1, @controller.wiki.webs.size
end
def test_create_web
@wiki.system[:password] = 'pswd'
process 'create_web', 'system_password' => 'pswd', 'name' => 'Wiki Two', 'address' => 'wiki2'
assert_redirected_to :web => 'wiki2', :action => 'show', :id => 'HomePage'
wiki2 = @wiki.webs['wiki2']
assert wiki2
assert_equal 'Wiki Two', wiki2.name
assert_equal 'wiki2', wiki2.address
end
def test_create_web_default_password
@wiki.system[:password] = nil
process 'create_web', 'system_password' => 'instiki', 'name' => 'Wiki Two', 'address' => 'wiki2'
assert_redirected_to :web => 'wiki2', :action => 'show', :id => 'HomePage'
end
def test_create_web_failed_authentication
@wiki.system[:password] = 'pswd'
process 'create_web', 'system_password' => 'wrong', 'name' => 'Wiki Two', 'address' => 'wiki2'
assert_redirected_to :web => nil, :action => 'index'
assert_nil @wiki.webs['wiki2']
end
def test_edit
r = process 'edit', 'web' => 'wiki1', 'id' => 'HomePage'
assert_success
@ -151,13 +91,6 @@ class WikiControllerTest < Test::Unit::TestCase
end
def test_edit_web
process 'edit_web', 'web' => 'wiki1'
# this action simply renders a form
assert_success
end
def test_export_html
setup_wiki_with_three_pages
@ -279,32 +212,6 @@ class WikiControllerTest < Test::Unit::TestCase
end
def test_new_system
ApplicationController.wiki = WikiServiceWithNoPersistence.new
process('new_system')
assert_success
end
def test_new_system_system_already_initialized
assert @wiki.setup?
process('new_system')
assert_redirected_to :action => 'index'
end
def test_new_web
@wiki.system['password'] = 'pswd'
process 'new_web'
assert_success
end
def test_new_web_no_password_set
@wiki.system['password'] = nil
process 'new_web'
assert_redirected_to :action => 'index'
end
if ENV['INSTIKI_TEST_LATEX'] or defined? $INSTIKI_TEST_PDFLATEX
def test_pdf
@ -630,46 +537,6 @@ class WikiControllerTest < Test::Unit::TestCase
end
def test_update_web
@wiki.system[:password] = 'pswd'
process('update_web', 'system_password' => 'pswd',
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever',
'safe_mode' => 'on', 'password' => 'new_password', 'published' => 'on',
'brackets_only' => 'on', 'count_pages' => 'on', 'allow_uploads' => 'on')
assert_redirected_to :web => 'renamed_wiki1', :action => 'show', :id => 'HomePage'
assert_equal 'renamed_wiki1', @web.address
assert_equal 'Renamed Wiki1', @web.name
assert_equal :markdown, @web.markup
assert_equal 'blue', @web.color
assert @web.safe_mode
assert_equal 'new_password', @web.password
assert @web.published
assert @web.brackets_only
assert @web.count_pages
assert @web.allow_uploads
end
def test_update_web_opposite_values
@wiki.system[:password] = 'pswd'
process('update_web', 'system_password' => 'pswd',
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever',
'password' => 'new_password')
# safe_mode, published, brackets_only, count_pages, allow_uploads not set
# and should become false
assert_redirected_to :web => 'renamed_wiki1', :action => 'show', :id => 'HomePage'
assert !@web.safe_mode
assert !@web.published
assert !@web.brackets_only
assert !@web.count_pages
assert !@web.allow_uploads
end
def test_web_list
another_wiki = @wiki.create_web('Another Wiki', 'another_wiki')