REST API for retrieving wiki pages (#7082).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10716 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang committed 2012-10-25 19:44:04 +00:00
1 parent b2e035fa96
commit 9e31308720
8 files changed
+161 -7

No files matched your search

+15 -6
View File
@@ -36,6 +36,7 @@ class WikiController < ApplicationController
before_filter :find_wiki, :authorize
before_filter :find_existing_or_new_page, :only => [:show, :edit, :update]
before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy, :destroy_version]
accept_api_auth :index, :show
helper :attachments
include AttachmentsHelper
@@ -45,7 +46,13 @@ class WikiController < ApplicationController
# List of pages, sorted alphabetically and by parent (hierarchy)
def index
load_pages_for_index
@pages_by_parent_id = @pages.group_by(&:parent_id)
respond_to do |format|
format.html {
@pages_by_parent_id = @pages.group_by(&:parent_id)
}
format.api
end
end
# List of page, by last update
@@ -57,7 +64,7 @@ class WikiController < ApplicationController
# display a page (in editing mode if it doesn't exist)
def show
if @page.new_record?
if User.current.allowed_to?(:edit_wiki_pages, @project) && editable?
if User.current.allowed_to?(:edit_wiki_pages, @project) && editable? && !api_request?
edit
render :action => 'edit'
else
@@ -66,8 +73,7 @@ class WikiController < ApplicationController
return
end
if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project)
# Redirects user to the current version if he's not allowed to view previous versions
redirect_to :version => nil
deny_access
return
end
@content = @page.content_for_version(params[:version])
@@ -89,7 +95,10 @@ class WikiController < ApplicationController
@content.current_version? &&
Redmine::WikiFormatting.supports_section_edit?
render :action => 'show'
respond_to do |format|
format.html
format.api
end
end
# edit an existing page or a new one
@@ -321,6 +330,6 @@ private
end
def load_pages_for_index
@pages = @wiki.pages.with_updated_on.all(:order => 'title', :include => {:wiki => :project})
@pages = @wiki.pages.with_updated_on.order("#{WikiPage.table_name}.title").includes(:wiki => :project).includes(:parent).all
end
end
+1 -1
View File
@@ -50,7 +50,7 @@ class WikiPage < ActiveRecord::Base
# eager load information about last updates, without loading text
scope :with_updated_on, {
:select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on",
:select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on, #{WikiContent.table_name}.version",
:joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id"
}
+13
View File
@@ -0,0 +1,13 @@
api.array :wiki_pages do
@pages.each do |page|
api.wiki_page do
api.title page.title
if page.parent
api.parent :title => page.parent.title
end
api.version page.version
api.created_on page.created_on
api.updated_on page.updated_on
end
end
end
+11
View File
@@ -0,0 +1,11 @@
api.wiki_page do
api.title @page.title
if @page.parent
api.parent :title => @page.parent.title
end
api.text @content.text
api.version @content.version
api.author(:id => @content.author_id, :name => @content.author.name)
api.created_on @page.created_on
api.updated_on @content.updated_on
end