diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/notes_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/snippets_controller.rb | 63 |
2 files changed, 65 insertions, 0 deletions
diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index d0a40eb18e4..1703c00d5e5 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -41,6 +41,8 @@ class NotesController < ApplicationController Notify.note_commit_email(u, @note).deliver when "Issue" then Notify.note_issue_email(u, @note).deliver + when "Snippet" + true else Notify.note_wall_email(u, @note).deliver end diff --git a/app/controllers/snippets_controller.rb b/app/controllers/snippets_controller.rb new file mode 100644 index 00000000000..5a6ffa4f913 --- /dev/null +++ b/app/controllers/snippets_controller.rb @@ -0,0 +1,63 @@ +class SnippetsController < ApplicationController + before_filter :authenticate_user! + before_filter :project + + # Authorize + before_filter :add_project_abilities + before_filter :authorize_read_snippet! + before_filter :authorize_write_snippet!, :only => [:new, :create, :close, :edit, :update, :sort] + + respond_to :html + + def index + @snippets = @project.snippets + end + + def new + @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]) + authorize_admin_snippet! unless @snippet.author == current_user + + @snippet.destroy + + respond_to do |format| + format.js { render :nothing => true } + end + end +end |