@@ -41,12 +41,11 class ContextMenusController < ApplicationController | |||||
41 | else |
|
41 | else | |
42 | @assignables = @project.assignable_users |
|
42 | @assignables = @project.assignable_users | |
43 | end |
|
43 | end | |
44 | @trackers = @project.trackers |
|
|||
45 | else |
|
44 | else | |
46 | #when multiple projects, we only keep the intersection of each set |
|
45 | #when multiple projects, we only keep the intersection of each set | |
47 | @assignables = @projects.map(&:assignable_users).reduce(:&) |
|
46 | @assignables = @projects.map(&:assignable_users).reduce(:&) | |
48 | @trackers = @projects.map(&:trackers).reduce(:&) |
|
|||
49 | end |
|
47 | end | |
|
48 | @trackers = @projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&) | |||
50 | @versions = @projects.map {|p| p.shared_versions.open}.reduce(:&) |
|
49 | @versions = @projects.map {|p| p.shared_versions.open}.reduce(:&) | |
51 |
|
50 | |||
52 | @priorities = IssuePriority.active.reverse |
|
51 | @priorities = IssuePriority.active.reverse |
@@ -230,7 +230,7 class IssuesController < ApplicationController | |||||
230 | end |
|
230 | end | |
231 | @custom_fields = @issues.map{|i|i.editable_custom_fields}.reduce(:&) |
|
231 | @custom_fields = @issues.map{|i|i.editable_custom_fields}.reduce(:&) | |
232 | @assignables = target_projects.map(&:assignable_users).reduce(:&) |
|
232 | @assignables = target_projects.map(&:assignable_users).reduce(:&) | |
233 |
@trackers = target_projects.map( |
|
233 | @trackers = target_projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&) | |
234 | @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&) |
|
234 | @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&) | |
235 | @categories = target_projects.map {|p| p.issue_categories}.reduce(:&) |
|
235 | @categories = target_projects.map {|p| p.issue_categories}.reduce(:&) | |
236 | if @copy |
|
236 | if @copy | |
@@ -465,7 +465,7 class IssuesController < ApplicationController | |||||
465 | @issue.safe_attributes = attrs |
|
465 | @issue.safe_attributes = attrs | |
466 |
|
466 | |||
467 | if @issue.project |
|
467 | if @issue.project | |
468 |
@issue.tracker ||= @issue. |
|
468 | @issue.tracker ||= @issue.allowed_target_trackers.first | |
469 | if @issue.tracker.nil? |
|
469 | if @issue.tracker.nil? | |
470 | render_error l(:error_no_tracker_in_project) |
|
470 | render_error l(:error_no_tracker_in_project) | |
471 | return false |
|
471 | return false |
@@ -168,6 +168,16 module IssuesHelper | |||||
168 | link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs)) |
|
168 | link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs)) | |
169 | end |
|
169 | end | |
170 |
|
170 | |||
|
171 | def trackers_options_for_select(issue) | |||
|
172 | trackers = issue.allowed_target_trackers | |||
|
173 | if issue.new_record? && issue.parent_issue_id.present? | |||
|
174 | trackers = trackers.reject do |tracker| | |||
|
175 | issue.tracker_id != tracker.id && tracker.disabled_core_fields.include?('parent_issue_id') | |||
|
176 | end | |||
|
177 | end | |||
|
178 | trackers.collect {|t| [t.name, t.id]} | |||
|
179 | end | |||
|
180 | ||||
171 | class IssueFieldsRows |
|
181 | class IssueFieldsRows | |
172 | include ActionView::Helpers::TagHelper |
|
182 | include ActionView::Helpers::TagHelper | |
173 |
|
183 |
@@ -479,12 +479,14 class Issue < ActiveRecord::Base | |||||
479 | end |
|
479 | end | |
480 |
|
480 | |||
481 | if (t = attrs.delete('tracker_id')) && safe_attribute?('tracker_id') |
|
481 | if (t = attrs.delete('tracker_id')) && safe_attribute?('tracker_id') | |
482 | self.tracker_id = t |
|
482 | if allowed_target_trackers(user).where(:id => t.to_i).exists? | |
|
483 | self.tracker_id = t | |||
|
484 | end | |||
483 | end |
|
485 | end | |
484 | if project |
|
486 | if project | |
485 |
# Set |
|
487 | # Set a default tracker to accept custom field values | |
486 | # even if tracker is not specified |
|
488 | # even if tracker is not specified | |
487 |
self.tracker ||= |
|
489 | self.tracker ||= allowed_target_trackers(user).first | |
488 | end |
|
490 | end | |
489 |
|
491 | |||
490 | statuses_allowed = new_statuses_allowed_to(user) |
|
492 | statuses_allowed = new_statuses_allowed_to(user) | |
@@ -822,16 +824,6 class Issue < ActiveRecord::Base | |||||
822 | !leaf? |
|
824 | !leaf? | |
823 | end |
|
825 | end | |
824 |
|
826 | |||
825 | def assignable_trackers |
|
|||
826 | trackers = project.trackers |
|
|||
827 | if new_record? && parent_issue_id.present? |
|
|||
828 | trackers = trackers.reject do |tracker| |
|
|||
829 | tracker_id != tracker.id && tracker.disabled_core_fields.include?('parent_issue_id') |
|
|||
830 | end |
|
|||
831 | end |
|
|||
832 | trackers |
|
|||
833 | end |
|
|||
834 |
|
||||
835 | # Users the issue can be assigned to |
|
827 | # Users the issue can be assigned to | |
836 | def assignable_users |
|
828 | def assignable_users | |
837 | users = project.assignable_users.to_a |
|
829 | users = project.assignable_users.to_a | |
@@ -1373,6 +1365,20 class Issue < ActiveRecord::Base | |||||
1373 | end |
|
1365 | end | |
1374 | Project.where(condition).having_trackers |
|
1366 | Project.where(condition).having_trackers | |
1375 | end |
|
1367 | end | |
|
1368 | ||||
|
1369 | # Returns a scope of trackers that user can assign the issue to | |||
|
1370 | def allowed_target_trackers(user=User.current) | |||
|
1371 | if project | |||
|
1372 | self.class.allowed_target_trackers(project, user, tracker_id_was) | |||
|
1373 | else | |||
|
1374 | Tracker.none | |||
|
1375 | end | |||
|
1376 | end | |||
|
1377 | ||||
|
1378 | # Returns a scope of trackers that user can assign project issues to | |||
|
1379 | def self.allowed_target_trackers(project, user=User.current, current_tracker=nil) | |||
|
1380 | project.trackers.sorted | |||
|
1381 | end | |||
1376 |
|
1382 | |||
1377 | private |
|
1383 | private | |
1378 |
|
1384 |
@@ -199,7 +199,14 class MailHandler < ActionMailer::Base | |||||
199 | end |
|
199 | end | |
200 |
|
200 | |||
201 | issue = Issue.new(:author => user, :project => project) |
|
201 | issue = Issue.new(:author => user, :project => project) | |
202 |
|
|
202 | attributes = issue_attributes_from_keywords(issue) | |
|
203 | if handler_options[:no_permission_check] | |||
|
204 | issue.tracker_id = attributes['tracker_id'] | |||
|
205 | if project | |||
|
206 | issue.tracker_id ||= project.trackers.first.try(:id) | |||
|
207 | end | |||
|
208 | end | |||
|
209 | issue.safe_attributes = attributes | |||
203 | issue.safe_attributes = {'custom_field_values' => custom_field_values_from_keywords(issue)} |
|
210 | issue.safe_attributes = {'custom_field_values' => custom_field_values_from_keywords(issue)} | |
204 | issue.subject = cleaned_up_subject |
|
211 | issue.subject = cleaned_up_subject | |
205 | if issue.subject.blank? |
|
212 | if issue.subject.blank? | |
@@ -420,10 +427,6 class MailHandler < ActionMailer::Base | |||||
420 | 'done_ratio' => get_keyword(:done_ratio, :format => '(\d|10)?0') |
|
427 | 'done_ratio' => get_keyword(:done_ratio, :format => '(\d|10)?0') | |
421 | }.delete_if {|k, v| v.blank? } |
|
428 | }.delete_if {|k, v| v.blank? } | |
422 |
|
429 | |||
423 | if issue.new_record? && attrs['tracker_id'].nil? |
|
|||
424 | attrs['tracker_id'] = issue.project.trackers.first.try(:id) |
|
|||
425 | end |
|
|||
426 |
|
||||
427 | attrs |
|
430 | attrs | |
428 | end |
|
431 | end | |
429 |
|
432 |
@@ -14,7 +14,7 | |||||
14 | <% end %> |
|
14 | <% end %> | |
15 |
|
15 | |||
16 | <% if @issue.safe_attribute? 'tracker_id' %> |
|
16 | <% if @issue.safe_attribute? 'tracker_id' %> | |
17 |
<p><%= f.select :tracker_id, |
|
17 | <p><%= f.select :tracker_id, trackers_options_for_select(@issue), {:required => true}, | |
18 | :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %></p> |
|
18 | :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %></p> | |
19 | <% end %> |
|
19 | <% end %> | |
20 |
|
20 |
@@ -1,5 +1,5 | |||||
1 | <div class="contextual"> |
|
1 | <div class="contextual"> | |
2 |
<% if User.current.allowed_to?(:add_issues, @project, :global => true) && (@project.nil? || |
|
2 | <% if User.current.allowed_to?(:add_issues, @project, :global => true) && (@project.nil? || Issue.allowed_target_trackers(@project).any?) %> | |
3 | <%= link_to l(:label_issue_new), _new_project_issue_path(@project), :class => 'icon icon-add new-issue' %> |
|
3 | <%= link_to l(:label_issue_new), _new_project_issue_path(@project), :class => 'icon icon-add new-issue' %> | |
4 | <% end %> |
|
4 | <% end %> | |
5 | </div> |
|
5 | </div> |
@@ -233,7 +233,7 Redmine::MenuManager.map :project_menu do |menu| | |||||
233 | menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural |
|
233 | menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural | |
234 | menu.push :new_issue, { :controller => 'issues', :action => 'new', :copy_from => nil }, :param => :project_id, :caption => :label_issue_new, |
|
234 | menu.push :new_issue, { :controller => 'issues', :action => 'new', :copy_from => nil }, :param => :project_id, :caption => :label_issue_new, | |
235 | :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) }, |
|
235 | :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) }, | |
236 |
:if => Proc.new { |p| Setting.new_project_issue_tab_enabled? && p |
|
236 | :if => Proc.new { |p| Setting.new_project_issue_tab_enabled? && Issue.allowed_target_trackers(p).any? }, | |
237 | :permission => :add_issues |
|
237 | :permission => :add_issues | |
238 | menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :param => :project_id, :caption => :label_gantt |
|
238 | menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :param => :project_id, :caption => :label_gantt | |
239 | menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar |
|
239 | menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar |
@@ -737,9 +737,10 class IssueTest < ActiveSupport::TestCase | |||||
737 | target = Tracker.find(2) |
|
737 | target = Tracker.find(2) | |
738 | target.core_fields = %w(assigned_to_id due_date) |
|
738 | target.core_fields = %w(assigned_to_id due_date) | |
739 | target.save! |
|
739 | target.save! | |
|
740 | user = User.find(2) | |||
740 |
|
741 | |||
741 | issue = Issue.new(:tracker => source) |
|
742 | issue = Issue.new(:project => Project.find(1), :tracker => source) | |
742 |
issue.s |
|
743 | issue.send :safe_attributes=, {'tracker_id' => 2, 'due_date' => '2012-07-14'}, user | |
743 | assert_equal target, issue.tracker |
|
744 | assert_equal target, issue.tracker | |
744 | assert_equal Date.parse('2012-07-14'), issue.due_date |
|
745 | assert_equal Date.parse('2012-07-14'), issue.due_date | |
745 | end |
|
746 | end |
General Comments 0
You need to be logged in to leave comments.
Login now