summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2010-09-10 19:44:45 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2010-09-10 19:44:45 +0000
commit41f8d043eb29452ff11baf5e5286cd907cda742e (patch)
tree6d66e1b4d7ea8f8c312ce3ab551d9e7704d7164a
parent109b42f4828c0966e771809afcfd99d545af3ca0 (diff)
downloadredmine-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
-rw-r--r--app/models/query.rb23
-rw-r--r--config/locales/en.yml1
-rw-r--r--test/object_daddy_helpers.rb5
-rw-r--r--test/unit/query_test.rb68
4 files changed, 96 insertions, 1 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
diff --git a/config/locales/en.yml b/config/locales/en.yml
index ba7a2da23..cc4e31185 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -294,6 +294,7 @@ en:
field_sharing: Sharing
field_parent_issue: Parent task
field_member_of_group: Member of Group
+ field_assigned_to_role: Member of Role
setting_app_title: Application title
setting_app_subtitle: Application subtitle
diff --git a/test/object_daddy_helpers.rb b/test/object_daddy_helpers.rb
index 7b144b18f..c94ada229 100644
--- a/test/object_daddy_helpers.rb
+++ b/test/object_daddy_helpers.rb
@@ -13,6 +13,11 @@ module ObjectDaddyHelpers
User.spawn(attributes)
end
+ def User.add_to_project(user, project, roles)
+ roles = [roles] unless roles.is_a?(Array)
+ Member.generate!(:principal => user, :project => project, :roles => roles)
+ end
+
# Generate the default Query
def Query.generate_default!(attributes={})
query = Query.spawn(attributes)
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb
index acab56ffd..f737b2f0c 100644
--- a/test/unit/query_test.rb
+++ b/test/unit/query_test.rb
@@ -404,7 +404,29 @@ class QueryTest < ActiveSupport::TestCase
end
end
-
+
+ context "'assigned_to_role' filter" do
+ should "be present" do
+ assert @query.available_filters.keys.include?("assigned_to_role")
+ end
+
+ should "be an optional list" do
+ assert_equal :list_optional, @query.available_filters["assigned_to_role"][:type]
+ end
+
+ should "have a list of the Roles as values" do
+ assert @query.available_filters["assigned_to_role"][:values].include?(['Manager',1])
+ assert @query.available_filters["assigned_to_role"][:values].include?(['Developer',2])
+ assert @query.available_filters["assigned_to_role"][:values].include?(['Reporter',3])
+ end
+
+ should "not include the built in Roles as values" do
+ assert ! @query.available_filters["assigned_to_role"][:values].include?(['Non member',4])
+ assert ! @query.available_filters["assigned_to_role"][:values].include?(['Anonymous',5])
+ end
+
+ end
+
end
context "#statement" do
@@ -453,6 +475,50 @@ class QueryTest < ActiveSupport::TestCase
end
end
+
+ context "with 'assigned_to_role' filter" do
+ setup do
+ # No fixtures
+ MemberRole.delete_all
+ Member.delete_all
+ Role.delete_all
+
+ @manager_role = Role.generate!(:name => 'Manager')
+ @developer_role = Role.generate!(:name => 'Developer')
+
+ @project = Project.generate!
+ @manager = User.generate!
+ @developer = User.generate!
+ @boss = User.generate!
+ User.add_to_project(@manager, @project, @manager_role)
+ User.add_to_project(@developer, @project, @developer_role)
+ User.add_to_project(@boss, @project, [@manager_role, @developer_role])
+ end
+
+ should "search assigned to for users with the Role" do
+ @query = Query.new(:name => '_')
+ @query.add_filter('assigned_to_role', '=', [@manager_role.id.to_s])
+
+ assert_query_statement_includes @query, "#{Issue.table_name}.assigned_to_id IN ('#{@manager.id}','#{@boss.id}')"
+ assert_find_issues_with_query_is_successful @query
+ end
+
+ should "search assigned to for users not assigned to any Role (none)" do
+ @query = Query.new(:name => '_')
+ @query.add_filter('assigned_to_role', '!*', [''])
+
+ assert_query_statement_includes @query, "#{Issue.table_name}.assigned_to_id IS NULL OR #{Issue.table_name}.assigned_to_id NOT IN ('#{@manager.id}','#{@developer.id}','#{@boss.id}')"
+ assert_find_issues_with_query_is_successful @query
+ end
+
+ should "search assigned to for users assigned to any Role (all)" do
+ @query = Query.new(:name => '_')
+ @query.add_filter('assigned_to_role', '*', [''])
+
+ assert_query_statement_includes @query, "#{Issue.table_name}.assigned_to_id IN ('#{@manager.id}','#{@developer.id}','#{@boss.id}')"
+ assert_find_issues_with_query_is_successful @query
+ end
+ end
end
end