summaryrefslogtreecommitdiff
path: root/app/controllers/snippets_controller.rb
diff options
context:
space:
mode:
authorgitlabhq <m@gitlabhq.com>2011-10-17 00:07:10 +0300
committergitlabhq <m@gitlabhq.com>2011-10-17 00:07:10 +0300
commit9265de3d25715aeafd38a4ef41596dca058dc18c (patch)
treee755a2c4c0c0451c90a8bc0e75ffae1950a2f6fd /app/controllers/snippets_controller.rb
parent526ad466c86e69c3447c192d8cae8da653556058 (diff)
downloadgitlab-ce-9265de3d25715aeafd38a4ef41596dca058dc18c.tar.gz
snippets are ready
Diffstat (limited to 'app/controllers/snippets_controller.rb')
-rw-r--r--app/controllers/snippets_controller.rb63
1 files changed, 63 insertions, 0 deletions
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