Class: IssuesController

Inherits:
ApplicationController show all
Includes:
AttachmentsHelper, CustomFieldsHelper, IssueRelationsHelper, IssuesHelper, ProjectsHelper, QueriesHelper, Redmine::Export::PDF, RepositoriesHelper, SortHelper, WatchersHelper
Defined in:
app/controllers/issues_controller.rb

Overview

Redmine - project management software Copyright (C) 2006-2014 Jean-Philippe Lang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program 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 General Public License for more details.

You should have received a copy of the GNU 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.

Constant Summary

Constants included from ApplicationHelper

ApplicationHelper::HEADING_RE, ApplicationHelper::MACROS_RE, ApplicationHelper::MACRO_SUB_RE, ApplicationHelper::TOC_RE

Constants included from CustomFieldsHelper

CustomFieldsHelper::CUSTOM_FIELDS_TABS

Instance Method Summary collapse

Methods included from Redmine::Export::PDF

#calc_col_width, #fetch_row_values, #get_issues_to_pdf_write_cells, #is_cjk?, #issue_to_pdf, #issues_to_pdf, #issues_to_pdf_draw_borders, #issues_to_pdf_write_cells, #render_table_header, #wiki_page_to_pdf, #wiki_pages_to_pdf, #write_page_hierarchy, #write_wiki_page

Methods included from IssuesHelper

#bulk_edit_error_messages, #details_to_strings, #email_issue_attributes, #find_name_by_reflection, #issue_fields_rows, #issue_heading, #issue_list, #issues_destroy_confirmation_message, #link_to_new_subtask, #query_links, #render_api_issue_children, #render_custom_fields_rows, #render_descendants_tree, #render_email_issue_attributes, #render_issue_subject_with_tree, #render_issue_tooltip, #render_sidebar_queries, #show_detail, #sidebar_queries

Methods included from ApplicationHelper

#accesskey, #anchor, #api_meta, #authoring, #authorize_for, #avatar, #back_url, #back_url_hidden_field_tag, #body_css_classes, #breadcrumb, #calendar_for, #catch_macros, #check_all_links, #checked_image, #context_menu, #current_theme, #delete_link, #due_date_distance_in_words, #email_delivery_enabled?, #error_messages_for, #favicon, #favicon_path, #favicon_url, #format_activity_day, #format_activity_description, #format_activity_title, #format_object, #format_version_name, #heads_for_theme, #html_hours, #html_title, #image_tag, #include_calendar_headers_tags, #include_in_api_response?, #inject_macros, #javascript_heads, #javascript_include_tag, #labelled_fields_for, #labelled_form_for, #lang_options_for_select, #link_to_attachment, #link_to_function, #link_to_if_authorized, #link_to_issue, #link_to_message, #link_to_project, #link_to_project_settings, #link_to_revision, #link_to_user, #link_to_version, #option_tag, #other_formats_links, #page_header_title, #parse_headings, #parse_inline_attachments, #parse_non_pre_blocks, #parse_redmine_links, #parse_sections, #parse_wiki_links, #preview_link, #principals_check_box_tags, #principals_options_for_select, #progress_bar, #project_tree, #project_tree_options_for_select, #raw_json, #render_flash_messages, #render_page_hierarchy, #render_project_jump_box, #render_project_nested_lists, #render_tabs, #reorder_links, #replace_toc, #robot_exclusion_tag, #sanitize_anchor_name, #sidebar_content?, #simple_format_without_paragraph, #stylesheet_link_tag, #syntax_highlight, #syntax_highlight_lines, #textilizable, #thumbnail_tag, #time_tag, #title, #to_path_param, #toggle_checkboxes_link, #toggle_link, #truncate_lines, #truncate_single_line_raw, #view_layouts_base_sidebar_hook_response, #wiki_page_path

Methods included from Redmine::Pagination::Helper

#pagination_links_each, #pagination_links_full, #per_page_links, #per_page_options

Methods included from Redmine::I18n

#current_language, #day_letter, #day_name, #find_language, #format_date, #format_time, included, #l, #l_hours, #l_or_humanize, #languages_options, #ll, #month_name, #set_language_if_valid, #valid_languages

