Patch by Jens Krämer and Marius BALTEANU. git-svn-id: http://svn.redmine.org/redmine/trunk@18386 e93f8b46-1217-0410-a6f0-8f06a7374b81tags/4.1.0
@@ -168,6 +168,13 @@ class Version < ActiveRecord::Base | |||
user.allowed_to?(:view_issues, self.project) | |||
end | |||
def visible_custom_field_values(user = nil) | |||
user ||= User.current | |||
custom_field_values.select do |value| | |||
value.custom_field.visible_by?(project, user) | |||
end | |||
end | |||
# Version files have same visibility as project files | |||
def attachments_visible?(*args) | |||
project.present? && project.attachments_visible?(*args) |
@@ -21,4 +21,8 @@ class VersionCustomField < CustomField | |||
def type_name | |||
:label_version_plural | |||
end | |||
def visible_by?(project, user=User.current) | |||
super || (roles & user.roles_for_project(project)).present? | |||
end | |||
end |
@@ -53,7 +53,7 @@ | |||
<%= call_hook(:"view_custom_fields_form_#{@custom_field.type.to_s.underscore}", :custom_field => @custom_field, :form => f) %> | |||
</div> | |||
<% if %w(IssueCustomField TimeEntryCustomField ProjectCustomField).include?(@custom_field.class.name) %> | |||
<% if %w(IssueCustomField TimeEntryCustomField ProjectCustomField VersionCustomField).include?(@custom_field.class.name) %> | |||
<%= render :partial => 'visibility_by_role_selector', :locals => { :f => f } %> | |||
<% end %> | |||
@@ -14,7 +14,7 @@ | |||
<p><%= f.check_box :default_project_version, :label => :field_default_version %></p> | |||
<% end %> | |||
<% @version.custom_field_values.each do |value| %> | |||
<% @version.visible_custom_field_values.each do |value| %> | |||
<p><%= custom_field_tag_with_label :version, value %></p> | |||
<% end %> | |||
@@ -11,7 +11,7 @@ api.array :versions, api_meta(:total_count => @versions.size) do | |||
api.sharing version.sharing | |||
api.wiki_page_title version.wiki_page_title | |||
render_api_custom_values version.custom_field_values, api | |||
render_api_custom_values version.visible_custom_field_values, api | |||
api.created_on version.created_on | |||
api.updated_on version.updated_on |
@@ -9,7 +9,7 @@ api.version do | |||
api.sharing @version.sharing | |||
api.wiki_page_title @version.wiki_page_title | |||
render_api_custom_values @version.custom_field_values, api | |||
render_api_custom_values @version.visible_custom_field_values, api | |||
api.created_on @version.created_on | |||
api.updated_on @version.updated_on |
@@ -146,6 +146,26 @@ class CustomFieldsControllerTest < Redmine::ControllerTest | |||
end | |||
end | |||
def test_new_version_custom_field | |||
get :new, :params => { | |||
:type => 'VersionCustomField' | |||
} | |||
assert_response :success | |||
assert_select 'form#custom_field_form' do | |||
assert_select 'select#custom_field_field_format[name=?]', 'custom_field[field_format]' do | |||
assert_select 'option[value=user]', :text => 'User' | |||
assert_select 'option[value=version]', :text => 'Version' | |||
end | |||
# Visibility | |||
assert_select 'input[type=radio][name=?]', 'custom_field[visible]', 2 | |||
assert_select 'input[type=checkbox][name=?]', 'custom_field[role_ids][]', 3 | |||
assert_select 'input[type=hidden][name=type][value=VersionCustomField]' | |||
end | |||
end | |||
def test_new_time_entry_custom_field_should_not_show_trackers_and_projects | |||
get :new, :params => { | |||
:type => 'TimeEntryCustomField' |