Improved behavior of JavaScript in the author field [from I2 patch by court3nay]

This commit is contained in:
Alexey Verkhovsky 2005-11-04 05:23:34 +00:00
parent 35b77f6440
commit dea8d70c48
6 changed files with 28 additions and 39 deletions

View file

@ -2,7 +2,7 @@
# Likewise will all the methods added be available for all controllers. # Likewise will all the methods added be available for all controllers.
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
before_filter :connect_to_model, :setup_url_generator, :set_content_type_header, :set_robots_metatag before_filter :connect_to_model, :check_authorization, :setup_url_generator, :set_content_type_header, :set_robots_metatag
after_filter :remember_location, :teardown_url_generator after_filter :remember_location, :teardown_url_generator
# For injecting a different wiki model implementation. Intended for use in tests # For injecting a different wiki model implementation. Intended for use in tests
@ -20,15 +20,8 @@ class ApplicationController < ActionController::Base
protected protected
def authorized?
@web.nil? ||
@web.password.nil? ||
cookies['web_address'] == @web.password ||
password_check(@params['password'])
end
def check_authorization def check_authorization
if in_a_web? and authorization_needed? and not authorized? and if in_a_web? and authorization_needed? and not authorized?
redirect_to :controller => 'wiki', :action => 'login', :web => @web_name redirect_to :controller => 'wiki', :action => 'login', :web => @web_name
return false return false
end end
@ -41,14 +34,13 @@ class ApplicationController < ActionController::Base
if @web_name if @web_name
@web = @wiki.webs[@web_name] @web = @wiki.webs[@web_name]
if @web.nil? if @web.nil?
render_text "Unknown web '#{@web_name}'", '404 Not Found' render :status => 404, :text => "Unknown web '#{@web_name}'"
return false return false
end end
end end
@page_name = @file_name = @params['id'] @page_name = @file_name = @params['id']
@page = @wiki.read_page(@web_name, @page_name) unless @page_name.nil? @page = @wiki.read_page(@web_name, @page_name) unless @page_name.nil?
@author = cookies['author'] || 'AnonymousCoward' @author = cookies['author'] || 'AnonymousCoward'
check_authorization
end end
FILE_TYPES = { FILE_TYPES = {
@ -67,10 +59,6 @@ class ApplicationController < ActionController::Base
super(file, options) super(file, options)
end end
def in_a_web?
not @web_name.nil?
end
def password_check(password) def password_check(password)
if password == @web.password if password == @web.password
cookies['web_address'] = password cookies['web_address'] = password
@ -168,8 +156,20 @@ class ApplicationController < ActionController::Base
self.class.wiki self.class.wiki
end end
private
def in_a_web?
not @web_name.nil?
end
def authorization_needed? def authorization_needed?
not %w( login authenticate published rss_with_content rss_with_headlines ).include?(action_name) not %w( login authenticate published rss_with_content rss_with_headlines ).include?(action_name)
end end
def authorized?
@web.password.nil? or
cookies['web_address'] == @web.password or
password_check(@params['password'])
end
end end

View file

@ -1,9 +1,4 @@
require 'fileutils' # Controller responsible for serving files and pictures.
require 'application'
require 'instiki_errors'
# Controller that is responsible for serving files and pictures.
# Disabled in version 0.10
class FileController < ApplicationController class FileController < ApplicationController
@ -46,8 +41,6 @@ class FileController < ApplicationController
end end
def import def import
return if file_uploads_disabled?
check_authorization check_authorization
if @params['file'] if @params['file']
@problems = [] @problems = []
@ -69,15 +62,8 @@ class FileController < ApplicationController
protected protected
def check_allow_uploads def check_allow_uploads
# TODO enable file uploads again after 0.10 release
unless RAILS_ENV == 'test'
render_text 'File uploads are not ready for general use in Instiki 0.10', '403 Forbidden'
return false
end
unless @web.allow_uploads? unless @web.allow_uploads?
render_text 'File uploads are blocked by the webmaster', '403 Forbidden' render :status => 403, :text => 'File uploads are blocked by the webmaster'
return false return false
end end
end end

View file

@ -217,9 +217,9 @@ class WikiController < ApplicationController
end end
def save def save
redirect_home if @page_name.nil? render(:status => 404, :text => 'Undefined page name') and return if @page_name.nil?
cookies['author'] = { :value => @params['author'], :expires => Time.utc(2030) }
cookies['author'] = { :value => @params['author'], :expires => Time.utc(2030) }
begin begin
if @page if @page
wiki.revise_page(@web_name, @page_name, @params['content'], Time.now, wiki.revise_page(@web_name, @page_name, @params['content'], Time.now,

View file

@ -18,8 +18,9 @@
</p> </p>
<p> <p>
<input type="submit" value="Submit" accesskey="s"/> as <input type="submit" value="Submit" accesskey="s"/> as
<input type="text" name="author" id="authorName" value="<%= @author %>" <%= text_field_tag :author, @author,
onClick="this.value == 'AnonymousCoward' ? this.value = '' : true" /> :onfocus => "this.value == 'AnonymousCoward' ? this.value = '' : true;",
:onblur => "this.value == '' ? this.value = 'AnonymousCoward' : true" %>
| |
<%= link_to('Cancel', {:web => @web.address, :action => 'cancel_edit', :id => @page.name}, <%= link_to('Cancel', {:web => @web.address, :action => 'cancel_edit', :id => @page.name},
{:accesskey => 'c'}) {:accesskey => 'c'})

View file

@ -18,7 +18,9 @@
</p> </p>
<p> <p>
<input type="submit" value="Submit" accesskey="s"/> as <input type="submit" value="Submit" accesskey="s"/> as
<input type="text" name="author" id="authorName" value="<%= @author %>" onClick="this.value == 'AnonymousCoward' ? this.value = '' : true" /> <%= text_field_tag :author, @author,
:onfocus => "this.value == 'AnonymousCoward' ? this.value = '' : true;",
:onblur => "this.value == '' ? this.value = 'AnonymousCoward' : true" %>
</p> </p>
<%= end_form_tag %> <%= end_form_tag %>

View file

@ -121,12 +121,12 @@ class FileControllerTest < Test::Unit::TestCase
def test_uploads_blocking def test_uploads_blocking
set_web_property :allow_uploads, true set_web_property :allow_uploads, true
r = process 'file', 'web' => 'wiki1', 'id' => 'filename' process 'file', 'web' => 'wiki1', 'id' => 'filename'
assert_success assert_success
set_web_property :allow_uploads, false set_web_property :allow_uploads, false
r = process 'file', 'web' => 'wiki1', 'id' => 'filename' process 'file', 'web' => 'wiki1', 'id' => 'filename'
assert_equal '403 Forbidden', r.headers['Status'] assert_response 403
end end
end end