From b367a94c4d4dd13a769d86f85af7aef6e65739d2 Mon Sep 17 00:00:00 2001
From: Roberto Piccini
Date: Thu, 19 May 2016 14:46:37 +0200
Subject: [PATCH 1/4] use default assignee only if category is not specified or
it doesn't have a default assignee itself
---
.gitignore | 2 ++
app/views/settings/_default_assign.erb | 27 ++++++++++++-------
config/locales/en.yml | 6 ++++-
.../hooks/default_assign_issues_hooks.rb | 4 +--
lib/default_assign_issue_patch.rb | 13 ++++++---
5 files changed, 35 insertions(+), 17 deletions(-)
create mode 100644 .gitignore
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..116e954
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+# ide files
+.idea
\ No newline at end of file
diff --git a/app/views/settings/_default_assign.erb b/app/views/settings/_default_assign.erb
index 0167e9d..6d7ebcb 100644
--- a/app/views/settings/_default_assign.erb
+++ b/app/views/settings/_default_assign.erb
@@ -40,14 +40,21 @@
<%= check_box_tag('settings[interactive_assignment]', true, interactive_assignment) %>
- <%= l(:self_assignment_explanation) %>
-
- <%= label('settings[self_assignment]', l(:self_assignment)) %>
- <%-
- self_assignment = @settings['self_assignment'] || 'false'
- self_assignment = (self_assignment == 'true')
- -%>
- <%= hidden_field_tag('settings[self_assignment]', false) %>
- <%= check_box_tag('settings[self_assignment]', true, self_assignment) %>
-
+ <%= l(:self_assignment_explanation) %>
+
+ <%= label('settings[self_assignment]', l(:self_assignment)) %>
+ <%-
+ self_assignment = @settings['self_assignment'] || 'false'
+ self_assignment = (self_assignment == 'true')
+ -%>
+ <%= hidden_field_tag('settings[self_assignment]', false) %>
+ <%= check_box_tag('settings[self_assignment]', true, self_assignment) %>
+
+
+
+ <%= label 'settings[override_category_assignee]', l(:override_category_assignee, scope: :default_assign) %>
+ <%= hidden_field_tag('settings[override_category_assignee]', false) %>
+ <%= check_box_tag('settings[override_category_assignee]', true, @settings['override_category_assignee'] == 'true') %>
+ <%= content_tag :em, l(:override_category_assignee_info, scope: :default_assign), class: 'info' %>
+
diff --git a/config/locales/en.yml b/config/locales/en.yml
index edc129c..3145215 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -6,7 +6,8 @@ en:
interactive_assignment_explanation: >
When creating a new issue, the plugin can populate the assignee with the
default assignee you've chosen above, so that it'll be visible even before
- you've created the issue. However, when you change certain fields, the form
+ you've created the issue. It works only if Override Category Assignee is enabled.
+ However, when you change certain fields, the form
is reloaded and the default assignee is recalculated. This might be what you
want, or it might be undesirable, so you can make the choice yourself:
interactive_assignment: "Set Assignee Interactively"
@@ -18,3 +19,6 @@ en:
assignee set, tick the box below to assign the issue to the user who just
created the issue, if possible. If the box is left unticked, there will be
no assignee, which is the default behaviour in Redmine.
+ default_assign:
+ override_category_assignee_info: "Override Category Assignee"
+ override_category_assignee: "Override Category Assignee"
\ No newline at end of file
diff --git a/lib/default_assign/hooks/default_assign_issues_hooks.rb b/lib/default_assign/hooks/default_assign_issues_hooks.rb
index 2c76f64..7c2b6b4 100644
--- a/lib/default_assign/hooks/default_assign_issues_hooks.rb
+++ b/lib/default_assign/hooks/default_assign_issues_hooks.rb
@@ -7,7 +7,7 @@ def view_issues_form_details_top(context = {})
interactive_assignment =
Setting.plugin_redmine_default_assign['interactive_assignment'] || 'true'
interactive_assignment = (interactive_assignment == 'true')
- return if not interactive_assignment
+ return if !interactive_assignment || Setting.plugin_redmine_default_assign[:override_category_assignee] != 'true'
if context[:project].default_assignee.blank?
self_assignment =
@@ -22,5 +22,5 @@ def view_issues_form_details_top(context = {})
end
nil
- end
+ end
end
diff --git a/lib/default_assign_issue_patch.rb b/lib/default_assign_issue_patch.rb
index 42d6fb1..8c58449 100644
--- a/lib/default_assign_issue_patch.rb
+++ b/lib/default_assign_issue_patch.rb
@@ -6,16 +6,21 @@ def self.included(base) # :nodoc:
# Same as typing in the class
base.class_eval do
- unloadable
+ unloadable # Send unloadable so it will not be unloaded in development
- before_create :assign_default_assignee
+ before_save :assign_default_assignee
end
end
module InstanceMethods
- # If the issue isn't assigned to someone and a default assignee
- # is set, set it.
+ # If the issue isn't assigned to someone and
+ # there isn't category's assignee with 'override category assignee' setting enabled
+ # and a default assignee is set,
+ # set it.
def assign_default_assignee
+ return if category.present? && category.assigned_to.present? &&
+ Setting.plugin_redmine_default_assign[:override_category_assignee] != 'true'
+
return if not self.assigned_to.nil?
default_assignee = self.project.default_assignee
if default_assignee.blank?
From 6636d906296570c0fbb146b6ce95aa603a9baea2 Mon Sep 17 00:00:00 2001
From: Roberto Piccini
Date: Thu, 19 May 2016 15:25:28 +0200
Subject: [PATCH 2/4] add missing translation placeholder
---
config/locales/de.yml | 3 +++
config/locales/es.yml | 3 +++
config/locales/fr.yml | 3 +++
config/locales/it.yml | 3 +++
config/locales/ja.yml | 3 +++
config/locales/ru.yml | 3 +++
6 files changed, 18 insertions(+)
diff --git a/config/locales/de.yml b/config/locales/de.yml
index c68a3b7..dd6a33c 100644
--- a/config/locales/de.yml
+++ b/config/locales/de.yml
@@ -17,3 +17,6 @@ de:
assignee set, tick the box below to assign the issue to the user who just
created the issue, if possible. If the box is left unticked, there will be
no assignee, which is the default behaviour in Redmine.
+ default_assign:
+ override_category_assignee_info: "Override Category Assignee"
+ override_category_assignee: "Override Category Assignee"
\ No newline at end of file
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 09847b4..646d7cf 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -18,3 +18,6 @@ es:
assignee set, tick the box below to assign the issue to the user who just
created the issue, if possible. If the box is left unticked, there will be
no assignee, which is the default behaviour in Redmine.
+ default_assign:
+ override_category_assignee_info: "Override Category Assignee"
+ override_category_assignee: "Override Category Assignee"
\ No newline at end of file
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index d3c07be..595b515 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -20,3 +20,6 @@ fr:
si-dessous pour tentir l'assignement de l'auteur de la demande. Sans
sélection, il n'y aura aucun assignement pour la demande, ce qui est le
comportement normal de Redmine.
+ default_assign:
+ override_category_assignee_info: "Override Category Assignee"
+ override_category_assignee: "Override Category Assignee"
\ No newline at end of file
diff --git a/config/locales/it.yml b/config/locales/it.yml
index 328df76..cf71ae3 100644
--- a/config/locales/it.yml
+++ b/config/locales/it.yml
@@ -19,3 +19,6 @@ it:
assignee set, tick the box below to assign the issue to the user who just
created the issue, if possible. If the box is left unticked, there will be
no assignee, which is the default behaviour in Redmine.
+ default_assign:
+ override_category_assignee_info: "Override Category Assignee"
+ override_category_assignee: "Override Category Assignee"
\ No newline at end of file
diff --git a/config/locales/ja.yml b/config/locales/ja.yml
index 9bb103f..0997d6c 100644
--- a/config/locales/ja.yml
+++ b/config/locales/ja.yml
@@ -18,3 +18,6 @@ ja:
assignee set, tick the box below to assign the issue to the user who just
created the issue, if possible. If the box is left unticked, there will be
no assignee, which is the default behaviour in Redmine.
+ default_assign:
+ override_category_assignee_info: "Override Category Assignee"
+ override_category_assignee: "Override Category Assignee"
\ No newline at end of file
diff --git a/config/locales/ru.yml b/config/locales/ru.yml
index c455c22..bd83fc6 100644
--- a/config/locales/ru.yml
+++ b/config/locales/ru.yml
@@ -18,3 +18,6 @@ ru:
назначить задачу и если в проекте не выбрано на кого назначать по умолчанию,
то задача будет назначена на автора задачи. Если этот пункт не выбран
задача не будет ни на кого назначена - как сделано в Redmine по умолчанию.
+ default_assign:
+ override_category_assignee_info: "Override Category Assignee"
+ override_category_assignee: "Override Category Assignee"
\ No newline at end of file
From ccfe33fa6227a18d0631badffca82684743d05de Mon Sep 17 00:00:00 2001
From: Roberto Piccini
Date: Thu, 19 May 2016 15:30:00 +0200
Subject: [PATCH 3/4] split long return statement
---
lib/default_assign/hooks/default_assign_issues_hooks.rb | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/default_assign/hooks/default_assign_issues_hooks.rb b/lib/default_assign/hooks/default_assign_issues_hooks.rb
index 7c2b6b4..f33f051 100644
--- a/lib/default_assign/hooks/default_assign_issues_hooks.rb
+++ b/lib/default_assign/hooks/default_assign_issues_hooks.rb
@@ -7,7 +7,9 @@ def view_issues_form_details_top(context = {})
interactive_assignment =
Setting.plugin_redmine_default_assign['interactive_assignment'] || 'true'
interactive_assignment = (interactive_assignment == 'true')
- return if !interactive_assignment || Setting.plugin_redmine_default_assign[:override_category_assignee] != 'true'
+ return if !interactive_assignment
+ # if interactive_assignment is true don't do anything if 'override category assignee' is false
+ return if Setting.plugin_redmine_default_assign[:override_category_assignee] != 'true'
if context[:project].default_assignee.blank?
self_assignment =
From da8b54eabb6f91d36bc56e44405ec4a70be4c492 Mon Sep 17 00:00:00 2001
From: Roberto Piccini
Date: Thu, 19 May 2016 15:42:10 +0200
Subject: [PATCH 4/4] bugfix: forked from a previous version
---
lib/default_assign_issue_patch.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/default_assign_issue_patch.rb b/lib/default_assign_issue_patch.rb
index 8c58449..d329bfe 100644
--- a/lib/default_assign_issue_patch.rb
+++ b/lib/default_assign_issue_patch.rb
@@ -8,7 +8,7 @@ def self.included(base) # :nodoc:
base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
- before_save :assign_default_assignee
+ before_create :assign_default_assignee
end
end