Feature #23997 » 0001-Per-role-visibility-settings-for-project-custom-fiel.patch
| app/models/project.rb | ||
|---|---|---|
|
end
|
||
|
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
|
||
|
private
|
||
|
def update_inherited_members
|
||
| app/models/project_custom_field.rb | ||
|---|---|---|
|
:label_project_plural
|
||
|
end
|
||
|
def visible_by?(project, user=User.current)
|
||
|
super || (roles & user.roles_for_project(project)).present?
|
||
|
end
|
||
|
def visibility_by_project_condition(project_key=nil, user=User.current, id_column=nil)
|
||
|
project_key ||= "#{Project.table_name}.id"
|
||
|
super(project_key, user, id_column)
|
||
| app/views/custom_fields/_form.html.erb | ||
|---|---|---|
|
<% when "ProjectCustomField" %>
|
||
|
<div class="box tabular">
|
||
|
<p><%= f.check_box :is_required %></p>
|
||
|
<p><%= f.check_box :visible %></p>
|
||
|
<% if @custom_field.format.searchable_supported %>
|
||
|
<p><%= f.check_box :searchable %></p>
|
||
|
<% end %>
|
||
| ... | ... | |
|
<p><%= f.check_box :is_filter %></p>
|
||
|
<% end %>
|
||
|
</div>
|
||
|
<%= render :partial => 'visibility_by_role_selector' %>
|
||
|
<% when "VersionCustomField" %>
|
||
|
<div class="box tabular">
|
||
| app/views/projects/_form.html.erb | ||
|---|---|---|
|
<%= wikitoolbar_for 'project_description' %>
|
||
|
<% @project.custom_field_values.each do |value| %>
|
||
|
<% @project.visible_custom_field_values.each do |value| %>
|
||
|
<p><%= custom_field_tag_with_label :project, value %></p>
|
||
|
<% end %>
|
||
|
<%= call_hook(:view_projects_form, :project => @project, :form => f) %>
|
||
| app/views/projects/show.html.erb | ||
|---|---|---|
|
<ul class="subprojects">
|
||
|
<% @subprojects.each do |project| %>
|
||
|
<li><%= link_to(project.name, project_path(project), :class => project.css_classes).html_safe %></li>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
|
</ul>
|
||
|
</div>
|
||
|
<% end %>
|
||
| test/functional/custom_fields_controller_test.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def test_new_project_custom_field
|
||
|
get :new, :params => {
|
||
|
:type => 'ProjectCustomField'
|
||
|
}
|
||
|
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=ProjectCustomField]'
|
||
|
end
|
||
|
end
|
||
|
def test_new_time_entry_custom_field_should_not_show_trackers_and_projects
|
||
|
get :new, :params => {
|
||
|
:type => 'TimeEntryCustomField'
|
||
| test/functional/projects_controller_test.rb | ||
|---|---|---|
|
assert_select 'a#tab-activities'
|
||
|
end
|
||
|
def test_settings_should_not_display_custom_fields_not_visible_for_user
|
||
|
@request.session[:user_id] = 2
|
||
|
ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
|
||
|
get :settings, :params => {
|
||
|
:id => 'ecookbook'
|
||
|
}
|
||
|
assert_response :success
|
||
|
assert_select 'select#project_custom_field_values_3', :count => 0
|
||
|
end
|
||
|
def test_update
|
||
|
@request.session[:user_id] = 2 # manager
|
||
|
post :update, :params => {
|
||