Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 37 additions & 26 deletions app/views/settings/_default_assign.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,42 @@
-%>

<% unless users.empty? %>
<%=
select_tag("settings[default_assignee_id]",
content_tag(:option, '') +
options_from_collection_for_select(users, :id, :name,
unless selected.blank?
Integer(selected)
end
),
:multiple => false,
:size => 5)
%>
<% else %>
<%= link_to(l(:default_assign_missing_users),
:controller => 'users', :action => 'index') %>
<% end %>
</p>
<%=
select_tag("settings[default_assignee_id]",
content_tag(:option, '') +
options_from_collection_for_select(users, :id, :name,
unless selected.blank?
Integer(selected)
end
),
:multiple => false,
:size => 5)
%>
<% else %>
<%= link_to(l(:default_assign_missing_users),
:controller => 'users', :action => 'index') %>
<% end %>
</p>

<p><%= l(:interactive_assignment_explanation) %></p>
<p>
<%= label('settings[interactive_assignment]', l(:interactive_assignment)) %>
<%-
interactive_assignment = @settings['interactive_assignment'] || 'true'
interactive_assignment = (interactive_assignment == 'true')
-%>
<%= hidden_field_tag('settings[interactive_assignment]', false) %>
<%= check_box_tag('settings[interactive_assignment]', true, interactive_assignment) %>
</p>
<p><%= l(:interactive_assignment_explanation) %></p>
<p>
<%= label('settings[interactive_assignment]', l(:interactive_assignment)) %>
<%-
interactive_assignment = @settings['interactive_assignment'] || 'true'
interactive_assignment = (interactive_assignment == 'true')
-%>
<%= hidden_field_tag('settings[interactive_assignment]', false) %>
<%= check_box_tag('settings[interactive_assignment]', true, interactive_assignment) %>
</p>

<p><%= l(:self_assignment_explanation) %></p>
<p>
<%= 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) %>
</p>
</fieldset>
6 changes: 6 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ de:
interactive_assignment: "Zuständigen interaktiv setzen"
label_user: "Benutzer"
none_selected: "<Keiner>"
self_assignment: "Assign issue author"
self_assignment_explanation: >
When a new issue is created with no assignee, and the project has no default
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.
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ en:
interactive_assignment: "Set Assignee Interactively"
label_user: "User"
none_selected: "<None>"
self_assignment: "Assign issue author"
self_assignment_explanation: >
When a new issue is created with no assignee, and the project has no default
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.
6 changes: 6 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ es:
interactive_assignment: "Set Assignee Interactively"
label_user: "Usuario"
none_selected: "<None>"
self_assignment: "Assign issue author"
self_assignment_explanation: >
When a new issue is created with no assignee, and the project has no default
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.
9 changes: 8 additions & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ fr:
default_assign_settings_help: "Assignement par defaut pour les nouveaux projets"
interactive_assignment: "Assignement interactif"
interactive_assignment_explanation: >
Quand vous créez une nouvel demande, le plugin peut peupler le champs
Quand vous créez une nouvelle demande, le plugin peut peupler le champs
"Assigné à" immédiatement avec le choix vous avez faite si dessus avant
que vous ayez créé la demande. Par contre, quand vous changiez certains
champs, le formulaire est rechargé et le champs "Assigné à" est calculé
de nouveau. Ceci pourrait être ce que vous voulez, ou peut être pas, donc
vous pouvez faire le choix vous-même:
label_user: "Utilisateur"
none_selected: "<Aucun>"
self_assignment: "Assignement de l'auteur"
self_assignment_explanation: >
Quand on crée une nouvelle demande sans assignement, et il n'y a aucun
assignement par défaut spécifié pour le project, sélectionez la case
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.
6 changes: 6 additions & 0 deletions config/locales/it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ it:
interactive_assignment: "Imposta l'assegnatario in maniera interattiva"
label_user: "Utente"
none_selected: "<Nessuno>"
self_assignment: "Assign issue author"
self_assignment_explanation: >
When a new issue is created with no assignee, and the project has no default
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.
6 changes: 6 additions & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ ja:
interactive_assignment: "Set Assignee Interactively"
label_user: "ユーザー"
none_selected: "<None>"
self_assignment: "Assign issue author"
self_assignment_explanation: >
When a new issue is created with no assignee, and the project has no default
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.
8 changes: 7 additions & 1 deletion config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ ru:
Однако, при изменении некоторых полей, форма может быть перезагружена и
ответственный по умолчанию переназначается. Такое поведение может быть приемлимым,
либо нежелательным. Выбор за вами:
interactive_assignment: "Выберать ответственного интерактивно"
interactive_assignment: "Выбирать ответственного интерактивно"
label_user: "Пользователь"
none_selected: "<Пусто>"
self_assignment: "Назначать задачу на автора"
self_assignment_explanation: >
Если этот пунт выбран - при создании новой задачи, если не выбрано на кого
назначить задачу и если в проекте не выбрано на кого назначать по умолчанию,
то задача будет назначена на автора задачи. Если этот пункт не выбран
задача не будет ни на кого назначена - как сделано в Redmine по умолчанию.
17 changes: 17 additions & 0 deletions db/migrate/001_add_default_assignee_to_project.rb.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class AddDefaultAssigneeToProject < ActiveRecord::Migration[4.2]
def self.up
# Work around migration name change (Github issue #27)
old_num = '20090508035844'
num_deleted =
::ActiveRecord::Base.connection.delete(<<-SQL.squish)
delete from schema_migrations
where version = '#{old_num}-redmine_default_assign'
SQL
return if num_deleted > 0
add_column :projects, :default_assignee_id, :integer
end

