2012-09-27 20:59:42 +02:00
|
|
|
class WikisController < ProjectResourceController
|
2012-02-20 19:16:55 +01:00
|
|
|
before_filter :authorize_read_wiki!
|
2012-08-11 00:07:50 +02:00
|
|
|
before_filter :authorize_write_wiki!, only: [:edit, :create, :history]
|
|
|
|
before_filter :authorize_admin_wiki!, only: :destroy
|
2013-01-11 20:04:14 +01:00
|
|
|
|
2012-08-09 06:34:29 +02:00
|
|
|
def pages
|
2013-01-11 20:04:14 +01:00
|
|
|
@wiki_pages = @project.wikis.group(:slug).ordered
|
2012-08-09 06:34:29 +02:00
|
|
|
end
|
|
|
|
|
2012-02-19 15:35:31 +01:00
|
|
|
def show
|
2013-01-11 20:04:14 +01:00
|
|
|
if params[:version_id]
|
|
|
|
@wiki = @project.wikis.find(params[:version_id])
|
2012-02-19 20:52:05 +01:00
|
|
|
else
|
2013-01-11 20:04:14 +01:00
|
|
|
@wiki = @project.wikis.where(slug: params[:id]).ordered.first
|
2012-02-19 20:52:05 +01:00
|
|
|
end
|
2012-02-21 23:31:18 +01:00
|
|
|
|
2012-08-11 00:07:50 +02:00
|
|
|
@note = @project.notes.new(noteable: @wiki)
|
2012-07-20 02:09:19 +02:00
|
|
|
|
2012-07-26 13:45:17 +02:00
|
|
|
if @wiki
|
|
|
|
render 'show'
|
|
|
|
else
|
|
|
|
if can?(current_user, :write_wiki, @project)
|
2012-08-11 00:07:50 +02:00
|
|
|
@wiki = @project.wikis.new(slug: params[:id])
|
2012-07-26 13:45:17 +02:00
|
|
|
render 'edit'
|
|
|
|
else
|
|
|
|
render 'empty'
|
2012-02-19 18:05:35 +01:00
|
|
|
end
|
2012-02-19 15:35:31 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2013-01-11 20:04:14 +01:00
|
|
|
@wiki = @project.wikis.where(slug: params[:id]).ordered.first
|
2012-02-19 18:05:35 +01:00
|
|
|
@wiki = Wiki.regenerate_from @wiki
|
2012-02-19 15:35:31 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2012-02-19 18:05:35 +01:00
|
|
|
@wiki = @project.wikis.new(params[:wiki])
|
2012-02-19 20:52:05 +01:00
|
|
|
@wiki.user = current_user
|
2012-02-19 15:35:31 +01:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if @wiki.save
|
2012-02-19 18:05:35 +01:00
|
|
|
format.html { redirect_to [@project, @wiki], notice: 'Wiki was successfully updated.' }
|
2012-02-19 15:35:31 +01:00
|
|
|
else
|
|
|
|
format.html { render action: "edit" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-02-19 20:52:05 +01:00
|
|
|
|
|
|
|
def history
|
2013-01-11 20:04:14 +01:00
|
|
|
@wiki_pages = @project.wikis.where(slug: params[:id]).ordered
|
2012-02-19 20:52:05 +01:00
|
|
|
end
|
2013-01-11 20:04:14 +01:00
|
|
|
|
2012-02-19 15:35:31 +01:00
|
|
|
def destroy
|
2012-08-11 00:07:50 +02:00
|
|
|
@wikis = @project.wikis.where(slug: params[:id]).delete_all
|
2012-02-19 15:35:31 +01:00
|
|
|
|
|
|
|
respond_to do |format|
|
2012-02-20 18:16:55 +01:00
|
|
|
format.html { redirect_to project_wiki_path(@project, :index), notice: "Page was successfully deleted" }
|
2012-02-19 15:35:31 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|