summaryrefslogtreecommitdiff
path: root/app/controllers/notes_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/notes_controller.rb')
-rw-r--r--app/controllers/notes_controller.rb49
1 files changed, 49 insertions, 0 deletions
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