BigW Consortium Gitlab

notes_controller.rb 951 Bytes
Newer Older
gitlabhq committed
1
class NotesController < ApplicationController
Nihad Abbasov committed
2
  before_filter :project
gitlabhq committed
3 4 5

  # Authorize
  before_filter :add_project_abilities
6 7

  before_filter :authorize_read_note!
Nihad Abbasov committed
8
  before_filter :authorize_write_note!, :only => [:create]
gitlabhq committed
9 10 11

  respond_to :js

12
  def index
13 14
    notes
    respond_with(@notes)
15 16
  end

gitlabhq committed
17 18 19
  def create
    @note = @project.notes.new(params[:note])
    @note.author = current_user
Valery Sizov committed
20
    @note.notify = true if params[:notify] == '1'
21
    @note.notify_author = true if params[:notify_author] == '1'
Valery Sizov committed
22
    @note.save
gitlabhq committed
23 24 25

    respond_to do |format|
      format.html {redirect_to :back}
Nihad Abbasov committed
26
      format.js
gitlabhq committed
27 28 29 30 31
    end
  end

  def destroy
    @note = @project.notes.find(params[:id])
gitlabhq committed
32
    return access_denied! unless can?(current_user, :admin_note, @note)
gitlabhq committed
33 34 35
    @note.destroy

    respond_to do |format|
Nihad Abbasov committed
36
      format.js { render :nothing => true }
gitlabhq committed
37 38 39
    end
  end

40 41
  protected 

42
  def notes
Dmitriy Zaporozhets committed
43
    @notes = NotesLoad.new(project, current_user, params).execute
44
  end
gitlabhq committed
45
end