gitlabhq/app/controllers/snippets_controller.rb

63 lines
1.3 KiB
Ruby
Raw Normal View History

2011-10-16 23:07:10 +02:00
class SnippetsController < ApplicationController
before_filter :authenticate_user!
before_filter :project
2011-10-16 23:07:10 +02:00
# Authorize
before_filter :add_project_abilities
before_filter :authorize_read_snippet!
before_filter :authorize_write_snippet!, :only => [:new, :create, :close, :edit, :update, :sort]
2011-10-16 23:07:10 +02:00
respond_to :html
def index
@snippets = @project.snippets
end
def new
2011-10-16 23:07:10 +02:00
@snippet = @project.snippets.new
end
def create
@snippet = @project.snippets.new(params[:snippet])
@snippet.author = current_user
@snippet.save
if @snippet.valid?
redirect_to [@project, @snippet]
else
respond_with(@snippet)
end
end
def edit
@snippet = @project.snippets.find(params[:id])
end
def update
@snippet = @project.snippets.find(params[:id])
@snippet.update_attributes(params[:snippet])
if @snippet.valid?
redirect_to [@project, @snippet]
else
respond_with(@snippet)
end
end
def show
@snippet = @project.snippets.find(params[:id])
@notes = @snippet.notes
@note = @project.notes.new(:noteable => @snippet)
end
def destroy
@snippet = @project.snippets.find(params[:id])
2011-10-17 12:39:03 +02:00
return access_denied! unless can?(current_user, :admin_snippet, @snippet)
2011-10-16 23:07:10 +02:00
@snippet.destroy
2011-10-17 12:39:03 +02:00
redirect_to project_snippets_path(@project)
2011-10-16 23:07:10 +02:00
end
end