gitlab-org--gitlab-foss/app/controllers/wikis_controller.rb

96 lines
2.1 KiB
Ruby
Raw Normal View History

class WikisController < ProjectResourceController
2012-02-20 13:16:55 -05:00
before_filter :authorize_read_wiki!
before_filter :authorize_write_wiki!, only: [:edit, :create, :history]
before_filter :authorize_admin_wiki!, only: :destroy
before_filter :load_gollum_wiki
2013-01-11 14:04:14 -05:00
2012-08-09 00:34:29 -04:00
def pages
@wiki_pages = @gollum_wiki.pages
2012-08-09 00:34:29 -04:00
end
2012-02-19 09:35:31 -05:00
def show
@wiki = @gollum_wiki.find_page(params[:id], params[:version_id])
if @wiki
render 'show'
else
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
@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
@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
@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
@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
def git_access
2012-02-19 09:35:31 -05:00
end
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