gitlabhq/app/controllers/wikis_controller.rb
Dmitriy Zaporozhets 49d58492f2 Wiki abilities
2012-02-20 21:16:55 +03:00

69 lines
1.7 KiB
Ruby

class WikisController < ApplicationController
before_filter :project
before_filter :add_project_abilities
before_filter :authorize_read_wiki!
before_filter :authorize_write_wiki!, :except => [:show, :destroy]
before_filter :authorize_admin_wiki!, :only => :destroy
layout "project"
def show
if params[:old_page_id]
@wiki = @project.wikis.find(params[:old_page_id])
else
@wiki = @project.wikis.where(:slug => params[:id]).order("created_at").last
end
respond_to do |format|
if @wiki
format.html
else
@wiki = @project.wikis.new(:slug => params[:id])
format.html { render "edit" }
end
end
end
def edit
@wiki = @project.wikis.where(:slug => params[:id]).order("created_at").last
@wiki = Wiki.regenerate_from @wiki
end
def create
@wiki = @project.wikis.new(params[:wiki])
@wiki.user = current_user
respond_to do |format|
if @wiki.save
format.html { redirect_to [@project, @wiki], notice: 'Wiki was successfully updated.' }
else
format.html { render action: "edit" }
end
end
end
def history
@wikis = @project.wikis.where(:slug => params[:id]).order("created_at")
end
def destroy
@wikis = @project.wikis.where(:slug => params[:id]).delete_all
respond_to do |format|
format.html { redirect_to project_wiki_path(@project, :index), notice: "Page was successfully deleted" }
end
end
protected
def authorize_read_wiki!
can?(current_user, :read_wiki, @project)
end
def authorize_write_wiki!
can?(current_user, :write_wiki, @project)
end
def authorize_admin_wiki!
can?(current_user, :admin_wiki, @project)
end
end