diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-02-12 17:35:57 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-02-12 17:35:57 +0000 |
commit | e1b828de95ececbe630e74caf3b18e47c669c58d (patch) | |
tree | c4d7752813e127a9d23e1df4487630cb0590aea7 | |
parent | 571494a028fc9355f918987cba9b1c89e8b2dc5f (diff) | |
download | redmine-e1b828de95ececbe630e74caf3b18e47c669c58d.tar.gz redmine-e1b828de95ececbe630e74caf3b18e47c669c58d.zip |
Adds ability to filter watched issues (#846).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2456 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/query.rb | 37 | ||||
-rw-r--r-- | lang/bg.yml | 1 | ||||
-rw-r--r-- | lang/ca.yml | 1 | ||||
-rw-r--r-- | lang/cs.yml | 1 | ||||
-rw-r--r-- | lang/da.yml | 1 | ||||
-rw-r--r-- | lang/de.yml | 1 | ||||
-rw-r--r-- | lang/en.yml | 1 | ||||
-rw-r--r-- | lang/es.yml | 1 | ||||
-rw-r--r-- | lang/fi.yml | 1 | ||||
-rw-r--r-- | lang/fr.yml | 1 | ||||
-rw-r--r-- | lang/gl.yml | 1 | ||||
-rw-r--r-- | lang/he.yml | 1 | ||||
-rw-r--r-- | lang/hu.yml | 1 | ||||
-rw-r--r-- | lang/it.yml | 1 | ||||
-rw-r--r-- | lang/ja.yml | 1 | ||||
-rw-r--r-- | lang/ko.yml | 1 | ||||
-rw-r--r-- | lang/lt.yml | 1 | ||||
-rw-r--r-- | lang/mk.yml | 1 | ||||
-rw-r--r-- | lang/nl.yml | 1 | ||||
-rw-r--r-- | lang/no.yml | 1 | ||||
-rw-r--r-- | lang/pl.yml | 1 | ||||
-rw-r--r-- | lang/pt-br.yml | 1 | ||||
-rw-r--r-- | lang/pt.yml | 1 | ||||
-rw-r--r-- | lang/ro.yml | 1 | ||||
-rw-r--r-- | lang/ru.yml | 1 | ||||
-rw-r--r-- | lang/sk.yml | 1 | ||||
-rw-r--r-- | lang/sl.yml | 1 | ||||
-rw-r--r-- | lang/sr.yml | 1 | ||||
-rw-r--r-- | lang/sv.yml | 1 | ||||
-rw-r--r-- | lang/th.yml | 1 | ||||
-rw-r--r-- | lang/tr.yml | 1 | ||||
-rw-r--r-- | lang/uk.yml | 1 | ||||
-rw-r--r-- | lang/vn.yml | 1 | ||||
-rw-r--r-- | lang/zh-tw.yml | 1 | ||||
-rw-r--r-- | lang/zh.yml | 1 | ||||
-rw-r--r-- | test/fixtures/watchers.yml | 4 | ||||
-rw-r--r-- | test/unit/query_test.rb | 22 |
37 files changed, 81 insertions, 16 deletions
diff --git a/app/models/query.rb b/app/models/query.rb index 4689f5fb8..23742cfa5 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -165,6 +165,10 @@ class Query < ActiveRecord::Base end @available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values } unless user_values.empty? @available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values } unless user_values.empty? + + if User.current.logged? + @available_filters["watcher_id"] = { :type => :list, :order => 15, :values => [["<< #{l(:label_me)} >>", "me"]] } + end if project # project specific filters @@ -288,31 +292,34 @@ class Query < ActiveRecord::Base next if field == "subproject_id" v = values_for(field).clone next unless v and !v.empty? - + operator = operator_for(field) + + # "me" value subsitution + if %w(assigned_to_id author_id watcher_id).include?(field) + v.push(User.current.logged? ? User.current.id.to_s : "0") if v.delete("me") + end + sql = '' - is_custom_filter = false if field =~ /^cf_(\d+)$/ # custom field db_table = CustomValue.table_name db_field = 'value' is_custom_filter = true sql << "#{Issue.table_name}.id IN (SELECT #{Issue.table_name}.id FROM #{Issue.table_name} LEFT OUTER JOIN #{db_table} ON #{db_table}.customized_type='Issue' AND #{db_table}.customized_id=#{Issue.table_name}.id AND #{db_table}.custom_field_id=#{$1} WHERE " + sql << sql_for_field(field, operator, v, db_table, db_field, true) + ')' + elsif field == 'watcher_id' + db_table = Watcher.table_name + db_field = 'user_id' + sql << "#{Issue.table_name}.id #{ operator == '=' ? 'IN' : 'NOT IN' } (SELECT #{db_table}.watchable_id FROM #{db_table} WHERE #{db_table}.watchable_type='Issue' AND " + sql << sql_for_field(field, '=', v, db_table, db_field) + ')' else # regular field db_table = Issue.table_name db_field = field - sql << '(' + sql << '(' + sql_for_field(field, operator, v, db_table, db_field) + ')' end - - # "me" value subsitution - if %w(assigned_to_id author_id).include?(field) - v.push(User.current.logged? ? User.current.id.to_s : "0") if v.delete("me") - end - - sql = sql + sql_for_field(field, v, db_table, db_field, is_custom_filter) - - sql << ')' filters_clauses << sql + end if filters and valid? (filters_clauses << project_statement).join(' AND ') @@ -320,10 +327,10 @@ class Query < ActiveRecord::Base private - # Helper method to generate the WHERE sql for a +field+ with a +value+ - def sql_for_field(field, value, db_table, db_field, is_custom_filter) + # Helper method to generate the WHERE sql for a +field+, +operator+ and a +value+ + def sql_for_field(field, operator, value, db_table, db_field, is_custom_filter=false) sql = '' - case operator_for field + case operator when "=" sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")" when "!" diff --git a/lang/bg.yml b/lang/bg.yml index 379ff4fcc..0079c4ab2 100644 --- a/lang/bg.yml +++ b/lang/bg.yml @@ -706,3 +706,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/ca.yml b/lang/ca.yml index f4e5375e3..770cc305c 100644 --- a/lang/ca.yml +++ b/lang/ca.yml @@ -707,3 +707,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL
setting_openid: Allow OpenID login and registration
label_login_with_open_id_option: or login with OpenID
+field_watcher: Watcher
diff --git a/lang/cs.yml b/lang/cs.yml index 947c9e46c..bbfdfae4d 100644 --- a/lang/cs.yml +++ b/lang/cs.yml @@ -711,3 +711,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/da.yml b/lang/da.yml index 910a51b11..c07d6be88 100644 --- a/lang/da.yml +++ b/lang/da.yml @@ -708,3 +708,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/de.yml b/lang/de.yml index fef1f7969..366b7dd06 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -709,3 +709,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/en.yml b/lang/en.yml index 1bb9fff85..f4f59df22 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -188,6 +188,7 @@ field_default_value: Default value field_comments_sorting: Display comments field_parent_title: Parent page field_editable: Editable +field_watcher: Watcher setting_app_title: Application title setting_app_subtitle: Application subtitle diff --git a/lang/es.yml b/lang/es.yml index 52eac46ca..67f103416 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -691,3 +691,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/fi.yml b/lang/fi.yml index 973ff7ee9..65478776d 100644 --- a/lang/fi.yml +++ b/lang/fi.yml @@ -706,3 +706,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/fr.yml b/lang/fr.yml index 71f44de8f..4a7c51708 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -188,6 +188,7 @@ field_comments_sorting: Afficher les commentaires field_parent_title: Page parent field_editable: Modifiable field_identity_url: URL OpenID +field_watcher: Observateur setting_app_title: Titre de l'application setting_app_subtitle: Sous-titre de l'application diff --git a/lang/gl.yml b/lang/gl.yml index 119e86063..701fe22c7 100644 --- a/lang/gl.yml +++ b/lang/gl.yml @@ -691,3 +691,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL
setting_openid: Allow OpenID login and registration
label_login_with_open_id_option: or login with OpenID
+field_watcher: Watcher
diff --git a/lang/he.yml b/lang/he.yml index dba80c698..7a1519ae0 100644 --- a/lang/he.yml +++ b/lang/he.yml @@ -706,3 +706,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/hu.yml b/lang/hu.yml index bdf110d7e..697b26a1c 100644 --- a/lang/hu.yml +++ b/lang/hu.yml @@ -707,3 +707,4 @@ setting_repository_log_display_limit: Maximum hány revízió jelenjen meg a fá field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/it.yml b/lang/it.yml index 07e41cbb1..418f3529d 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -706,3 +706,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/ja.yml b/lang/ja.yml index b450380d6..b92287678 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -707,3 +707,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/ko.yml b/lang/ko.yml index fd8ba9f95..008fe866c 100644 --- a/lang/ko.yml +++ b/lang/ko.yml @@ -706,3 +706,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/lt.yml b/lang/lt.yml index 6bcd87b92..0a732a59a 100644 --- a/lang/lt.yml +++ b/lang/lt.yml @@ -708,3 +708,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/mk.yml b/lang/mk.yml index b2e7d4bea..269d4dddb 100644 --- a/lang/mk.yml +++ b/lang/mk.yml @@ -708,3 +708,4 @@ text_custom_field_possible_values_info: 'One line for each value' field_identity_url: OpenID URL
setting_openid: Allow OpenID login and registration
label_login_with_open_id_option: or login with OpenID
+field_watcher: Watcher
diff --git a/lang/nl.yml b/lang/nl.yml index 122779fec..859972ee0 100644 --- a/lang/nl.yml +++ b/lang/nl.yml @@ -691,3 +691,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/no.yml b/lang/no.yml index e00e36501..10bf48427 100644 --- a/lang/no.yml +++ b/lang/no.yml @@ -707,3 +707,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/pl.yml b/lang/pl.yml index f8d6a5ef9..1ca3da32c 100644 --- a/lang/pl.yml +++ b/lang/pl.yml @@ -725,3 +725,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/pt-br.yml b/lang/pt-br.yml index eb18eb330..073c8e377 100644 --- a/lang/pt-br.yml +++ b/lang/pt-br.yml @@ -707,3 +707,4 @@ setting_repository_log_display_limit: Número máximo de revisões exibidas no a field_identity_url: OpenID URL
setting_openid: Allow OpenID login and registration
label_login_with_open_id_option: or login with OpenID
+field_watcher: Watcher
diff --git a/lang/pt.yml b/lang/pt.yml index cf76ccb11..7836f0fc6 100644 --- a/lang/pt.yml +++ b/lang/pt.yml @@ -708,3 +708,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/ro.yml b/lang/ro.yml index 4c6f3cbaa..ac06ccda5 100644 --- a/lang/ro.yml +++ b/lang/ro.yml @@ -706,3 +706,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/ru.yml b/lang/ru.yml index 1d067286b..87be71e2c 100644 --- a/lang/ru.yml +++ b/lang/ru.yml @@ -741,3 +741,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/sk.yml b/lang/sk.yml index 4d41041eb..351173a32 100644 --- a/lang/sk.yml +++ b/lang/sk.yml @@ -711,3 +711,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL
setting_openid: Allow OpenID login and registration
label_login_with_open_id_option: or login with OpenID
+field_watcher: Watcher
diff --git a/lang/sl.yml b/lang/sl.yml index ea142ce4a..bd51bda35 100644 --- a/lang/sl.yml +++ b/lang/sl.yml @@ -708,3 +708,4 @@ text_custom_field_possible_values_info: 'One line for each value' field_identity_url: OpenID URL
setting_openid: Allow OpenID login and registration
label_login_with_open_id_option: or login with OpenID
+field_watcher: Watcher
diff --git a/lang/sr.yml b/lang/sr.yml index 86ca019ec..7455d20e0 100644 --- a/lang/sr.yml +++ b/lang/sr.yml @@ -707,3 +707,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/sv.yml b/lang/sv.yml index ad20e0d3a..884dd16a4 100644 --- a/lang/sv.yml +++ b/lang/sv.yml @@ -708,3 +708,4 @@ enumeration_activities: Aktiviteter (tidsuppföljning) field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/th.yml b/lang/th.yml index d1910c727..7cb03a1b8 100644 --- a/lang/th.yml +++ b/lang/th.yml @@ -709,3 +709,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/tr.yml b/lang/tr.yml index cc3d67fc8..8766b1127 100644 --- a/lang/tr.yml +++ b/lang/tr.yml @@ -707,3 +707,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/uk.yml b/lang/uk.yml index 779c94386..235bbadb8 100644 --- a/lang/uk.yml +++ b/lang/uk.yml @@ -708,3 +708,4 @@ text_custom_field_possible_values_info: 'One line for each value' field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/vn.yml b/lang/vn.yml index 75f294edc..e4f4fd47c 100644 --- a/lang/vn.yml +++ b/lang/vn.yml @@ -709,3 +709,4 @@ setting_repository_log_display_limit: Maximum number of revisions displayed on f field_identity_url: OpenID URL
setting_openid: Allow OpenID login and registration
label_login_with_open_id_option: or login with OpenID
+field_watcher: Watcher
diff --git a/lang/zh-tw.yml b/lang/zh-tw.yml index 598023c0c..9f3788a85 100644 --- a/lang/zh-tw.yml +++ b/lang/zh-tw.yml @@ -709,3 +709,4 @@ enumeration_activities: 活動 (時間追蹤) field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/lang/zh.yml b/lang/zh.yml index cac4377b6..4be80b3bb 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -709,3 +709,4 @@ enumeration_activities: 活动(时间跟踪) field_identity_url: OpenID URL setting_openid: Allow OpenID login and registration label_login_with_open_id_option: or login with OpenID +field_watcher: Watcher diff --git a/test/fixtures/watchers.yml b/test/fixtures/watchers.yml index 6c8cdfb5e..803b03e5e 100644 --- a/test/fixtures/watchers.yml +++ b/test/fixtures/watchers.yml @@ -7,4 +7,8 @@ watchers_002: watchable_type: Message watchable_id: 1 user_id: 1 +watchers_003: + watchable_type: Issue + watchable_id: 2 + user_id: 1
\ No newline at end of file diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 3bdc4a7a2..d568604c3 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -18,7 +18,7 @@ require File.dirname(__FILE__) + '/../test_helper' class QueryTest < Test::Unit::TestCase - fixtures :projects, :enabled_modules, :users, :members, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :versions, :queries + fixtures :projects, :enabled_modules, :users, :members, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :watchers, :custom_fields, :custom_values, :versions, :queries def test_custom_fields_for_all_projects_should_be_available_in_global_queries query = Query.new(:project => nil, :name => '_') @@ -162,6 +162,26 @@ class QueryTest < Test::Unit::TestCase find_issues_with_query(query) end + def test_filter_watched_issues + User.current = User.find(1) + query = Query.new(:name => '_', :filters => { 'watcher_id' => {:operator => '=', :values => ['me']}}) + result = find_issues_with_query(query) + assert_not_nil result + assert !result.empty? + assert_equal Issue.visible.watched_by(User.current).sort_by(&:id), result.sort_by(&:id) + User.current = nil + end + + def test_filter_unwatched_issues + User.current = User.find(1) + query = Query.new(:name => '_', :filters => { 'watcher_id' => {:operator => '!', :values => ['me']}}) + result = find_issues_with_query(query) + assert_not_nil result + assert !result.empty? + assert_equal((Issue.visible - Issue.watched_by(User.current)).sort_by(&:id).size, result.sort_by(&:id).size) + User.current = nil + end + def test_default_columns q = Query.new assert !q.columns.empty? |