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

  # Authorize
  before_filter :add_project_abilities
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
6 7

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

  respond_to :js

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

gitlabhq's avatar
gitlabhq committed
17
  def create
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
18
    @note = Notes::CreateContext.new(project, current_user, params).execute
gitlabhq's avatar
gitlabhq committed
19 20 21

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

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

    respond_to do |format|
Nihad Abbasov's avatar
Nihad Abbasov committed
32
      format.js { render :nothing => true }
gitlabhq's avatar
gitlabhq committed
33 34 35
    end
  end

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

  protected
41

42
  def notes
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
43
    @notes = Notes::LoadContext.new(project, current_user, params).execute
44
  end
gitlabhq's avatar
gitlabhq committed
45
end