From 9ba1224867665844b117fa037e1465bb706b3685 Mon Sep 17 00:00:00 2001 From: gitlabhq Date: Sun, 9 Oct 2011 00:36:38 +0300 Subject: init commit --- app/controllers/notes_controller.rb | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 app/controllers/notes_controller.rb (limited to 'app/controllers/notes_controller.rb') diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb new file mode 100644 index 00000000000..d0a40eb18e4 --- /dev/null +++ b/app/controllers/notes_controller.rb @@ -0,0 +1,49 @@ +class NotesController < ApplicationController + before_filter :project + + # Authorize + before_filter :add_project_abilities + before_filter :authorize_write_note!, :only => [:create] + before_filter :authorize_admin_note!, :only => [:destroy] + + respond_to :js + + def create + @note = @project.notes.new(params[:note]) + @note.author = current_user + + if @note.save + notify if params[:notify] == '1' + end + + + respond_to do |format| + format.html {redirect_to :back} + format.js + end + end + + def destroy + @note = @project.notes.find(params[:id]) + @note.destroy + + respond_to do |format| + format.js { render :nothing => true } + end + end + + protected + + def notify + @project.users.reject { |u| u.id == current_user.id } .each do |u| + case @note.noteable_type + when "Commit" then + Notify.note_commit_email(u, @note).deliver + when "Issue" then + Notify.note_issue_email(u, @note).deliver + else + Notify.note_wall_email(u, @note).deliver + end + end + end +end -- cgit v1.2.1