@@ -0,0 +1,13 | |||
|
1 | api.array :wiki_pages do | |
|
2 | @pages.each do |page| | |
|
3 | api.wiki_page do | |
|
4 | api.title page.title | |
|
5 | if page.parent | |
|
6 | api.parent :title => page.parent.title | |
|
7 | end | |
|
8 | api.version page.version | |
|
9 | api.created_on page.created_on | |
|
10 | api.updated_on page.updated_on | |
|
11 | end | |
|
12 | end | |
|
13 | end |
@@ -0,0 +1,11 | |||
|
1 | api.wiki_page do | |
|
2 | api.title @page.title | |
|
3 | if @page.parent | |
|
4 | api.parent :title => @page.parent.title | |
|
5 | end | |
|
6 | api.text @content.text | |
|
7 | api.version @content.version | |
|
8 | api.author(:id => @content.author_id, :name => @content.author.name) | |
|
9 | api.created_on @page.created_on | |
|
10 | api.updated_on @content.updated_on | |
|
11 | end |
@@ -0,0 +1,85 | |||
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
|
3 | # | |
|
4 | # This program is free software; you can redistribute it and/or | |
|
5 | # modify it under the terms of the GNU General Public License | |
|
6 | # as published by the Free Software Foundation; either version 2 | |
|
7 | # of the License, or (at your option) any later version. | |
|
8 | # | |
|
9 | # This program is distributed in the hope that it will be useful, | |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
12 | # GNU General Public License for more details. | |
|
13 | # | |
|
14 | # You should have received a copy of the GNU General Public License | |
|
15 | # along with this program; if not, write to the Free Software | |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
|
17 | ||
|
18 | require File.expand_path('../../../test_helper', __FILE__) | |
|
19 | ||
|
20 | class ApiTest::WikiPagesTest < ActionController::IntegrationTest | |
|
21 | fixtures :projects, :users, :roles, :members, :member_roles, | |
|
22 | :enabled_modules, :wikis, :wiki_pages, :wiki_contents, | |
|
23 | :wiki_content_versions, :attachments | |
|
24 | ||
|
25 | def setup | |
|
26 | Setting.rest_api_enabled = '1' | |
|
27 | end | |
|
28 | ||
|
29 | test "GET /projects/:project_id/wiki/index.xml should return wiki pages" do | |
|
30 | get '/projects/ecookbook/wiki/index.xml' | |
|
31 | assert_response :success | |
|
32 | assert_equal 'application/xml', response.content_type | |
|
33 | assert_select 'wiki_pages[type=array]' do | |
|
34 | assert_select 'wiki_page', :count => Wiki.find(1).pages.count | |
|
35 | assert_select 'wiki_page' do | |
|
36 | assert_select 'title', :text => 'CookBook_documentation' | |
|
37 | assert_select 'version', :text => '3' | |
|
38 | assert_select 'created_on' | |
|
39 | assert_select 'updated_on' | |
|
40 | end | |
|
41 | end | |
|
42 | end | |
|
43 | ||
|
44 | test "GET /projects/:project_id/wiki/:title.xml should return wiki page" do | |
|
45 | get '/projects/ecookbook/wiki/CookBook_documentation.xml' | |
|
46 | assert_response :success | |
|
47 | assert_equal 'application/xml', response.content_type | |
|
48 | assert_select 'wiki_page' do | |
|
49 | assert_select 'title', :text => 'CookBook_documentation' | |
|
50 | assert_select 'version', :text => '3' | |
|
51 | assert_select 'text' | |
|
52 | assert_select 'author' | |
|
53 | assert_select 'created_on' | |
|
54 | assert_select 'updated_on' | |
|
55 | end | |
|
56 | end | |
|
57 | ||
|
58 | test "GET /projects/:project_id/wiki/:title.xml with unknown title and edit permission should respond with 404" do | |
|
59 | get '/projects/ecookbook/wiki/Invalid_Page.xml', {}, credentials('jsmith') | |
|
60 | assert_response 404 | |
|
61 | assert_equal 'application/xml', response.content_type | |
|
62 | end | |
|
63 | ||
|
64 | test "GET /projects/:project_id/wiki/:title/:version.xml should return wiki page version" do | |
|
65 | get '/projects/ecookbook/wiki/CookBook_documentation/2.xml' | |
|
66 | assert_response :success | |
|
67 | assert_equal 'application/xml', response.content_type | |
|
68 | assert_select 'wiki_page' do | |
|
69 | assert_select 'title', :text => 'CookBook_documentation' | |
|
70 | assert_select 'version', :text => '2' | |
|
71 | assert_select 'text' | |
|
72 | assert_select 'author' | |
|
73 | assert_select 'created_on' | |
|
74 | assert_select 'updated_on' | |
|
75 | end | |
|
76 | end | |
|
77 | ||
|
78 | test "GET /projects/:project_id/wiki/:title/:version.xml without permission should be denied" do | |
|
79 | Role.anonymous.remove_permission! :view_wiki_edits | |
|
80 | ||
|
81 | get '/projects/ecookbook/wiki/CookBook_documentation/2.xml' | |
|
82 | assert_response 401 | |
|
83 | assert_equal 'application/xml', response.content_type | |
|
84 | end | |
|
85 | end |
@@ -36,6 +36,7 class WikiController < ApplicationController | |||
|
36 | 36 | before_filter :find_wiki, :authorize |
|
37 | 37 | before_filter :find_existing_or_new_page, :only => [:show, :edit, :update] |
|
38 | 38 | before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy, :destroy_version] |
|
39 | accept_api_auth :index, :show | |
|
39 | 40 | |
|
40 | 41 | helper :attachments |
|
41 | 42 | include AttachmentsHelper |
@@ -45,7 +46,13 class WikiController < ApplicationController | |||
|
45 | 46 | # List of pages, sorted alphabetically and by parent (hierarchy) |
|
46 | 47 | def index |
|
47 | 48 | load_pages_for_index |
|
48 | @pages_by_parent_id = @pages.group_by(&:parent_id) | |
|
49 | ||
|
50 | respond_to do |format| | |
|
51 | format.html { | |
|
52 | @pages_by_parent_id = @pages.group_by(&:parent_id) | |
|
53 | } | |
|
54 | format.api | |
|
55 | end | |
|
49 | 56 | end |
|
50 | 57 | |
|
51 | 58 | # List of page, by last update |
@@ -57,7 +64,7 class WikiController < ApplicationController | |||
|
57 | 64 | # display a page (in editing mode if it doesn't exist) |
|
58 | 65 | def show |
|
59 | 66 | if @page.new_record? |
|
60 | if User.current.allowed_to?(:edit_wiki_pages, @project) && editable? | |
|
67 | if User.current.allowed_to?(:edit_wiki_pages, @project) && editable? && !api_request? | |
|
61 | 68 | edit |
|
62 | 69 | render :action => 'edit' |
|
63 | 70 | else |
@@ -66,8 +73,7 class WikiController < ApplicationController | |||
|
66 | 73 | return |
|
67 | 74 | end |
|
68 | 75 | if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project) |
|
69 | # Redirects user to the current version if he's not allowed to view previous versions | |
|
70 | redirect_to :version => nil | |
|
76 | deny_access | |
|
71 | 77 | return |
|
72 | 78 | end |
|
73 | 79 | @content = @page.content_for_version(params[:version]) |
@@ -89,7 +95,10 class WikiController < ApplicationController | |||
|
89 | 95 | @content.current_version? && |
|
90 | 96 | Redmine::WikiFormatting.supports_section_edit? |
|
91 | 97 | |
|
92 | render :action => 'show' | |
|
98 | respond_to do |format| | |
|
99 | format.html | |
|
100 | format.api | |
|
101 | end | |
|
93 | 102 | end |
|
94 | 103 | |
|
95 | 104 | # edit an existing page or a new one |
@@ -321,6 +330,6 private | |||
|
321 | 330 | end |
|
322 | 331 | |
|
323 | 332 | def load_pages_for_index |
|
324 |
@pages = @wiki.pages.with_updated_on. |
|
|
333 | @pages = @wiki.pages.with_updated_on.order("#{WikiPage.table_name}.title").includes(:wiki => :project).includes(:parent).all | |
|
325 | 334 | end |
|
326 | 335 | end |
@@ -50,7 +50,7 class WikiPage < ActiveRecord::Base | |||
|
50 | 50 | |
|
51 | 51 | # eager load information about last updates, without loading text |
|
52 | 52 | scope :with_updated_on, { |
|
53 | :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on", | |
|
53 | :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on, #{WikiContent.table_name}.version", | |
|
54 | 54 | :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id" |
|
55 | 55 | } |
|
56 | 56 |
@@ -75,6 +75,13 class WikiControllerTest < ActionController::TestCase | |||
|
75 | 75 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => /Current version/ |
|
76 | 76 | end |
|
77 | 77 | |
|
78 | def test_show_old_version_without_permission_should_be_denied | |
|
79 | Role.anonymous.remove_permission! :view_wiki_edits | |
|
80 | ||
|
81 | get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2' | |
|
82 | assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fprojects%2Fecookbook%2Fwiki%2FCookBook_documentation%2F2' | |
|
83 | end | |
|
84 | ||
|
78 | 85 | def test_show_first_version |
|
79 | 86 | get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '1' |
|
80 | 87 | assert_response :success |
@@ -34,6 +34,16 class RoutingWikiTest < ActionController::IntegrationTest | |||
|
34 | 34 | :id => 'lalala', :format => 'pdf' } |
|
35 | 35 | ) |
|
36 | 36 | assert_routing( |
|
37 | { :method => 'get', :path => "/projects/567/wiki/lalala.xml" }, | |
|
38 | { :controller => 'wiki', :action => 'show', :project_id => '567', | |
|
39 | :id => 'lalala', :format => 'xml' } | |
|
40 | ) | |
|
41 | assert_routing( | |
|
42 | { :method => 'get', :path => "/projects/567/wiki/lalala.json" }, | |
|
43 | { :controller => 'wiki', :action => 'show', :project_id => '567', | |
|
44 | :id => 'lalala', :format => 'json' } | |
|
45 | ) | |
|
46 | assert_routing( | |
|
37 | 47 | { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/diff" }, |
|
38 | 48 | { :controller => 'wiki', :action => 'diff', :project_id => '1', |
|
39 | 49 | :id => 'CookBook_documentation' } |
@@ -44,6 +54,16 class RoutingWikiTest < ActionController::IntegrationTest | |||
|
44 | 54 | :id => 'CookBook_documentation', :version => '2' } |
|
45 | 55 | ) |
|
46 | 56 | assert_routing( |
|
57 | { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/2.xml" }, | |
|
58 | { :controller => 'wiki', :action => 'show', :project_id => '1', | |
|
59 | :id => 'CookBook_documentation', :version => '2', :format => 'xml' } | |
|
60 | ) | |
|
61 | assert_routing( | |
|
62 | { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/2.json" }, | |
|
63 | { :controller => 'wiki', :action => 'show', :project_id => '1', | |
|
64 | :id => 'CookBook_documentation', :version => '2', :format => 'json' } | |
|
65 | ) | |
|
66 | assert_routing( | |
|
47 | 67 | { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/2/diff" }, |
|
48 | 68 | { :controller => 'wiki', :action => 'diff', :project_id => '1', |
|
49 | 69 | :id => 'CookBook_documentation', :version => '2' } |
@@ -72,6 +92,14 class RoutingWikiTest < ActionController::IntegrationTest | |||
|
72 | 92 | { :method => 'get', :path => "/projects/567/wiki/index" }, |
|
73 | 93 | { :controller => 'wiki', :action => 'index', :project_id => '567' } |
|
74 | 94 | ) |
|
95 | assert_routing( | |
|
96 | { :method => 'get', :path => "/projects/567/wiki/index.xml" }, | |
|
97 | { :controller => 'wiki', :action => 'index', :project_id => '567', :format => 'xml' } | |
|
98 | ) | |
|
99 | assert_routing( | |
|
100 | { :method => 'get', :path => "/projects/567/wiki/index.json" }, | |
|
101 | { :controller => 'wiki', :action => 'index', :project_id => '567', :format => 'json' } | |
|
102 | ) | |
|
75 | 103 | end |
|
76 | 104 | |
|
77 | 105 | def test_wiki_resources |
@@ -130,6 +130,7 class WikiPageTest < ActiveSupport::TestCase | |||
|
130 | 130 | assert_not_nil page.read_attribute(:updated_on) |
|
131 | 131 | assert_equal Time.gm(2007, 3, 6, 23, 10, 51), page.content.updated_on |
|
132 | 132 | assert_equal page.content.updated_on, page.updated_on |
|
133 | assert_not_nil page.read_attribute(:version) | |
|
133 | 134 | end |
|
134 | 135 | |
|
135 | 136 | def test_descendants |
General Comments 0
You need to be logged in to leave comments.
Login now