aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb
blob: 887e8e63797927304ed903480206c505b61ce528 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#
# SonarQube, open source software quality management tool.
# Copyright (C) 2008-2014 SonarSource
# mailto:contact AT sonarsource DOT com
#
# SonarQube is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# SonarQube is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
require 'set'

class IssuesController < ApplicationController

  SECTION=Navigation::SECTION_ISSUES

  before_filter :init_options
  before_filter :load_fav_filters, :only => [:index, :search, :search2, :filter, :manage, :favourites, :toggle_fav]

  PAGE_SIZE = 100

  # GET /issues/index
  def index
    redirect_to :action => 'search'
  end

  # GET /issues/search
  def search

  end

  # GET /issues/manage
  def manage
    @issues_query = Internal.issues.emptyIssueQuery()
    @filters = Internal.issues.findIssueFiltersForCurrentUser()
    @shared_filters = Internal.issues.findSharedFiltersForCurrentUser()
    @favourite_filter_ids = @favourite_filters.map { |filter| filter.id }
  end

  # GET /issues/save_as_form?[&criteria]
  def save_as_form
    @filter_query_serialized = Internal.issues.serializeFilterQuery(criteria_params)
    render :partial => 'issues/filter_save_as_form'
  end

  # POST /issues/save_as?name=<name>[&parameters]
  def save_as
    verify_post_request
    options = {'name' => params[:name], 'description' => params[:description], 'data' => URI.unescape(params[:data]), 'shared' => params[:shared]=='true'}
    @filter = Internal.issues.createIssueFilter(options)
    render :text => @filter.id.to_s, :status => 200
  end

  # POST /issues/save?id=<id>&[criteria]
  def save
    verify_post_request
    require_parameters :id

    @filter = Internal.issues.updateIssueFilterQuery(params[:id].to_i, criteria_params)
    render :text => @filter.id.to_s, :status => 200
  end

  # GET /issues/edit_form/<filter id>
  def edit_form
    require_parameters :id
    @filter = find_filter(params[:id].to_i)
    render :partial => 'issues/filter_edit_form'
  end

  # POST /issues/edit/<filter id>?name=<name>&description=<description>&shared=<true|false>
  def edit
    verify_post_request

    existing_filter = find_filter(params[:id].to_i)
    options = {'id' => params[:id].to_s, 'name' => params[:name], 'description' => params[:description],
               'data' => existing_filter.data, 'shared' => params[:shared]=='true', 'user' => params[:user]}
    @filter = Internal.issues.updateIssueFilter(options)
    render :text => @filter.id.to_s, :status => 200
  end

  # GET /issues/copy_form/<filter id>
  def copy_form
    require_parameters :id
    @filter = find_filter(params[:id].to_i)
    @filter.setUser(nil)
    @filter.setShared(false)
    render :partial => 'issues/filter_copy_form'
  end

  # POST /issues/copy/<filter id>?name=<copy name>&description=<copy description>
  def copy
    verify_post_request

    options = {'name' => params[:name], 'description' => params[:description], 'shared' => params[:shared]=='true'}
    @filter = Internal.issues.copyIssueFilter(params[:id].to_i, options)
    render :text => @filter.id.to_s, :status => 200
  end

  # POST /issues/delete/<filter id>
  def delete
    verify_post_request
    require_parameters :id
    Internal.issues.deleteIssueFilter(params[:id].to_i)
    redirect_to :action => 'manage'
  end

  # GET /issues/favourites
  def favourites
    verify_ajax_request
    render :partial => 'issues/filter_favourites'
  end

  # POST /issues/toggle_fav/<filter id>
  def toggle_fav
    verify_ajax_request
    require_parameters :id
    render :text => Internal.issues.toggleFavouriteIssueFilter(params[:id].to_i), :status => 200
  end

  # GET /issues/bulk_change_form?[&criteria]
  def bulk_change_form
    access_denied unless logged_in?

    issues_query_params = criteria_params.clone.merge({'pageSize' => -1})
    # SONAR-4654 pagination parameters should be remove when loading issues for bulk change
    issues_query_params.delete('pageIndex')
    if params[:id]
      @issues = Internal.issues.execute(params[:id].to_i, issues_query_params).issues()
    else
      @issues = Internal.issues.execute(issues_query_params).issues()
    end
    @projects = Set.new(@issues.map {|issue| issue.projectKey()})

    render :partial => 'issues/bulk_change_form'
  end

  # POST /issues/bulk_change?criteria
  def bulk_change
    verify_post_request
    Internal.issues.bulkChange(params, params[:comment], params[:sendNotifications] == 'true')
    render :text => '', :status => 200
  end


  private

  def init_options
    @options_for_statuses = Internal.issues.listStatus().map { |s| [message('issue.status.' + s), s] }
    @options_for_resolutions = Internal.issues.listResolutions().map { |s| [message('issue.resolution.' + s), s] }
  end

  def load_fav_filters
    @favourite_filters = Internal.issues.findFavouriteIssueFiltersForCurrentUser() if logged_in?
  end

  def find_filter(id)
    Internal.issues.findIssueFilter(id)
  end

  def criteria_params
    new_params = params.clone
    new_params.delete('controller')
    new_params.delete('action')
    new_params
  end

  def init_params
    params['pageSize'] = PAGE_SIZE unless request.xhr?
  end

  def issues_query_params_sanitized
    Internal.issues.sanitizeFilterQuery(params).to_hash
  end

  def issues_query_params_from_filter(filter)
    Internal.issues.deserializeFilterQuery(filter).to_hash
  end

end