From 0c9f58d083cc884ed42df9af41acf181519eb99b Mon Sep 17 00:00:00 2001
From: Vincent Robert
Date: Mon, 14 Mar 2022 14:12:36 +0100
Subject: [PATCH 01/20] Remove dubugging code for production
---
app/views/issues/_edit_closed.html.erb | 2 --
lib/redmine_tiny_features/hooks.rb | 8 ++++----
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/app/views/issues/_edit_closed.html.erb b/app/views/issues/_edit_closed.html.erb
index 4530e23..3e7c631 100644
--- a/app/views/issues/_edit_closed.html.erb
+++ b/app/views/issues/_edit_closed.html.erb
@@ -34,8 +34,6 @@
})
$("#issue-form").on("change", "#issue_status_id", function () {
var status_id = parseInt($(this).val())
- console.log(status_id)
- console.log($.inArray(status_id, <%= IssueStatus.where(:is_closed => true).pluck(:id).inspect %>))
if ($.inArray(status_id, <%= IssueStatus.where(:is_closed => true).pluck(:id).inspect %>) < 0) {
showIfIssueOpen()
}
diff --git a/lib/redmine_tiny_features/hooks.rb b/lib/redmine_tiny_features/hooks.rb
index 47b498c..d1126c5 100644
--- a/lib/redmine_tiny_features/hooks.rb
+++ b/lib/redmine_tiny_features/hooks.rb
@@ -2,12 +2,12 @@ module RedmineTinyFeatures
class Hooks < Redmine::Hook::ViewListener
#adds our css on each page
def view_layouts_base_html_head(context)
- stylesheet_link_tag("tiny_features", :plugin => "redmine_tiny_features")+
- javascript_include_tag('redmine_tiny_features.js', plugin: 'redmine_tiny_features')
+ stylesheet_link_tag("tiny_features", :plugin => "redmine_tiny_features") +
+ javascript_include_tag('redmine_tiny_features.js', plugin: 'redmine_tiny_features')
end
- def controller_journals_edit_post(context={})
- if Setting["plugin_redmine_tiny_features"]["journalize_note_deletion"].present?
+ def controller_journals_edit_post(context = {})
+ if Setting["plugin_redmine_tiny_features"]["journalize_note_deletion"].present?
journal = context[:journal]
if context[:journal].notes.blank?
journal.issue.init_journal(User.current).note_removed(journal)
From d2888c1cc5487cfc10736f92a54dcdfce44af0a8 Mon Sep 17 00:00:00 2001
From: Vincent Robert
Date: Mon, 14 Mar 2022 15:54:43 +0100
Subject: [PATCH 02/20] Update reminders rake task: add max_delay
---
README.md | 1 +
init.rb | 1 +
lib/redmine_tiny_features/mailer_patch.rb | 59 +++++++++++++++++++++++
spec/models/mailer_patch_spec.rb | 42 ++++++++++++++++
4 files changed, 103 insertions(+)
create mode 100644 lib/redmine_tiny_features/mailer_patch.rb
create mode 100644 spec/models/mailer_patch_spec.rb
diff --git a/README.md b/README.md
index 524e97b..d465f38 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,7 @@ Here is a complete list of the features:
* Improve load time of **users filters** when there are thousands entries
* Save **note deletion** in issue journal
* Fix **pasted images** when using Chrome (may be fixed in future Redmine versions according to this issue https://www.redmine.org/issues/36013)
+* **Reminders rake task: add max-delay option** to define the maximum number of days after which reminders stop to be sent
## Test status
diff --git a/init.rb b/init.rb
index 35088fc..e2fbda6 100644
--- a/init.rb
+++ b/init.rb
@@ -15,6 +15,7 @@
require_dependency 'redmine_tiny_features/time_entry_query_patch'
require_dependency 'redmine_tiny_features/issues_helper_patch'
require_dependency 'redmine_tiny_features/journal_patch'
+ require_dependency 'redmine_tiny_features/mailer_patch'
end
Redmine::Plugin.register :redmine_tiny_features do
diff --git a/lib/redmine_tiny_features/mailer_patch.rb b/lib/redmine_tiny_features/mailer_patch.rb
new file mode 100644
index 0000000..d17630b
--- /dev/null
+++ b/lib/redmine_tiny_features/mailer_patch.rb
@@ -0,0 +1,59 @@
+require_dependency 'mailer'
+
+class Mailer < ActionMailer::Base
+
+ # Sends reminders to issue assignees
+ # Available options:
+ # * :days => how many days in the future to remind about (defaults to 7)
+ # * :tracker => id of tracker for filtering issues (defaults to all trackers)
+ # * :project => id or identifier of project to process (defaults to all projects)
+ # * :users => array of user/group ids who should be reminded
+ # * :version => name of target version for filtering issues (defaults to none)
+ ####### ADDED BY TINY FEATURES PLUGIN 1/3 #######
+ # * :max_delay => ignore older issues: how many days after due date to stop sending reminders (defaults to none)
+ def self.reminders(options = {})
+ days = options[:days] || 7
+ ####### ADDED BY TINY FEATURES PLUGIN 2/3 #######
+ max_delay = options[:max_delay] || nil
+ project = options[:project] ? Project.find(options[:project]) : nil
+ tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
+ target_version_id = options[:version] ? Version.named(options[:version]).pluck(:id) : nil
+ if options[:version] && target_version_id.blank?
+ raise ActiveRecord::RecordNotFound.new("Couldn't find Version named #{options[:version]}")
+ end
+
+ user_ids = options[:users]
+
+ scope =
+ Issue.open.where(
+ "#{Issue.table_name}.assigned_to_id IS NOT NULL" \
+ " AND #{Project.table_name}.status = #{Project::STATUS_ACTIVE}" \
+ " AND #{Issue.table_name}.due_date <= ?", days.day.from_now.to_date
+ )
+ scope = scope.where(:assigned_to_id => user_ids) if user_ids.present?
+ scope = scope.where(:project_id => project.id) if project
+ scope = scope.where(:fixed_version_id => target_version_id) if target_version_id.present?
+ scope = scope.where(:tracker_id => tracker.id) if tracker
+ ####### ADDED BY TINY FEATURES PLUGIN 3/3 #######
+ scope = scope.where("#{Issue.table_name}.due_date > ?", max_delay.day.ago.to_date) if max_delay
+ issues_by_assignee = scope.includes(:status, :assigned_to, :project, :tracker).
+ group_by(&:assigned_to)
+ issues_by_assignee.keys.each do |assignee|
+ if assignee.is_a?(Group)
+ assignee.users.each do |user|
+ issues_by_assignee[user] ||= []
+ issues_by_assignee[user] += issues_by_assignee[assignee]
+ end
+ end
+ end
+
+ issues_by_assignee.each do |assignee, issues|
+ if assignee.is_a?(User) && assignee.active? && issues.present?
+ visible_issues = issues.select { |i| i.visible?(assignee) }
+ visible_issues.sort! { |a, b| (a.due_date <=> b.due_date).nonzero? || (a.id <=> b.id) }
+ reminder(assignee, visible_issues, days).deliver_later if visible_issues.present?
+ end
+ end
+ end
+
+end
diff --git a/spec/models/mailer_patch_spec.rb b/spec/models/mailer_patch_spec.rb
new file mode 100644
index 0000000..9bbf974
--- /dev/null
+++ b/spec/models/mailer_patch_spec.rb
@@ -0,0 +1,42 @@
+require "spec_helper"
+require "rails_helper"
+
+describe "Mailer" do
+
+ include ActiveSupport::Testing::Assertions
+
+ fixtures :users, :email_addresses, :user_preferences,
+ :roles, :members, :member_roles,
+ :issues, :issue_statuses, :issue_relations,
+ :versions, :trackers, :projects_trackers,
+ :issue_categories, :enabled_modules, :enumerations
+
+ it "does not send reminders for older issues when using max_delay option" do
+
+ user = User.find(2)
+ user.pref.update_attribute :time_zone, 'UTC'
+
+ Issue.generate!(:assigned_to => user, :due_date => 20.days.from_now, :subject => 'quux')
+ Issue.generate!(:assigned_to => user, :due_date => 0.days.from_now, :subject => 'baz')
+ Issue.generate!(:assigned_to => user, :due_date => 1.days.from_now, :subject => 'qux')
+ Issue.generate!(:assigned_to => user, :due_date => 10.days.ago, :subject => 'foo')
+ Issue.generate!(:assigned_to => user, :due_date => 100.days.ago, :subject => 'bar')
+ ActionMailer::Base.deliveries.clear
+
+ Mailer.reminders(:days => 7, :users => [user.id], :max_delay => 30)
+
+ assert_equal 1, ActionMailer::Base.deliveries.size
+
+ email = ActionMailer::Base.deliveries.last
+ expect(email).to_not be_nil
+
+ mail_boy = email.parts.first.body.encoded
+
+ expect(mail_boy).to_not match(/quux/)
+ expect(mail_boy).to match(/foo \(10 days late\)/)
+ expect(mail_boy).to match(/baz \(Due in 0 days\)/)
+ expect(mail_boy).to match(/qux \(Due in 1 day\)/)
+ expect(mail_boy).to_not match(/bar/)
+
+ end
+end
From 1ce562aa860284bd539465a6d770938b2ca1894b Mon Sep 17 00:00:00 2001
From: Vincent Robert
Date: Mon, 14 Mar 2022 15:59:56 +0100
Subject: [PATCH 03/20] Update reminder rake task
---
lib/tasks/reminder.rake | 47 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
create mode 100644 lib/tasks/reminder.rake
diff --git a/lib/tasks/reminder.rake b/lib/tasks/reminder.rake
new file mode 100644
index 0000000..874cf9c
--- /dev/null
+++ b/lib/tasks/reminder.rake
@@ -0,0 +1,47 @@
+# Redmine - project management software
+# Copyright (C) 2006-2021 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+desc <<-END_DESC
+Send reminders about issues due in the next days.
+
+Available options:
+ * days => number of days to remind about (defaults to 7)
+ * tracker => id of tracker (defaults to all trackers)
+ * project => id or identifier of project (defaults to all projects)
+ * users => comma separated list of user/group ids who should be reminded
+ * version => name of target version for filtering issues (defaults to none)
+ * max_delay => ignore older issues: how many days after due date to stop sending reminders (defaults to none)
+
+Example:
+ rails redmine_tiny_features:send_reminders days=7 users="1,23, 56" max_delay=100 RAILS_ENV="production"
+END_DESC
+
+namespace :redmine_tiny_features do
+ task :send_reminders => :environment do
+ options = {}
+ options[:days] = ENV['days'].presence&.to_i
+ options[:project] = ENV['project'].presence
+ options[:tracker] = ENV['tracker'].presence&.to_i
+ options[:users] = ENV['users'].presence.to_s.split(',').each(&:strip!)
+ options[:version] = ENV['version'].presence
+ options[:max_delay] = ENV['max_delay'].presence&.to_i
+
+ Mailer.with_synched_deliveries do
+ Mailer.reminders(options)
+ end
+ end
+end
From bc2799df1bb7d5a92bb255bd259bffd31432b7ca Mon Sep 17 00:00:00 2001
From: Vincent Robert
Date: Tue, 29 Mar 2022 11:25:19 +0200
Subject: [PATCH 04/20] Improve comments
---
lib/redmine_tiny_features/mailer_patch.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/redmine_tiny_features/mailer_patch.rb b/lib/redmine_tiny_features/mailer_patch.rb
index d17630b..a9dd415 100644
--- a/lib/redmine_tiny_features/mailer_patch.rb
+++ b/lib/redmine_tiny_features/mailer_patch.rb
@@ -7,7 +7,7 @@ class Mailer < ActionMailer::Base
# * :days => how many days in the future to remind about (defaults to 7)
# * :tracker => id of tracker for filtering issues (defaults to all trackers)
# * :project => id or identifier of project to process (defaults to all projects)
- # * :users => array of user/group ids who should be reminded
+ # * :users => array of assigned user/group ids who should be reminded
# * :version => name of target version for filtering issues (defaults to none)
####### ADDED BY TINY FEATURES PLUGIN 1/3 #######
# * :max_delay => ignore older issues: how many days after due date to stop sending reminders (defaults to none)
From c651a17a09641c0ce2d8f975fb3f5702233595ff Mon Sep 17 00:00:00 2001
From: Vincent Robert
Date: Tue, 29 Mar 2022 11:36:39 +0200
Subject: [PATCH 05/20] Update CI config: add latest Redmine releases
---
.github/workflows/{4_1_6.yml => 4_1_7.yml} | 4 ++--
.github/workflows/{4_2_4.yml => 4_2_5.yml} | 4 ++--
README.md | 8 ++++----
3 files changed, 8 insertions(+), 8 deletions(-)
rename .github/workflows/{4_1_6.yml => 4_1_7.yml} (99%)
rename .github/workflows/{4_2_4.yml => 4_2_5.yml} (99%)
diff --git a/.github/workflows/4_1_6.yml b/.github/workflows/4_1_7.yml
similarity index 99%
rename from .github/workflows/4_1_6.yml
rename to .github/workflows/4_1_7.yml
index 940cb20..e04974a 100644
--- a/.github/workflows/4_1_6.yml
+++ b/.github/workflows/4_1_7.yml
@@ -1,8 +1,8 @@
-name: Tests 4.1.6
+name: Tests 4.1.7
env:
PLUGIN_NAME: redmine_tiny_features
- REDMINE_VERSION: 4.1.6
+ REDMINE_VERSION: 4.1.7
RAILS_ENV: test
on:
diff --git a/.github/workflows/4_2_4.yml b/.github/workflows/4_2_5.yml
similarity index 99%
rename from .github/workflows/4_2_4.yml
rename to .github/workflows/4_2_5.yml
index b16d641..4e9e929 100644
--- a/.github/workflows/4_2_4.yml
+++ b/.github/workflows/4_2_5.yml
@@ -1,8 +1,8 @@
-name: Tests 4.2.4
+name: Tests 4.2.5
env:
PLUGIN_NAME: redmine_tiny_features
- REDMINE_VERSION: 4.2.4
+ REDMINE_VERSION: 4.2.5
RAILS_ENV: test
on:
diff --git a/README.md b/README.md
index d465f38..a601648 100644
--- a/README.md
+++ b/README.md
@@ -18,11 +18,11 @@ Here is a complete list of the features:
|Plugin branch| Redmine Version | Test Status |
|-------------|-------------------|------------------|
-|master | 4.2.4 | [![4.2.4][1]][5] |
-|master | 4.1.6 | [![4.1.6][2]][5] |
+|master | 4.2.5 | [![4.2.5][1]][5] |
+|master | 4.1.7 | [![4.1.7][2]][5] |
|master | master | [![master][3]][5]|
-[1]: https://github.com/nanego/redmine_tiny_features/actions/workflows/4_2_4.yml/badge.svg
-[2]: https://github.com/nanego/redmine_tiny_features/actions/workflows/4_1_6.yml/badge.svg
+[1]: https://github.com/nanego/redmine_tiny_features/actions/workflows/4_2_5.yml/badge.svg
+[2]: https://github.com/nanego/redmine_tiny_features/actions/workflows/4_1_7.yml/badge.svg
[3]: https://github.com/nanego/redmine_tiny_features/actions/workflows/master.yml/badge.svg
[5]: https://github.com/nanego/redmine_tiny_features/actions
From a5766ec5d81c80067530245d6b22efed319bbc89 Mon Sep 17 00:00:00 2001
From: Vincent Robert
Date: Tue, 31 May 2022 15:55:32 +0200
Subject: [PATCH 06/20] Add new 'Range' custom-field format
---
README.md | 1 +
.../custom_fields/formats/_range.html.erb | 14 ++++++
config/locales/en.yml | 5 ++-
config/locales/fr.yml | 3 ++
db/migrate/002_add_step_to_custom_fields.rb | 7 +++
.../field_format_patch.rb | 44 +++++++++++++++++++
spec/controllers/issues_controller_spec.rb | 28 ++++++++++++
spec/controllers/queries_controller_spec.rb | 1 -
spec/models/custom_field_spec.rb | 44 +++++++++++++++++++
9 files changed, 145 insertions(+), 2 deletions(-)
create mode 100644 app/views/custom_fields/formats/_range.html.erb
create mode 100644 db/migrate/002_add_step_to_custom_fields.rb
create mode 100644 spec/controllers/issues_controller_spec.rb
create mode 100644 spec/models/custom_field_spec.rb
diff --git a/README.md b/README.md
index a601648..8dd68ba 100644
--- a/README.md
+++ b/README.md
@@ -13,6 +13,7 @@ Here is a complete list of the features:
* Save **note deletion** in issue journal
* Fix **pasted images** when using Chrome (may be fixed in future Redmine versions according to this issue https://www.redmine.org/issues/36013)
* **Reminders rake task: add max-delay option** to define the maximum number of days after which reminders stop to be sent
+* Add **range** custom-field format
## Test status
diff --git a/app/views/custom_fields/formats/_range.html.erb b/app/views/custom_fields/formats/_range.html.erb
new file mode 100644
index 0000000..69c8277
--- /dev/null
+++ b/app/views/custom_fields/formats/_range.html.erb
@@ -0,0 +1,14 @@
+
+ <%=l(:label_min_max_range)%>
+ <%= f.text_field :min_value, :size => 5, :no_label => true %> -
+ <%= f.text_field :max_value, :size => 5, :no_label => true %>
+
+
+
+ <%=l(:label_steps)%>
+ <%= f.text_field :steps, :size => 5, :no_label => true %>
+
+
+ <%= l(:field_default_value) %>
+ <%= f.text_field :default_value, :size => 5, :no_label => true %>
+
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 06b170d..c4d32ba 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -20,4 +20,7 @@ en:
label_note: 'Note '
setting_journalize_note_deletion: Journalize the note deletion
label_of: 'of '
- text_note_deleted: "%{label} (#%{old}) deleted"
\ No newline at end of file
+ text_note_deleted: "%{label} (#%{old}) deleted"
+ label_range: "Range"
+ label_min_max_range: "Min / Max values"
+ label_steps: "Step"
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index f3c9d88..b0b874a 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -21,3 +21,6 @@ fr:
setting_journalize_note_deletion: Traçabilité des effacements de note
label_of: 'de '
text_note_deleted: "%{label} (#%{old}) supprimée"
+ label_range: "Intervalle"
+ label_min_max_range: "Valeurs minimale et maximale"
+ label_steps: "Incrément"
diff --git a/db/migrate/002_add_step_to_custom_fields.rb b/db/migrate/002_add_step_to_custom_fields.rb
new file mode 100644
index 0000000..4487b15
--- /dev/null
+++ b/db/migrate/002_add_step_to_custom_fields.rb
@@ -0,0 +1,7 @@
+class AddStepToCustomFields < ActiveRecord::Migration[5.2]
+ def change
+ add_column :custom_fields, :steps, :integer
+ add_column :custom_fields, :min_value, :integer
+ add_column :custom_fields, :max_value, :integer
+ end
+end
diff --git a/lib/redmine_tiny_features/field_format_patch.rb b/lib/redmine_tiny_features/field_format_patch.rb
index a7838d4..45d5862 100644
--- a/lib/redmine_tiny_features/field_format_patch.rb
+++ b/lib/redmine_tiny_features/field_format_patch.rb
@@ -14,5 +14,49 @@ def possible_values_records(custom_field, object = nil)
end
end
+ class RangeFormat < Numeric
+ add 'range'
+
+ self.form_partial = 'custom_fields/formats/range'
+
+ def label
+ "label_range"
+ end
+
+ field_attributes :steps, :min_value, :max_value
+
+ def edit_tag(view, tag_id, tag_name, custom_value, options = {})
+ edit_tag = view.range_field_tag(tag_name,
+ custom_value.value || custom_value.custom_field.default_value,
+ options.merge(id: tag_id,
+ min: custom_value.custom_field.min_value,
+ max: custom_value.custom_field.max_value,
+ step: custom_value.custom_field.steps))
+ edit_tag
+ end
+
+ def cast_single_value(custom_field, value, customized = nil)
+ value.to_i
+ end
+
+ def validate_single_value(custom_field, value, customized = nil)
+ errs = super
+ errs << ::I18n.t('activerecord.errors.messages.not_a_number') unless /^[+-]?\d+$/.match?(value.to_s.strip)
+ errs
+ end
+
+ def query_filter_options(custom_field, query)
+ { :type => :integer }
+ end
+
+ def group_statement(custom_field)
+ order_statement(custom_field)
+ end
+ end
+
end
end
+
+class CustomField < ActiveRecord::Base
+ safe_attributes("steps", "min_value", "max_value")
+end
diff --git a/spec/controllers/issues_controller_spec.rb b/spec/controllers/issues_controller_spec.rb
new file mode 100644
index 0000000..5a8a355
--- /dev/null
+++ b/spec/controllers/issues_controller_spec.rb
@@ -0,0 +1,28 @@
+require "spec_helper"
+
+describe IssuesController, type: :controller do
+ render_views
+
+ fixtures :projects, :users, :members, :member_roles, :roles,
+ :issues, :journals, :journal_details, :enabled_modules,
+ :trackers, :issue_statuses, :enumerations, :custom_fields,
+ :custom_values, :custom_fields_projects, :projects_trackers
+
+ before do
+ User.current = User.find(1)
+ @request.session[:user_id] = 1 # admin
+ end
+
+ describe "range custom-field format" do
+ it "can sum several range fields" do
+ field = IssueCustomField.generate!(:field_format => 'range', :is_for_all => true)
+ CustomValue.create!(:customized => Issue.find(1), :custom_field => field, :value => '20')
+ CustomValue.create!(:customized => Issue.find(2), :custom_field => field, :value => '30')
+ get(:index, :params => { :t => ["cf_#{field.id}"] })
+ assert_response :success
+ assert_select '.query-totals'
+ assert_select ".total-for-cf-#{field.id} span.value", :text => '50'
+ end
+ end
+
+end
diff --git a/spec/controllers/queries_controller_spec.rb b/spec/controllers/queries_controller_spec.rb
index 8200e54..0185e44 100644
--- a/spec/controllers/queries_controller_spec.rb
+++ b/spec/controllers/queries_controller_spec.rb
@@ -5,7 +5,6 @@
describe QueriesController, type: :controller do
-
fixtures :users, :projects, :members, :roles
before do
diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb
new file mode 100644
index 0000000..9d0dab1
--- /dev/null
+++ b/spec/models/custom_field_spec.rb
@@ -0,0 +1,44 @@
+require "spec_helper"
+
+describe "CustomField" do
+ describe "Range custom-field format" do
+
+ it "validates Range custom-field before saving" do
+ field = CustomField.new(:name => 'test_before_validation', :field_format => 'range')
+ field.min_value = 0
+ field.max_value = 20
+ field.steps = 2
+ field.searchable = true
+ expect(field.save).to be_truthy
+
+ field.reload
+
+ expect(field.steps).to eq 2
+ expect(field.max_value).to eq 20
+ expect(field.searchable).to be_falsey # Integer values are not searchable
+ end
+
+ it "validates the default_value" do
+ field = CustomField.new(:name => 'Test', :field_format => 'range')
+ field.default_value = 'abc'
+ expect(field.valid?).to be_falsey
+ field.default_value = '6'
+ expect(field.valid?).to be_truthy
+ end
+
+ it "validates possible values" do
+ f = CustomField.new(:field_format => 'range')
+
+ assert f.valid_field_value?(nil)
+ assert f.valid_field_value?('')
+ assert !f.valid_field_value?(' ')
+ assert f.valid_field_value?('123')
+ assert f.valid_field_value?(' 123 ')
+ assert f.valid_field_value?('+123')
+ assert f.valid_field_value?('-123')
+ assert !f.valid_field_value?('9abc')
+ assert f.valid_field_value?(123)
+ end
+
+ end
+end
From f216365de04fd817ecfa6fc7f57cc1134c9e3162 Mon Sep 17 00:00:00 2001
From: Vincent Robert
Date: Tue, 31 May 2022 19:44:30 +0200
Subject: [PATCH 07/20] Range input field: display selected value
---
assets/stylesheets/tiny_features.css | 7 +++++++
lib/redmine_tiny_features/field_format_patch.rb | 9 +++++++++
2 files changed, 16 insertions(+)
diff --git a/assets/stylesheets/tiny_features.css b/assets/stylesheets/tiny_features.css
index 78e3454..bb80d96 100644
--- a/assets/stylesheets/tiny_features.css
+++ b/assets/stylesheets/tiny_features.css
@@ -13,3 +13,10 @@
table.trackers-permissions td.role {color:#999;font-size:90%;font-weight:normal !important;text-align:center;vertical-align:bottom;}
.permissions-header {padding-left: 16px;display: inline-block;}
+
+.range_selected_value {
+ color: #505050;
+ line-height: 1.5em;
+ word-wrap: break-word;
+ padding-left: 8px;
+}
diff --git a/lib/redmine_tiny_features/field_format_patch.rb b/lib/redmine_tiny_features/field_format_patch.rb
index 45d5862..e8ea546 100644
--- a/lib/redmine_tiny_features/field_format_patch.rb
+++ b/lib/redmine_tiny_features/field_format_patch.rb
@@ -32,6 +32,15 @@ def edit_tag(view, tag_id, tag_name, custom_value, options = {})
min: custom_value.custom_field.min_value,
max: custom_value.custom_field.max_value,
step: custom_value.custom_field.steps))
+ edit_tag << view.content_tag(:span, custom_value.value, class: "range_selected_value")
+ edit_tag << view.javascript_tag(
+ <<~JAVASCRIPT
+ $(document).on("input change", "##{tag_id}", function(e) {
+ var value = $(this).val();
+ $(this).next('.range_selected_value').html(value);
+ })
+ JAVASCRIPT
+ )
edit_tag
end
From 2b88d89182e5944315b64288f6831ddfb96c87cf Mon Sep 17 00:00:00 2001
From: jtilatti <104084083+jtilatti@users.noreply.github.com>
Date: Thu, 2 Jun 2022 09:47:54 +0200
Subject: [PATCH 08/20] Add option to activate Select2 on core select filters
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* Déplacement des méthodes de redmine_datetime_custom_field dans redmine_tiny_features
* Supppresion de l'option de pagination quand le plugin redmine_base_select2 n'est pas installé
* Modification de la fonction AddFilter pour prendre en compte la présence ou non du plugin redmine_datetime_custom_field
* Modification du test suite au masquage de l'option pagination quand le plugin redmine_base_select2 n'est pas installé
* Ajout de l'option sur le select2 (avec tests à corriger)
* Correction des tests pour l'option sur select2
* Complétion du Readme
* Changement du nom de la classe css disabled
Co-authored-by: julie
Co-authored-by: Julie TILATTI
Co-authored-by: Vincent Robert
---
README.md | 3 +-
app/overrides/queries/_filters.rb | 13 +++--
...ine_plugin_tiny_features_settings.html.erb | 40 +++++++++++++--
assets/javascripts/redmine_tiny_features.js | 50 ++++++++++++-------
assets/stylesheets/tiny_features.css | 4 ++
config/locales/en.yml | 1 +
config/locales/fr.yml | 1 +
init.rb | 5 +-
.../issue_query_patch.rb | 2 +-
.../time_entry_query_patch.rb | 2 +-
spec/controllers/journals_controller_spec.rb | 1 +
spec/models/issue_query_patch_spec.rb | 35 ++++++++++++-
spec/models/time_entry_query_patch_spec.rb | 3 +-
.../settings_redmine_tiny_features_spec.rb | 16 +++---
14 files changed, 136 insertions(+), 40 deletions(-)
diff --git a/README.md b/README.md
index 8dd68ba..6e5a1b2 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,8 @@ Here is a complete list of the features:
* Define a **default project** selected when creating a new issue without being in a specific project
* Add **check-all / uncheck-all shortcuts** to roles filters
* Improve **roles synthesis** by adding missing informations about issues permissions and trackers
-* Improve load time of **users filters** when there are thousands entries
+* Use or not the select2 plugin
+* Improve load time of **users filters** when there are thousands entries and when the select2 plugin is used
* Save **note deletion** in issue journal
* Fix **pasted images** when using Chrome (may be fixed in future Redmine versions according to this issue https://www.redmine.org/issues/36013)
* **Reminders rake task: add max-delay option** to define the maximum number of days after which reminders stop to be sent
diff --git a/app/overrides/queries/_filters.rb b/app/overrides/queries/_filters.rb
index 9677e53..451b9a4 100644
--- a/app/overrides/queries/_filters.rb
+++ b/app/overrides/queries/_filters.rb
@@ -3,11 +3,17 @@
:insert_after => "div.add-filter",
:text => <
+ // declaration this functions here, in order to generate the path by rails
+
+ function useRedminePluginSelect2(){
+ return <%= Setting.plugin_redmine_tiny_features.key?('use_select2') %>
+ }
- // declaration this function here, in order to generate the path by rails
function updateSelect2ForElements() {
- var activePagination = '<%= Setting["plugin_redmine_tiny_features"]["paginate_issue_filters_values"].present?%>';
- if (activePagination === 'true'){
+ var activeSelect2 = useRedminePluginSelect2()
+ var activePagination = '<%= Setting["plugin_redmine_tiny_features"]["paginate_issue_filters_values"].present? %>';
+
+ if (activeSelect2 && activePagination === 'true'){
// check if values_author_id_1 defined
if ($('#values_author_id_1').length > 0) {
setConfigurationForSelect2($('#values_author_id_1'), '<%= author_values_pagination_path %>');
@@ -27,6 +33,5 @@
}
}
}
-
SELECT2
\ No newline at end of file
diff --git a/app/views/settings/_redmine_plugin_tiny_features_settings.html.erb b/app/views/settings/_redmine_plugin_tiny_features_settings.html.erb
index c4842ca..7f28a7c 100644
--- a/app/views/settings/_redmine_plugin_tiny_features_settings.html.erb
+++ b/app/views/settings/_redmine_plugin_tiny_features_settings.html.erb
@@ -34,13 +34,22 @@
-
+<% if Redmine::Plugin.installed?(:redmine_base_select2) %>
+ <%= label_tag '', { style: 'width: auto;' } do %>
+ <%= check_box_tag "settings[use_select2]", '1', Setting["plugin_redmine_tiny_features"]["use_select2"], :onclick=>"hidePagination()" %>
+ <%= l("setting_use_select2") %>
+ <% end %>
+
+
+
+
<%= label_tag '', { style: 'width: auto;' } do %>
<%= check_box_tag "settings[paginate_issue_filters_values]", '1', Setting["plugin_redmine_tiny_features"]["paginate_issue_filters_values"] %>
<%= l("setting_paginate_issue_filters_values") %>
<% end %>
+<% end %>
@@ -52,8 +61,31 @@
<%= javascript_tag do %>
$(function() {
- if ((typeof $().select2) === 'function') {
- $('#settings_default_project').select2();
- }
+ if ((typeof $().select2) === 'function') {
+ $('#settings_default_project').select2();
+ }
});
+
+ // Avoid to activate pagination if select2 is not active
+ function hidePagination(){
+ paginationObject = $('#paginate_issue_filters_values input')[0]
+ paginationLabel = $('#paginate_issue_filters_values label')[0]
+ select2Checked = $('#settings_use_select2')[0].checked
+
+ if(!select2Checked){
+ paginationObject.checked = false
+ paginationObject.disabled = true
+ paginationLabel.classList.add("disabled-settings-redmine-tiny-features")
+
+ } else {
+ paginationObject.disabled = false
+ paginationLabel.classList.remove("disabled-settings-redmine-tiny-features")
+ }
+ }
+
+ // Add to disabled option pagination when select2 option is not checked when the page is launched
+ hidePagination()
<% end %>
+
+
+
diff --git a/assets/javascripts/redmine_tiny_features.js b/assets/javascripts/redmine_tiny_features.js
index 33ebf40..0c9f0fc 100644
--- a/assets/javascripts/redmine_tiny_features.js
+++ b/assets/javascripts/redmine_tiny_features.js
@@ -36,7 +36,6 @@ function redminePluginDatetimeCustomFieldInstalled() {
}
$(function() {
- if (!redminePluginDatetimeCustomFieldInstalled()) {
addFilter = function (field, operator, values) {
var fieldId = field.replace('.', '_');
var tr = $('#tr_'+fieldId);
@@ -55,42 +54,57 @@ $(function() {
if (tr.length > 0) {
tr.show();
} else {
- buildFilterRow(field, operator, values);
+ if (redminePluginDatetimeCustomFieldInstalled() && (filterOptions['type'] == "date" || filterOptions['type'] == "date_past" )) {
+ buildDateTimeFilterRow(field, operator, values);
+ } else {
+ buildFilterRow(field, operator, values);
+ }
}
$('#cb_'+fieldId).prop('checked', true);
toggleFilter(field);
- toggleMultiSelectIconInit();
+ if(!redminePluginDatetimeCustomFieldInstalled()){
+ toggleMultiSelectIconInit();
+ }
$('#add_filter_select').val('').find('option').each(function() {
if ($(this).attr('value') == field) {
$(this).attr('disabled', true);
}
});
-
addSelect2ToSelectTagsForTinyFeatures();
}
- }
});
+function toggleMultiSelect(el) {
+ if (el.attr('multiple')) {
+ el.removeAttr('multiple');
+ el.attr('size', 1);
+ } else {
+ el.attr('multiple', true);
+ if (el.children().length > 10)
+ el.attr('size', 10);
+ else
+ el.attr('size', 4);
+ }
+ // Patch
+ addSelect2ToSelectTagsForTinyFeatures()
+}
+
/*
Override for addSelect2ToSelectTags, because of addFilter takes time ,we should wait for it to finish.
We use this method of override by variable to ensure that it is executed even if the function addSelect2ToSelectTags of plugin
redmine_datetime_custom_field installed loaded after addSelect2ToSelectTags of this plugin
*/
-addSelect2ToSelectTags = function(){
- $(document).ready(function(){
- addSelect2ToSelectTagsForTinyFeatures();
- });
-}
-
function addSelect2ToSelectTagsForTinyFeatures() {
- if ((typeof $().select2) === 'function') {
- $('#filters select.value').select2({
- containerCss: {width: '300px', minwidth: '300px'},
- width: 'style'
- });
- updateSelect2ForElements();
- }
+ $(document).ready(function(){
+ if (((typeof $().select2) === 'function') && useRedminePluginSelect2() ) {
+ $('#filters select.value').select2({
+ containerCss: {width: '300px', minwidth: '300px'},
+ width: 'style'
+ });
+ updateSelect2ForElements();
+ }
+ })
}
function setConfigurationForSelect2(element, url) {
diff --git a/assets/stylesheets/tiny_features.css b/assets/stylesheets/tiny_features.css
index bb80d96..a37619c 100644
--- a/assets/stylesheets/tiny_features.css
+++ b/assets/stylesheets/tiny_features.css
@@ -14,6 +14,10 @@
table.trackers-permissions td.role {color:#999;font-size:90%;font-weight:normal !important;text-align:center;vertical-align:bottom;}
.permissions-header {padding-left: 16px;display: inline-block;}
+.disabled-settings-redmine-tiny-features {
+ color : #aaa
+}
+
.range_selected_value {
color: #505050;
line-height: 1.5em;
diff --git a/config/locales/en.yml b/config/locales/en.yml
index c4d32ba..9349757 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -21,6 +21,7 @@ en:
setting_journalize_note_deletion: Journalize the note deletion
label_of: 'of '
text_note_deleted: "%{label} (#%{old}) deleted"
+ setting_use_select2: Apply select2 to filters fields
label_range: "Range"
label_min_max_range: "Min / Max values"
label_steps: "Step"
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index b0b874a..f2aab5c 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -21,6 +21,7 @@ fr:
setting_journalize_note_deletion: Traçabilité des effacements de note
label_of: 'de '
text_note_deleted: "%{label} (#%{old}) supprimée"
+ setting_use_select2: Activer Select2 pour faciliter l'utilisation des listes déroulantes
label_range: "Intervalle"
label_min_max_range: "Valeurs minimale et maximale"
label_steps: "Incrément"
diff --git a/init.rb b/init.rb
index e2fbda6..6b2839c 100644
--- a/init.rb
+++ b/init.rb
@@ -34,7 +34,8 @@
'open_issue_when_editing_closed_issues': '',
'simplified_version_form': '1',
'default_project': '',
- 'paginate_issue_filters_values': Rails.env.test? ? '0' : '1',
- 'journalize_note_deletion': Rails.env.test? ? '0' : '1'
+ 'paginate_issue_filters_values': Rails.env.test? || !(Redmine::Plugin.installed?(:redmine_base_select2)) ? '0' : '1',
+ 'journalize_note_deletion': Rails.env.test? ? '0' : '1',
+ 'use_select2': Rails.env.test? || !(Redmine::Plugin.installed?(:redmine_base_select2)) ? '0' : '1'
}
end
diff --git a/lib/redmine_tiny_features/issue_query_patch.rb b/lib/redmine_tiny_features/issue_query_patch.rb
index 92d8d9d..8d6ff4b 100644
--- a/lib/redmine_tiny_features/issue_query_patch.rb
+++ b/lib/redmine_tiny_features/issue_query_patch.rb
@@ -14,7 +14,7 @@ module IssueQueryPatch
def initialize_available_filters
super
# Add this condition,because of there are tests for available_filters in redmine core
- if Setting["plugin_redmine_tiny_features"]["paginate_issue_filters_values"].present?
+ if Setting["plugin_redmine_tiny_features"]["use_select2"].present? && Setting["plugin_redmine_tiny_features"]["paginate_issue_filters_values"].present?
add_available_filter(
"author_id",
:type => :list, :values => lambda { [] }
diff --git a/lib/redmine_tiny_features/time_entry_query_patch.rb b/lib/redmine_tiny_features/time_entry_query_patch.rb
index 3382a58..9b2ac51 100644
--- a/lib/redmine_tiny_features/time_entry_query_patch.rb
+++ b/lib/redmine_tiny_features/time_entry_query_patch.rb
@@ -17,7 +17,7 @@ module TimeEntryQueryPatch
def initialize_available_filters
super
# Add this condition,because of there are tests for available_filters in redmine core
- if Setting["plugin_redmine_tiny_features"]["paginate_issue_filters_values"].present?
+ if Setting["plugin_redmine_tiny_features"]["use_select2"].present? && Setting["plugin_redmine_tiny_features"]["paginate_issue_filters_values"].present?
add_available_filter(
"user_id",
:type => :list_optional, :values => lambda { [] }
diff --git a/spec/controllers/journals_controller_spec.rb b/spec/controllers/journals_controller_spec.rb
index 25a7e28..fa53c7d 100644
--- a/spec/controllers/journals_controller_spec.rb
+++ b/spec/controllers/journals_controller_spec.rb
@@ -20,6 +20,7 @@
"warning_message_on_closed_issues"=>"1",
"default_open_status"=>"2",
"default_project"=>"1",
+ "use_select2"=>"1",
"paginate_issue_filters_values"=>"1",
"journalize_note_deletion"=>"1"
}
diff --git a/spec/models/issue_query_patch_spec.rb b/spec/models/issue_query_patch_spec.rb
index 33aea92..3473734 100644
--- a/spec/models/issue_query_patch_spec.rb
+++ b/spec/models/issue_query_patch_spec.rb
@@ -13,10 +13,11 @@
it "should contain empty values for available_filter author_id, assigned_to_id, updated_by, last_updated_by" do
- Setting.send "plugin_redmine_tiny_features=", {
+ Setting["plugin_redmine_tiny_features"] = {
"warning_message_on_closed_issues"=>"1",
"default_open_status"=>"2",
"default_project"=>"1",
+ "use_select2"=>"1",
"paginate_issue_filters_values"=>"1"
}
@@ -26,4 +27,36 @@
expect(issue_query.available_filters["updated_by"][:values]).to be_empty
expect(issue_query.available_filters["last_updated_by"][:values]).to be_empty
end
+
+ it "should not contain empty values for available_filter author_id, assigned_to_id, updated_by, last_updated_by (use_select2 deactivated only)" do
+
+ Setting["plugin_redmine_tiny_features"] = {
+ "warning_message_on_closed_issues"=>"1",
+ "default_open_status"=>"2",
+ "default_project"=>"1",
+ "paginate_issue_filters_values"=>"1"
+ }
+
+ issue_query = IssueQuery.new
+ expect(issue_query.available_filters["author_id"][:values]).not_to be_empty
+ expect(issue_query.available_filters["assigned_to_id"][:values]).not_to be_empty
+ expect(issue_query.available_filters["updated_by"][:values]).not_to be_empty
+ expect(issue_query.available_filters["last_updated_by"][:values]).not_to be_empty
+ end
+
+ it "should not contain empty values for available_filter author_id, assigned_to_id, updated_by, last_updated_by (use_select2 and paginate_issue_filters_values deactivated)" do
+
+ Setting["plugin_redmine_tiny_features"] = {
+ "warning_message_on_closed_issues"=>"1",
+ "default_open_status"=>"2",
+ "default_project"=>"1",
+ }
+
+ issue_query = IssueQuery.new
+ expect(issue_query.available_filters["author_id"][:values]).not_to be_empty
+ expect(issue_query.available_filters["assigned_to_id"][:values]).not_to be_empty
+ expect(issue_query.available_filters["updated_by"][:values]).not_to be_empty
+ expect(issue_query.available_filters["last_updated_by"][:values]).not_to be_empty
+ end
+
end
diff --git a/spec/models/time_entry_query_patch_spec.rb b/spec/models/time_entry_query_patch_spec.rb
index d8230dc..f99a630 100644
--- a/spec/models/time_entry_query_patch_spec.rb
+++ b/spec/models/time_entry_query_patch_spec.rb
@@ -12,10 +12,11 @@
end
it "should contain empty values for available_filter author_id, user_id" do
- Setting.send "plugin_redmine_tiny_features=", {
+ Setting["plugin_redmine_tiny_features"] = {
"warning_message_on_closed_issues"=>"1",
"default_open_status"=>"2",
"default_project"=>"1",
+ "use_select2"=>"1",
"paginate_issue_filters_values"=>"1"
}
diff --git a/spec/system/settings_redmine_tiny_features_spec.rb b/spec/system/settings_redmine_tiny_features_spec.rb
index 9b703f6..3359707 100644
--- a/spec/system/settings_redmine_tiny_features_spec.rb
+++ b/spec/system/settings_redmine_tiny_features_spec.rb
@@ -4,13 +4,15 @@
fixtures :users
it "Should active the option paginate_issue_filters_values" do
+ if Redmine::Plugin.installed?(:redmine_base_select2)
+ log_user('admin', 'admin')
+ visit 'settings/plugin/redmine_tiny_features'
- log_user('admin', 'admin')
- visit 'settings/plugin/redmine_tiny_features'
-
- find("input[name='settings[paginate_issue_filters_values]']").click
- find("input[name='commit']").click
- expect(Setting["plugin_redmine_tiny_features"]["paginate_issue_filters_values"]).to eq "1"
-
+ find("input[name='settings[use_select2]']").click
+ find("input[name='settings[paginate_issue_filters_values]']").click
+ find("input[name='commit']").click
+ expect(Setting["plugin_redmine_tiny_features"]["use_select2"]).to eq '1'
+ expect(Setting["plugin_redmine_tiny_features"]["paginate_issue_filters_values"]).to eq "1"
+ end
end
end
From 306a5ed174333f33a7d32c85900d416118f0440e Mon Sep 17 00:00:00 2001
From: Yazan
Date: Wed, 8 Jun 2022 10:20:23 +0200
Subject: [PATCH 09/20] =?UTF-8?q?Mettre=20=C3=A0=20jour=20la=20table=20dis?=
=?UTF-8?q?abled=5Fcustom=5Ffield=5Fenumerations=20en=20cas=20de=20suppres?=
=?UTF-8?q?sion=20en=20cascade?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
init.rb | 2 ++
.../custom_field_enumeration_patch.rb | 5 ++++
.../custom_field_patch.rb | 8 ++++++
lib/redmine_tiny_features/project_patch.rb | 2 +-
spec/models/custom_field_spec.rb | 28 +++++++++++++++++++
5 files changed, 44 insertions(+), 1 deletion(-)
create mode 100644 lib/redmine_tiny_features/custom_field_enumeration_patch.rb
create mode 100644 lib/redmine_tiny_features/custom_field_patch.rb
diff --git a/init.rb b/init.rb
index 6b2839c..fc3b7e7 100644
--- a/init.rb
+++ b/init.rb
@@ -16,6 +16,8 @@
require_dependency 'redmine_tiny_features/issues_helper_patch'
require_dependency 'redmine_tiny_features/journal_patch'
require_dependency 'redmine_tiny_features/mailer_patch'
+ require_dependency 'redmine_tiny_features/custom_field_enumeration_patch'
+ require_dependency 'redmine_tiny_features/custom_field_patch'
end
Redmine::Plugin.register :redmine_tiny_features do
diff --git a/lib/redmine_tiny_features/custom_field_enumeration_patch.rb b/lib/redmine_tiny_features/custom_field_enumeration_patch.rb
new file mode 100644
index 0000000..5451669
--- /dev/null
+++ b/lib/redmine_tiny_features/custom_field_enumeration_patch.rb
@@ -0,0 +1,5 @@
+require_dependency 'custom_field_enumeration'
+
+class CustomFieldEnumeration < ActiveRecord::Base
+ has_many :disabled_custom_field_enumerations, :dependent => :delete_all
+end
\ No newline at end of file
diff --git a/lib/redmine_tiny_features/custom_field_patch.rb b/lib/redmine_tiny_features/custom_field_patch.rb
new file mode 100644
index 0000000..11789f7
--- /dev/null
+++ b/lib/redmine_tiny_features/custom_field_patch.rb
@@ -0,0 +1,8 @@
+require_dependency 'custom_field'
+
+class CustomField < ActiveRecord::Base
+ ##### PATCH ,to call the destroy method of (CustomFieldEnumeration has :dependent => :delete_all)
+ has_many :enumerations, lambda {order(:position)},
+ :class_name => 'CustomFieldEnumeration',
+ :dependent => :destroy
+end
\ No newline at end of file
diff --git a/lib/redmine_tiny_features/project_patch.rb b/lib/redmine_tiny_features/project_patch.rb
index 00a05a5..85d3120 100644
--- a/lib/redmine_tiny_features/project_patch.rb
+++ b/lib/redmine_tiny_features/project_patch.rb
@@ -2,6 +2,6 @@
class Project < ActiveRecord::Base
- has_many :disabled_custom_field_enumerations
+ has_many :disabled_custom_field_enumerations, :dependent => :delete_all
end
diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb
index 9d0dab1..fcf147e 100644
--- a/spec/models/custom_field_spec.rb
+++ b/spec/models/custom_field_spec.rb
@@ -40,5 +40,33 @@
assert f.valid_field_value?(123)
end
+ describe "Update the table disabled_custom_field_enumerations in case of cascade deleting" do
+ let(:project) { Project.find(1) }
+ let(:field) { CustomField.create(:name => 'Test', :field_format => 'enumeration') }
+ let(:c_f_e1) { CustomFieldEnumeration.create(name: 'val1', position: 1, active: true, custom_field_id: field.id) }
+ let(:c_f_e2) { CustomFieldEnumeration.create(name: 'val2', position: 2, active: true, custom_field_id: field.id) }
+
+ before do
+ CustomFieldEnumeration.create(name: 'val3', position: 3, active: true, custom_field_id: field.id)
+ DisabledCustomFieldEnumeration.create(project: project, custom_field_enumeration_id: c_f_e1.id)
+ DisabledCustomFieldEnumeration.create(project: project, custom_field_enumeration_id: c_f_e2.id)
+ expect(DisabledCustomFieldEnumeration.count).to eq(2)
+ end
+
+ it "Should update the table disabled_custom_field_enumerations when deleting a project" do
+ project.destroy
+ expect(DisabledCustomFieldEnumeration.count).to eq(0)
+ end
+
+ it "Should update the table disabled_custom_field_enumerations when deleting a customField" do
+ field.destroy
+ expect(DisabledCustomFieldEnumeration.count).to eq(0)
+ end
+
+ it "Should update the table disabled_custom_field_enumerations when deleting a CustomFieldEnumeration" do
+ c_f_e1.destroy
+ expect(DisabledCustomFieldEnumeration.count).to eq(1)
+ end
+ end
end
end
From f59c87422cb01502418fdd1f1f65041d08293477 Mon Sep 17 00:00:00 2001
From: Vincent Robert
Date: Mon, 13 Jun 2022 15:53:54 +0200
Subject: [PATCH 10/20] Apply default value when field is required but not set
---
README.md | 1 +
.../field_format_patch.rb | 34 +++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/README.md b/README.md
index 8dd68ba..8878124 100644
--- a/README.md
+++ b/README.md
@@ -14,6 +14,7 @@ Here is a complete list of the features:
* Fix **pasted images** when using Chrome (may be fixed in future Redmine versions according to this issue https://www.redmine.org/issues/36013)
* **Reminders rake task: add max-delay option** to define the maximum number of days after which reminders stop to be sent
* Add **range** custom-field format
+* Apply **default value** to existing-issues custom-fields if field is required and not set
## Test status
diff --git a/lib/redmine_tiny_features/field_format_patch.rb b/lib/redmine_tiny_features/field_format_patch.rb
index e8ea546..c28e0d7 100644
--- a/lib/redmine_tiny_features/field_format_patch.rb
+++ b/lib/redmine_tiny_features/field_format_patch.rb
@@ -14,6 +14,40 @@ def possible_values_records(custom_field, object = nil)
end
end
+ class List < Base
+ # Renders the edit tag as check box or radio tags
+ def check_box_edit_tag(view, tag_id, tag_name, custom_value, options={})
+ opts = []
+ unless custom_value.custom_field.multiple? || custom_value.custom_field.is_required?
+ opts << ["(#{l(:label_none)})", '']
+ end
+ opts += possible_custom_value_options(custom_value)
+ s = ''.html_safe
+ tag_method = custom_value.custom_field.multiple? ? :check_box_tag : :radio_button_tag
+ opts.each do |label, value|
+ value ||= label
+ checked = (custom_value.value.is_a?(Array) && custom_value.value.include?(value)) ||
+ custom_value.value.to_s == value
+
+ #################
+ ##### START PATCH
+ if custom_value.value.blank? && custom_value.custom_field.is_required? && custom_value.custom_field.default_value.present?
+ checked = custom_value.custom_field.default_value == value
+ end
+ ## END PATCH
+ #################
+
+ tag = view.send(tag_method, tag_name, value, checked, :id => nil)
+ s << view.content_tag('label', tag + ' ' + label)
+ end
+ if custom_value.custom_field.multiple?
+ s << view.hidden_field_tag(tag_name, '', :id => nil)
+ end
+ css = "#{options[:class]} check_box_group"
+ view.content_tag('span', s, options.merge(:class => css))
+ end
+ end
+
class RangeFormat < Numeric
add 'range'
From 28611d2020b0ab411ea44a420c6a5cb1f69b2d69 Mon Sep 17 00:00:00 2001
From: Vincent Robert
Date: Wed, 22 Jun 2022 12:01:35 +0200
Subject: [PATCH 11/20] Update CI config: add latest Redmine releases
---
.github/workflows/{4_2_5.yml => 4_2_7.yml} | 4 ++--
README.md | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
rename .github/workflows/{4_2_5.yml => 4_2_7.yml} (99%)
diff --git a/.github/workflows/4_2_5.yml b/.github/workflows/4_2_7.yml
similarity index 99%
rename from .github/workflows/4_2_5.yml
rename to .github/workflows/4_2_7.yml
index 4e9e929..e15d0c8 100644
--- a/.github/workflows/4_2_5.yml
+++ b/.github/workflows/4_2_7.yml
@@ -1,8 +1,8 @@
-name: Tests 4.2.5
+name: Tests 4.2.7
env:
PLUGIN_NAME: redmine_tiny_features
- REDMINE_VERSION: 4.2.5
+ REDMINE_VERSION: 4.2.7
RAILS_ENV: test
on:
diff --git a/README.md b/README.md
index 4859448..15d7ed9 100644
--- a/README.md
+++ b/README.md
@@ -21,11 +21,11 @@ Here is a complete list of the features:
|Plugin branch| Redmine Version | Test Status |
|-------------|-------------------|------------------|
-|master | 4.2.5 | [![4.2.5][1]][5] |
+|master | 4.2.7 | [![4.2.7][1]][5] |
|master | 4.1.7 | [![4.1.7][2]][5] |
|master | master | [![master][3]][5]|
-[1]: https://github.com/nanego/redmine_tiny_features/actions/workflows/4_2_5.yml/badge.svg
+[1]: https://github.com/nanego/redmine_tiny_features/actions/workflows/4_2_7.yml/badge.svg
[2]: https://github.com/nanego/redmine_tiny_features/actions/workflows/4_1_7.yml/badge.svg
[3]: https://github.com/nanego/redmine_tiny_features/actions/workflows/master.yml/badge.svg
[5]: https://github.com/nanego/redmine_tiny_features/actions
From 09447bccb4a5b46942b0ae3a09beea10fc438f6a Mon Sep 17 00:00:00 2001
From: Vincent Robert
Date: Tue, 2 Aug 2022 16:32:11 +0200
Subject: [PATCH 12/20] Improve compatibility with RedmineLimitedVisibility
plugin
---
assets/javascripts/redmine_tiny_features.js | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/assets/javascripts/redmine_tiny_features.js b/assets/javascripts/redmine_tiny_features.js
index 0c9f0fc..3a97704 100644
--- a/assets/javascripts/redmine_tiny_features.js
+++ b/assets/javascripts/redmine_tiny_features.js
@@ -35,6 +35,11 @@ function redminePluginDatetimeCustomFieldInstalled() {
return !(typeof buildDateTimeFilterRow === "undefined")
}
+// check if plugin redmine_limited_visibility is installed
+function redminePluginLimitedVisibilityIsInstalled() {
+ return !(typeof buildListVisibilityFilterRow === "undefined")
+}
+
$(function() {
addFilter = function (field, operator, values) {
var fieldId = field.replace('.', '_');
@@ -54,14 +59,24 @@ $(function() {
if (tr.length > 0) {
tr.show();
} else {
- if (redminePluginDatetimeCustomFieldInstalled() && (filterOptions['type'] == "date" || filterOptions['type'] == "date_past" )) {
+ if (redminePluginDatetimeCustomFieldInstalled() && (filterOptions['type'] == "date" || filterOptions['type'] == "date_past" )) {
buildDateTimeFilterRow(field, operator, values);
} else {
- buildFilterRow(field, operator, values);
+ if (redminePluginLimitedVisibilityIsInstalled() && (filterOptions['type'] == "list_visibility")) {
+ buildListVisibilityFilterRow(field, operator, values);
+ } else {
+ buildFilterRow(field, operator, values);
+ }
}
}
$('#cb_'+fieldId).prop('checked', true);
- toggleFilter(field);
+
+ if (redminePluginLimitedVisibilityIsInstalled() && ($("#operators_" + fieldId).val() == 'mine')) {
+ enableValues(field, []);
+ } else {
+ toggleFilter(field);
+ }
+
if(!redminePluginDatetimeCustomFieldInstalled()){
toggleMultiSelectIconInit();
}
From d3c46836fe53a7a1fce69268d9694581a5e20722 Mon Sep 17 00:00:00 2001
From: Vincent Robert
Date: Tue, 9 Aug 2022 16:13:37 +0200
Subject: [PATCH 13/20] Fix performance issue when filtering by custom-values
---
README.md | 1 +
init.rb | 1 +
.../issue_custom_field_patch.rb | 13 +++
lib/redmine_tiny_features/project_patch.rb | 79 ++++++++++++++++++-
4 files changed, 93 insertions(+), 1 deletion(-)
create mode 100644 lib/redmine_tiny_features/issue_custom_field_patch.rb
diff --git a/README.md b/README.md
index 15d7ed9..1b1bb3d 100644
--- a/README.md
+++ b/README.md
@@ -16,6 +16,7 @@ Here is a complete list of the features:
* **Reminders rake task: add max-delay option** to define the maximum number of days after which reminders stop to be sent
* Add **range** custom-field format
* Apply **default value** to existing-issues custom-fields if field is required and not set
+* Fix performance problem when filtering issues by custom-values (remove this patch when issue has been addressed in Redmine Core: https://www.redmine.org/issues/37565)
## Test status
diff --git a/init.rb b/init.rb
index fc3b7e7..2371dd4 100644
--- a/init.rb
+++ b/init.rb
@@ -18,6 +18,7 @@
require_dependency 'redmine_tiny_features/mailer_patch'
require_dependency 'redmine_tiny_features/custom_field_enumeration_patch'
require_dependency 'redmine_tiny_features/custom_field_patch'
+ require_dependency 'redmine_tiny_features/issue_custom_field_patch'
end
Redmine::Plugin.register :redmine_tiny_features do
diff --git a/lib/redmine_tiny_features/issue_custom_field_patch.rb b/lib/redmine_tiny_features/issue_custom_field_patch.rb
new file mode 100644
index 0000000..2fd38b0
--- /dev/null
+++ b/lib/redmine_tiny_features/issue_custom_field_patch.rb
@@ -0,0 +1,13 @@
+class IssueCustomField < CustomField
+
+ def visibility_by_project_condition(project_key = nil, user = User.current, id_column = nil)
+ sql = super
+ id_column ||= id
+ tracker_condition = "#{Issue.table_name}.tracker_id IN (SELECT tracker_id FROM #{table_name_prefix}custom_fields_trackers#{table_name_suffix} WHERE custom_field_id = #{id_column})"
+ project_condition = "EXISTS (SELECT 1 FROM #{CustomField.table_name} ifa WHERE ifa.is_for_all = #{self.class.connection.quoted_true} AND ifa.id = #{id_column})" +
+ " OR #{Issue.table_name}.project_id IN (SELECT project_id FROM #{table_name_prefix}custom_fields_projects#{table_name_suffix} WHERE custom_field_id = #{id_column})"
+
+ "((#{sql}) AND (#{tracker_condition}) AND (#{project_condition}) AND (#{Issue.visible_condition(user, { skip_pre_condition: true })}))"
+ end
+
+end
diff --git a/lib/redmine_tiny_features/project_patch.rb b/lib/redmine_tiny_features/project_patch.rb
index 85d3120..6e276d4 100644
--- a/lib/redmine_tiny_features/project_patch.rb
+++ b/lib/redmine_tiny_features/project_patch.rb
@@ -2,6 +2,83 @@
class Project < ActiveRecord::Base
- has_many :disabled_custom_field_enumerations, :dependent => :delete_all
+ has_many :disabled_custom_field_enumerations, :dependent => :delete_all
end
+
+module RedmineTinyFeatures
+ module ProjectPatch
+
+ # Returns a SQL conditions string used to find all projects for which +user+ has the given +permission+
+ #
+ # Valid options:
+ # * :skip_pre_condition => true don't check that the module is enabled (eg. when the condition is already set elsewhere in the query)
+ # * :project => project limit the condition to project
+ # * :with_subprojects => true limit the condition to project and its subprojects
+ # * :member => true limit the condition to the user projects
+ def allowed_to_condition(user, permission, options={})
+ perm = Redmine::AccessControl.permission(permission)
+ if options[:skip_pre_condition]
+ base_statement = "1=1"
+ else
+ base_statement = if perm && perm.read?
+ "#{Project.table_name}.status <> #{Project::STATUS_ARCHIVED}"
+ else
+ "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}"
+ end
+ if perm && perm.project_module
+ # If the permission belongs to a project module, make sure the module is enabled
+ base_statement +=
+ " AND EXISTS (SELECT 1 AS one FROM #{EnabledModule.table_name} em" \
+ " WHERE em.project_id = #{Project.table_name}.id" \
+ " AND em.name='#{perm.project_module}')"
+ end
+ end
+ if project = options[:project]
+ project_statement = project.project_condition(options[:with_subprojects])
+ base_statement = "(#{project_statement}) AND (#{base_statement})"
+ end
+
+ if user.admin?
+ base_statement
+ else
+ statement_by_role = {}
+ unless options[:member]
+ role = user.builtin_role
+ if role.allowed_to?(permission)
+ s = "#{Project.table_name}.is_public = #{connection.quoted_true}"
+ if user.id
+ group = role.anonymous? ? Group.anonymous : Group.non_member
+ principal_ids = [user.id, group.id].compact
+ s =
+ "(#{s} AND #{Project.table_name}.id NOT IN " \
+ "(SELECT project_id FROM #{Member.table_name} " \
+ "WHERE user_id IN (#{principal_ids.join(',')})))"
+ end
+ statement_by_role[role] = s
+ end
+ end
+ user.project_ids_by_role.each do |role, project_ids|
+ if role.allowed_to?(permission) && project_ids.any?
+ statement_by_role[role] = "#{Project.table_name}.id IN (#{project_ids.join(',')})"
+ end
+ end
+ if statement_by_role.empty?
+ "1=0"
+ else
+ if block_given?
+ statement_by_role.each do |role, statement|
+ if s = yield(role, user)
+ statement_by_role[role] = "(#{statement} AND (#{s}))"
+ end
+ end
+ end
+ "((#{base_statement}) AND (#{statement_by_role.values.join(' OR ')}))"
+ end
+ end
+ end
+
+ end
+end
+
+Project.singleton_class.prepend RedmineTinyFeatures::ProjectPatch
From f52597c7a5a080922e435c22372e304347726577 Mon Sep 17 00:00:00 2001
From: Vincent Robert
Date: Tue, 9 Aug 2022 17:32:53 +0200
Subject: [PATCH 14/20] Add missing dependency
---
lib/redmine_tiny_features/issue_custom_field_patch.rb | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lib/redmine_tiny_features/issue_custom_field_patch.rb b/lib/redmine_tiny_features/issue_custom_field_patch.rb
index 2fd38b0..99d4ee8 100644
--- a/lib/redmine_tiny_features/issue_custom_field_patch.rb
+++ b/lib/redmine_tiny_features/issue_custom_field_patch.rb
@@ -1,3 +1,5 @@
+require 'issue_custom_field'
+
class IssueCustomField < CustomField
def visibility_by_project_condition(project_key = nil, user = User.current, id_column = nil)
From 641e53e58cb87af0570a50526e02dcd7a9cb24c9 Mon Sep 17 00:00:00 2001
From: Yazan ALAEDDIN
Date: Fri, 9 Sep 2022 12:36:50 +0200
Subject: [PATCH 15/20] =?UTF-8?q?Pouvoir=20filtrer=20les=20projets=20par?=
=?UTF-8?q?=20modules=20activ=C3=A9s?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
config/locales/en.yml | 1 +
config/locales/fr.yml | 1 +
init.rb | 1 +
lib/redmine_tiny_features/project_patch.rb | 12 ++--
.../project_query_patch.rb | 38 ++++++++++++
spec/controllers/projects_controller_spec.rb | 61 +++++++++++++++++++
spec/models/project_query_spec.rb | 57 +++++++++++++++++
7 files changed, 167 insertions(+), 4 deletions(-)
create mode 100644 lib/redmine_tiny_features/project_query_patch.rb
create mode 100644 spec/controllers/projects_controller_spec.rb
create mode 100644 spec/models/project_query_spec.rb
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 9349757..58ecc18 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -25,3 +25,4 @@ en:
label_range: "Range"
label_min_max_range: "Min / Max values"
label_steps: "Step"
+ field_module_enabled: "Enabled modules"
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index f2aab5c..d08ea96 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -25,3 +25,4 @@ fr:
label_range: "Intervalle"
label_min_max_range: "Valeurs minimale et maximale"
label_steps: "Incrément"
+ field_module_enabled: "Modules activés"
diff --git a/init.rb b/init.rb
index 2371dd4..59969b4 100644
--- a/init.rb
+++ b/init.rb
@@ -19,6 +19,7 @@
require_dependency 'redmine_tiny_features/custom_field_enumeration_patch'
require_dependency 'redmine_tiny_features/custom_field_patch'
require_dependency 'redmine_tiny_features/issue_custom_field_patch'
+ require_dependency 'redmine_tiny_features/project_query_patch'
end
Redmine::Plugin.register :redmine_tiny_features do
diff --git a/lib/redmine_tiny_features/project_patch.rb b/lib/redmine_tiny_features/project_patch.rb
index 6e276d4..f294393 100644
--- a/lib/redmine_tiny_features/project_patch.rb
+++ b/lib/redmine_tiny_features/project_patch.rb
@@ -4,6 +4,10 @@ class Project < ActiveRecord::Base
has_many :disabled_custom_field_enumerations, :dependent => :delete_all
+ def module_enabled
+ EnabledModule.where("project_id = ? ", self.id).map { |e_m| l("project_module_#{e_m.name}") }
+ end
+
end
module RedmineTinyFeatures
@@ -22,10 +26,10 @@ def allowed_to_condition(user, permission, options={})
base_statement = "1=1"
else
base_statement = if perm && perm.read?
- "#{Project.table_name}.status <> #{Project::STATUS_ARCHIVED}"
- else
- "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}"
- end
+ "#{Project.table_name}.status <> #{Project::STATUS_ARCHIVED}"
+ else
+ "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}"
+ end
if perm && perm.project_module
# If the permission belongs to a project module, make sure the module is enabled
base_statement +=
diff --git a/lib/redmine_tiny_features/project_query_patch.rb b/lib/redmine_tiny_features/project_query_patch.rb
new file mode 100644
index 0000000..41d2594
--- /dev/null
+++ b/lib/redmine_tiny_features/project_query_patch.rb
@@ -0,0 +1,38 @@
+require_dependency 'query'
+require_dependency 'project_query'
+
+class ProjectQuery < Query
+ self.available_columns << QueryColumn.new(:module_enabled, :sortable => false, :default_order => 'asc')
+end
+
+module PluginRedmineTinyFeatures
+ module ProjectQueryPatch
+
+ def initialize_available_filters
+ super
+
+ module_values = EnabledModule.all.collect { |s| [l("project_module_#{s.name}"), s.name] }.sort_by { |v| v.first }.uniq
+ add_available_filter("module_enabled", :type => :list_subprojects, :values => module_values)
+ end
+
+ def sql_for_module_enabled_field(field, operator, value)
+ case operator
+ when "!*", "*"
+ module_enabled_table = EnabledModule.table_name
+ project_table = Project.table_name
+ #return only the projects for which a particular module or module group is activated
+ "#{project_table}.id #{ operator == '*' ? 'IN' : 'NOT IN' } (SELECT #{module_enabled_table}.project_id FROM #{module_enabled_table} " +
+ "JOIN #{project_table} ON #{module_enabled_table}.project_id = #{project_table}.id " + ') '
+ when "=", "!"
+ module_enabled_table = EnabledModule.table_name
+ project_table = Project.table_name
+ #return only the projects for which a particular module or module group is activated
+ "#{project_table}.id #{ operator == '=' ? 'IN' : 'NOT IN' } (SELECT #{module_enabled_table}.project_id FROM #{module_enabled_table} " +
+ "JOIN #{project_table} ON #{module_enabled_table}.project_id = #{project_table}.id AND " +
+ sql_for_field('name', '=', value, module_enabled_table, 'name') + ') '
+ end
+ end
+ end
+end
+
+ProjectQuery.prepend PluginRedmineTinyFeatures::ProjectQueryPatch
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb
new file mode 100644
index 0000000..b415625
--- /dev/null
+++ b/spec/controllers/projects_controller_spec.rb
@@ -0,0 +1,61 @@
+require "spec_helper"
+require "active_support/testing/assertions"
+
+describe ProjectsController, type: :controller do
+ include ActiveSupport::Testing::Assertions
+
+ render_views
+
+ fixtures :users, :projects, :enabled_modules
+
+ before do
+ @request.session[:user_id] = 1 #=> admin ; permissions are hard...
+ end
+
+ context "Add a filter on the projects page: module activated" do
+
+ it "should query use module_enabled when index with column module_enabled" do
+ columns = ['name', 'module_enabled']
+ get :index, params: { :set_filter => 1, :c => columns }
+ expect(response).to be_successful
+ # query should use specified columns
+ query = assigns(:query)
+
+ assert_kind_of ProjectQuery, query
+ expect(query.column_names.map(&:to_s)).to eq columns
+ end
+
+ it "should ensure that the changes are compatible with the CSV" do
+ module_test = "issue_tracking"
+ columns = ['name', 'module_enabled']
+
+ get :index, params: { :set_filter => 1,
+ :f => ["module_enabled"],
+ :op => { "module_enabled" => "=" },
+ :v => { "module_enabled" => [module_test] },
+ :c => columns,
+ :format => 'csv' }
+
+ expect(response).to be_successful
+ expect(response.media_type).to eq 'text/csv'
+
+ lines = response.body.chomp.split("\n")
+
+ expect(lines[0].split(',')[1]).to eq "Enabled modules"
+
+ # projects for which the module Issue tracking is enabled
+ ids = EnabledModule.where(name: module_test).map{ |e_m| e_m.project_id }
+ # except the first line ( names of columns )
+ expect(lines.count - 1).to eq(ids.count)
+
+ project_csv = []
+
+ lines.count.times do |count|
+ project_csv.push( lines[count].split(',')[0]) if count > 0
+ expect(lines[count].split(',').to_s).to include("Issue tracking") if count > 0
+ end
+
+ expect(project_csv.sort).to eq(Project.where(id: ids).map(&:name).sort)
+ end
+ end
+end
\ No newline at end of file
diff --git a/spec/models/project_query_spec.rb b/spec/models/project_query_spec.rb
new file mode 100644
index 0000000..5e92a51
--- /dev/null
+++ b/spec/models/project_query_spec.rb
@@ -0,0 +1,57 @@
+require 'spec_helper'
+
+describe "ProjectQuery" do
+ fixtures :users, :projects, :enabled_modules
+
+ before do
+ User.current = User.find(1)
+ end
+
+ def find_projects_with_query(query)
+ Project.where(
+ query.statement
+ ).all
+ end
+
+ it "should ProjectQuery have available_filters module_enabled" do
+ query = ProjectQuery.new
+ expect(query.available_filters).to include 'module_enabled'
+ end
+
+ describe "should filter projects with module_enabled" do
+ let!(:module_test) { "wiki" }
+
+ it "operator equal =" do
+ # projects for which the module wiki is enabled
+ ids = EnabledModule.where(name: module_test).map{|e_m| e_m.project_id }
+ query = ProjectQuery.new(:name => '_', :filters => { 'module_enabled' => { :operator => '=', :values => [module_test] } })
+ result = find_projects_with_query(query)
+
+ expect(result.count).to eq (ids.count)
+ expect(result.to_a).to eq(Project.where(id: ids))
+ end
+
+ it "operator not equal !" do
+ ids = EnabledModule.where(name: module_test).map{|e_m| e_m.project_id }
+ query = ProjectQuery.new(:name => '_', :filters => { 'module_enabled' => { :operator => '!', :values => [module_test] } })
+ result = find_projects_with_query(query)
+
+ expect(result.count).to eq ((Project.count - ids.count))
+ expect(result.to_a).not_to eq(Project.where(id: ids))
+ end
+
+ it "operator all *" do
+ query = ProjectQuery.new(:name => '_', :filters => { 'module_enabled' => { :operator => '*', :values => [''] } })
+ result = find_projects_with_query(query)
+
+ expect(result.count).to eq (EnabledModule.all.map{ |e_m| e_m.project_id }.uniq.count)
+ end
+
+ it "operator any !*" do
+ query = ProjectQuery.new(:name => '_', :filters => { 'module_enabled' => { :operator => '!*', :values => [''] } })
+ result = find_projects_with_query(query)
+
+ expect(result.count).to eq ((Project.all.map(&:id).uniq - EnabledModule.all.map{ |e_m| e_m.project_id }.uniq).count)
+ end
+ end
+end
From 3dd8805b7f41c407d006f5941f760fda51c01d0f Mon Sep 17 00:00:00 2001
From: Vincent Robert
Date: Mon, 12 Sep 2022 16:22:49 +0200
Subject: [PATCH 16/20] Complete Readme and include new enabled-modules filter
and column
---
README.md | 1 +
lib/redmine_tiny_features/project_patch.rb | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 1b1bb3d..840c6a0 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,7 @@ Here is a complete list of the features:
* Add **range** custom-field format
* Apply **default value** to existing-issues custom-fields if field is required and not set
* Fix performance problem when filtering issues by custom-values (remove this patch when issue has been addressed in Redmine Core: https://www.redmine.org/issues/37565)
+* Add **enabled modules** filter and column in projects list
## Test status
diff --git a/lib/redmine_tiny_features/project_patch.rb b/lib/redmine_tiny_features/project_patch.rb
index f294393..81bf07d 100644
--- a/lib/redmine_tiny_features/project_patch.rb
+++ b/lib/redmine_tiny_features/project_patch.rb
@@ -5,7 +5,7 @@ class Project < ActiveRecord::Base
has_many :disabled_custom_field_enumerations, :dependent => :delete_all
def module_enabled
- EnabledModule.where("project_id = ? ", self.id).map { |e_m| l("project_module_#{e_m.name}") }
+ EnabledModule.where("project_id = ? ", self.id).order(:name).map { |e_m| l("project_module_#{e_m.name}") }
end
end
From 0522eac032bd9a4230ad944ef6ac3ddb224ea6d9 Mon Sep 17 00:00:00 2001
From: Yazan ALAEDDIN
Date: Wed, 5 Oct 2022 14:19:42 +0200
Subject: [PATCH 17/20] Ajouter une option pour les trackers qui permet de
bloquer la copie des demandes
---
app/overrides/context_menus/issues.rb | 6 ++++++
app/overrides/issues/_action_menu.rb | 6 ++++++
app/overrides/trackers/_form.rb | 7 +++++++
...21004142452_add_trackers_prevent_copy_issues.rb | 5 +++++
lib/redmine_tiny_features/tracker_patch.rb | 3 +++
spec/models/tracker_query_spec.rb | 14 ++++++++++++++
6 files changed, 41 insertions(+)
create mode 100644 app/overrides/context_menus/issues.rb
create mode 100644 app/overrides/issues/_action_menu.rb
create mode 100644 app/overrides/trackers/_form.rb
create mode 100644 db/migrate/20221004142452_add_trackers_prevent_copy_issues.rb
create mode 100644 lib/redmine_tiny_features/tracker_patch.rb
create mode 100644 spec/models/tracker_query_spec.rb
diff --git a/app/overrides/context_menus/issues.rb b/app/overrides/context_menus/issues.rb
new file mode 100644
index 0000000..b185b66
--- /dev/null
+++ b/app/overrides/context_menus/issues.rb
@@ -0,0 +1,6 @@
+Deface::Override.new :virtual_path => 'context_menus/issues',
+ :name => 'hide-copy-issue-if-tracker-prevents-it',
+ :insert_bottom=> 'erb[loud]:contains("context_menu_link l(:button_copy)")',
+ :text => <<-HIDE_LINK
+ if !@issue.tracker.prevent_copy_issues
+HIDE_LINK
\ No newline at end of file
diff --git a/app/overrides/issues/_action_menu.rb b/app/overrides/issues/_action_menu.rb
new file mode 100644
index 0000000..cd05437
--- /dev/null
+++ b/app/overrides/issues/_action_menu.rb
@@ -0,0 +1,6 @@
+Deface::Override.new :virtual_path => 'issues/_action_menu',
+ :name => 'hide-copy-issue-if-tracker-prevents-it',
+ :insert_bottom=> 'erb[loud]:contains("link_to l(:button_copy)")',
+ :text => <<-HIDE_LINK
+ && !@issue.tracker.prevent_copy_issues
+HIDE_LINK
\ No newline at end of file
diff --git a/app/overrides/trackers/_form.rb b/app/overrides/trackers/_form.rb
new file mode 100644
index 0000000..379f682
--- /dev/null
+++ b/app/overrides/trackers/_form.rb
@@ -0,0 +1,7 @@
+Deface::Override.new :virtual_path => "trackers/_form",
+ :name => "add-prevent-copy-issues",
+ :insert_after => "p:eq(2)",
+ :text => <<-EOS
+<%= f.check_box :prevent_copy_issues %>
+EOS
+
diff --git a/db/migrate/20221004142452_add_trackers_prevent_copy_issues.rb b/db/migrate/20221004142452_add_trackers_prevent_copy_issues.rb
new file mode 100644
index 0000000..6ecde04
--- /dev/null
+++ b/db/migrate/20221004142452_add_trackers_prevent_copy_issues.rb
@@ -0,0 +1,5 @@
+class AddTrackersPreventCopyIssues < ActiveRecord::Migration[5.2]
+ def change
+ add_column :trackers, :prevent_copy_issues, :boolean, :default => false
+ end
+end
diff --git a/lib/redmine_tiny_features/tracker_patch.rb b/lib/redmine_tiny_features/tracker_patch.rb
new file mode 100644
index 0000000..a2db022
--- /dev/null
+++ b/lib/redmine_tiny_features/tracker_patch.rb
@@ -0,0 +1,3 @@
+class Tracker < ActiveRecord::Base
+ safe_attributes('prevent_copy_issues')
+end
\ No newline at end of file
diff --git a/spec/models/tracker_query_spec.rb b/spec/models/tracker_query_spec.rb
new file mode 100644
index 0000000..37a8afa
--- /dev/null
+++ b/spec/models/tracker_query_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe "TrackerPatch" do
+ fixtures :trackers
+
+ it "should Tracker#prevent_copy_issues" do
+ tracker = Tracker.find(1)
+ tracker.safe_attributes=({ "prevent_copy_issues" => 1 })
+ assert tracker.prevent_copy_issues
+
+ tracker.safe_attributes=({ "prevent_copy_issues" => 0 })
+ assert !tracker.prevent_copy_issues
+ end
+end
\ No newline at end of file
From eee50928ecf73dca5f4eb68dc0d83626ba8e7998 Mon Sep 17 00:00:00 2001
From: Yazan ALAEDDIN
Date: Wed, 5 Oct 2022 14:27:11 +0200
Subject: [PATCH 18/20] test l'absence de lien copy dans les pages issue/show +
issues/index
---
init.rb | 1 +
spec/system/issues_spec.rb | 32 ++++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/init.rb b/init.rb
index 59969b4..9e18884 100644
--- a/init.rb
+++ b/init.rb
@@ -15,6 +15,7 @@
require_dependency 'redmine_tiny_features/time_entry_query_patch'
require_dependency 'redmine_tiny_features/issues_helper_patch'
require_dependency 'redmine_tiny_features/journal_patch'
+ require_dependency 'redmine_tiny_features/tracker_patch'
require_dependency 'redmine_tiny_features/mailer_patch'
require_dependency 'redmine_tiny_features/custom_field_enumeration_patch'
require_dependency 'redmine_tiny_features/custom_field_patch'
diff --git a/spec/system/issues_spec.rb b/spec/system/issues_spec.rb
index 9416000..3f49d05 100644
--- a/spec/system/issues_spec.rb
+++ b/spec/system/issues_spec.rb
@@ -115,5 +115,37 @@ def log_user(login, password)
end
end
+ describe "option prevent copy issues" do
+ it "Show link copy when its tracker allows copy issues page(issue/show)" do
+ visit 'issues/2'
+ expect(page).to have_selector('a' , class: 'icon-copy', text: 'Copy')
+ end
+
+ it "Show link copy when its tracker allows copy issues page(issue/index)" do
+ visit 'issues/'
+
+ find('tr#issue-2>td.buttons>a.icon-actions').click
+ expect(page).to have_selector('a.icon-copy')
+ end
+
+ it "Hide link copy when its tracker prevents copy issues page(issue/show)" do
+ tracker_test = Tracker.find(2)
+ tracker_test.prevent_copy_issues = true
+ tracker_test.save
+
+ visit 'issues/2'
+ expect(page).to_not have_selector('a', class: 'icon-copy', text: 'Copy')
+ end
+
+ it "Hide link copy when its tracker prevents copy issues page(issue/index)" do
+ tracker_test = Tracker.find(2)
+ tracker_test.prevent_copy_issues = true
+ tracker_test.save
+
+ visit 'issues/'
+ find('tr#issue-2>td.buttons>a.icon-actions').click
+ expect(page).to_not have_selector('a.icon-copy')
+ end
+ end
end
From c35d439d3f47c54133bfc9271fa9e8f0daa4a8a9 Mon Sep 17 00:00:00 2001
From: Yazan ALAEDDIN
Date: Wed, 5 Oct 2022 14:47:51 +0200
Subject: [PATCH 19/20] Ajouter la conditions @issue.present?
---
app/overrides/context_menus/issues.rb | 2 +-
app/overrides/issues/_action_menu.rb | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/overrides/context_menus/issues.rb b/app/overrides/context_menus/issues.rb
index b185b66..1fa95a5 100644
--- a/app/overrides/context_menus/issues.rb
+++ b/app/overrides/context_menus/issues.rb
@@ -2,5 +2,5 @@
:name => 'hide-copy-issue-if-tracker-prevents-it',
:insert_bottom=> 'erb[loud]:contains("context_menu_link l(:button_copy)")',
:text => <<-HIDE_LINK
- if !@issue.tracker.prevent_copy_issues
+ if @issue.present? && !@issue.tracker.prevent_copy_issues
HIDE_LINK
\ No newline at end of file
diff --git a/app/overrides/issues/_action_menu.rb b/app/overrides/issues/_action_menu.rb
index cd05437..3ad1d53 100644
--- a/app/overrides/issues/_action_menu.rb
+++ b/app/overrides/issues/_action_menu.rb
@@ -2,5 +2,5 @@
:name => 'hide-copy-issue-if-tracker-prevents-it',
:insert_bottom=> 'erb[loud]:contains("link_to l(:button_copy)")',
:text => <<-HIDE_LINK
- && !@issue.tracker.prevent_copy_issues
+ && @issue.present? && !@issue.tracker.prevent_copy_issues
HIDE_LINK
\ No newline at end of file
From 7e5277e1fd9fa023ca9b3a0214378b34ca8b3f93 Mon Sep 17 00:00:00 2001
From: Yazan ALAEDDIN
Date: Wed, 5 Oct 2022 15:40:59 +0200
Subject: [PATCH 20/20] =?UTF-8?q?Pr=C3=A9ciser=20le=20s=C3=A9lecteur=20,ca?=
=?UTF-8?q?r=20il=20y=20a=20deux=20s=C3=A9lecteurs=20qui=20correspondent?=
=?UTF-8?q?=20=C3=A0=20context=5Fmenu=5Flink=20l(:button=5Fcopy)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/overrides/context_menus/issues.rb | 4 ++--
app/overrides/issues/_action_menu.rb | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/app/overrides/context_menus/issues.rb b/app/overrides/context_menus/issues.rb
index 1fa95a5..70904fd 100644
--- a/app/overrides/context_menus/issues.rb
+++ b/app/overrides/context_menus/issues.rb
@@ -1,6 +1,6 @@
Deface::Override.new :virtual_path => 'context_menus/issues',
:name => 'hide-copy-issue-if-tracker-prevents-it',
- :insert_bottom=> 'erb[loud]:contains("context_menu_link l(:button_copy)")',
+ :insert_bottom=> 'erb[loud]:contains("context_menu_link l(:button_copy), project_copy_issue_path(@project, @issue)")',
:text => <<-HIDE_LINK
- if @issue.present? && !@issue.tracker.prevent_copy_issues
+ if !@issue.tracker.prevent_copy_issues
HIDE_LINK
\ No newline at end of file
diff --git a/app/overrides/issues/_action_menu.rb b/app/overrides/issues/_action_menu.rb
index 3ad1d53..e00b73a 100644
--- a/app/overrides/issues/_action_menu.rb
+++ b/app/overrides/issues/_action_menu.rb
@@ -2,5 +2,5 @@
:name => 'hide-copy-issue-if-tracker-prevents-it',
:insert_bottom=> 'erb[loud]:contains("link_to l(:button_copy)")',
:text => <<-HIDE_LINK
- && @issue.present? && !@issue.tracker.prevent_copy_issues
+ && !@issue.tracker.prevent_copy_issues
HIDE_LINK
\ No newline at end of file