diff options
author | Go MAEDA <maeda@farend.jp> | 2019-10-23 01:20:07 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2019-10-23 01:20:07 +0000 |
commit | b1f110860652270ca8e98020b0f4e8fe90e85ba7 (patch) | |
tree | c5db7b53697e1aba4024baac0ef4ff75ef231052 | |
parent | 63205a70ef0156a17b4f89881be9eed1b9855b30 (diff) | |
download | redmine-b1f110860652270ca8e98020b0f4e8fe90e85ba7.tar.gz redmine-b1f110860652270ca8e98020b0f4e8fe90e85ba7.zip |
Option to filter after my bookmarked projects (#32302, #29482, #31355).
Patch by Marius BALTEANU.
git-svn-id: http://svn.redmine.org/redmine/trunk@18842 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/query.rb | 8 | ||||
-rw-r--r-- | app/models/user.rb | 7 | ||||
-rw-r--r-- | config/locales/en.yml | 1 | ||||
-rw-r--r-- | test/fixtures/user_preferences.yml | 1 | ||||
-rw-r--r-- | test/unit/query_test.rb | 21 | ||||
-rw-r--r-- | test/unit/user_test.rb | 7 |
6 files changed, 43 insertions, 2 deletions
diff --git a/app/models/query.rb b/app/models/query.rb index fe0cada37..dafc51fdd 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -528,8 +528,9 @@ class Query < ActiveRecord::Base def project_values project_values = [] - if User.current.logged? && User.current.memberships.any? - project_values << ["<< #{l(:label_my_projects).downcase} >>", "mine"] + if User.current.logged? + project_values << ["<< #{l(:label_my_projects).downcase} >>", "mine"] if User.current.memberships.any? + project_values << ["<< #{l(:label_my_bookmarks).downcase} >>", "bookmarks"] if User.current.bookmarked_project_ids.any? end project_values += all_projects_values project_values @@ -915,6 +916,9 @@ class Query < ActiveRecord::Base if v.delete('mine') v += User.current.memberships.map(&:project_id).map(&:to_s) end + if v.delete('bookmarks') + v += User.current.bookmarked_project_ids + end end if field =~ /^cf_(\d+)\.cf_(\d+)$/ diff --git a/app/models/user.rb b/app/models/user.rb index 84832de39..e4291580e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -840,6 +840,13 @@ class User < Principal end end + def bookmarked_project_ids + project_ids = [] + bookmarked_project_ids = self.pref[:bookmarked_project_ids] + project_ids = bookmarked_project_ids.split(',') unless bookmarked_project_ids.nil? + project_ids.map(&:to_i) + end + protected def validate_password_length diff --git a/config/locales/en.yml b/config/locales/en.yml index 6ab780552..ba4b4b5ee 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1076,6 +1076,7 @@ en: label_display_type: Display results as label_display_type_list: List label_display_type_board: Board + label_my_bookmarks: My bookmarks button_login: Login button_submit: Submit diff --git a/test/fixtures/user_preferences.yml b/test/fixtures/user_preferences.yml index a08c46023..0e739956a 100644 --- a/test/fixtures/user_preferences.yml +++ b/test/fixtures/user_preferences.yml @@ -11,6 +11,7 @@ user_preferences_001: - issuesassignedtome top: - calendar + :bookmarked_project_ids: "1,5" id: 1 user_id: 1 diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index db0d4c884..3524338eb 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -922,6 +922,27 @@ class QueryTest < ActiveSupport::TestCase assert_nil result.detect {|issue| !User.current.member_of?(issue.project)} end + def test_filter_my_bookmarks + User.current = User.find(1) + query = ProjectQuery.new(:name => '_') + filter = query.available_filters['id'] + assert_not_nil filter + assert_include 'bookmarks', filter[:values].map{|v| v[1]} + + query.filters = { 'id' => {:operator => '=', :values => ['bookmarks']}} + result = query.results_scope + + assert_equal [1,5], result.map(&:id).sort + end + + def test_filter_my_bookmarks_for_user_without_bookmarked_projects + User.current = User.find(2) + query = ProjectQuery.new(:name => '_') + filter = query.available_filters['id'] + + assert_not_include 'bookmarks', filter[:values].map{|v| v[1]} + end + def test_filter_watched_issues User.current = User.find(1) query = IssueQuery.new(:name => '_', :filters => { 'watcher_id' => {:operator => '=', :values => ['me']}}) diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 20e34d99c..d44f35958 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -1280,6 +1280,13 @@ class UserTest < ActiveSupport::TestCase assert_equal user, User.try_to_login(user.login, "unsalted") end + def test_bookmarked_project_ids + # User with bookmarked projects + assert_equal [1, 5], User.find(1).bookmarked_project_ids + # User without bookmarked projects + assert_equal [], User.find(2).bookmarked_project_ids + end + if Object.const_defined?(:OpenID) def test_setting_identity_url normalized_open_id_url = 'http://example.com/' |