Field set as read-only still available in the issues list context menu (#16755).
git-svn-id: http://svn.redmine.org/redmine/trunk@13124 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
2d3f3cd9aa
commit
382ca5055a
|
@ -55,7 +55,7 @@ class ContextMenusController < ApplicationController
|
|||
|
||||
@options_by_custom_field = {}
|
||||
if @can[:edit]
|
||||
custom_fields = @issues.map(&:available_custom_fields).reduce(:&).reject(&:multiple?)
|
||||
custom_fields = @issues.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?)
|
||||
custom_fields.each do |field|
|
||||
values = field.possible_values_options(@projects)
|
||||
if values.present?
|
||||
|
|
|
@ -483,6 +483,11 @@ class Issue < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
# Returns the custom fields that can be edited by the given user
|
||||
def editable_custom_fields(user=nil)
|
||||
editable_custom_field_values(user).map(&:custom_field).uniq
|
||||
end
|
||||
|
||||
# Returns the names of attributes that are read-only for user or the current user
|
||||
# For users with multiple roles, the read-only fields are the intersection of
|
||||
# read-only fields of each role
|
||||
|
|
|
@ -198,6 +198,18 @@ class ContextMenusControllerTest < ActionController::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_context_menu_should_show_enabled_custom_fields_for_the_role_only
|
||||
enabled_cf = IssueCustomField.generate!(:field_format => 'bool', :is_for_all => true, :tracker_ids => [1], :visible => false, :role_ids => [1,2])
|
||||
disabled_cf = IssueCustomField.generate!(:field_format => 'bool', :is_for_all => true, :tracker_ids => [1], :visible => false, :role_ids => [2])
|
||||
issue = Issue.generate!(:project_id => 1, :tracker_id => 1)
|
||||
|
||||
@request.session[:user_id] = 2
|
||||
get :issues, :ids => [issue.id]
|
||||
|
||||
assert_select "li.cf_#{enabled_cf.id}"
|
||||
assert_select "li.cf_#{disabled_cf.id}", 0
|
||||
end
|
||||
|
||||
def test_context_menu_by_assignable_user_should_include_assigned_to_me_link
|
||||
@request.session[:user_id] = 2
|
||||
get :issues, :ids => [1]
|
||||
|
|
|
@ -706,6 +706,16 @@ class IssueTest < ActiveSupport::TestCase
|
|||
assert values.detect {|value| value.custom_field == cf2}
|
||||
end
|
||||
|
||||
def test_editable_custom_fields_should_return_custom_field_that_is_enabled_for_the_role_only
|
||||
enabled_cf = IssueCustomField.generate!(:is_for_all => true, :tracker_ids => [1], :visible => false, :role_ids => [1,2])
|
||||
disabled_cf = IssueCustomField.generate!(:is_for_all => true, :tracker_ids => [1], :visible => false, :role_ids => [2])
|
||||
user = User.find(2)
|
||||
issue = Issue.new(:project_id => 1, :tracker_id => 1)
|
||||
|
||||
assert_include enabled_cf, issue.editable_custom_fields(user)
|
||||
assert_not_include disabled_cf, issue.editable_custom_fields(user)
|
||||
end
|
||||
|
||||
def test_safe_attributes_should_accept_target_tracker_writable_fields
|
||||
WorkflowPermission.delete_all
|
||||
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
|
||||
|
|
Loading…
Reference in New Issue