]> source.dussan.org Git - redmine.git/commitdiff
Option to filter after my bookmarked projects (#32302, #29482, #31355).
authorGo MAEDA <maeda@farend.jp>
Wed, 23 Oct 2019 01:20:07 +0000 (01:20 +0000)
committerGo MAEDA <maeda@farend.jp>
Wed, 23 Oct 2019 01:20:07 +0000 (01:20 +0000)
Patch by Marius BALTEANU.

git-svn-id: http://svn.redmine.org/redmine/trunk@18842 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/query.rb
app/models/user.rb
config/locales/en.yml
test/fixtures/user_preferences.yml
test/unit/query_test.rb
test/unit/user_test.rb

index fe0cada379caae211ac74b37b091e7f49c9289dd..dafc51fdd6c66fb2b8b395ae9e085dbeaf7402bd 100644 (file)
@@ -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+)$/
index 84832de3925039eb689a97fc635d4130a15fc58d..e4291580e6c30ea69bd344feec40dffcf104b13e 100644 (file)
@@ -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
index 6ab7805521a00e8d877f2d59a0155228c02b6084..ba4b4b5ee2dd488061199a2612af82a4e519d7e5 100644 (file)
@@ -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
index a08c46023e21e5cb2f70f6fbcc06ebe56ec840a1..0e739956a1527bc5d237d096aa7b68d93d693fb4 100644 (file)
@@ -11,6 +11,7 @@ user_preferences_001:
       - issuesassignedtome
       top:
       - calendar
+    :bookmarked_project_ids: "1,5"
 
   id: 1
   user_id: 1
index db0d4c884a752e2649fc9386d4f925a76f6e7b67..3524338eb69d008b973cb3812c837b39542f27e9 100644 (file)
@@ -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']}})
index 20e34d99c6a6ef1f3e6f08c8ab96f0b482b0fef3..d44f359588eaaf94f4e706d8bd4567539e64fbec 100644 (file)
@@ -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/'