##// END OF EJS Templates
Don't add the inclusion error when tracker is not set, the blank error is enough....
Don't add the inclusion error when tracker is not set, the blank error is enough. git-svn-id: http://svn.redmine.org/redmine/trunk@15492 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r15084:c4fd1750f703
r15110:90d14b71b365
Show More
issues_controller.rb
563 lines | 19.6 KiB | text/x-ruby | RubyLexer
/ app / controllers / issues_controller.rb
Jean-Philippe Lang
Adds support for free ticket filtering and custom queries on Calendar....
r1796 # Redmine - project management software
Jean-Philippe Lang
Updates copyright for 2016....
r14856 # Copyright (C) 2006-2016 Jean-Philippe Lang
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 #
# 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.
Toshi MARUYAMA
remove trailing white-spaces from issues controller source....
r5703 #
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 # 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.
Toshi MARUYAMA
remove trailing white-spaces from issues controller source....
r5703 #
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 # 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.
class IssuesController < ApplicationController
Jean-Philippe Lang
Contextual quick search (#3263)....
r2829 default_search_scope :issues
Toshi MARUYAMA
remove trailing white-spaces from issues controller source....
r5703
Eric Davis
Refactor: move IssuesController#reply to JournalsController...
r3827 before_filter :find_issue, :only => [:show, :edit, :update]
Jean-Philippe Lang
Removed dead code....
r8831 before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
Jean-Philippe Lang
Implements /issues/new form for creating issues outside a project (#1003)....
r13617 before_filter :authorize, :except => [:index, :new, :create]
before_filter :find_optional_project, :only => [:index, :new, :create]
Jean-Philippe Lang
Removed IssuesController#update_form action, use #new and #edit instead....
r13615 before_filter :build_new_issue_from_params, :only => [:new, :create]
Jean-Philippe Lang
Separation of RSS/API auth actions....
r6077 accept_rss_auth :index, :show
accept_api_auth :index, :show, :create, :update, :destroy
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330
Jean-Philippe Lang
Rescue invalid query statement error with an error message....
r2990 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
Toshi MARUYAMA
remove trailing white-spaces from issues controller source....
r5703
Jean-Philippe Lang
Administrators can edit issue notes....
r1091 helper :journals
Jean-Philippe Lang
Fixed version field on issue view page now links to the corresponding version in the roadmap....
r559 helper :projects
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 helper :custom_fields
Jean-Philippe Lang
Issue relations first commit (not thoroughly tested). 4 kinds of relation are available:...
r503 helper :issue_relations
Jean-Philippe Lang
Added watchers for message boards (watchers controller modified to support any watchable model)....
r527 helper :watchers
Jean-Philippe Lang
Attachments can now be added to wiki pages (original patch by Pavol Murin). Only authorized users can add/delete attachments....
r538 helper :attachments
Jean-Philippe Lang
Added a cross-project issue list. It displays the issues of all the projects visible by the user....
r673 helper :queries
Jean-Philippe Lang
Fixed: PDF export of a issue list grouped by a custom field raises an error (#4600)....
r3219 include QueriesHelper
Toshi MARUYAMA
Fix associated revisions label on issue page....
r4532 helper :repositories
Jean-Philippe Lang
Added a cross-project issue list. It displays the issues of all the projects visible by the user....
r673 helper :sort
include SortHelper
Jean-Philippe Lang
Addq "please select" to activity select box if no activity is set as default (#937)....
r1588 helper :timelog
Jean-Philippe Lang
data locking for issues...
r21
Jean-Philippe Lang
Added a cross-project issue list. It displays the issues of all the projects visible by the user....
r673 def index
retrieve_query
Jean-Philippe Lang
Ability to save "sort order" in custom queries (#2899)....
r2504 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
Eric Davis
Refactor: Extract Query#sortable_columns from the controller....
r3490 sort_update(@query.sortable_columns)
Jean-Philippe Lang
Ability to sort issues by grouped column (#3511)....
r10543 @query.sort_criteria = sort_criteria.to_a
Toshi MARUYAMA
remove trailing white-spaces from issues controller source....
r5703
Jean-Philippe Lang
Added a cross-project issue list. It displays the issues of all the projects visible by the user....
r673 if @query.valid?
Jean-Philippe Lang
Restores object count and adds offset/limit attributes to API responses for paginated collections (#6140)....
r4375 case params[:format]
Jean-Philippe Lang
Fixed: invalid format parameter returns a DoubleRenderError on issues index (#4737)....
r3254 when 'csv', 'pdf'
Jean-Philippe Lang
Restores object count and adds offset/limit attributes to API responses for paginated collections (#6140)....
r4375 @limit = Setting.issues_export_limit.to_i
Jean-Philippe Lang
Preload issue relations when exporting issues to CSV with all columns (#16091)....
r12635 if params[:columns] == 'all'
@query.column_names = @query.available_inline_columns.map(&:name)
end
Jean-Philippe Lang
Fixed: invalid format parameter returns a DoubleRenderError on issues index (#4737)....
r3254 when 'atom'
Jean-Philippe Lang
Restores object count and adds offset/limit attributes to API responses for paginated collections (#6140)....
r4375 @limit = Setting.feeds_limit.to_i
when 'xml', 'json'
@offset, @limit = api_offset_and_limit
Jean-Philippe Lang
Preload authors for /issues API calls....
r12637 @query.column_names = %w(author)
Jean-Philippe Lang
Fixed: invalid format parameter returns a DoubleRenderError on issues index (#4737)....
r3254 else
Jean-Philippe Lang
Restores object count and adds offset/limit attributes to API responses for paginated collections (#6140)....
r4375 @limit = per_page_option
Jean-Philippe Lang
Display links to Atom feeds (closes #496, #750)....
r1171 end
Toshi MARUYAMA
remove trailing white-spaces from issues controller source....
r5703
Jean-Philippe Lang
Move issues, journals, versions queries from IssuesController to Query model....
r2989 @issue_count = @query.issue_count
Jean-Philippe Lang
Deprecation warnings (#12774)....
r10909 @issue_pages = Paginator.new @issue_count, @limit, params['page']
@offset ||= @issue_pages.offset
Jean-Philippe Lang
Move issues, journals, versions queries from IssuesController to Query model....
r2989 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
Toshi MARUYAMA
remove trailing white-spaces from issues controller source....
r5703 :order => sort_clause,
:offset => @offset,
Jean-Philippe Lang
Restores object count and adds offset/limit attributes to API responses for paginated collections (#6140)....
r4375 :limit => @limit)
Jean-Philippe Lang
Move issues, journals, versions queries from IssuesController to Query model....
r2989 @issue_count_by_group = @query.issue_count_by_group
Toshi MARUYAMA
remove trailing white-spaces from issues controller source....
r5703
Jean-Philippe Lang
ProjectsController#list_issues, #export_issues_csv and #export_issues_pdf merged into IssuesController#index...
r874 respond_to do |format|
Toshi MARUYAMA
remove hard-coded '.rhtml' from IssuesController 'index' (#6317)....
r6902 format.html { render :template => 'issues/index', :layout => !request.xhr? }
Toshi MARUYAMA
remove trailing white-spaces from app/controllers/issues_controller.rb....
r6764 format.api {
Jean-Philippe Lang
Display visible relations in API response....
r10304 Issue.load_visible_relations(@issues) if include_in_api_response?('relations')
Jean-Philippe Lang
Ability to load relations on /issues API (#7366)....
r6193 }
Jean-Philippe Lang
Adds project name to issues feed title (#1323)....
r1627 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
Jean-Philippe Lang
Isolates csv options for a hash param (#1159)....
r14292 format.csv { send_data(query_to_csv(@issues, @query, params[:csv]), :type => 'text/csv; header=present', :filename => 'issues.csv') }
Jean-Philippe Lang
Adds support for macro and Redmine links in PDF export (#13051)....
r13562 format.pdf { send_file_headers! :type => 'application/pdf', :filename => 'issues.pdf' }
Jean-Philippe Lang
ProjectsController#list_issues, #export_issues_csv and #export_issues_pdf merged into IssuesController#index...
r874 end
else
Jean-Philippe Lang
Respond with errors and appropriate content type on /issues API calls with invalid query params (#8883)....
r6189 respond_to do |format|
Toshi MARUYAMA
respond nothing in case of content type is not html with invalid query params (#8883, #6317)....
r6904 format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
format.any(:atom, :csv, :pdf) { render(:nothing => true) }
Jean-Philippe Lang
Respond with errors and appropriate content type on /issues API calls with invalid query params (#8883)....
r6189 format.api { render_validation_errors(@query) }
end
Jean-Philippe Lang
Added a cross-project issue list. It displays the issues of all the projects visible by the user....
r673 end
Jean-Philippe Lang
Queries can be marked as 'For all projects'. Such queries will be available on all projects and on the global issue list (#897, closes #671)....
r1296 rescue ActiveRecord::RecordNotFound
render_404
Jean-Philippe Lang
ProjectsController#list_issues, #export_issues_csv and #export_issues_pdf merged into IssuesController#index...
r874 end
Toshi MARUYAMA
remove trailing white-spaces from issues controller source....
r5703
Jean-Philippe Lang
data locking for issues...
r21 def show
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 @journals = @issue.journals.includes(:user, :details).
references(:user, :details).
Jean-Philippe Lang
Sort journals by created_on then id (#14881)....
r13992 reorder(:created_on, :id).to_a
Jean-Philippe Lang
Add a user preference to choose how comments/replies are displayed: in chronological or reverse chronological order (#589, #776)....
r1183 @journals.each_with_index {|j,i| j.indice = i+1}
Jean-Philippe Lang
Private issue notes (#1554)....
r10336 @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
Jean-Philippe Lang
Avoid lots of CustomField.find_by_id calls when displaying an issue history with custom fields (#15072)....
r11987 Journal.preload_journals_details_custom_fields(@journals)
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 @journals.select! {|journal| journal.notes? || journal.visible_details.any?}
Jean-Philippe Lang
Fixed no method error due to typo....
r5326 @journals.reverse! if User.current.wants_comments_in_reverse_order?
Toshi MARUYAMA
remove trailing white-spaces from issues controller source....
r5703
Jean-Philippe Lang
Preload changeset associations (#19706)....
r13857 @changesets = @issue.changesets.visible.preload(:repository, :user).to_a
Jean-Philippe Lang
Fixed: associated changesets from other projects are not visible if the current project doesn't have the repository module enabled (#3087)....
r8629 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
Toshi MARUYAMA
remove trailing white-spaces from issues controller source....
r5703
Jean-Philippe Lang
Moves relations fetching from views to the controller and skip invalid relations (#7385)....
r4621 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
Jean-Philippe Lang
Merged IssuesController #edit and #update into a single actions....
r1115 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
Jean-Baptiste Barth
Do not show inactive issue priorities where not necessary (#8573)....
r5950 @priorities = IssuePriority.active
Jean-Philippe Lang
Initialize TimeEntry with issue and project for the issue edit form....
r5154 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
Jean-Philippe Lang
Always instanciate a relation....
r11380 @relation = IssueRelation.new
Jean-Philippe Lang
ProjectsController#list_issues, #export_issues_csv and #export_issues_pdf merged into IssuesController#index...
r874 respond_to do |format|
Jean-Philippe Lang
Adds previous/next links to issue (#2850)....
r8368 format.html {
retrieve_previous_and_next_issue_ids
render :template => 'issues/show'
}
Jean-Philippe Lang
Adds a pseudo format to api template names and overrides ActionController#default_template so that api templates are chosen automatically....
r4352 format.api
Eric Davis
Refactor: move IssuesController#changes to JournalsController#index....
r3920 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
Jean-Philippe Lang
Private issue notes (#1554)....
r10336 format.pdf {
Jean-Philippe Lang
Adds support for macro and Redmine links in PDF export (#13051)....
r13562 send_file_headers! :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf"
Jean-Philippe Lang
Private issue notes (#1554)....
r10336 }
Jean-Philippe Lang
Merged IssuesController#export_pdf into IssuesController#show....
r799 end
Jean-Philippe Lang
data locking for issues...
r21 end
Jean-Philippe Lang
Initial commit...
r2
Jean-Philippe Lang
ProjectsController#add_issue moved to IssuesController#new....
r1066 def new
Eric Davis
Refactor: merge IssuesController#update_form into IssuesController#new...
r3897 respond_to do |format|
format.html { render :action => 'new', :layout => !request.xhr? }
Jean-Philippe Lang
Removed IssuesController#update_form action, use #new and #edit instead....
r13615 format.js
Eric Davis
Refactor: merge IssuesController#update_form into IssuesController#new...
r3897 end
Eric Davis
Refactor: Split IssuesController#new to #new and #create to match REST pattern....
r3574 end
def create
Jean-Philippe Lang
API: creating an issue with an invalid project_id should return 422 instead of 403 (#19276)....
r13759 unless User.current.allowed_to?(:add_issues, @issue.project, :global => true)
Jean-Philippe Lang
Adds a :copy_issues permission (#18855)....
r13603 raise ::Unauthorized
end
Eric Davis
Refactor: Split IssuesController#new to #new and #create to match REST pattern....
r3574 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
Jean-Philippe Lang
Adds support for adding attachments to issues through the REST API (#8171)....
r8808 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
Eric Davis
Refactor: Split IssuesController#new to #new and #create to match REST pattern....
r3574 if @issue.save
call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
respond_to do |format|
format.html {
Jean-Philippe Lang
Adds issue id link in the issue creation flash message (#3033)....
r6090 render_attachment_warning_if_needed(@issue)
Jean-Philippe Lang
Adds a title to the issue link in the flash message....
r10015 flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
Jean-Philippe Lang
Implements /issues/new form for creating issues outside a project (#1003)....
r13617 redirect_after_create
Eric Davis
Refactor: Split IssuesController#new to #new and #create to match REST pattern....
r3574 }
Jean-Philippe Lang
Adds a pseudo format to api template names and overrides ActionController#default_template so that api templates are chosen automatically....
r4352 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
Eric Davis
Refactor: Split IssuesController#new to #new and #create to match REST pattern....
r3574 end
return
else
respond_to do |format|
Jean-Philippe Lang
Don't render the issue form if issue.project is nil (#19276)....
r13764 format.html {
if @issue.project.nil?
render_error :status => 422
else
render :action => 'new'
end
}
Jean-Philippe Lang
Converts IssuesController to use the new API template system and makes xml/json responses consistent (#6136)....
r4344 format.api { render_validation_errors(@issue) }
Eric Davis
Refactor: Split IssuesController#new to #new and #create to match REST pattern....
r3574 end
end
Jean-Philippe Lang
ProjectsController#add_issue moved to IssuesController#new....
r1066 end
Toshi MARUYAMA
remove trailing white-spaces from issues controller source....
r5703
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 def edit
Jean-Philippe Lang
Better handling of issue update conflicts (#8691)....
r8654 return unless update_issue_from_params
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116
Eric Davis
Refactor: Move the updating of an Issue to the #update method....
r3372 respond_to do |format|
format.html { }
Jean-Philippe Lang
Removed IssuesController#update_form action, use #new and #edit instead....
r13615 format.js
Eric Davis
Refactor: Move the updating of an Issue to the #update method....
r3372 end
end
def update
Jean-Philippe Lang
Better handling of issue update conflicts (#8691)....
r8654 return unless update_issue_from_params
Jean-Philippe Lang
Adds support for adding attachments to issues through the REST API (#8171)....
r8808 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
Jean-Philippe Lang
Better handling of issue update conflicts (#8691)....
r8654 saved = false
begin
Jean-Philippe Lang
Fixed that controller_issues_edit_before/after_save hooks have no controller context (#15044)....
r11989 saved = save_issue_with_child_records
Jean-Philippe Lang
Better handling of issue update conflicts (#8691)....
r8654 rescue ActiveRecord::StaleObjectError
@conflict = true
if params[:last_journal_id]
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 @conflict_journals = @issue.journals_after(params[:last_journal_id]).to_a
Jean-Philippe Lang
Private issue notes (#1554)....
r10336 @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
Jean-Philippe Lang
Better handling of issue update conflicts (#8691)....
r8654 end
end
Eric Davis
Refactor: Move the updating of an Issue to the #update method....
r3372
Jean-Philippe Lang
Better handling of issue update conflicts (#8691)....
r8654 if saved
Eric Davis
Refactor: Moved the contents of #issue_update into Issue....
r3431 render_attachment_warning_if_needed(@issue)
Eric Davis
Remove double negative condition...
r3432 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
Eric Davis
Refactor: Moved the contents of #issue_update into Issue....
r3431
Eric Davis
Refactor: Extracted saving logic out of #update and into a utility method...
r3383 respond_to do |format|
Jean-Philippe Lang
Previous/next links may be lost after editing the issue (#14462)....
r14871 format.html { redirect_back_or_default issue_path(@issue, previous_and_next_issue_ids_params) }
Jean-Philippe Lang
Fixed that 200 API responses have a body containing one space (#11388)....
r9792 format.api { render_api_ok }
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 end
Eric Davis
Refactor: Extracted saving logic out of #update and into a utility method...
r3383 else
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 respond_to do |format|
Eric Davis
Refactor: Start to extract IssuesController#edit into #update (REST)....
r3366 format.html { render :action => 'edit' }
Jean-Philippe Lang
Converts IssuesController to use the new API template system and makes xml/json responses consistent (#6136)....
r4344 format.api { render_validation_errors(@issue) }
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 end
Jean-Philippe Lang
Merged IssuesController change_status and add_note actions....
r1030 end
Jean-Philippe Lang
data locking for issues...
r21 end
Jean-Philippe Lang
Copy issues via bulk update action....
r8418 # Bulk edit/copy a set of issues
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 def bulk_edit
Jean-Philippe Lang
Adds subtasking (#443) including:...
r3459 @issues.sort!
Jean-Philippe Lang
Copy issues via bulk update action....
r8418 @copy = params[:copy].present?
@notes = params[:notes]
Jean-Philippe Lang
Allows project to be changed from the bulk edit form....
r8416
Jean-Philippe Lang
Adds a :copy_issues permission (#18855)....
r13603 if @copy
unless User.current.allowed_to?(:copy_issues, @projects)
raise ::Unauthorized
end
Jean-Philippe Lang
Adds permission to edit and delete issues by role/tracker (#285)....
r15084 else
unless @issues.all?(&:attributes_editable?)
raise ::Unauthorized
end
Jean-Philippe Lang
Adds a :copy_issues permission (#18855)....
r13603 end
Jean-Philippe Lang
Removed :move_issues permission (#18855)....
r13599 @allowed_projects = Issue.allowed_target_projects
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]
Jean-Philippe Lang
Allows project to be changed from the bulk edit form....
r8416 end
end
target_projects ||= @projects
Jean-Philippe Lang
When copying issues, let the status be changed to default or left unchanged....
r9270 if @copy
Jean-Philippe Lang
Default status per tracker (#5991)....
r13153 # Copied issues will get their default statuses
@available_statuses = []
Jean-Philippe Lang
When copying issues, let the status be changed to default or left unchanged....
r9270 else
@available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
end
Jean-Philippe Lang
Fixed that the bulk edit form shows additional custom fields (#19163)....
r13770 @custom_fields = @issues.map{|i|i.editable_custom_fields}.reduce(:&)
Jean-Philippe Lang
Use #reduce instead of #inject for getting the intersection of arrays....
r8707 @assignables = target_projects.map(&:assignable_users).reduce(:&)
Jean-Philippe Lang
Adds Issue#allowed_target_trackers (#7839)....
r15048 @trackers = target_projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&)
Jean-Philippe Lang
Fixed that the bulk edit/copy form does not propose versions and categories for the target project (#10350)....
r8926 @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
@categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
Jean-Philippe Lang
Fixed MissingFeatureException: let user choose to copy attachments or not when bulk copying issues....
r9271 if @copy
@attachments_present = @issues.detect {|i| i.attachments.any?}.present?
Jean-Philippe Lang
Option to copy subtasks when copying issue(s) (#6965)....
r10144 @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
Jean-Philippe Lang
Fixed MissingFeatureException: let user choose to copy attachments or not when bulk copying issues....
r9271 end
Jean-Philippe Lang
Allows project to be changed from the bulk edit form....
r8416
Jean-Philippe Lang
Use #reduce instead of #inject for getting the intersection of arrays....
r8707 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
Jean-Philippe Lang
Preserve field values on bulk edit failure (#13943)....
r11557
@issue_params = params[:issue] || {}
@issue_params[:custom_field_values] ||= {}
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 end
Eric Davis
Refactor: extract #bulk_update method from IssuesController#bulk_edit....
r3923
def bulk_update
@issues.sort!
Jean-Philippe Lang
Copy issues via bulk update action....
r8418 @copy = params[:copy].present?
Jean-Philippe Lang
Fixed that copying issues always copy subtasks and attachments even if option is unchecked (#11787)....
r13886
Eric Davis
Refactor: extract method in bulk_update....
r3926 attributes = parse_params_for_bulk_issue_attributes(params)
Jean-Philippe Lang
Fixed that copying issues always copy subtasks and attachments even if option is unchecked (#11787)....
r13886 copy_subtasks = (params[:copy_subtasks] == '1')
copy_attachments = (params[:copy_attachments] == '1')
Eric Davis
Refactor: extract #bulk_update method from IssuesController#bulk_edit....
r3923
Jean-Philippe Lang
Adds a :copy_issues permission (#18855)....
r13603 if @copy
unless User.current.allowed_to?(:copy_issues, @projects)
raise ::Unauthorized
end
target_projects = @projects
if attributes['project_id'].present?
target_projects = Project.where(:id => attributes['project_id']).to_a
end
unless User.current.allowed_to?(:add_issues, target_projects)
raise ::Unauthorized
end
Jean-Philippe Lang
Adds permission to edit and delete issues by role/tracker (#285)....
r15084 else
unless @issues.all?(&:attributes_editable?)
raise ::Unauthorized
end
Jean-Philippe Lang
Adds a :copy_issues permission (#18855)....
r13603 end
Jean-Philippe Lang
Display the bulk edit form with error messages when some issues can not be saved (#13943)....
r11556 unsaved_issues = []
saved_issues = []
Jean-Philippe Lang
Do not copy subtasks twice when copying an issue and its descendants (#6965)....
r10146
Jean-Philippe Lang
Fixed that copying issues always copy subtasks and attachments even if option is unchecked (#11787)....
r13886 if @copy && copy_subtasks
Jean-Philippe Lang
Do not copy subtasks twice when copying an issue and its descendants (#6965)....
r10146 # 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
Jean-Philippe Lang
Fixed that bulk copy raises an error on validation failure (#13943)....
r11558 @issues.each do |orig_issue|
orig_issue.reload
Jean-Philippe Lang
Copy issues via bulk update action....
r8418 if @copy
Jean-Philippe Lang
Fixed that bulk copy raises an error on validation failure (#13943)....
r11558 issue = orig_issue.copy({},
Jean-Philippe Lang
Fixed that copying issues always copy subtasks and attachments even if option is unchecked (#11787)....
r13886 :attachments => copy_attachments,
:subtasks => copy_subtasks,
Jean-Philippe Lang
Configurable behavour for linking issues on copy (#18500)....
r13286 :link => link_copy?(params[:link_copy])
Jean-Philippe Lang
Option to copy subtasks when copying issue(s) (#6965)....
r10144 )
Jean-Philippe Lang
Fixed that bulk copy raises an error on validation failure (#13943)....
r11558 else
issue = orig_issue
Jean-Philippe Lang
Copy issues via bulk update action....
r8418 end
Eric Davis
Refactor: extract #bulk_update method from IssuesController#bulk_edit....
r3923 journal = issue.init_journal(User.current, params[:notes])
issue.safe_attributes = attributes
call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
Jean-Philippe Lang
Allows project to be changed from the bulk edit form....
r8416 if issue.save
Jean-Philippe Lang
Display the bulk edit form with error messages when some issues can not be saved (#13943)....
r11556 saved_issues << issue
Jean-Philippe Lang
Allows project to be changed from the bulk edit form....
r8416 else
Jean-Philippe Lang
Fixed that bulk copy raises an error on validation failure (#13943)....
r11558 unsaved_issues << orig_issue
Eric Davis
Refactor: extract #bulk_update method from IssuesController#bulk_edit....
r3923 end
end
Jean-Philippe Lang
Allows project to be changed from the bulk edit form....
r8416
Jean-Philippe Lang
Display the bulk edit form with error messages when some issues can not be saved (#13943)....
r11556 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)
Jean-Philippe Lang
Allows project to be changed from the bulk edit form....
r8416 end
else
Jean-Philippe Lang
Display the bulk edit form with error messages when some issues can not be saved (#13943)....
r11556 @saved_issues = @issues
@unsaved_issues = unsaved_issues
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 @issues = Issue.visible.where(:id => @unsaved_issues.map(&:id)).to_a
Jean-Philippe Lang
Display the bulk edit form with error messages when some issues can not be saved (#13943)....
r11556 bulk_edit
render :action => 'bulk_edit'
Jean-Philippe Lang
Allows project to be changed from the bulk edit form....
r8416 end
Eric Davis
Refactor: extract #bulk_update method from IssuesController#bulk_edit....
r3923 end
Toshi MARUYAMA
remove trailing white-spaces from issues controller source....
r5703
Jean-Philippe Lang
data locking for issues...
r21 def destroy
Jean-Philippe Lang
Adds permission to edit and delete issues by role/tracker (#285)....
r15084 raise Unauthorized unless @issues.all?(&:deletable?)
Jean-Philippe Lang
Cleanup of finders with :conditions option....
r11733 @hours = TimeEntry.where(:issue_id => @issues.map(&:id)).sum(:hours).to_f
Jean-Philippe Lang
Let the user choose when deleting issues with reported hours (closes #734, #71):...
r1168 if @hours > 0
case params[:todo]
when 'destroy'
# nothing to do
when 'nullify'
Toshi MARUYAMA
Rails4: replace deprecated Relation#update_all at IssuesController...
r12305 TimeEntry.where(['issue_id IN (?)', @issues]).update_all('issue_id = NULL')
Jean-Philippe Lang
Let the user choose when deleting issues with reported hours (closes #734, #71):...
r1168 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
Toshi MARUYAMA
Rails4: replace deprecated Relation#update_all at IssuesController...
r12305 TimeEntry.where(['issue_id IN (?)', @issues]).
update_all("issue_id = #{reassign_to.id}")
Jean-Philippe Lang
Let the user choose when deleting issues with reported hours (closes #734, #71):...
r1168 end
else
Jean-Philippe Lang
Converts IssuesController to use the new API template system and makes xml/json responses consistent (#6136)....
r4344 # display the destroy form if it's a user request
return unless api_request?
Jean-Philippe Lang
Let the user choose when deleting issues with reported hours (closes #734, #71):...
r1168 end
end
Jean-Philippe Lang
Fixed: bulk destroying parent and child issues raises a stale object error (#7920)....
r5163 @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
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 respond_to do |format|
Jean-Philippe Lang
Renamed #_issues_path to #_project_issues_path....
r10846 format.html { redirect_back_or_default _project_issues_path(@project) }
Jean-Philippe Lang
Fixed that 200 API responses have a body containing one space (#11388)....
r9792 format.api { render_api_ok }
Jean-Philippe Lang
XML REST API for issues that provides CRUD operations for Issues (#1214)....
r3196 end
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 end
Jean-Philippe Lang
Restores the "New issue" tab in the project menu and makes it optional (#6204)....
r15025 # Overrides Redmine::MenuManager::MenuController::ClassMethods for
# when the "New issue" tab is enabled
def current_menu_item
if Setting.new_project_issue_tab_enabled? && [:new, :create].include?(action_name.to_sym)
:new_issue
else
super
end
end
Jean-Philippe Lang
Code cleanup....
r10677 private
Toshi MARUYAMA
remove trailing white-spaces from issues controller source....
r5703
Jean-Philippe Lang
Adds previous/next links to issue (#2850)....
r8368 def retrieve_previous_and_next_issue_ids
Jean-Philippe Lang
Previous/next links may be lost after editing the issue (#14462)....
r14871 if params[:prev_issue_id].present? || params[:next_issue_id].present?
@prev_issue_id = params[:prev_issue_id].presence.try(:to_i)
@next_issue_id = params[:next_issue_id].presence.try(:to_i)
@issue_position = params[:issue_position].presence.try(:to_i)
@issue_count = params[:issue_count].presence.try(:to_i)
else
retrieve_query_from_session
if @query
sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
sort_update(@query.sortable_columns, 'issues_index_sort')
limit = 500
issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
if (idx = issue_ids.index(@issue.id)) && idx < limit
if issue_ids.size < 500
@issue_position = idx + 1
@issue_count = issue_ids.size
end
@prev_issue_id = issue_ids[idx - 1] if idx > 0
@next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
Jean-Philippe Lang
Display the position of the current issue in the query results....
r8543 end
Jean-Philippe Lang
Adds previous/next links to issue (#2850)....
r8368 end
end
end
Jean-Philippe Lang
Previous/next links may be lost after editing the issue (#14462)....
r14871 def previous_and_next_issue_ids_params
{
:prev_issue_id => params[:prev_issue_id],
:next_issue_id => params[:next_issue_id],
:issue_position => params[:issue_position],
:issue_count => params[:issue_count]
}.reject {|k,v| k.blank?}
end
Eric Davis
Refactor: Extracted the duplication from the last commit into a new method...
r3373 # Used by #edit and #update to set some common instance variables
# from the params
def update_issue_from_params
Jean-Philippe Lang
Initialize TimeEntry with issue and project for the issue edit form....
r5154 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 if params[:time_entry]
Jean-Philippe Lang
Use #safe_attributes= for building new time entry....
r14405 @time_entry.safe_attributes = params[:time_entry]
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 end
Toshi MARUYAMA
remove trailing white-spaces from issues controller source....
r5703
Jean-Philippe Lang
Private issue notes (#1554)....
r10336 @issue.init_journal(User.current)
Jean-Philippe Lang
Better handling of issue update conflicts (#8691)....
r8654
issue_attributes = params[:issue]
if issue_attributes && params[:conflict_resolution]
case params[:conflict_resolution]
when 'overwrite'
issue_attributes = issue_attributes.dup
issue_attributes.delete(:lock_version)
when 'add_notes'
Jean-Philippe Lang
Private note flag disappears in issue update conflict (#21551)....
r14602 issue_attributes = issue_attributes.slice(:notes, :private_notes)
Jean-Philippe Lang
Better handling of issue update conflicts (#8691)....
r8654 when 'cancel'
redirect_to issue_path(@issue)
return false
end
end
@issue.safe_attributes = issue_attributes
Jean-Philippe Lang
Fixed that improper statuses are proposed when changing status before tracker on the issue form (#10619)....
r9244 @priorities = IssuePriority.active
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
Jean-Philippe Lang
Better handling of issue update conflicts (#8691)....
r8654 true
Eric Davis
Refactor: Extracted the duplication from the last commit into a new method...
r3373 end
Eric Davis
Refactor: Extract method for setting the flash on bulk issue saves....
r3446
Jean-Philippe Lang
Updated code comments....
r13618 # Used by #new and #create to build a new issue from the params
# The new issue will be copied from an existing one if copy_from parameter is given
Eric Davis
Refactor: Extract duplicated code to a new method....
r3575 def build_new_issue_from_params
Jean-Philippe Lang
Removed IssuesController#update_form action, use #new and #edit instead....
r13615 @issue = Issue.new
if params[:copy_from]
begin
@issue.init_journal(User.current)
@copy_from = Issue.visible.find(params[:copy_from])
unless User.current.allowed_to?(:copy_issues, @copy_from.project)
raise ::Unauthorized
Jean-Philippe Lang
Adds an option of the copy form to enable/disable attachments copy (#3055)....
r8557 end
Jean-Philippe Lang
Removed IssuesController#update_form action, use #new and #edit instead....
r13615 @link_copy = link_copy?(params[:link_copy]) || request.get?
@copy_attachments = params[:copy_attachments].present? || request.get?
@copy_subtasks = params[:copy_subtasks].present? || request.get?
@issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks, :link => @link_copy)
Jean-Philippe Lang
Copying an issue does not copy parent task id (#12893)....
r14676 @issue.parent_issue_id = @copy_from.parent_id
Jean-Philippe Lang
Removed IssuesController#update_form action, use #new and #edit instead....
r13615 rescue ActiveRecord::RecordNotFound
render_404
return
Jean-Philippe Lang
Fixed an error when trying to copy an issue that does not exist....
r8550 end
Eric Davis
Refactor: merge IssuesController#update_form into IssuesController#new...
r3897 end
Jean-Philippe Lang
Removed IssuesController#update_form action, use #new and #edit instead....
r13615 @issue.project = @project
Jean-Philippe Lang
Implements /issues/new form for creating issues outside a project (#1003)....
r13617 if request.get?
@issue.project ||= @issue.allowed_target_projects.first
end
Jean-Philippe Lang
Removed IssuesController#update_form action, use #new and #edit instead....
r13615 @issue.author ||= User.current
Jean-Philippe Lang
Replace Date.today with User.current.today (#22320)....
r14997 @issue.start_date ||= User.current.today if Setting.default_issue_start_date_to_creation_date?
Toshi MARUYAMA
remove trailing white-spaces from issues controller source....
r5703
Jean-Philippe Lang
Makes new issue initial status settable in workflow (#5816)....
r14076 attrs = (params[:issue] || {}).deep_dup
if action_name == 'new' && params[:was_default_status] == attrs[:status_id]
attrs.delete(:status_id)
Jean-Philippe Lang
Default status per tracker (#5991)....
r13153 end
Jean-Philippe Lang
Set default project version after selecting a different project on the new issue form (#1828)....
r14406 if action_name == 'new' && params[:form_update_triggered_by] == 'issue_project_id'
# Discard submitted version when changing the project on the issue form
# so we can use the default version for the new project
attrs.delete(:fixed_version_id)
end
Jean-Philippe Lang
Makes new issue initial status settable in workflow (#5816)....
r14076 @issue.safe_attributes = attrs
Jean-Philippe Lang
Implements /issues/new form for creating issues outside a project (#1003)....
r13617 if @issue.project
Jean-Philippe Lang
Adds Issue#allowed_target_trackers (#7839)....
r15048 @issue.tracker ||= @issue.allowed_target_trackers.first
Jean-Philippe Lang
Implements /issues/new form for creating issues outside a project (#1003)....
r13617 if @issue.tracker.nil?
Jean-Philippe Lang
Limit trackers for new issue to certain roles (#7839)....
r15082 if @issue.project.trackers.any?
# None of the project trackers is allowed to the user
render_error :message => l(:error_no_tracker_allowed_for_new_issue_in_project), :status => 403
else
# Project has no trackers
render_error l(:error_no_tracker_in_project)
end
Jean-Philippe Lang
Implements /issues/new form for creating issues outside a project (#1003)....
r13617 return false
end
if @issue.status.nil?
render_error l(:error_no_default_issue_status)
return false
end
Jean-Philippe Lang
Default status per tracker (#5991)....
r13153 end
Jean-Philippe Lang
Use safe_attributes for issue watchers assignment....
r8077
Jean-Baptiste Barth
Do not show inactive issue priorities where not necessary (#8573)....
r5950 @priorities = IssuePriority.active
Jean-Philippe Lang
Makes new issue initial status settable in workflow (#5816)....
r14076 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
Eric Davis
Refactor: Extract duplicated code to a new method....
r3575 end
Eric Davis
Refactor: extract method in bulk_update....
r3926 def parse_params_for_bulk_issue_attributes(params)
attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
Jean-Philippe Lang
Let non required list/user/version custom fields to be set to blank when bulk editing (#10605)....
r9215 if custom = attributes[:custom_field_values]
custom.reject! {|k,v| v.blank?}
custom.keys.each do |k|
if custom[k].is_a?(Array)
custom[k] << '' if custom[k].delete('__none__')
else
custom[k] = '' if custom[k] == '__none__'
end
end
end
Eric Davis
Refactor: extract method in bulk_update....
r3926 attributes
end
Jean-Philippe Lang
Fixed that controller_issues_edit_before/after_save hooks have no controller context (#15044)....
r11989
# Saves @issue and a time_entry from the parameters
def save_issue_with_child_records
Issue.transaction do
if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, @issue.project)
time_entry = @time_entry || TimeEntry.new
time_entry.project = @issue.project
time_entry.issue = @issue
time_entry.user = User.current
time_entry.spent_on = User.current.today
time_entry.attributes = params[:time_entry]
@issue.time_entries << time_entry
end
call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
if @issue.save
call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
else
raise ActiveRecord::Rollback
end
end
end
Jean-Philippe Lang
Configurable behavour for linking issues on copy (#18500)....
r13286
Jean-Philippe Lang
Updated code comments....
r13618 # Returns true if the issue copy should be linked
# to the original issue
Jean-Philippe Lang
Configurable behavour for linking issues on copy (#18500)....
r13286 def link_copy?(param)
case Setting.link_copied_issue
when 'yes'
true
when 'no'
false
when 'ask'
param == '1'
end
end
Jean-Philippe Lang
Implements /issues/new form for creating issues outside a project (#1003)....
r13617
# Redirects user after a successful issue creation
def redirect_after_create
if params[:continue]
attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
if params[:project_id]
redirect_to new_project_issue_path(@issue.project, :issue => attrs)
else
attrs.merge! :project_id => @issue.project_id
redirect_to new_issue_path(:issue => attrs)
end
else
redirect_to issue_path(@issue)
end
end
Jean-Philippe Lang
Initial commit...
r2 end