]> git.openstreetmap.org Git - rails.git/commitdiff
Merge pull request #4201 from AntonKhorev/issues-limit-settings
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 27 Sep 2023 14:47:44 +0000 (15:47 +0100)
committerGitHub <noreply@github.com>
Wed, 27 Sep 2023 14:47:44 +0000 (15:47 +0100)
Move max value of issues counter to settings

app/helpers/issues_helper.rb
config/initializers/config.rb
config/locales/en.yml
config/settings.yml
test/helpers/issues_helper_test.rb [new file with mode: 0644]

index 7bc64cb83914d71fe4aa47fdbda94515c4c5e414..55bd0952f7ef27047117953f1010a833a161bfba 100644 (file)
@@ -26,9 +26,9 @@ module IssuesHelper
   end
 
   def open_issues_count
-    count = Issue.visible_to(current_user).open.limit(100).size
-    if count > 99
-      tag.span("99+", :class => "badge count-number")
+    count = Issue.visible_to(current_user).open.limit(Settings.max_issues_count).size
+    if count >= Settings.max_issues_count
+      tag.span(I18n.t("count.at_least_pattern", :count => Settings.max_issues_count), :class => "badge count-number")
     elsif count.positive?
       tag.span(count, :class => "badge count-number")
     end
index 983f0226669327e394b8577e34ac9ab845fde488..c1cc522a5e13b24eef5b2bae373c512d403b82f6 100644 (file)
@@ -77,6 +77,7 @@ Config.setup do |config|
     required(:tracepoints_per_page).filled(:int?)
     required(:max_number_of_way_nodes).filled(:int?)
     required(:max_number_of_relation_members).filled(:int?)
+    required(:max_issues_count).filled(:int?)
     required(:api_timeout).filled(:int?)
     required(:imagery_blacklist).maybe(:array?)
     required(:status).filled(:str?, :included_in? => ALLOWED_STATUS)
index 530dad2079f530f8134ee38cd37a020e68baafeb..da346e8e89abb15497867e4e8fd30db39824d1a1 100644 (file)
@@ -5,6 +5,8 @@ en:
     formats:
       friendly: "%e %B %Y at %H:%M"
       blog: "%e %B %Y"
+  count:
+    at_least_pattern: "%{count}+"
   helpers:
     file:
       prompt: Choose file
index e228247e03d617b5a4d1cd957b21b6498dca01e3..214f8a284e000168234913326293f7760c96c08d 100644 (file)
@@ -43,6 +43,8 @@ max_note_request_area: 25
 default_note_query_limit: 100
 # Maximum limit on the number of notes returned by the note search api method
 max_note_query_limit: 10000
+# Maximum value of open issues counter for moderators, anything equal or greater to this value "n" is shown as "n+"
+max_issues_count: 99
 # Zoom level to use for postcode results from the geocoder
 postcode_zoom: 15
 # Timeout for API calls in seconds
diff --git a/test/helpers/issues_helper_test.rb b/test/helpers/issues_helper_test.rb
new file mode 100644 (file)
index 0000000..f0b7c88
--- /dev/null
@@ -0,0 +1,30 @@
+require "test_helper"
+
+class IssuesHelperTest < ActionView::TestCase
+  attr_accessor :current_user
+
+  def test_issues_count
+    target_user = create(:user)
+    self.current_user = create(:moderator_user)
+
+    n = (Settings.max_issues_count - 1)
+    n.times do
+      create(:note_with_comments) do |note|
+        create(:issue, :reportable => note, :reported_user => target_user, :assigned_role => "moderator")
+      end
+    end
+    expected = <<~HTML.delete("\n")
+      <span class="badge count-number">#{n}</span>
+    HTML
+    assert_dom_equal expected, open_issues_count
+
+    n += 1
+    create(:note_with_comments) do |note|
+      create(:issue, :reportable => note, :reported_user => target_user, :assigned_role => "moderator")
+    end
+    expected = <<~HTML.delete("\n")
+      <span class="badge count-number">#{n}+</span>
+    HTML
+    assert_dom_equal expected, open_issues_count
+  end
+end