##// END OF EJS Templates
Fixed: wiki and changeset links not displayed when previewing issue description or notes....
Jean-Philippe Lang -
r1124:30a7314b861f
parent child
Show More
@@ -1,383 +1,383
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class IssuesController < ApplicationController
18 class IssuesController < ApplicationController
19 layout 'base'
19 layout 'base'
20 menu_item :new_issue, :only => :new
20 menu_item :new_issue, :only => :new
21
21
22 before_filter :find_issue, :only => [:show, :edit, :destroy_attachment]
22 before_filter :find_issue, :only => [:show, :edit, :destroy_attachment]
23 before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
23 before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
24 before_filter :find_project, :only => [:new, :update_form]
24 before_filter :find_project, :only => [:new, :update_form, :preview]
25 before_filter :authorize, :except => [:index, :changes, :preview, :update_form, :context_menu]
25 before_filter :authorize, :except => [:index, :changes, :preview, :update_form, :context_menu]
26 before_filter :find_optional_project, :only => [:index, :changes]
26 before_filter :find_optional_project, :only => [:index, :changes]
27 accept_key_auth :index, :changes
27 accept_key_auth :index, :changes
28
28
29 cache_sweeper :issue_sweeper, :only => [ :new, :edit, :bulk_edit, :destroy ]
29 cache_sweeper :issue_sweeper, :only => [ :new, :edit, :bulk_edit, :destroy ]
30
30
31 helper :journals
31 helper :journals
32 helper :projects
32 helper :projects
33 include ProjectsHelper
33 include ProjectsHelper
34 helper :custom_fields
34 helper :custom_fields
35 include CustomFieldsHelper
35 include CustomFieldsHelper
36 helper :ifpdf
36 helper :ifpdf
37 include IfpdfHelper
37 include IfpdfHelper
38 helper :issue_relations
38 helper :issue_relations
39 include IssueRelationsHelper
39 include IssueRelationsHelper
40 helper :watchers
40 helper :watchers
41 include WatchersHelper
41 include WatchersHelper
42 helper :attachments
42 helper :attachments
43 include AttachmentsHelper
43 include AttachmentsHelper
44 helper :queries
44 helper :queries
45 helper :sort
45 helper :sort
46 include SortHelper
46 include SortHelper
47 include IssuesHelper
47 include IssuesHelper
48
48
49 def index
49 def index
50 sort_init "#{Issue.table_name}.id", "desc"
50 sort_init "#{Issue.table_name}.id", "desc"
51 sort_update
51 sort_update
52 retrieve_query
52 retrieve_query
53 if @query.valid?
53 if @query.valid?
54 limit = %w(pdf csv).include?(params[:format]) ? Setting.issues_export_limit.to_i : per_page_option
54 limit = %w(pdf csv).include?(params[:format]) ? Setting.issues_export_limit.to_i : per_page_option
55 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
55 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
56 @issue_pages = Paginator.new self, @issue_count, limit, params['page']
56 @issue_pages = Paginator.new self, @issue_count, limit, params['page']
57 @issues = Issue.find :all, :order => sort_clause,
57 @issues = Issue.find :all, :order => sort_clause,
58 :include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ],
58 :include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ],
59 :conditions => @query.statement,
59 :conditions => @query.statement,
60 :limit => limit,
60 :limit => limit,
61 :offset => @issue_pages.current.offset
61 :offset => @issue_pages.current.offset
62 respond_to do |format|
62 respond_to do |format|
63 format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
63 format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
64 format.atom { render_feed(@issues, :title => l(:label_issue_plural)) }
64 format.atom { render_feed(@issues, :title => l(:label_issue_plural)) }
65 format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') }
65 format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') }
66 format.pdf { send_data(render(:template => 'issues/index.rfpdf', :layout => false), :type => 'application/pdf', :filename => 'export.pdf') }
66 format.pdf { send_data(render(:template => 'issues/index.rfpdf', :layout => false), :type => 'application/pdf', :filename => 'export.pdf') }
67 end
67 end
68 else
68 else
69 # Send html if the query is not valid
69 # Send html if the query is not valid
70 render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
70 render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
71 end
71 end
72 end
72 end
73
73
74 def changes
74 def changes
75 sort_init "#{Issue.table_name}.id", "desc"
75 sort_init "#{Issue.table_name}.id", "desc"
76 sort_update
76 sort_update
77 retrieve_query
77 retrieve_query
78 if @query.valid?
78 if @query.valid?
79 @changes = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ],
79 @changes = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ],
80 :conditions => @query.statement,
80 :conditions => @query.statement,
81 :limit => 25,
81 :limit => 25,
82 :order => "#{Journal.table_name}.created_on DESC"
82 :order => "#{Journal.table_name}.created_on DESC"
83 end
83 end
84 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
84 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
85 render :layout => false, :content_type => 'application/atom+xml'
85 render :layout => false, :content_type => 'application/atom+xml'
86 end
86 end
87
87
88 def show
88 def show
89 @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) }
89 @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) }
90 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
90 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
91 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
91 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
92 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
92 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
93 @activities = Enumeration::get_values('ACTI')
93 @activities = Enumeration::get_values('ACTI')
94 @priorities = Enumeration::get_values('IPRI')
94 @priorities = Enumeration::get_values('IPRI')
95 respond_to do |format|
95 respond_to do |format|
96 format.html { render :template => 'issues/show.rhtml' }
96 format.html { render :template => 'issues/show.rhtml' }
97 format.pdf { send_data(render(:template => 'issues/show.rfpdf', :layout => false), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
97 format.pdf { send_data(render(:template => 'issues/show.rfpdf', :layout => false), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
98 end
98 end
99 end
99 end
100
100
101 # Add a new issue
101 # Add a new issue
102 # The new issue will be created from an existing one if copy_from parameter is given
102 # The new issue will be created from an existing one if copy_from parameter is given
103 def new
103 def new
104 @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
104 @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
105 @issue.project = @project
105 @issue.project = @project
106 @issue.author = User.current
106 @issue.author = User.current
107 @issue.tracker ||= @project.trackers.find(params[:tracker_id] ? params[:tracker_id] : :first)
107 @issue.tracker ||= @project.trackers.find(params[:tracker_id] ? params[:tracker_id] : :first)
108 if @issue.tracker.nil?
108 if @issue.tracker.nil?
109 flash.now[:error] = 'No tracker is associated to this project. Please check the Project settings.'
109 flash.now[:error] = 'No tracker is associated to this project. Please check the Project settings.'
110 render :nothing => true, :layout => true
110 render :nothing => true, :layout => true
111 return
111 return
112 end
112 end
113
113
114 default_status = IssueStatus.default
114 default_status = IssueStatus.default
115 unless default_status
115 unless default_status
116 flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
116 flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
117 render :nothing => true, :layout => true
117 render :nothing => true, :layout => true
118 return
118 return
119 end
119 end
120 @issue.status = default_status
120 @issue.status = default_status
121 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker))
121 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker))
122
122
123 if request.get? || request.xhr?
123 if request.get? || request.xhr?
124 @issue.start_date ||= Date.today
124 @issue.start_date ||= Date.today
125 @custom_values = @issue.custom_values.empty? ?
125 @custom_values = @issue.custom_values.empty? ?
126 @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
126 @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
127 @issue.custom_values
127 @issue.custom_values
128 else
128 else
129 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
129 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
130 # Check that the user is allowed to apply the requested status
130 # Check that the user is allowed to apply the requested status
131 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
131 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
132 @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]) }
132 @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]) }
133 @issue.custom_values = @custom_values
133 @issue.custom_values = @custom_values
134 if @issue.save
134 if @issue.save
135 attach_files(@issue, params[:attachments])
135 attach_files(@issue, params[:attachments])
136 flash[:notice] = l(:notice_successful_create)
136 flash[:notice] = l(:notice_successful_create)
137 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
137 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
138 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
138 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
139 return
139 return
140 end
140 end
141 end
141 end
142 @priorities = Enumeration::get_values('IPRI')
142 @priorities = Enumeration::get_values('IPRI')
143 render :layout => !request.xhr?
143 render :layout => !request.xhr?
144 end
144 end
145
145
146 # Attributes that can be updated on workflow transition (without :edit permission)
146 # Attributes that can be updated on workflow transition (without :edit permission)
147 # TODO: make it configurable (at least per role)
147 # TODO: make it configurable (at least per role)
148 UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
148 UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
149
149
150 def edit
150 def edit
151 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
151 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
152 @activities = Enumeration::get_values('ACTI')
152 @activities = Enumeration::get_values('ACTI')
153 @priorities = Enumeration::get_values('IPRI')
153 @priorities = Enumeration::get_values('IPRI')
154 @custom_values = []
154 @custom_values = []
155 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
155 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
156
156
157 @notes = params[:notes]
157 @notes = params[:notes]
158 journal = @issue.init_journal(User.current, @notes)
158 journal = @issue.init_journal(User.current, @notes)
159 # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
159 # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
160 if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
160 if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
161 attrs = params[:issue].dup
161 attrs = params[:issue].dup
162 attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
162 attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
163 attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
163 attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
164 @issue.attributes = attrs
164 @issue.attributes = attrs
165 end
165 end
166
166
167 if request.get?
167 if request.get?
168 @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) }
168 @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) }
169 else
169 else
170 # Update custom fields if user has :edit permission
170 # Update custom fields if user has :edit permission
171 if @edit_allowed && params[:custom_fields]
171 if @edit_allowed && params[:custom_fields]
172 @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]) }
172 @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]) }
173 @issue.custom_values = @custom_values
173 @issue.custom_values = @custom_values
174 end
174 end
175 attachments = attach_files(@issue, params[:attachments])
175 attachments = attach_files(@issue, params[:attachments])
176 attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
176 attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
177 if @issue.save
177 if @issue.save
178 # Log spend time
178 # Log spend time
179 if current_role.allowed_to?(:log_time)
179 if current_role.allowed_to?(:log_time)
180 @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
180 @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
181 @time_entry.attributes = params[:time_entry]
181 @time_entry.attributes = params[:time_entry]
182 @time_entry.save
182 @time_entry.save
183 end
183 end
184 if !journal.new_record?
184 if !journal.new_record?
185 # Only send notification if something was actually changed
185 # Only send notification if something was actually changed
186 flash[:notice] = l(:notice_successful_update)
186 flash[:notice] = l(:notice_successful_update)
187 Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
187 Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
188 end
188 end
189 redirect_to(params[:back_to] || {:action => 'show', :id => @issue})
189 redirect_to(params[:back_to] || {:action => 'show', :id => @issue})
190 end
190 end
191 end
191 end
192 rescue ActiveRecord::StaleObjectError
192 rescue ActiveRecord::StaleObjectError
193 # Optimistic locking exception
193 # Optimistic locking exception
194 flash.now[:error] = l(:notice_locking_conflict)
194 flash.now[:error] = l(:notice_locking_conflict)
195 end
195 end
196
196
197 # Bulk edit a set of issues
197 # Bulk edit a set of issues
198 def bulk_edit
198 def bulk_edit
199 if request.post?
199 if request.post?
200 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
200 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
201 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
201 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
202 assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
202 assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
203 category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
203 category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
204 fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
204 fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
205
205
206 unsaved_issue_ids = []
206 unsaved_issue_ids = []
207 @issues.each do |issue|
207 @issues.each do |issue|
208 journal = issue.init_journal(User.current, params[:notes])
208 journal = issue.init_journal(User.current, params[:notes])
209 issue.priority = priority if priority
209 issue.priority = priority if priority
210 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
210 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
211 issue.category = category if category
211 issue.category = category if category
212 issue.fixed_version = fixed_version if fixed_version
212 issue.fixed_version = fixed_version if fixed_version
213 issue.start_date = params[:start_date] unless params[:start_date].blank?
213 issue.start_date = params[:start_date] unless params[:start_date].blank?
214 issue.due_date = params[:due_date] unless params[:due_date].blank?
214 issue.due_date = params[:due_date] unless params[:due_date].blank?
215 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
215 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
216 # Don't save any change to the issue if the user is not authorized to apply the requested status
216 # Don't save any change to the issue if the user is not authorized to apply the requested status
217 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
217 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
218 # Send notification for each issue (if changed)
218 # Send notification for each issue (if changed)
219 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
219 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
220 else
220 else
221 # Keep unsaved issue ids to display them in flash error
221 # Keep unsaved issue ids to display them in flash error
222 unsaved_issue_ids << issue.id
222 unsaved_issue_ids << issue.id
223 end
223 end
224 end
224 end
225 if unsaved_issue_ids.empty?
225 if unsaved_issue_ids.empty?
226 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
226 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
227 else
227 else
228 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
228 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
229 end
229 end
230 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
230 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
231 return
231 return
232 end
232 end
233 # Find potential statuses the user could be allowed to switch issues to
233 # Find potential statuses the user could be allowed to switch issues to
234 @available_statuses = Workflow.find(:all, :include => :new_status,
234 @available_statuses = Workflow.find(:all, :include => :new_status,
235 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
235 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
236 end
236 end
237
237
238 def move
238 def move
239 @allowed_projects = []
239 @allowed_projects = []
240 # find projects to which the user is allowed to move the issue
240 # find projects to which the user is allowed to move the issue
241 if User.current.admin?
241 if User.current.admin?
242 # admin is allowed to move issues to any active (visible) project
242 # admin is allowed to move issues to any active (visible) project
243 @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
243 @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
244 else
244 else
245 User.current.memberships.each {|m| @allowed_projects << m.project if m.role.allowed_to?(:move_issues)}
245 User.current.memberships.each {|m| @allowed_projects << m.project if m.role.allowed_to?(:move_issues)}
246 end
246 end
247 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
247 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
248 @target_project ||= @project
248 @target_project ||= @project
249 @trackers = @target_project.trackers
249 @trackers = @target_project.trackers
250 if request.post?
250 if request.post?
251 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
251 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
252 unsaved_issue_ids = []
252 unsaved_issue_ids = []
253 @issues.each do |issue|
253 @issues.each do |issue|
254 unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker)
254 unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker)
255 end
255 end
256 if unsaved_issue_ids.empty?
256 if unsaved_issue_ids.empty?
257 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
257 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
258 else
258 else
259 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
259 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
260 end
260 end
261 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
261 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
262 return
262 return
263 end
263 end
264 render :layout => false if request.xhr?
264 render :layout => false if request.xhr?
265 end
265 end
266
266
267 def destroy
267 def destroy
268 @issues.each(&:destroy)
268 @issues.each(&:destroy)
269 redirect_to :action => 'index', :project_id => @project
269 redirect_to :action => 'index', :project_id => @project
270 end
270 end
271
271
272 def destroy_attachment
272 def destroy_attachment
273 a = @issue.attachments.find(params[:attachment_id])
273 a = @issue.attachments.find(params[:attachment_id])
274 a.destroy
274 a.destroy
275 journal = @issue.init_journal(User.current)
275 journal = @issue.init_journal(User.current)
276 journal.details << JournalDetail.new(:property => 'attachment',
276 journal.details << JournalDetail.new(:property => 'attachment',
277 :prop_key => a.id,
277 :prop_key => a.id,
278 :old_value => a.filename)
278 :old_value => a.filename)
279 journal.save
279 journal.save
280 redirect_to :action => 'show', :id => @issue
280 redirect_to :action => 'show', :id => @issue
281 end
281 end
282
282
283 def context_menu
283 def context_menu
284 @issues = Issue.find_all_by_id(params[:ids], :include => :project)
284 @issues = Issue.find_all_by_id(params[:ids], :include => :project)
285 if (@issues.size == 1)
285 if (@issues.size == 1)
286 @issue = @issues.first
286 @issue = @issues.first
287 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
287 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
288 @assignables = @issue.assignable_users
288 @assignables = @issue.assignable_users
289 @assignables << @issue.assigned_to if @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
289 @assignables << @issue.assigned_to if @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
290 end
290 end
291 projects = @issues.collect(&:project).compact.uniq
291 projects = @issues.collect(&:project).compact.uniq
292 @project = projects.first if projects.size == 1
292 @project = projects.first if projects.size == 1
293
293
294 @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
294 @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
295 :update => (@issue && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && !@allowed_statuses.empty?))),
295 :update => (@issue && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && !@allowed_statuses.empty?))),
296 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
296 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
297 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
297 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
298 :delete => (@project && User.current.allowed_to?(:delete_issues, @project))
298 :delete => (@project && User.current.allowed_to?(:delete_issues, @project))
299 }
299 }
300
300
301 @priorities = Enumeration.get_values('IPRI').reverse
301 @priorities = Enumeration.get_values('IPRI').reverse
302 @statuses = IssueStatus.find(:all, :order => 'position')
302 @statuses = IssueStatus.find(:all, :order => 'position')
303 @back = request.env['HTTP_REFERER']
303 @back = request.env['HTTP_REFERER']
304
304
305 render :layout => false
305 render :layout => false
306 end
306 end
307
307
308 def update_form
308 def update_form
309 @issue = Issue.new(params[:issue])
309 @issue = Issue.new(params[:issue])
310 render :action => :new, :layout => false
310 render :action => :new, :layout => false
311 end
311 end
312
312
313 def preview
313 def preview
314 issue = Issue.find_by_id(params[:id])
314 issue = @project.issues.find_by_id(params[:id])
315 @attachements = issue.attachments if issue
315 @attachements = issue.attachments if issue
316 @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil)
316 @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil)
317 render :partial => 'common/preview'
317 render :partial => 'common/preview'
318 end
318 end
319
319
320 private
320 private
321 def find_issue
321 def find_issue
322 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
322 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
323 @project = @issue.project
323 @project = @issue.project
324 rescue ActiveRecord::RecordNotFound
324 rescue ActiveRecord::RecordNotFound
325 render_404
325 render_404
326 end
326 end
327
327
328 # Filter for bulk operations
328 # Filter for bulk operations
329 def find_issues
329 def find_issues
330 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
330 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
331 raise ActiveRecord::RecordNotFound if @issues.empty?
331 raise ActiveRecord::RecordNotFound if @issues.empty?
332 projects = @issues.collect(&:project).compact.uniq
332 projects = @issues.collect(&:project).compact.uniq
333 if projects.size == 1
333 if projects.size == 1
334 @project = projects.first
334 @project = projects.first
335 else
335 else
336 # TODO: let users bulk edit/move/destroy issues from different projects
336 # TODO: let users bulk edit/move/destroy issues from different projects
337 render_error 'Can not bulk edit/move/destroy issues from different projects' and return false
337 render_error 'Can not bulk edit/move/destroy issues from different projects' and return false
338 end
338 end
339 rescue ActiveRecord::RecordNotFound
339 rescue ActiveRecord::RecordNotFound
340 render_404
340 render_404
341 end
341 end
342
342
343 def find_project
343 def find_project
344 @project = Project.find(params[:project_id])
344 @project = Project.find(params[:project_id])
345 rescue ActiveRecord::RecordNotFound
345 rescue ActiveRecord::RecordNotFound
346 render_404
346 render_404
347 end
347 end
348
348
349 def find_optional_project
349 def find_optional_project
350 return true unless params[:project_id]
350 return true unless params[:project_id]
351 @project = Project.find(params[:project_id])
351 @project = Project.find(params[:project_id])
352 authorize
352 authorize
353 rescue ActiveRecord::RecordNotFound
353 rescue ActiveRecord::RecordNotFound
354 render_404
354 render_404
355 end
355 end
356
356
357 # Retrieve query from session or build a new query
357 # Retrieve query from session or build a new query
358 def retrieve_query
358 def retrieve_query
359 if !params[:query_id].blank?
359 if !params[:query_id].blank?
360 @query = Query.find(params[:query_id], :conditions => {:project_id => (@project ? @project.id : nil)})
360 @query = Query.find(params[:query_id], :conditions => {:project_id => (@project ? @project.id : nil)})
361 session[:query] = {:id => @query.id, :project_id => @query.project_id}
361 session[:query] = {:id => @query.id, :project_id => @query.project_id}
362 else
362 else
363 if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
363 if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
364 # Give it a name, required to be valid
364 # Give it a name, required to be valid
365 @query = Query.new(:name => "_")
365 @query = Query.new(:name => "_")
366 @query.project = @project
366 @query.project = @project
367 if params[:fields] and params[:fields].is_a? Array
367 if params[:fields] and params[:fields].is_a? Array
368 params[:fields].each do |field|
368 params[:fields].each do |field|
369 @query.add_filter(field, params[:operators][field], params[:values][field])
369 @query.add_filter(field, params[:operators][field], params[:values][field])
370 end
370 end
371 else
371 else
372 @query.available_filters.keys.each do |field|
372 @query.available_filters.keys.each do |field|
373 @query.add_short_filter(field, params[field]) if params[field]
373 @query.add_short_filter(field, params[field]) if params[field]
374 end
374 end
375 end
375 end
376 session[:query] = {:project_id => @query.project_id, :filters => @query.filters}
376 session[:query] = {:project_id => @query.project_id, :filters => @query.filters}
377 else
377 else
378 @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
378 @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
379 @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters])
379 @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters])
380 end
380 end
381 end
381 end
382 end
382 end
383 end
383 end
@@ -1,40 +1,41
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class JournalsController < ApplicationController
18 class JournalsController < ApplicationController
19 layout 'base'
19 layout 'base'
20 before_filter :find_journal
20 before_filter :find_journal
21
21
22 def edit
22 def edit
23 if request.post?
23 if request.post?
24 @journal.update_attributes(:notes => params[:notes]) if params[:notes]
24 @journal.update_attributes(:notes => params[:notes]) if params[:notes]
25 respond_to do |format|
25 respond_to do |format|
26 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
26 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
27 format.js { render :action => 'update' }
27 format.js { render :action => 'update' }
28 end
28 end
29 return
29 return
30 end
30 end
31 end
31 end
32
32
33 private
33 private
34 def find_journal
34 def find_journal
35 @journal = Journal.find(params[:id])
35 @journal = Journal.find(params[:id])
36 render_403 and return false unless @journal.editable_by?(User.current)
36 render_403 and return false unless @journal.editable_by?(User.current)
37 @project = @journal.journalized.project
37 rescue ActiveRecord::RecordNotFound
38 rescue ActiveRecord::RecordNotFound
38 render_404
39 render_404
39 end
40 end
40 end
41 end
@@ -1,39 +1,39
1 <% labelled_tabular_form_for :issue, @issue,
1 <% labelled_tabular_form_for :issue, @issue,
2 :url => {:action => 'edit', :id => @issue},
2 :url => {:action => 'edit', :id => @issue},
3 :html => {:id => 'issue-form',
3 :html => {:id => 'issue-form',
4 :multipart => true} do |f| %>
4 :multipart => true} do |f| %>
5 <%= error_messages_for 'issue' %>
5 <%= error_messages_for 'issue' %>
6 <div class="box">
6 <div class="box">
7 <% if @edit_allowed || !@allowed_statuses.empty? %>
7 <% if @edit_allowed || !@allowed_statuses.empty? %>
8 <fieldset>
8 <fieldset>
9 <legend><%= l(:label_change_properties) %>
9 <legend><%= l(:label_change_properties) %>
10 <% if !@issue.new_record? && !@issue.errors.any? && @edit_allowed %>
10 <% if !@issue.new_record? && !@issue.errors.any? && @edit_allowed %>
11 <small>(<%= link_to l(:label_more), {}, :onclick => 'Effect.toggle("issue_descr_fields", "appear", {duration:0.3}); return false;' %>)</small>
11 <small>(<%= link_to l(:label_more), {}, :onclick => 'Effect.toggle("issue_descr_fields", "appear", {duration:0.3}); return false;' %>)</small>
12 <% end %>
12 <% end %>
13 </legend>
13 </legend>
14 <%= render :partial => (@edit_allowed ? 'form' : 'form_update'), :locals => {:f => f} %>
14 <%= render :partial => (@edit_allowed ? 'form' : 'form_update'), :locals => {:f => f} %>
15 </fieldset>
15 </fieldset>
16 <% end %>
16 <% end %>
17
17
18 <fieldset><legend><%= l(:field_notes) %></legend>
18 <fieldset><legend><%= l(:field_notes) %></legend>
19 <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %>
19 <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %>
20 <%= wikitoolbar_for 'notes' %>
20 <%= wikitoolbar_for 'notes' %>
21
21
22 <p id="attachments_p"><label><%=l(:label_attachment_new)%>
22 <p id="attachments_p"><label><%=l(:label_attachment_new)%>
23 <%= image_to_function 'add.png', 'addFileField();return false;' %></label>
23 <%= image_to_function 'add.png', 'addFileField();return false;' %></label>
24 <%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)</em></p>
24 <%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)</em></p>
25 </fieldset>
25 </fieldset>
26 </div>
26 </div>
27
27
28 <%= f.hidden_field :lock_version %>
28 <%= f.hidden_field :lock_version %>
29 <%= submit_tag l(:button_submit) %>
29 <%= submit_tag l(:button_submit) %>
30 <%= link_to_remote l(:label_preview),
30 <%= link_to_remote l(:label_preview),
31 { :url => { :controller => 'issues', :action => 'preview', :id => @issue },
31 { :url => { :controller => 'issues', :action => 'preview', :project_id => @project, :id => @issue },
32 :method => 'post',
32 :method => 'post',
33 :update => 'preview',
33 :update => 'preview',
34 :with => 'Form.serialize("issue-form")',
34 :with => 'Form.serialize("issue-form")',
35 :complete => "Element.scrollTo('preview')"
35 :complete => "Element.scrollTo('preview')"
36 }, :accesskey => accesskey(:preview) %>
36 }, :accesskey => accesskey(:preview) %>
37 <% end %>
37 <% end %>
38
38
39 <div id="preview" class="wiki"></div>
39 <div id="preview" class="wiki"></div>
@@ -1,19 +1,19
1 <h2><%=l(:label_issue_new)%></h2>
1 <h2><%=l(:label_issue_new)%></h2>
2
2
3 <% labelled_tabular_form_for :issue, @issue,
3 <% labelled_tabular_form_for :issue, @issue,
4 :html => {:multipart => true, :id => 'issue-form'} do |f| %>
4 :html => {:multipart => true, :id => 'issue-form'} do |f| %>
5 <%= error_messages_for 'issue' %>
5 <%= error_messages_for 'issue' %>
6 <div class="box">
6 <div class="box">
7 <%= render :partial => 'issues/form', :locals => {:f => f} %>
7 <%= render :partial => 'issues/form', :locals => {:f => f} %>
8 </div>
8 </div>
9 <%= submit_tag l(:button_create) %>
9 <%= submit_tag l(:button_create) %>
10 <%= link_to_remote l(:label_preview),
10 <%= link_to_remote l(:label_preview),
11 { :url => { :controller => 'issues', :action => 'preview', :id => @issue },
11 { :url => { :controller => 'issues', :action => 'preview', :project_id => @project, :id => @issue },
12 :method => 'post',
12 :method => 'post',
13 :update => 'preview',
13 :update => 'preview',
14 :with => "Form.serialize('issue-form')",
14 :with => "Form.serialize('issue-form')",
15 :complete => "Element.scrollTo('preview')"
15 :complete => "Element.scrollTo('preview')"
16 }, :accesskey => accesskey(:preview) %>
16 }, :accesskey => accesskey(:preview) %>
17 <% end %>
17 <% end %>
18
18
19 <div id="preview" class="wiki"></div>
19 <div id="preview" class="wiki"></div>
General Comments 0
You need to be logged in to leave comments. Login now