2011-10-16 23:07:10 +02:00
|
|
|
class SnippetsController < ApplicationController
|
|
|
|
before_filter :authenticate_user!
|
2011-10-26 15:46:25 +02:00
|
|
|
before_filter :project
|
2011-10-16 23:07:10 +02:00
|
|
|
|
|
|
|
# Authorize
|
|
|
|
before_filter :add_project_abilities
|
|
|
|
before_filter :authorize_read_snippet!
|
2011-10-26 15:46:25 +02:00
|
|
|
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
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
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
|