2013-06-23 12:47:22 -04:00
|
|
|
class Projects::WikisController < Projects::ApplicationController
|
2012-02-20 13:16:55 -05:00
|
|
|
before_filter :authorize_read_wiki!
|
2012-08-10 18:07:50 -04:00
|
|
|
before_filter :authorize_write_wiki!, only: [:edit, :create, :history]
|
|
|
|
before_filter :authorize_admin_wiki!, only: :destroy
|
2013-03-03 22:43:52 -05:00
|
|
|
before_filter :load_gollum_wiki
|
2013-01-11 14:04:14 -05:00
|
|
|
|
2012-08-09 00:34:29 -04:00
|
|
|
def pages
|
2013-03-03 22:43:52 -05:00
|
|
|
@wiki_pages = @gollum_wiki.pages
|
2012-08-09 00:34:29 -04:00
|
|
|
end
|
|
|
|
|
2012-02-19 09:35:31 -05:00
|
|
|
def show
|
2013-03-03 22:43:52 -05:00
|
|
|
@wiki = @gollum_wiki.find_page(params[:id], params[:version_id])
|
2012-02-21 17:31:18 -05:00
|
|
|
|
2012-07-26 07:45:17 -04:00
|
|
|
if @wiki
|
|
|
|
render 'show'
|
|
|
|
else
|
2013-03-03 22:43:52 -05:00
|
|
|
return render('empty') unless can?(current_user, :write_wiki, @project)
|
|
|
|
@wiki = WikiPage.new(@gollum_wiki)
|
|
|
|
@wiki.title = params[:id]
|
|
|
|
|
|
|
|
render 'edit'
|
2012-02-19 09:35:31 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2013-03-03 22:43:52 -05:00
|
|
|
@wiki = @gollum_wiki.find_page(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@wiki = @gollum_wiki.find_page(params[:id])
|
|
|
|
|
|
|
|
return render('empty') unless can?(current_user, :write_wiki, @project)
|
|
|
|
|
|
|
|
if @wiki.update(content, format, message)
|
|
|
|
redirect_to [@project, @wiki], notice: 'Wiki was successfully updated.'
|
|
|
|
else
|
|
|
|
render 'edit'
|
|
|
|
end
|
2012-02-19 09:35:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2013-03-03 22:43:52 -05:00
|
|
|
@wiki = WikiPage.new(@gollum_wiki)
|
|
|
|
|
|
|
|
if @wiki.create(wiki_params)
|
|
|
|
redirect_to project_wiki_path(@project, @wiki), notice: 'Wiki was successfully updated.'
|
|
|
|
else
|
|
|
|
render action: "edit"
|
2012-02-19 09:35:31 -05:00
|
|
|
end
|
|
|
|
end
|
2012-02-19 14:52:05 -05:00
|
|
|
|
|
|
|
def history
|
2013-04-03 14:05:10 -04:00
|
|
|
@wiki = @gollum_wiki.find_page(params[:id])
|
|
|
|
|
|
|
|
redirect_to(project_wiki_path(@project, :home), notice: "Page not found") unless @wiki
|
2012-02-19 14:52:05 -05:00
|
|
|
end
|
2013-01-11 14:04:14 -05:00
|
|
|
|
2012-02-19 09:35:31 -05:00
|
|
|
def destroy
|
2013-03-03 22:43:52 -05:00
|
|
|
@wiki = @gollum_wiki.find_page(params[:id])
|
|
|
|
@wiki.delete if @wiki
|
|
|
|
redirect_to project_wiki_path(@project, :home), notice: "Page was successfully deleted"
|
|
|
|
end
|
2012-02-19 09:35:31 -05:00
|
|
|
|
2013-03-03 22:43:52 -05:00
|
|
|
def git_access
|
2012-02-19 09:35:31 -05:00
|
|
|
end
|
2013-03-03 22:43:52 -05:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def load_gollum_wiki
|
|
|
|
@gollum_wiki = GollumWiki.new(@project, current_user)
|
|
|
|
|
|
|
|
# Call #wiki to make sure the Wiki Repo is initialized
|
|
|
|
@gollum_wiki.wiki
|
|
|
|
rescue GollumWiki::CouldNotCreateWikiError => ex
|
|
|
|
flash[:notice] = "Could not create Wiki Repository at this time. Please try again later."
|
|
|
|
redirect_to @project
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
def wiki_params
|
|
|
|
params[:wiki].slice(:title, :content, :format, :message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def content
|
|
|
|
params[:wiki][:content]
|
|
|
|
end
|
|
|
|
|
|
|
|
def format
|
|
|
|
params[:wiki][:format]
|
|
|
|
end
|
|
|
|
|
|
|
|
def message
|
|
|
|
params[:wiki][:message]
|
|
|
|
end
|
|
|
|
|
2012-02-19 09:35:31 -05:00
|
|
|
end
|