Methods included from GravatarHelper::PublicMethods

#gravatar, #gravatar_api_url, #gravatar_for, #gravatar_url

Methods included from Redmine::WikiFormatting::Macros::Definitions

#exec_macro, #extract_macro_options, #macro_exists?

Methods included from SortHelper

#sort_clause, #sort_clear, #sort_criteria, #sort_css_classes, #sort_header_tag, #sort_init, #sort_link, #sort_name, #sort_update

Methods included from RepositoriesHelper

#bazaar_field_tags, #cvs_field_tags, #darcs_field_tags, #filesystem_field_tags, #format_revision, #git_field_tags, #index_commits, #index_head, #mercurial_field_tags, #render_changes_tree, #render_changeset_changes, #render_properties, #repository_field_tags, #scm_log_encoding_tag, #scm_path_encoding_tag, #scm_path_info, #scm_path_info_tag, #scm_select_tag, #subversion_field_tags, #truncate_at_line_break, #with_leading_slash

Methods included from QueriesHelper

#available_block_columns_tags, #column_content, #column_header, #column_value, #csv_content, #csv_value, #filters_options_for_select, #query_available_inline_columns_options, #query_columns_hidden_tags, #query_filters_hidden_tags, #query_hidden_tags, #query_selected_inline_columns_options, #query_to_csv, #render_query_columns_selection, #retrieve_query, #retrieve_query_from_session

Methods included from AttachmentsHelper

#container_attachments_edit_path, #container_attachments_path, #link_to_attachments, #render_api_attachment

Methods included from WatchersHelper

#watcher_css, #watcher_link, #watchers_checkboxes, #watchers_list

Methods included from IssueRelationsHelper

#collection_for_relation_type_select

Methods included from CustomFieldsHelper

#custom_field_formats_for_select, #custom_field_label_tag, #custom_field_tag, #custom_field_tag_for_bulk_edit, #custom_field_tag_id, #custom_field_tag_name, #custom_field_tag_with_label, #custom_field_type_options, #edit_tag_style_tag, #format_value, #render_api_custom_values, #render_custom_field_format_partial, #render_custom_fields_tabs, #show_value

Methods included from ProjectsHelper

#format_version_sharing, #parent_project_select_tag, #project_settings_tabs, #render_api_includes, #render_project_action_links, #render_project_hierarchy, #version_options_for_select

Methods inherited from ApplicationController

#_include_layout?, accept_api_auth, #accept_api_auth?, accept_rss_auth, #accept_rss_auth?, #api_key_from_request, #api_offset_and_limit, #api_request?, #api_switch_user_from_request, #authorize, #authorize_global, #autologin_cookie_name, #back_url, #check_if_login_required, #check_password_change, #check_project_privacy, #deny_access, #filename_for_content_disposition, #find_attachments, #find_current_user, #find_issue, #find_issues, #find_model_object, #find_optional_project, #find_project_by_project_id, #find_project_from_association, #force_logout_if_password_changed, #handle_unverified_request, #logged_user=, #logout_user, #missing_template, model_object, #parse_qvalues, #per_page_option, #query_statement_invalid, #redirect_back_or_default, #redirect_to_referer_or, #render_403, #render_404, #render_api_head, #render_api_ok, #render_attachment_warning_if_needed, #render_error, #render_feed, #render_validation_errors, #require_admin, #require_admin_or_api_request, #require_login, #session_expiration, #session_expired?, #set_localization, #start_user_session, #try_to_autologin, #use_layout, #user_setup, #verify_authenticity_token

Methods included from Redmine::MenuManager::MenuController

#current_menu_item, included, #menu_items, #redirect_to_project_menu_item

Methods included from Redmine::Search::Controller

#default_search_scope, #default_search_scopes, included

Methods included from RoutesHelper

#_new_time_entry_path, #_project_calendar_path, #_project_gantt_path, #_project_issues_path, #_report_time_entries_path, #_time_entries_path

Methods included from Redmine::Pagination

#deprecated_paginate, #paginate, #paginator

Instance Method Details

#bulk_editObject

Bulk edit/copy a set of issues


219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'app/controllers/issues_controller.rb', line 219

