Makes the wiki sidebar editable (#5208).
The content of the wiki page named 'Sidebar' is rendered in the sidebar if it exists. Permission to edit protected pages is required to create this page. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3632 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
3979224693
commit
5879273739
|
@ -33,7 +33,7 @@ class WikiController < ApplicationController
|
||||||
page_title = params[:page]
|
page_title = params[:page]
|
||||||
@page = @wiki.find_or_new_page(page_title)
|
@page = @wiki.find_or_new_page(page_title)
|
||||||
if @page.new_record?
|
if @page.new_record?
|
||||||
if User.current.allowed_to?(:edit_wiki_pages, @project)
|
if User.current.allowed_to?(:edit_wiki_pages, @project) && editable?
|
||||||
edit
|
edit
|
||||||
render :action => 'edit'
|
render :action => 'edit'
|
||||||
else
|
else
|
||||||
|
|
|
@ -29,6 +29,12 @@ class Wiki < ActiveRecord::Base
|
||||||
!user.nil? && user.allowed_to?(:view_wiki_pages, project)
|
!user.nil? && user.allowed_to?(:view_wiki_pages, project)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the wiki page that acts as the sidebar content
|
||||||
|
# or nil if no such page exists
|
||||||
|
def sidebar
|
||||||
|
@sidebar ||= find_page('Sidebar', :with_redirect => false)
|
||||||
|
end
|
||||||
|
|
||||||
# find the page with the given title
|
# find the page with the given title
|
||||||
# if page doesn't exist, return a new page
|
# if page doesn't exist, return a new page
|
||||||
def find_or_new_page(title)
|
def find_or_new_page(title)
|
||||||
|
|
|
@ -34,6 +34,10 @@ class WikiContent < ActiveRecord::Base
|
||||||
page.project
|
page.project
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def attachments
|
||||||
|
page.nil? ? [] : page.attachments
|
||||||
|
end
|
||||||
|
|
||||||
# Returns the mail adresses of users that should be notified
|
# Returns the mail adresses of users that should be notified
|
||||||
def recipients
|
def recipients
|
||||||
notified = project.notified_users
|
notified = project.notified_users
|
||||||
|
|
|
@ -41,6 +41,15 @@ class WikiPage < ActiveRecord::Base
|
||||||
validates_uniqueness_of :title, :scope => :wiki_id, :case_sensitive => false
|
validates_uniqueness_of :title, :scope => :wiki_id, :case_sensitive => false
|
||||||
validates_associated :content
|
validates_associated :content
|
||||||
|
|
||||||
|
# Wiki pages that are protected by default
|
||||||
|
DEFAULT_PROTECTED_PAGES = %w(sidebar)
|
||||||
|
|
||||||
|
def after_initialize
|
||||||
|
if new_record? && DEFAULT_PROTECTED_PAGES.include?(title.to_s.downcase)
|
||||||
|
self.protected = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def visible?(user=User.current)
|
def visible?(user=User.current)
|
||||||
!user.nil? && user.allowed_to?(:view_wiki_pages, project)
|
!user.nil? && user.allowed_to?(:view_wiki_pages, project)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
<% if @wiki && @wiki.sidebar -%>
|
||||||
|
<%= textilizable @wiki.sidebar.content, :text %>
|
||||||
|
<% end -%>
|
||||||
|
|
||||||
<h3><%= l(:label_wiki) %></h3>
|
<h3><%= l(:label_wiki) %></h3>
|
||||||
|
|
||||||
<%= link_to l(:field_start_page), {:action => 'index', :page => nil} %><br />
|
<%= link_to l(:field_start_page), {:action => 'index', :page => nil} %><br />
|
||||||
|
|
|
@ -70,6 +70,17 @@ class WikiControllerTest < ActionController::TestCase
|
||||||
:alt => 'This is a logo' }
|
:alt => 'This is a logo' }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_show_with_sidebar
|
||||||
|
page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
|
||||||
|
page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
|
||||||
|
page.save!
|
||||||
|
|
||||||
|
get :index, :id => 1, :page => 'Another_page'
|
||||||
|
assert_response :success
|
||||||
|
assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
|
||||||
|
:content => /Side bar content for test_show_with_sidebar/
|
||||||
|
end
|
||||||
|
|
||||||
def test_show_unexistent_page_without_edit_right
|
def test_show_unexistent_page_without_edit_right
|
||||||
get :index, :id => 1, :page => 'Unexistent page'
|
get :index, :id => 1, :page => 'Unexistent page'
|
||||||
assert_response 404
|
assert_response 404
|
||||||
|
|
|
@ -33,11 +33,18 @@ class WikiPageTest < ActiveSupport::TestCase
|
||||||
page.title = "Page"
|
page.title = "Page"
|
||||||
assert page.save
|
assert page.save
|
||||||
page.reload
|
page.reload
|
||||||
|
assert !page.protected?
|
||||||
|
|
||||||
@wiki.reload
|
@wiki.reload
|
||||||
assert @wiki.pages.include?(page)
|
assert @wiki.pages.include?(page)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_sidebar_should_be_protected_by_default
|
||||||
|
page = @wiki.find_or_new_page('sidebar')
|
||||||
|
assert page.new_record?
|
||||||
|
assert page.protected?
|
||||||
|
end
|
||||||
|
|
||||||
def test_find_or_new_page
|
def test_find_or_new_page
|
||||||
page = @wiki.find_or_new_page("CookBook documentation")
|
page = @wiki.find_or_new_page("CookBook documentation")
|
||||||
assert_kind_of WikiPage, page
|
assert_kind_of WikiPage, page
|
||||||
|
|
|
@ -43,4 +43,23 @@ class WikiTest < ActiveSupport::TestCase
|
||||||
assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
|
assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
|
||||||
assert_equal 'テスト', Wiki.titleize('テスト')
|
assert_equal 'テスト', Wiki.titleize('テスト')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "#sidebar" do
|
||||||
|
setup do
|
||||||
|
@wiki = Wiki.find(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "return nil if undefined" do
|
||||||
|
assert_nil @wiki.sidebar
|
||||||
|
end
|
||||||
|
|
||||||
|
should "return a WikiPage if defined" do
|
||||||
|
page = @wiki.pages.new(:title => 'Sidebar')
|
||||||
|
page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
|
||||||
|
page.save!
|
||||||
|
|
||||||
|
assert_kind_of WikiPage, @wiki.sidebar
|
||||||
|
assert_equal 'Sidebar', @wiki.sidebar.title
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue