summaryrefslogtreecommitdiff
path: root/app/controllers/notes_controller.rb
blob: d0a40eb18e4d9efc1900f4243847b51e03cfc0ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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