mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-19 15:01:14 +00:00
Adds Issue#allowed_target_trackers (#7839).
git-svn-id: http://svn.redmine.org/redmine/trunk@15430 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
fad71f8b4b
commit
a6828512c0
@ -41,12 +41,11 @@ class ContextMenusController < ApplicationController
|
|||||||
else
|
else
|
||||||
@assignables = @project.assignable_users
|
@assignables = @project.assignable_users
|
||||||
end
|
end
|
||||||
@trackers = @project.trackers
|
|
||||||
else
|
else
|
||||||
#when multiple projects, we only keep the intersection of each set
|
#when multiple projects, we only keep the intersection of each set
|
||||||
@assignables = @projects.map(&:assignable_users).reduce(:&)
|
@assignables = @projects.map(&:assignable_users).reduce(:&)
|
||||||
@trackers = @projects.map(&:trackers).reduce(:&)
|
|
||||||
end
|
end
|
||||||
|
@trackers = @projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&)
|
||||||
@versions = @projects.map {|p| p.shared_versions.open}.reduce(:&)
|
@versions = @projects.map {|p| p.shared_versions.open}.reduce(:&)
|
||||||
|
|
||||||
@priorities = IssuePriority.active.reverse
|
@priorities = IssuePriority.active.reverse
|
||||||
|
|||||||
@ -230,7 +230,7 @@ class IssuesController < ApplicationController
|
|||||||
end
|
end
|
||||||
@custom_fields = @issues.map{|i|i.editable_custom_fields}.reduce(:&)
|
@custom_fields = @issues.map{|i|i.editable_custom_fields}.reduce(:&)
|
||||||
@assignables = target_projects.map(&:assignable_users).reduce(:&)
|
@assignables = target_projects.map(&:assignable_users).reduce(:&)
|
||||||
@trackers = target_projects.map(&:trackers).reduce(:&)
|
@trackers = target_projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&)
|
||||||
@versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
|
@versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
|
||||||
@categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
|
@categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
|
||||||
if @copy
|
if @copy
|
||||||
@ -465,7 +465,7 @@ class IssuesController < ApplicationController
|
|||||||
@issue.safe_attributes = attrs
|
@issue.safe_attributes = attrs
|
||||||
|
|
||||||
if @issue.project
|
if @issue.project
|
||||||
@issue.tracker ||= @issue.project.trackers.first
|
@issue.tracker ||= @issue.allowed_target_trackers.first
|
||||||
if @issue.tracker.nil?
|
if @issue.tracker.nil?
|
||||||
render_error l(:error_no_tracker_in_project)
|
render_error l(:error_no_tracker_in_project)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@ -168,6 +168,16 @@ module IssuesHelper
|
|||||||
link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
|
link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def trackers_options_for_select(issue)
|
||||||
|
trackers = issue.allowed_target_trackers
|
||||||
|
if issue.new_record? && issue.parent_issue_id.present?
|
||||||
|
trackers = trackers.reject do |tracker|
|
||||||
|
issue.tracker_id != tracker.id && tracker.disabled_core_fields.include?('parent_issue_id')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
trackers.collect {|t| [t.name, t.id]}
|
||||||
|
end
|
||||||
|
|
||||||
class IssueFieldsRows
|
class IssueFieldsRows
|
||||||
include ActionView::Helpers::TagHelper
|
include ActionView::Helpers::TagHelper
|
||||||
|
|
||||||
|
|||||||
@ -479,12 +479,14 @@ class Issue < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
if (t = attrs.delete('tracker_id')) && safe_attribute?('tracker_id')
|
if (t = attrs.delete('tracker_id')) && safe_attribute?('tracker_id')
|
||||||
|
if allowed_target_trackers(user).where(:id => t.to_i).exists?
|
||||||
self.tracker_id = t
|
self.tracker_id = t
|
||||||
end
|
end
|
||||||
|
end
|
||||||
if project
|
if project
|
||||||
# Set the default tracker to accept custom field values
|
# Set a default tracker to accept custom field values
|
||||||
# even if tracker is not specified
|
# even if tracker is not specified
|
||||||
self.tracker ||= project.trackers.first
|
self.tracker ||= allowed_target_trackers(user).first
|
||||||
end
|
end
|
||||||
|
|
||||||
statuses_allowed = new_statuses_allowed_to(user)
|
statuses_allowed = new_statuses_allowed_to(user)
|
||||||
@ -822,16 +824,6 @@ class Issue < ActiveRecord::Base
|
|||||||
!leaf?
|
!leaf?
|
||||||
end
|
end
|
||||||
|
|
||||||
def assignable_trackers
|
|
||||||
trackers = project.trackers
|
|
||||||
if new_record? && parent_issue_id.present?
|
|
||||||
trackers = trackers.reject do |tracker|
|
|
||||||
tracker_id != tracker.id && tracker.disabled_core_fields.include?('parent_issue_id')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
trackers
|
|
||||||
end
|
|
||||||
|
|
||||||
# Users the issue can be assigned to
|
# Users the issue can be assigned to
|
||||||
def assignable_users
|
def assignable_users
|
||||||
users = project.assignable_users.to_a
|
users = project.assignable_users.to_a
|
||||||
@ -1374,6 +1366,20 @@ class Issue < ActiveRecord::Base
|
|||||||
Project.where(condition).having_trackers
|
Project.where(condition).having_trackers
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a scope of trackers that user can assign the issue to
|
||||||
|
def allowed_target_trackers(user=User.current)
|
||||||
|
if project
|
||||||
|
self.class.allowed_target_trackers(project, user, tracker_id_was)
|
||||||
|
else
|
||||||
|
Tracker.none
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns a scope of trackers that user can assign project issues to
|
||||||
|
def self.allowed_target_trackers(project, user=User.current, current_tracker=nil)
|
||||||
|
project.trackers.sorted
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def after_project_change
|
def after_project_change
|
||||||
|
|||||||
@ -199,7 +199,14 @@ class MailHandler < ActionMailer::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
issue = Issue.new(:author => user, :project => project)
|
issue = Issue.new(:author => user, :project => project)
|
||||||
issue.safe_attributes = issue_attributes_from_keywords(issue)
|
attributes = issue_attributes_from_keywords(issue)
|
||||||
|
if handler_options[:no_permission_check]
|
||||||
|
issue.tracker_id = attributes['tracker_id']
|
||||||
|
if project
|
||||||
|
issue.tracker_id ||= project.trackers.first.try(:id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
issue.safe_attributes = attributes
|
||||||
issue.safe_attributes = {'custom_field_values' => custom_field_values_from_keywords(issue)}
|
issue.safe_attributes = {'custom_field_values' => custom_field_values_from_keywords(issue)}
|
||||||
issue.subject = cleaned_up_subject
|
issue.subject = cleaned_up_subject
|
||||||
if issue.subject.blank?
|
if issue.subject.blank?
|
||||||
@ -420,10 +427,6 @@ class MailHandler < ActionMailer::Base
|
|||||||
'done_ratio' => get_keyword(:done_ratio, :format => '(\d|10)?0')
|
'done_ratio' => get_keyword(:done_ratio, :format => '(\d|10)?0')
|
||||||
}.delete_if {|k, v| v.blank? }
|
}.delete_if {|k, v| v.blank? }
|
||||||
|
|
||||||
if issue.new_record? && attrs['tracker_id'].nil?
|
|
||||||
attrs['tracker_id'] = issue.project.trackers.first.try(:id)
|
|
||||||
end
|
|
||||||
|
|
||||||
attrs
|
attrs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if @issue.safe_attribute? 'tracker_id' %>
|
<% if @issue.safe_attribute? 'tracker_id' %>
|
||||||
<p><%= f.select :tracker_id, @issue.assignable_trackers.collect {|t| [t.name, t.id]}, {:required => true},
|
<p><%= f.select :tracker_id, trackers_options_for_select(@issue), {:required => true},
|
||||||
:onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %></p>
|
:onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<div class="contextual">
|
<div class="contextual">
|
||||||
<% if User.current.allowed_to?(:add_issues, @project, :global => true) && (@project.nil? || @project.trackers.any?) %>
|
<% if User.current.allowed_to?(:add_issues, @project, :global => true) && (@project.nil? || Issue.allowed_target_trackers(@project).any?) %>
|
||||||
<%= link_to l(:label_issue_new), _new_project_issue_path(@project), :class => 'icon icon-add new-issue' %>
|
<%= link_to l(:label_issue_new), _new_project_issue_path(@project), :class => 'icon icon-add new-issue' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -233,7 +233,7 @@ Redmine::MenuManager.map :project_menu do |menu|
|
|||||||
menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
|
menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
|
||||||
menu.push :new_issue, { :controller => 'issues', :action => 'new', :copy_from => nil }, :param => :project_id, :caption => :label_issue_new,
|
menu.push :new_issue, { :controller => 'issues', :action => 'new', :copy_from => nil }, :param => :project_id, :caption => :label_issue_new,
|
||||||
:html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) },
|
:html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) },
|
||||||
:if => Proc.new { |p| Setting.new_project_issue_tab_enabled? && p.trackers.any? },
|
:if => Proc.new { |p| Setting.new_project_issue_tab_enabled? && Issue.allowed_target_trackers(p).any? },
|
||||||
:permission => :add_issues
|
:permission => :add_issues
|
||||||
menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :param => :project_id, :caption => :label_gantt
|
menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :param => :project_id, :caption => :label_gantt
|
||||||
menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar
|
menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar
|
||||||
|
|||||||
@ -737,9 +737,10 @@ class IssueTest < ActiveSupport::TestCase
|
|||||||
target = Tracker.find(2)
|
target = Tracker.find(2)
|
||||||
target.core_fields = %w(assigned_to_id due_date)
|
target.core_fields = %w(assigned_to_id due_date)
|
||||||
target.save!
|
target.save!
|
||||||
|
user = User.find(2)
|
||||||
|
|
||||||
issue = Issue.new(:tracker => source)
|
issue = Issue.new(:project => Project.find(1), :tracker => source)
|
||||||
issue.safe_attributes = {'tracker_id' => 2, 'due_date' => '2012-07-14'}
|
issue.send :safe_attributes=, {'tracker_id' => 2, 'due_date' => '2012-07-14'}, user
|
||||||
assert_equal target, issue.tracker
|
assert_equal target, issue.tracker
|
||||||
assert_equal Date.parse('2012-07-14'), issue.due_date
|
assert_equal Date.parse('2012-07-14'), issue.due_date
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user