BigW Consortium Gitlab

notes_controller.rb 975 Bytes
Newer Older
1
class NotesController < ProjectResourceController
gitlabhq committed
2
  # Authorize
3
  before_filter :authorize_read_note!
4
  before_filter :authorize_write_note!, only: [:create]
gitlabhq committed
5 6 7

  respond_to :js

8
  def index
9
    notes
10 11 12 13 14
    if params[:target_type] == "merge_request"
      @mixed_targets = true
      @main_target_type = params[:target_type].camelize
    end

15
    respond_with(@notes)
16 17
  end

gitlabhq committed
18
  def create
19
    @note = Notes::CreateContext.new(project, current_user, params).execute
gitlabhq committed
20 21 22

    respond_to do |format|
      format.html {redirect_to :back}
Nihad Abbasov committed
23
      format.js
gitlabhq committed
24 25 26 27 28
    end
  end

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

    respond_to do |format|
33
      format.js { render nothing: true }
gitlabhq committed
34 35 36
    end
  end

37
  def preview
38
    render text: view_context.markdown(params[:note])
39 40 41
  end

  protected
42

43
  def notes
44
    @notes = Notes::LoadContext.new(project, current_user, params).execute
45
  end
gitlabhq committed
46
end