diff options
author | Eric Davis <edavis@littlestreamsoftware.com> | 2010-09-10 19:44:45 +0000 |
---|---|---|
committer | Eric Davis <edavis@littlestreamsoftware.com> | 2010-09-10 19:44:45 +0000 |
commit | 41f8d043eb29452ff11baf5e5286cd907cda742e (patch) | |
tree | 6d66e1b4d7ea8f8c312ce3ab551d9e7704d7164a /app/models | |
parent | 109b42f4828c0966e771809afcfd99d545af3ca0 (diff) | |
download | redmine-41f8d043eb29452ff11baf5e5286cd907cda742e.tar.gz redmine-41f8d043eb29452ff11baf5e5286cd907cda742e.zip |
Added a "Member of Role" to the issues filters. #5869
This filter will check an issue's assigned to field for users who have
(or don't have) a specific Role(s).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4078 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/query.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/app/models/query.rb b/app/models/query.rb index 96e99ef94..4b2cc7557 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -198,6 +198,9 @@ class Query < ActiveRecord::Base group_values = Group.all.collect {|g| [g.name, g.id] } @available_filters["member_of_group"] = { :type => :list_optional, :order => 6, :values => group_values } unless group_values.empty? + + role_values = Role.givable.collect {|r| [r.name, r.id] } + @available_filters["assigned_to_role"] = { :type => :list_optional, :order => 7, :values => role_values } unless role_values.empty? if User.current.logged? @available_filters["watcher_id"] = { :type => :list, :order => 15, :values => [["<< #{l(:label_me)} >>", "me"]] } @@ -451,6 +454,26 @@ class Query < ActiveRecord::Base sql << '(' + sql_for_field("assigned_to_id", operator, members_of_groups, Issue.table_name, "assigned_to_id", false) + ')' + elsif field == "assigned_to_role" # named field + if operator == "*" # Any Role + roles = Role.givable + operator = '=' # Override the operator since we want to find by assigned_to + elsif operator == "!*" # No role + roles = Role.givable + operator = '!' # Override the operator since we want to find by assigned_to + else + roles = Role.givable.find_all_by_id(v) + end + roles ||= [] + + members_of_roles = roles.inject([]) {|user_ids, role| + if role && role.members + user_ids << role.members.collect(&:user_id) + end + user_ids.flatten.uniq.compact + }.sort.collect(&:to_s) + + sql << '(' + sql_for_field("assigned_to_id", operator, members_of_roles, Issue.table_name, "assigned_to_id", false) + ')' else # regular field db_table = Issue.table_name |