2006-06-28 22:11:03 +04:00
# redMine - project management software
2007-01-27 18:01:19 +03:00
# Copyright (C) 2006-2007 Jean-Philippe Lang
2006-06-28 22:11:03 +04:00
#
# 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.
class IssuesController < ApplicationController
2006-10-22 18:47:25 +04:00
layout 'base' , :except = > :export_pdf
2006-09-09 20:07:02 +04:00
before_filter :find_project , :authorize
2006-06-28 22:11:03 +04:00
2006-09-09 20:07:02 +04:00
helper :custom_fields
include CustomFieldsHelper
2006-10-22 18:47:25 +04:00
helper :ifpdf
include IfpdfHelper
2006-09-09 20:07:02 +04:00
def show
@status_options = @issue . status . workflows . find ( :all , :include = > :new_status , :conditions = > [ " role_id=? and tracker_id=? " , self . logged_in_user . role_for_project ( @project . id ) , @issue . tracker . id ] ) . collect { | w | w . new_status } if self . logged_in_user
2006-07-29 13:32:58 +04:00
@custom_values = @issue . custom_values . find ( :all , :include = > :custom_field )
2006-11-28 01:31:14 +03:00
@journals_count = @issue . journals . count
@journals = @issue . journals . find ( :all , :include = > [ :user , :details ] , :limit = > 15 , :order = > " journals.created_on desc " )
end
def history
@journals = @issue . journals . find ( :all , :include = > [ :user , :details ] , :order = > " journals.created_on desc " )
@journals_count = @journals . length
2006-10-22 18:47:25 +04:00
end
def export_pdf
@custom_values = @issue . custom_values . find ( :all , :include = > :custom_field )
@options_for_rfpdf || = { }
@options_for_rfpdf [ :file_name ] = " #{ @project . name } _ #{ @issue . long_id } .pdf "
2006-09-09 20:07:02 +04:00
end
2006-06-28 22:11:03 +04:00
2006-09-09 20:07:02 +04:00
def edit
@priorities = Enumeration :: get_values ( 'IPRI' )
if request . get?
@custom_values = @project . custom_fields_for_issues ( @issue . tracker ) . collect { | x | @issue . custom_values . find_by_custom_field_id ( x . id ) || CustomValue . new ( :custom_field = > x , :customized = > @issue ) }
else
begin
2006-11-28 01:31:14 +03:00
@issue . init_journal ( self . logged_in_user )
2006-09-09 20:07:02 +04:00
# Retrieve custom fields and values
@custom_values = @project . custom_fields_for_issues ( @issue . tracker ) . collect { | x | CustomValue . new ( :custom_field = > x , :customized = > @issue , :value = > params [ " custom_fields " ] [ x . id . to_s ] ) }
@issue . custom_values = @custom_values
@issue . attributes = params [ :issue ]
if @issue . save
flash [ :notice ] = l ( :notice_successful_update )
redirect_to :action = > 'show' , :id = > @issue
end
rescue ActiveRecord :: StaleObjectError
# Optimistic locking exception
flash [ :notice ] = l ( :notice_locking_conflict )
end
end
end
2006-10-21 20:07:34 +04:00
def add_note
2006-11-28 01:31:14 +03:00
unless params [ :notes ] . empty?
journal = @issue . init_journal ( self . logged_in_user , params [ :notes ] )
#@history = @issue.histories.build(params[:history])
#@history.author_id = self.logged_in_user.id if self.logged_in_user
#@history.status = @issue.status
if @issue . save
2006-10-21 20:07:34 +04:00
flash [ :notice ] = l ( :notice_successful_update )
2006-12-27 00:33:44 +03:00
Mailer . deliver_issue_edit ( journal ) if Permission . find_by_controller_and_action ( params [ :controller ] , params [ :action ] ) . mail_enabled?
2006-10-21 20:07:34 +04:00
redirect_to :action = > 'show' , :id = > @issue
return
end
end
show
render :action = > 'show'
end
2006-09-09 20:07:02 +04:00
def change_status
2006-11-28 01:31:14 +03:00
#@history = @issue.histories.build(params[:history])
2006-07-29 13:32:58 +04:00
@status_options = @issue . status . workflows . find ( :all , :conditions = > [ " role_id=? and tracker_id=? " , self . logged_in_user . role_for_project ( @project . id ) , @issue . tracker . id ] ) . collect { | w | w . new_status } if self . logged_in_user
2006-11-28 01:31:14 +03:00
@new_status = IssueStatus . find ( params [ :new_status_id ] )
2006-09-09 20:07:02 +04:00
if params [ :confirm ]
begin
2006-11-28 01:31:14 +03:00
#@history.author_id = self.logged_in_user.id if self.logged_in_user
#@issue.status = @history.status
#@issue.fixed_version_id = (params[:issue][:fixed_version_id])
#@issue.assigned_to_id = (params[:issue][:assigned_to_id])
#@issue.done_ratio = (params[:issue][:done_ratio])
#@issue.lock_version = (params[:issue][:lock_version])
2006-11-28 01:45:10 +03:00
journal = @issue . init_journal ( self . logged_in_user , params [ :notes ] )
2006-11-28 01:31:14 +03:00
@issue . status = @new_status
if @issue . update_attributes ( params [ :issue ] )
2006-09-09 20:07:02 +04:00
flash [ :notice ] = l ( :notice_successful_update )
2006-12-27 00:33:44 +03:00
Mailer . deliver_issue_edit ( journal ) if Permission . find_by_controller_and_action ( params [ :controller ] , params [ :action ] ) . mail_enabled?
2006-09-09 20:07:02 +04:00
redirect_to :action = > 'show' , :id = > @issue
end
rescue ActiveRecord :: StaleObjectError
# Optimistic locking exception
flash [ :notice ] = l ( :notice_locking_conflict )
end
end
2006-06-28 22:11:03 +04:00
@assignable_to = @project . members . find ( :all , :include = > :user ) . collect { | m | m . user }
2006-09-09 20:07:02 +04:00
end
def destroy
@issue . destroy
redirect_to :controller = > 'projects' , :action = > 'list_issues' , :id = > @project
end
2006-06-28 22:11:03 +04:00
def add_attachment
2006-11-05 21:38:20 +03:00
# Save the attachments
2007-01-27 18:01:19 +03:00
@attachments = [ ]
params [ :attachments ] . each { | file |
next unless file . size > 0
a = Attachment . create ( :container = > @issue , :file = > file , :author = > logged_in_user )
@attachments << a unless a . new_record?
2006-11-05 21:38:20 +03:00
} if params [ :attachments ] and params [ :attachments ] . is_a? Array
2007-01-27 18:01:19 +03:00
Mailer . deliver_attachments_add ( @attachments ) if ! @attachments . empty? and Permission . find_by_controller_and_action ( params [ :controller ] , params [ :action ] ) . mail_enabled?
2006-06-28 22:11:03 +04:00
redirect_to :action = > 'show' , :id = > @issue
end
def destroy_attachment
@issue . attachments . find ( params [ :attachment_id ] ) . destroy
redirect_to :action = > 'show' , :id = > @issue
end
2006-07-29 13:32:58 +04:00
# Send the file in stream mode
def download
@attachment = @issue . attachments . find ( params [ :attachment_id ] )
send_file @attachment . diskfile , :filename = > @attachment . filename
2006-11-22 01:27:47 +03:00
rescue
2007-01-02 11:47:07 +03:00
render_404
2006-07-29 13:32:58 +04:00
end
2006-06-28 22:11:03 +04:00
private
2006-07-29 13:32:58 +04:00
def find_project
2006-09-09 20:07:02 +04:00
@issue = Issue . find ( params [ :id ] , :include = > [ :project , :tracker , :status , :author , :priority , :category ] )
2006-07-29 13:32:58 +04:00
@project = @issue . project
2006-11-12 21:50:30 +03:00
@html_title = " #{ @project . name } - #{ @issue . tracker . name } # #{ @issue . id } "
2007-01-02 11:47:07 +03:00
rescue ActiveRecord :: RecordNotFound
render_404
2006-07-29 13:32:58 +04:00
end
2006-06-28 22:11:03 +04:00
end