@@ -33,7 +33,7 class WikiController < ApplicationController | |||||
33 | page_title = params[:page] |
|
33 | page_title = params[:page] | |
34 | @page = @wiki.find_or_new_page(page_title) |
|
34 | @page = @wiki.find_or_new_page(page_title) | |
35 | if @page.new_record? |
|
35 | if @page.new_record? | |
36 | if User.current.allowed_to?(:edit_wiki_pages, @project) |
|
36 | if User.current.allowed_to?(:edit_wiki_pages, @project) && editable? | |
37 | edit |
|
37 | edit | |
38 | render :action => 'edit' |
|
38 | render :action => 'edit' | |
39 | else |
|
39 | else |
@@ -29,6 +29,12 class Wiki < ActiveRecord::Base | |||||
29 | !user.nil? && user.allowed_to?(:view_wiki_pages, project) |
|
29 | !user.nil? && user.allowed_to?(:view_wiki_pages, project) | |
30 | end |
|
30 | end | |
31 |
|
31 | |||
|
32 | # Returns the wiki page that acts as the sidebar content | |||
|
33 | # or nil if no such page exists | |||
|
34 | def sidebar | |||
|
35 | @sidebar ||= find_page('Sidebar', :with_redirect => false) | |||
|
36 | end | |||
|
37 | ||||
32 | # find the page with the given title |
|
38 | # find the page with the given title | |
33 | # if page doesn't exist, return a new page |
|
39 | # if page doesn't exist, return a new page | |
34 | def find_or_new_page(title) |
|
40 | def find_or_new_page(title) |
@@ -34,6 +34,10 class WikiContent < ActiveRecord::Base | |||||
34 | page.project |
|
34 | page.project | |
35 | end |
|
35 | end | |
36 |
|
36 | |||
|
37 | def attachments | |||
|
38 | page.nil? ? [] : page.attachments | |||
|
39 | end | |||
|
40 | ||||
37 | # Returns the mail adresses of users that should be notified |
|
41 | # Returns the mail adresses of users that should be notified | |
38 | def recipients |
|
42 | def recipients | |
39 | notified = project.notified_users |
|
43 | notified = project.notified_users |
@@ -41,6 +41,15 class WikiPage < ActiveRecord::Base | |||||
41 | validates_uniqueness_of :title, :scope => :wiki_id, :case_sensitive => false |
|
41 | validates_uniqueness_of :title, :scope => :wiki_id, :case_sensitive => false | |
42 | validates_associated :content |
|
42 | validates_associated :content | |
43 |
|
43 | |||
|
44 | # Wiki pages that are protected by default | |||
|
45 | DEFAULT_PROTECTED_PAGES = %w(sidebar) | |||
|
46 | ||||
|
47 | def after_initialize | |||
|
48 | if new_record? && DEFAULT_PROTECTED_PAGES.include?(title.to_s.downcase) | |||
|
49 | self.protected = true | |||
|
50 | end | |||
|
51 | end | |||
|
52 | ||||
44 | def visible?(user=User.current) |
|
53 | def visible?(user=User.current) | |
45 | !user.nil? && user.allowed_to?(:view_wiki_pages, project) |
|
54 | !user.nil? && user.allowed_to?(:view_wiki_pages, project) | |
46 | end |
|
55 | end |
@@ -1,3 +1,7 | |||||
|
1 | <% if @wiki && @wiki.sidebar -%> | |||
|
2 | <%= textilizable @wiki.sidebar.content, :text %> | |||
|
3 | <% end -%> | |||
|
4 | ||||
1 | <h3><%= l(:label_wiki) %></h3> |
|
5 | <h3><%= l(:label_wiki) %></h3> | |
2 |
|
6 | |||
3 | <%= link_to l(:field_start_page), {:action => 'index', :page => nil} %><br /> |
|
7 | <%= link_to l(:field_start_page), {:action => 'index', :page => nil} %><br /> |
@@ -70,6 +70,17 class WikiControllerTest < ActionController::TestCase | |||||
70 | :alt => 'This is a logo' } |
|
70 | :alt => 'This is a logo' } | |
71 | end |
|
71 | end | |
72 |
|
72 | |||
|
73 | def test_show_with_sidebar | |||
|
74 | page = Project.find(1).wiki.pages.new(:title => 'Sidebar') | |||
|
75 | page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') | |||
|
76 | page.save! | |||
|
77 | ||||
|
78 | get :index, :id => 1, :page => 'Another_page' | |||
|
79 | assert_response :success | |||
|
80 | assert_tag :tag => 'div', :attributes => {:id => 'sidebar'}, | |||
|
81 | :content => /Side bar content for test_show_with_sidebar/ | |||
|
82 | end | |||
|
83 | ||||
73 | def test_show_unexistent_page_without_edit_right |
|
84 | def test_show_unexistent_page_without_edit_right | |
74 | get :index, :id => 1, :page => 'Unexistent page' |
|
85 | get :index, :id => 1, :page => 'Unexistent page' | |
75 | assert_response 404 |
|
86 | assert_response 404 |
@@ -33,11 +33,18 class WikiPageTest < ActiveSupport::TestCase | |||||
33 | page.title = "Page" |
|
33 | page.title = "Page" | |
34 | assert page.save |
|
34 | assert page.save | |
35 | page.reload |
|
35 | page.reload | |
|
36 | assert !page.protected? | |||
36 |
|
37 | |||
37 | @wiki.reload |
|
38 | @wiki.reload | |
38 | assert @wiki.pages.include?(page) |
|
39 | assert @wiki.pages.include?(page) | |
39 | end |
|
40 | end | |
40 |
|
41 | |||
|
42 | def test_sidebar_should_be_protected_by_default | |||
|
43 | page = @wiki.find_or_new_page('sidebar') | |||
|
44 | assert page.new_record? | |||
|
45 | assert page.protected? | |||
|
46 | end | |||
|
47 | ||||
41 | def test_find_or_new_page |
|
48 | def test_find_or_new_page | |
42 | page = @wiki.find_or_new_page("CookBook documentation") |
|
49 | page = @wiki.find_or_new_page("CookBook documentation") | |
43 | assert_kind_of WikiPage, page |
|
50 | assert_kind_of WikiPage, page |
@@ -43,4 +43,23 class WikiTest < ActiveSupport::TestCase | |||||
43 | assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES') |
|
43 | assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES') | |
44 | assert_equal 'テスト', Wiki.titleize('テスト') |
|
44 | assert_equal 'テスト', Wiki.titleize('テスト') | |
45 | end |
|
45 | end | |
|
46 | ||||
|
47 | context "#sidebar" do | |||
|
48 | setup do | |||
|
49 | @wiki = Wiki.find(1) | |||
|
50 | end | |||
|
51 | ||||
|
52 | should "return nil if undefined" do | |||
|
53 | assert_nil @wiki.sidebar | |||
|
54 | end | |||
|
55 | ||||
|
56 | should "return a WikiPage if defined" do | |||
|
57 | page = @wiki.pages.new(:title => 'Sidebar') | |||
|
58 | page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') | |||
|
59 | page.save! | |||
|
60 | ||||
|
61 | assert_kind_of WikiPage, @wiki.sidebar | |||
|
62 | assert_equal 'Sidebar', @wiki.sidebar.title | |||
|
63 | end | |||
|
64 | end | |||
46 | end |
|
65 | end |
General Comments 0
You need to be logged in to leave comments.
Login now