issues_controller.rb 2.67 KB
Newer Older
1
class IssuesController < ProjectResourceController
2
  before_filter :module_enabled
3
  before_filter :issue, only: [:edit, :update, :show]
randx's avatar
randx committed
4

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
5
  # Allow read any issue
gitlabhq's avatar
gitlabhq committed
6
  before_filter :authorize_read_issue!
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
7 8

  # Allow write(create) issue
9
  before_filter :authorize_write_issue!, only: [:new, :create]
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
10 11

  # Allow modify issue
12
  before_filter :authorize_modify_issue!, only: [:edit, :update]
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
13

gitlabhq's avatar
gitlabhq committed
14
  respond_to :js, :html
gitlabhq's avatar
gitlabhq committed
15 16

  def index
17
    @issues = issues_filtered
18
    @issues = @issues.page(params[:page]).per(20)
gitlabhq's avatar
gitlabhq committed
19

gitlabhq's avatar
gitlabhq committed
20 21 22
    respond_to do |format|
      format.html # index.html.erb
      format.js
23
      format.atom { render layout: false }
gitlabhq's avatar
gitlabhq committed
24 25 26 27
    end
  end

  def new
28
    @issue = @project.issues.new(params[:issue])
gitlabhq's avatar
gitlabhq committed
29 30 31 32 33 34 35 36
    respond_with(@issue)
  end

  def edit
    respond_with(@issue)
  end

  def show
37
    @note = @project.notes.new(noteable: @issue)
gitlabhq's avatar
gitlabhq committed
38

Nihad Abbasov's avatar
Nihad Abbasov committed
39
    respond_to do |format|
gitlabhq's avatar
gitlabhq committed
40
      format.html
41
      format.js
gitlabhq's avatar
gitlabhq committed
42
    end
gitlabhq's avatar
gitlabhq committed
43 44 45 46 47
  end

  def create
    @issue = @project.issues.new(params[:issue])
    @issue.author = current_user
Valery Sizov's avatar
Valery Sizov committed
48
    @issue.save
gitlabhq's avatar
gitlabhq committed
49

50
    respond_to do |format|
51
      format.html do
52
        if @issue.valid?
53 54 55 56 57
          redirect_to project_issue_path(@project, @issue)
        else
          render :new
        end
      end
58 59
      format.js
    end
gitlabhq's avatar
gitlabhq committed
60 61 62
  end

  def update
63
    @issue.update_attributes(params[:issue].merge(author_id_of_changes: current_user.id))
gitlabhq's avatar
gitlabhq committed
64 65 66

    respond_to do |format|
      format.js
67
      format.html do
68 69 70 71 72 73
        if @issue.valid?
          redirect_to [@project, @issue]
        else
          render :edit
        end
      end
gitlabhq's avatar
gitlabhq committed
74 75 76
    end
  end

VSizov's avatar
VSizov committed
77
  def sort
78 79
    return render_404 unless can?(current_user, :admin_issue, @project)

80
    @issues = @project.issues.where(id: params['issue'])
VSizov's avatar
VSizov committed
81 82 83 84 85
    @issues.each do |issue|
      issue.position = params['issue'].index(issue.id.to_s) + 1
      issue.save
    end

86
    render nothing: true
VSizov's avatar
VSizov committed
87
  end
gitlabhq's avatar
gitlabhq committed
88

Adam Leonard's avatar
Adam Leonard committed
89
  def search
90 91
    terms = params['terms']

92
    @issues = issues_filtered
Nihad Abbasov's avatar
Nihad Abbasov committed
93
    @issues = @issues.where("title LIKE ?", "%#{terms}%") unless terms.blank?
94
    @issues = @issues.page(params[:page]).per(100)
Adam Leonard's avatar
Adam Leonard committed
95

96
    render partial: 'issues'
Adam Leonard's avatar
Adam Leonard committed
97 98
  end

randx's avatar
randx committed
99 100
  def bulk_update
    result = IssuesBulkUpdateContext.new(project, current_user, params).execute
101
    redirect_to :back, notice: "#{result[:count]} issues updated"
randx's avatar
randx committed
102 103
  end

Nihad Abbasov's avatar
Nihad Abbasov committed
104
  protected
gitlabhq's avatar
gitlabhq committed
105 106 107 108

  def issue
    @issue ||= @project.issues.find(params[:id])
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
109 110

  def authorize_modify_issue!
111
    return render_404 unless can?(current_user, :modify_issue, @issue)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
112 113 114
  end

  def authorize_admin_issue!
115
    return render_404 unless can?(current_user, :admin_issue, @issue)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
116
  end
117 118 119 120

  def module_enabled
    return render_404 unless @project.issues_enabled
  end
121 122

  def issues_filtered
123
    @issues = IssuesListContext.new(project, current_user, params).execute
randx's avatar
randx committed
124
  end
gitlabhq's avatar
gitlabhq committed
125
end