Patch #28138 » 0001-Display-new-issue-link-in-version-page.patch
app/helpers/versions_helper.rb | ||
---|---|---|
73 | 73 |
def status_by_options_for_select(value) |
74 | 74 |
options_for_select(STATUS_BY_CRITERIAS.collect {|criteria| [l("field_#{criteria}".to_sym), criteria]}, value) |
75 | 75 |
end |
76 | ||
77 |
def link_to_new_issue(version, project) |
|
78 |
if version.open? && User.current.allowed_to?(:add_issues, project) |
|
79 |
trackers = Issue.allowed_target_trackers(project) |
|
80 | ||
81 |
unless trackers.empty? |
|
82 |
issue = Issue.new(:project => project) |
|
83 |
new_issue_tracker = trackers.detect do |tracker| |
|
84 |
issue.tracker = tracker |
|
85 |
issue.safe_attribute?('fixed_version_id') |
|
86 |
end |
|
87 |
end |
|
88 | ||
89 |
if new_issue_tracker |
|
90 |
attrs = { |
|
91 |
:tracker_id => new_issue_tracker, |
|
92 |
:fixed_version_id => version.id |
|
93 |
} |
|
94 |
link_to l(:label_issue_new), new_project_issue_path(project, :issue => attrs), :class => 'icon icon-add' |
|
95 |
end |
|
96 |
end |
|
97 |
end |
|
76 | 98 |
end |
app/views/versions/show.html.erb | ||
---|---|---|
2 | 2 |
<%= link_to(l(:button_edit), edit_version_path(@version), :class => 'icon icon-edit') if User.current.allowed_to?(:manage_versions, @version.project) %> |
3 | 3 |
<%= link_to_if_authorized(l(:button_edit_associated_wikipage, :page_title => @version.wiki_page_title), {:controller => 'wiki', :action => 'edit', :project_id => @version.project, :id => Wiki.titleize(@version.wiki_page_title)}, :class => 'icon icon-edit') unless @version.wiki_page_title.blank? || @version.project.wiki.nil? %> |
4 | 4 |
<%= delete_link version_path(@version, :back_url => url_for(:controller => 'versions', :action => 'index', :project_id => @version.project)) if User.current.allowed_to?(:manage_versions, @version.project) %> |
5 |
<%= link_to_new_issue(@version, @project) %> |
|
5 | 6 |
<%= call_hook(:view_versions_show_contextual, { :version => @version, :project => @project }) %> |
6 | 7 |
</div> |
7 | 8 |
test/functional/versions_controller_test.rb | ||
---|---|---|
206 | 206 |
end |
207 | 207 |
end |
208 | 208 | |
209 |
def test_show_should_display_link_to_new_issue |
|
210 |
@request.session[:user_id] = 1 |
|
211 |
get :show, :params => {:id => 3} |
|
212 | ||
213 |
assert_response :success |
|
214 |
assert_select 'a.icon.icon-add', :text => 'New issue' |
|
215 |
end |
|
216 | ||
209 | 217 |
def test_new |
210 | 218 |
@request.session[:user_id] = 2 |
211 | 219 |
get :new, :params => {:project_id => '1'} |
test/helpers/version_helper_test.rb | ||
---|---|---|
53 | 53 |
version.project = Project.find(5) |
54 | 54 |
assert_match /^\/issues\?/, version_filtered_issues_path(version) |
55 | 55 |
end |
56 | ||
57 |
def test_link_to_new_issue_should_return_link_to_add_issue |
|
58 |
version = Version.find(3) |
|
59 |
project = Project.find(1) |
|
60 |
User.current = User.find(1) |
|
61 | ||
62 |
# href should contain the following params: |
|
63 |
# fixed_version_id=3 |
|
64 |
# tracker_id=1 |
|
65 |
assert_select_in link_to_new_issue(version, project), '[href=?]', '/projects/ecookbook/issues/new?issue%5Bfixed_version_id%5D=3&issue%5Btracker_id%5D=1', :text => 'New issue' |
|
66 |
end |
|
67 | ||
68 |
def test_link_to_new_issue_should_return_nil_if_version_status_is_not_open |
|
69 |
# locked version |
|
70 |
version = Version.find(2) |
|
71 |
project = Project.find(1) |
|
72 |
User.current = User.find(1) |
|
73 | ||
74 |
assert_nil link_to_new_issue(version, project) |
|
75 |
end |
|
76 | ||
77 |
def test_link_to_new_issue_should_return_nil_if_user_does_not_have_permission_to_add_issue |
|
78 |
Role.find(1).remove_permission! :add_issues |
|
79 |
version = Version.find(3) |
|
80 |
project = Project.find(1) |
|
81 |
User.current = User.find(2) |
|
82 | ||
83 |
assert_nil link_to_new_issue(version, project) |
|
84 |
end |
|
85 | ||
86 |
def test_link_to_new_issue_should_return_nil_if_no_tracker_is_available_for_project |
|
87 |
trackers = Tracker::CORE_FIELDS - %w(fixed_version_id) |
|
88 |
# disable fixed_version_id field for all trackers |
|
89 |
Tracker.all.each do |tracker| |
|
90 |
tracker.core_fields = trackers |
|
91 |
tracker.save! |
|
92 |
end |
|
93 | ||
94 |
version = Version.find(3) |
|
95 |
project = Project.find(1) |
|
96 |
User.current = User.find(2) |
|
97 | ||
98 |
assert_nil link_to_new_issue(version, project) |
|
99 |
end |
|
100 | ||
101 |
def test_link_to_new_issue_should_take_into_account_user_permissions_on_fixed_version_id_field |
|
102 |
WorkflowPermission.delete_all |
|
103 |
WorkflowPermission.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :field_name => 'fixed_version_id', :rule => 'readonly') |
|
104 | ||
105 |
version = Version.find(3) |
|
106 |
project = Project.find(1) |
|
107 |
User.current = User.find(2) |
|
108 | ||
109 |
# href should contain param tracker_id=2 because for tracker_id 1, user has only readonly permissions on fixed_version_id |
|
110 |
assert_select_in link_to_new_issue(version, project), '[href=?]', '/projects/ecookbook/issues/new?issue%5Bfixed_version_id%5D=3&issue%5Btracker_id%5D=2' |
|
111 |
end |
|
56 | 112 |
end |