def bulk_edit
  @issues.sort!
  @copy = params[:copy].present?
  @notes = params[:notes]

  if User.current.allowed_to?(:move_issues, @projects)
    @allowed_projects = Issue.allowed_target_projects_on_move
    if params[:issue]
      @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
      if @target_project
        target_projects = [@target_project]
      end
    end
  end
  target_projects ||= @projects

  if @copy
    # Copied issues will get their default statuses
    @available_statuses = []
  else
    @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
  end
  @custom_fields = target_projects.map{|p|p.all_issue_custom_fields.visible}.reduce(:&)
  @assignables = target_projects.map(&:assignable_users).reduce(:&)
  @trackers = target_projects.map(&:trackers).reduce(:&)
  @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
  @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
  if @copy
    @attachments_present = @issues.detect {|i| i.attachments.any?}.present?
    @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
  end

  @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)

  @issue_params = params[:issue] || {}
  @issue_params[:custom_field_values] ||= {}
end

#bulk_updateObject


257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'app/controllers/issues_controller.rb', line 257

def bulk_update
  @issues.sort!
  @copy = params[:copy].present?
  attributes = parse_params_for_bulk_issue_attributes(params)

  unsaved_issues = []
  saved_issues = []

  if @copy && params[:copy_subtasks].present?
    # Descendant issues will be copied with the parent task
    # Don't copy them twice
    @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}}
  end

  @issues.each do |orig_issue|
    orig_issue.reload
    if @copy
      issue = orig_issue.copy({},
        :attachments => params[:copy_attachments].present?,
        :subtasks => params[:copy_subtasks].present?,
        :link => link_copy?(params[:link_copy])
      )
    else
      issue = orig_issue
    end
    journal = issue.init_journal(User.current, params[:notes])
    issue.safe_attributes = attributes
    call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
    if issue.save
      saved_issues << issue
    else
      unsaved_issues << orig_issue
    end
  end

  if unsaved_issues.empty?
    flash[:notice] = l(:notice_successful_update) unless saved_issues.empty?
    if params[:follow]
      if @issues.size == 1 && saved_issues.size == 1
        redirect_to issue_path(saved_issues.first)
      elsif saved_issues.map(&:project).uniq.size == 1
        redirect_to project_issues_path(saved_issues.map(&:project).first)
      end
    else
      redirect_back_or_default _project_issues_path(@project)
    end
  else
    @saved_issues = @issues
    @unsaved_issues = unsaved_issues
    @issues = Issue.visible.where(:id => @unsaved_issues.map(&:id)).to_a
    bulk_edit
    render :action => 'bulk_edit'
  end
end

#createObject


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
# File 'app/controllers/issues_controller.rb', line 147

def create
  call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
  @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
  if @issue.save
    call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
    respond_to do |format|
      format.html {
        render_attachment_warning_if_needed(@issue)
        flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
        if params[:continue]
          attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
          redirect_to new_project_issue_path(@issue.project, :issue => attrs)
        else
          redirect_to issue_path(@issue)
        end
      }
      format.api  { render :action => 'show', :status => :created, :location => issue_url(@issue) }
    end
    return
  else
    respond_to do |format|
      format.html { render :action => 'new' }
      format.api  { render_validation_errors(@issue) }
    end
  end
end

#destroyObject


312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'app/controllers/issues_controller.rb', line 312

def destroy
  @hours = TimeEntry.where(:issue_id => @issues.map(&:id)).sum(:hours).to_f
  if @hours > 0
    case params[:todo]
    when 'destroy'
      # nothing to do
    when 'nullify'
      TimeEntry.where(['issue_id IN (?)', @issues]).update_all('issue_id = NULL')
    when 'reassign'
      reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
      if reassign_to.nil?
        flash.now[:error] = l(:error_issue_not_found_in_project)
        return
      else
        TimeEntry.where(['issue_id IN (?)', @issues]).
          update_all("issue_id = #{reassign_to.id}")
      end
    else
      # display the destroy form if it's a user request
      return unless api_request?
    end
  end
  @issues.each do |issue|
    begin
      issue.reload.destroy
    rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
      # nothing to do, issue was already deleted (eg. by a parent)
    end
  end
  respond_to do |format|
    format.html { redirect_back_or_default _project_issues_path(@project) }
    format.api  { render_api_ok }
  end
