@@ -55,7 +55,7 class ContextMenusController < ApplicationController | |||
|
55 | 55 | |
|
56 | 56 | @options_by_custom_field = {} |
|
57 | 57 | if @can[:edit] |
|
58 |
custom_fields = @issues.map(&: |
|
|
58 | custom_fields = @issues.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?) | |
|
59 | 59 | custom_fields.each do |field| |
|
60 | 60 | values = field.possible_values_options(@projects) |
|
61 | 61 | if values.present? |
@@ -483,6 +483,11 class Issue < ActiveRecord::Base | |||
|
483 | 483 | end |
|
484 | 484 | end |
|
485 | 485 | |
|
486 | # Returns the custom fields that can be edited by the given user | |
|
487 | def editable_custom_fields(user=nil) | |
|
488 | editable_custom_field_values(user).map(&:custom_field).uniq | |
|
489 | end | |
|
490 | ||
|
486 | 491 | # Returns the names of attributes that are read-only for user or the current user |
|
487 | 492 | # For users with multiple roles, the read-only fields are the intersection of |
|
488 | 493 | # read-only fields of each role |
@@ -198,6 +198,18 class ContextMenusControllerTest < ActionController::TestCase | |||
|
198 | 198 | end |
|
199 | 199 | end |
|
200 | 200 | |
|
201 | def test_context_menu_should_show_enabled_custom_fields_for_the_role_only | |
|
202 | enabled_cf = IssueCustomField.generate!(:field_format => 'bool', :is_for_all => true, :tracker_ids => [1], :visible => false, :role_ids => [1,2]) | |
|
203 | disabled_cf = IssueCustomField.generate!(:field_format => 'bool', :is_for_all => true, :tracker_ids => [1], :visible => false, :role_ids => [2]) | |
|
204 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1) | |
|
205 | ||
|
206 | @request.session[:user_id] = 2 | |
|
207 | get :issues, :ids => [issue.id] | |
|
208 | ||
|
209 | assert_select "li.cf_#{enabled_cf.id}" | |
|
210 | assert_select "li.cf_#{disabled_cf.id}", 0 | |
|
211 | end | |
|
212 | ||
|
201 | 213 | def test_context_menu_by_assignable_user_should_include_assigned_to_me_link |
|
202 | 214 | @request.session[:user_id] = 2 |
|
203 | 215 | get :issues, :ids => [1] |
@@ -706,6 +706,16 class IssueTest < ActiveSupport::TestCase | |||
|
706 | 706 | assert values.detect {|value| value.custom_field == cf2} |
|
707 | 707 | end |
|
708 | 708 | |
|
709 | def test_editable_custom_fields_should_return_custom_field_that_is_enabled_for_the_role_only | |
|
710 | enabled_cf = IssueCustomField.generate!(:is_for_all => true, :tracker_ids => [1], :visible => false, :role_ids => [1,2]) | |
|
711 | disabled_cf = IssueCustomField.generate!(:is_for_all => true, :tracker_ids => [1], :visible => false, :role_ids => [2]) | |
|
712 | user = User.find(2) | |
|
713 | issue = Issue.new(:project_id => 1, :tracker_id => 1) | |
|
714 | ||
|
715 | assert_include enabled_cf, issue.editable_custom_fields(user) | |
|
716 | assert_not_include disabled_cf, issue.editable_custom_fields(user) | |
|
717 | end | |
|
718 | ||
|
709 | 719 | def test_safe_attributes_should_accept_target_tracker_writable_fields |
|
710 | 720 | WorkflowPermission.delete_all |
|
711 | 721 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, |
General Comments 0
You need to be logged in to leave comments.
Login now