From 2f77bfde91846b799d70a436783a8eee2741bf75 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 8 Apr 2017 08:02:06 +0000 Subject: [PATCH] Option to set a default assignee on each project (#482). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Patch by Felix Schäfer. git-svn-id: http://svn.redmine.org/redmine/trunk@16525 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/projects_helper.rb | 5 +++++ app/models/issue.rb | 10 +++++++--- app/models/member.rb | 9 ++++++++- app/models/principal.rb | 5 +++++ app/models/project.rb | 4 +++- app/views/projects/_form.html.erb | 4 ++++ config/locales/de.yml | 1 + config/locales/en.yml | 1 + config/locales/fr.yml | 1 + ...0309214320_add_project_default_assigned_to_id.rb | 13 +++++++++++++ 10 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20170309214320_add_project_default_assigned_to_id.rb diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 3e1f0d804..cd0d7840f 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -89,6 +89,11 @@ module ProjectsHelper version_options_for_select(versions, project.default_version) end + def project_default_assigned_to_options(project) + assignable_users = (project.assignable_users.to_a + [project.default_assigned_to]).uniq.compact + principals_options_for_select(assignable_users, project.default_assigned_to) + end + def format_version_sharing(sharing) sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing) l("label_version_sharing_#{sharing}") diff --git a/app/models/issue.rb b/app/models/issue.rb index 4d3d1dbe1..3d8df790b 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1762,10 +1762,14 @@ class Issue < ActiveRecord::Base end end - # Default assignment based on category + # Default assignment based on project or category def default_assign - if assigned_to.nil? && category && category.assigned_to - self.assigned_to = category.assigned_to + if assigned_to.nil? + if category && category.assigned_to + self.assigned_to = category.assigned_to + elsif project && project.default_assigned_to + self.assigned_to = project.default_assigned_to + end end end diff --git a/app/models/member.rb b/app/models/member.rb index 24376d303..0911422c4 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -27,7 +27,7 @@ class Member < ActiveRecord::Base validate :validate_role attr_protected :id - before_destroy :set_issue_category_nil + before_destroy :set_issue_category_nil, :remove_from_project_default_assigned_to scope :active, lambda { joins(:principal).where(:users => {:status => Principal::STATUS_ACTIVE})} @@ -151,6 +151,13 @@ class Member < ActiveRecord::Base end end + def remove_from_project_default_assigned_to + if user_id && project && project.default_assigned_to_id == user_id + # remove project based auto assignments for this member + project.update_column(:default_assigned_to_id, nil) + end + end + # Returns the roles that the member is allowed to manage # in the project the member belongs to def managed_roles diff --git a/app/models/principal.rb b/app/models/principal.rb index b8ab4ea97..324a74252 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -105,6 +105,7 @@ class Principal < ActiveRecord::Base scope :sorted, lambda { order(*Principal.fields_for_order_statement)} before_create :set_default_empty_values + before_destroy :nullify_projects_default_assigned_to def reload(*args) @project_ids = nil @@ -180,6 +181,10 @@ class Principal < ActiveRecord::Base principal end + def nullify_projects_default_assigned_to + Project.where(default_assigned_to: self).update_all(default_assigned_to_id: nil) + end + protected # Make sure we don't try to insert NULL values (see #4632) diff --git a/app/models/project.rb b/app/models/project.rb index ce68c725c..420306889 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -39,6 +39,7 @@ class Project < ActiveRecord::Base has_many :issue_changes, :through => :issues, :source => :journals has_many :versions, :dependent => :destroy belongs_to :default_version, :class_name => 'Version' + belongs_to :default_assigned_to, :class_name => 'Principal' has_many :time_entries, :dependent => :destroy has_many :queries, :dependent => :delete_all has_many :documents, :dependent => :destroy @@ -743,7 +744,8 @@ class Project < ActiveRecord::Base 'tracker_ids', 'issue_custom_field_ids', 'parent_id', - 'default_version_id' + 'default_version_id', + 'default_assigned_to_id' safe_attributes 'enabled_module_names', :if => lambda {|project, user| diff --git a/app/views/projects/_form.html.erb b/app/views/projects/_form.html.erb index 1e5917e88..0cbdf422e 100644 --- a/app/views/projects/_form.html.erb +++ b/app/views/projects/_form.html.erb @@ -24,6 +24,10 @@

<%= f.select :default_version_id, project_default_version_options(@project), :include_blank => true %>

<% end %> +<% if @project.safe_attribute?('default_assigned_to_id') && (default_assigned_to_options = project_default_assigned_to_options(@project)).present? %> +

<%= f.select :default_assigned_to_id, default_assigned_to_options, include_blank: true %>

+<% end %> + <%= wikitoolbar_for 'project_description' %> <% @project.custom_field_values.each do |value| %> diff --git a/config/locales/de.yml b/config/locales/de.yml index 589de2a5f..a26e480e0 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -389,6 +389,7 @@ de: field_visible: Sichtbar field_warn_on_leaving_unsaved: Vor dem Verlassen einer Seite mit ungesichertem Text im Editor warnen field_watcher: Beobachter + field_default_assigned_to: Standardbearbeiter general_csv_decimal_separator: ',' general_csv_encoding: ISO-8859-1 diff --git a/config/locales/en.yml b/config/locales/en.yml index 5adcb8f8f..58dad5646 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -374,6 +374,7 @@ en: field_last_updated_by: Last updated by field_full_width_layout: Full width layout field_digest: Checksum + field_default_assigned_to: Default assignee setting_app_title: Application title setting_app_subtitle: Application subtitle diff --git a/config/locales/fr.yml b/config/locales/fr.yml index b4a78b20a..6a2e61053 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -386,6 +386,7 @@ fr: field_last_updated_by: Dernière mise à jour par field_full_width_layout: Afficher sur toute la largeur field_digest: Checksum + field_default_assigned_to: Assigné par défaut setting_app_title: Titre de l'application setting_app_subtitle: Sous-titre de l'application diff --git a/db/migrate/20170309214320_add_project_default_assigned_to_id.rb b/db/migrate/20170309214320_add_project_default_assigned_to_id.rb new file mode 100644 index 000000000..97a4b1905 --- /dev/null +++ b/db/migrate/20170309214320_add_project_default_assigned_to_id.rb @@ -0,0 +1,13 @@ +class AddProjectDefaultAssignedToId < ActiveRecord::Migration + def up + add_column :projects, :default_assigned_to_id, :integer, :default => nil + # Try to copy existing settings from the plugin if redmine_default_assign plugin was used + if column_exists?(:projects, :default_assignee_id, :integer) + Project.update_all('default_assigned_to_id = default_assignee_id') + end + end + + def down + remove_column :projects, :default_assigned_to_id + end +end -- 2.39.5