diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-08-15 09:15:13 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-08-15 09:15:13 +0000 |
commit | f820ccce3b02416c3b8ab5744eb262684040045d (patch) | |
tree | 121e8233ee5fd54155182b978613e636b7c4e8e5 /lib | |
parent | 9c8c1cdb542895c7dfc868d929dee6e3a579dd5a (diff) | |
download | redmine-f820ccce3b02416c3b8ab5744eb262684040045d.tar.gz redmine-f820ccce3b02416c3b8ab5744eb262684040045d.zip |
Use same logic for finding user as a custom field (#950).
git-svn-id: http://svn.redmine.org/redmine/trunk@14503 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib')
-rw-r--r-- | lib/redmine/field_format.rb | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/redmine/field_format.rb b/lib/redmine/field_format.rb index 05a329dbf..5fd1d6aa1 100644 --- a/lib/redmine/field_format.rb +++ b/lib/redmine/field_format.rb @@ -126,6 +126,22 @@ module Redmine [] end + def value_from_keyword(custom_field, keyword, object) + possible_values_options = possible_values_options(custom_field, object) + if possible_values_options.present? + keyword = keyword.to_s + if v = possible_values_options.detect {|text, id| keyword.casecmp(text) == 0} + if v.is_a?(Array) + v.last + else + v + end + end + else + keyword + end + end + # Returns the validation errors for custom_field # Should return an empty array if custom_field is valid def validate_custom_field(custom_field) @@ -659,9 +675,13 @@ module Redmine field_attributes :user_role def possible_values_options(custom_field, object=nil) + possible_values_records(custom_field, object).map {|u| [u.name, u.id.to_s]} + end + + def possible_values_records(custom_field, object=nil) if object.is_a?(Array) projects = object.map {|o| o.respond_to?(:project) ? o.project : nil}.compact.uniq - projects.map {|project| possible_values_options(custom_field, project)}.reduce(:&) || [] + projects.map {|project| possible_values_records(custom_field, project)}.reduce(:&) || [] elsif object.respond_to?(:project) && object.project scope = object.project.users if custom_field.user_role.is_a?(Array) @@ -670,12 +690,18 @@ module Redmine scope = scope.where("#{Member.table_name}.id IN (SELECT DISTINCT member_id FROM #{MemberRole.table_name} WHERE role_id IN (?))", role_ids) end end - scope.sorted.collect {|u| [u.to_s, u.id.to_s]} + scope.sorted else [] end end + def value_from_keyword(custom_field, keyword, object) + users = possible_values_records(custom_field, object).to_a + user = Principal.detect_by_keyword(users, keyword) + user ? user.id : nil + end + def before_custom_field_save(custom_field) super if custom_field.user_role.is_a?(Array) |