end

#editObject


174
175
176
177
178
179
180
181
# File 'app/controllers/issues_controller.rb', line 174

def edit
  return unless update_issue_from_params

  respond_to do |format|
    format.html { }
    format.xml  { }
  end
end

#indexObject


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
# File 'app/controllers/issues_controller.rb', line 54

def index
  retrieve_query
  sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
  sort_update(@query.sortable_columns)
  @query.sort_criteria = sort_criteria.to_a

  if @query.valid?
    case params[:format]
    when 'csv', 'pdf'
      @limit = Setting.issues_export_limit.to_i
      if params[:columns] == 'all'
        @query.column_names = @query.available_inline_columns.map(&:name)
      end
    when 'atom'
      @limit = Setting.feeds_limit.to_i
    when 'xml', 'json'
      @offset, @limit = api_offset_and_limit
      @query.column_names = %w(author)
    else
      @limit = per_page_option
    end

    @issue_count = @query.issue_count
    @issue_pages = Paginator.new @issue_count, @limit, params['page']
    @offset ||= @issue_pages.offset
    @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
                            :order => sort_clause,
                            :offset => @offset,
                            :limit => @limit)
    @issue_count_by_group = @query.issue_count_by_group

    respond_to do |format|
      format.html { render :template => 'issues/index', :layout => !request.xhr? }
      format.api  {
        Issue.load_visible_relations(@issues) if include_in_api_response?('relations')
      }
      format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
      format.csv  { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'issues.csv') }
      format.pdf  { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'issues.pdf') }
    end
  else
    respond_to do |format|
      format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
      format.any(:atom, :csv, :pdf) { render(:nothing => true) }
      format.api { render_validation_errors(@query) }
    end
  end
rescue ActiveRecord::RecordNotFound
  render_404
end

#newObject

Add a new issue The new issue will be created from an existing one if copy_from parameter is given


141
142
143
144
145
# File 'app/controllers/issues_controller.rb', line 141

def new
  respond_to do |format|
    format.html { render :action => 'new', :layout => !request.xhr? }
  end
end

#showObject


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
# File 'app/controllers/issues_controller.rb', line 105

def show
  @journals = @issue.journals.includes(:user, :details).
                  references(:user, :details).
                  reorder("#{Journal.table_name}.id ASC").to_a
  @journals.each_with_index {|j,i| j.indice = i+1}
  @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
  Journal.preload_journals_details_custom_fields(@journals)
  @journals.select! {|journal| journal.notes? || journal.visible_details.any?}
  @journals.reverse! if User.current.wants_comments_in_reverse_order?

  @changesets = @issue.changesets.visible.to_a
  @changesets.reverse! if User.current.wants_comments_in_reverse_order?

  @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
  @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
  @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
  @priorities = IssuePriority.active
  @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
  @relation = IssueRelation.new

  respond_to do |format|
    format.html {
      retrieve_previous_and_next_issue_ids
      render :template => 'issues/show'
    }
    format.api
    format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
    format.pdf  {
      pdf = issue_to_pdf(@issue, :journals => @journals)
      send_data(pdf, :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf")
    }
  end
end

#updateObject


183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'app/controllers/issues_controller.rb', line 183

def update
  return unless update_issue_from_params
  @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
  saved = false
  begin
    saved = save_issue_with_child_records
  rescue ActiveRecord::StaleObjectError
    @conflict = true
    if params[:last_journal_id]
      @conflict_journals = @issue.journals_after(params[:last_journal_id]).to_a
      @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
    end
  end

  if saved
    render_attachment_warning_if_needed(@issue)
    flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?

    respond_to do |format|
      format.html { redirect_back_or_default issue_path(@issue) }
      format.api  { render_api_ok }
    end
  else
    respond_to do |format|
      format.html { render :action => 'edit' }
      format.api  { render_validation_errors(@issue) }
    end
  end
end

#update_formObject

Updates the issue form when changing the project, status or tracker on issue creation/update


215
216
# File 'app/controllers/issues_controller.rb', line 215

def update_form
end