def self.down
remove_column :projects, :default_assignee_id
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddDefaultAssigneeToProject < ActiveRecord::Migration
class AddDefaultAssigneeToProject < ActiveRecord::Migration[5.2]
def self.up
add_column :projects, :default_assignee_id, :integer
end
Expand Down
8 changes: 5 additions & 3 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
require 'default_assign/hooks/default_assign_issues_hooks.rb'

if Rails::VERSION::MAJOR >= 3
ActionDispatch::Callbacks.to_prepare do
((Rails.version > "5")? ActiveSupport::Reloader : ActionDispatch::Callbacks).to_prepare do
require_dependency 'project'
require_dependency 'issue'
Project.send(:include, DefaultAssignProjectPatch)
Expand All @@ -27,10 +27,12 @@
Redmine::Plugin.register :redmine_default_assign do
name 'Default Assign plugin'
author 'Robert Chady / Paul Dann'
author_url 'https://github.com/giddie/redmine_default_assign'
description 'Plugin implementing Douglas Campos\' ticket-482 code as a plugin. It has since been extended to offer other features as well.'
version '0.4'
version '0.6'

settings :default => {'default_assignee_id' => nil,
'interactive_assignment' => true},
'interactive_assignment' => true,
'self_assignment' => false},
:partial => 'settings/default_assign'
end
18 changes: 12 additions & 6 deletions lib/default_assign/hooks/default_assign_issues_hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ def view_issues_form_details_top(context = {})
interactive_assignment = (interactive_assignment == 'true')
return if not interactive_assignment

if not context[:project].default_assignee.blank?
default_assignee = context[:project].default_assignee
if context[:project].assignable_users.include?(default_assignee)
context[:issue].assigned_to_id = default_assignee.id
end
project = context[:project]
if project.try(:default_assignee).blank?
self_assignment =
Setting.plugin_redmine_default_assign['self_assignment'] || 'false'
self_assignment = (self_assignment == 'true')
default_assignee = User.current if self_assignment
else
default_assignee = project.default_assignee
end
if project && project.assignable_users.include?(default_assignee)
context[:issue].assigned_to_id = default_assignee.id
end

nil
end
end
end
19 changes: 14 additions & 5 deletions lib/default_assign_issue_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,31 @@ def self.included(base) # :nodoc:

# Same as typing in the class
base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
unloadable

before_save :assign_default_assignee
before_create :assign_default_assignee
end
end

module InstanceMethods
# If the issue isn't assigned to someone and a default assignee
# is set, set it.
def assign_default_assignee
return if not self.assigned_to.nil?
default_assignee = self.project.default_assignee
unless default_assignee.blank?
if self.project.assignable_users.include?(default_assignee)
self.assigned_to ||= self.project.default_assignee
if default_assignee.blank?
self_assignment =
Setting.plugin_redmine_default_assign['self_assignment'] || 'false'
self_assignment = (self_assignment == 'true')
if self_assignment
default_assignee = User.current
else
return
end
end
if self.project.assignable_users.include?(default_assignee)
self.assigned_to = default_assignee
end
end
end
end
10 changes: 4 additions & 6 deletions lib/default_assign_project_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@ def self.included(base)

safe_attributes :default_assignee_id
belongs_to :default_assignee, :class_name => "Principal"
before_save :set_default_assignee
before_create :set_default_assignee
end
end

#module ClassMethods
#end

module InstanceMethods
def set_default_assignee
if not self.persisted?
self.default_assignee_id ||=
Setting.plugin_redmine_default_assign['default_assignee_id']
end
def set_default_assignee
self.default_assignee_id ||=
Setting.plugin_redmine_default_assign['default_assignee_id']
end
end
end