Feature #23997 » 0001-Per-role-visibility-for-version-custom-fields.patch
app/models/version.rb | ||
---|---|---|
168 | 168 |
user.allowed_to?(:view_issues, self.project) |
169 | 169 |
end |
170 | 170 | |
171 |
def visible_custom_field_values(user = nil) |
|
172 |
user ||= User.current |
|
173 |
custom_field_values.select do |value| |
|
174 |
value.custom_field.visible_by?(project, user) |
|
175 |
end |
|
176 |
end |
|
177 | ||
171 | 178 |
# Version files have same visibility as project files |
172 | 179 |
def attachments_visible?(*args) |
173 | 180 |
project.present? && project.attachments_visible?(*args) |
app/models/version_custom_field.rb | ||
---|---|---|
21 | 21 |
def type_name |
22 | 22 |
:label_version_plural |
23 | 23 |
end |
24 | ||
25 |
def visible_by?(project, user=User.current) |
|
26 |
super || (roles & user.roles_for_project(project)).present? |
|
27 |
end |
|
24 | 28 |
end |
app/views/custom_fields/_form.html.erb | ||
---|---|---|
53 | 53 |
<%= call_hook(:"view_custom_fields_form_#{@custom_field.type.to_s.underscore}", :custom_field => @custom_field, :form => f) %> |
54 | 54 |
</div> |
55 | 55 | |
56 |
<% if %w(IssueCustomField TimeEntryCustomField ProjectCustomField).include?(@custom_field.class.name) %> |
|
56 |
<% if %w(IssueCustomField TimeEntryCustomField ProjectCustomField VersionCustomField).include?(@custom_field.class.name) %>
|
|
57 | 57 |
<%= render :partial => 'visibility_by_role_selector', :locals => { :f => f } %> |
58 | 58 |
<% end %> |
59 | 59 |
app/views/versions/_form.html.erb | ||
---|---|---|
14 | 14 |
<p><%= f.check_box :default_project_version, :label => :field_default_version %></p> |
15 | 15 |
<% end %> |
16 | 16 | |
17 |
<% @version.custom_field_values.each do |value| %> |
|
17 |
<% @version.visible_custom_field_values.each do |value| %>
|
|
18 | 18 |
<p><%= custom_field_tag_with_label :version, value %></p> |
19 | 19 |
<% end %> |
20 | 20 |
app/views/versions/index.api.rsb | ||
---|---|---|
11 | 11 |
api.sharing version.sharing |
12 | 12 |
api.wiki_page_title version.wiki_page_title |
13 | 13 | |
14 |
render_api_custom_values version.custom_field_values, api |
|
14 |
render_api_custom_values version.visible_custom_field_values, api
|
|
15 | 15 | |
16 | 16 |
api.created_on version.created_on |
17 | 17 |
api.updated_on version.updated_on |
app/views/versions/show.api.rsb | ||
---|---|---|
9 | 9 |
api.sharing @version.sharing |
10 | 10 |
api.wiki_page_title @version.wiki_page_title |
11 | 11 | |
12 |
render_api_custom_values @version.custom_field_values, api |
|
12 |
render_api_custom_values @version.visible_custom_field_values, api
|
|
13 | 13 | |
14 | 14 |
api.created_on @version.created_on |
15 | 15 |
api.updated_on @version.updated_on |
test/functional/custom_fields_controller_test.rb | ||
---|---|---|
146 | 146 |
end |
147 | 147 |
end |
148 | 148 | |
149 |
def test_new_version_custom_field |
|
150 |
get :new, :params => { |
|
151 |
:type => 'VersionCustomField' |
|
152 |
} |
|
153 |
assert_response :success |
|
154 | ||
155 |
assert_select 'form#custom_field_form' do |
|
156 |
assert_select 'select#custom_field_field_format[name=?]', 'custom_field[field_format]' do |
|
157 |
assert_select 'option[value=user]', :text => 'User' |
|
158 |
assert_select 'option[value=version]', :text => 'Version' |
|
159 |
end |
|
160 | ||
161 |
# Visibility |
|
162 |
assert_select 'input[type=radio][name=?]', 'custom_field[visible]', 2 |
|
163 |
assert_select 'input[type=checkbox][name=?]', 'custom_field[role_ids][]', 3 |
|
164 | ||
165 |
assert_select 'input[type=hidden][name=type][value=VersionCustomField]' |
|
166 |
end |
|
167 |
end |
|
168 | ||
149 | 169 |
def test_new_time_entry_custom_field_should_not_show_trackers_and_projects |
150 | 170 |
get :new, :params => { |
151 | 171 |
:type => 'TimeEntryCustomField' |
test/functional/versions_custom_fields_visibility_test.rb | ||
---|---|---|
1 |
# frozen_string_literal: true |
|
2 | ||
3 |
# Redmine - project management software |
|
4 |
# Copyright (C) 2006-2019 Jean-Philippe Lang |
|
5 |
# |
|
6 |
# This program is free software; you can redistribute it and/or |
|
7 |
# modify it under the terms of the GNU General Public License |
|
8 |
# as published by the Free Software Foundation; either version 2 |
|
9 |
# of the License, or (at your option) any later version. |
|
10 |
# |
|
11 |
# This program is distributed in the hope that it will be useful, |
|
12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
# GNU General Public License for more details. |
|
15 |
# |
|
16 |
# You should have received a copy of the GNU General Public License |
|
17 |
# along with this program; if not, write to the Free Software |
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 | ||
20 |
require File.expand_path('../../test_helper', __FILE__) |
|
21 | ||
22 |
class VersionsCustomFieldsVisibilityTest < Redmine::ControllerTest |
|
23 |
tests VersionsController |
|
24 |
fixtures :projects, |
|
25 |
:users, :email_addresses, |
|
26 |
:roles, |
|
27 |
:members, |
|
28 |
:member_roles, |
|
29 |
:issue_statuses, |
|
30 |
:trackers, |
|
31 |
:projects_trackers, |
|
32 |
:enabled_modules, |
|
33 |
:versions, |
|
34 |
:custom_fields, :custom_values, :custom_fields_trackers |
|
35 | ||
36 |
def test_show_should_display_only_custom_fields_visible_to_user |
|
37 |
cf1 = VersionCustomField.create!(:name => 'cf1', :field_format => 'string') |
|
38 |
cf2 = VersionCustomField.create!(:name => 'cf2', :field_format => 'string', :visible => false, :role_ids => [1]) |
|
39 |
cf3 = VersionCustomField.create!(:name => 'cf3', :field_format => 'string', :visible => false, :role_ids => [3]) |
|
40 | ||
41 |
version = Version.find(2) |
|
42 |
version.custom_field_values = {cf1.id => 'Value1', cf2.id => 'Value2', cf3.id => 'Value3'} |
|
43 |
version.save! |
|
44 | ||
45 |
@request.session[:user_id] = 2 |
|
46 |
get :show, :params => { |
|
47 |
:id => 2 |
|
48 |
} |
|
49 |
assert_response :success |
|
50 | ||
51 |
assert_select '#roadmap' do |
|
52 |
assert_select 'span.label', :text => 'cf1:' |
|
53 |
assert_select 'span.label', :text => 'cf2:' |
|
54 |
assert_select 'span.label', {count: 0, text: 'cf3:'} |
|
55 |
end |
|
56 |
end |
|
57 | ||
58 |
def test_edit_should_display_only_custom_fields_visible_to_user |
|
59 |
cf1 = VersionCustomField.create!(:name => 'cf1', :field_format => 'string') |
|
60 |
cf2 = VersionCustomField.create!(:name => 'cf2', :field_format => 'string', :visible => false, :role_ids => [1]) |
|
61 |
cf3 = VersionCustomField.create!(:name => 'cf3', :field_format => 'string', :visible => false, :role_ids => [3]) |
|
62 | ||
63 |
version = Version.find(2) |
|
64 |
version.custom_field_values = {cf1.id => 'Value1', cf2.id => 'Value2', cf3.id => 'Value3'} |
|
65 |
version.save! |
|
66 | ||
67 |
@request.session[:user_id] = 2 |
|
68 |
get :edit, :params => { |
|
69 |
:id => 2 |
|
70 |
} |
|
71 |
assert_response :success |
|
72 | ||
73 |
assert_select 'form.edit_version' do |
|
74 |
assert_select 'input[id=?]', "version_custom_field_values_#{cf1.id}" |
|
75 |
assert_select 'input[id=?]', "version_custom_field_values_#{cf2.id}" |
|
76 |
assert_select 'input[id=?]', "version_custom_field_values_#{cf3.id}", 0 |
|
77 |
end |
|
78 |
end |
|
79 |
end |
- « Previous
- 1
- 2
- 3
- 4
- Next »