diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-04-08 08:02:06 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-04-08 08:02:06 +0000 |
commit | 2f77bfde91846b799d70a436783a8eee2741bf75 (patch) | |
tree | 462714ea74eaf4d1de0f83784ee0c0549076b018 /app | |
parent | e4fac91b7da8e4482da06fc33c3d9eeac2d66dc1 (diff) | |
download | redmine-2f77bfde91846b799d70a436783a8eee2741bf75.tar.gz redmine-2f77bfde91846b799d70a436783a8eee2741bf75.zip |
Option to set a default assignee on each project (#482).
Patch by Felix Schäfer.
git-svn-id: http://svn.redmine.org/redmine/trunk@16525 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/projects_helper.rb | 5 | ||||
-rw-r--r-- | app/models/issue.rb | 10 | ||||
-rw-r--r-- | app/models/member.rb | 9 | ||||
-rw-r--r-- | app/models/principal.rb | 5 | ||||
-rw-r--r-- | app/models/project.rb | 4 | ||||
-rw-r--r-- | app/views/projects/_form.html.erb | 4 |
6 files changed, 32 insertions, 5 deletions
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 @@ <p><%= f.select :default_version_id, project_default_version_options(@project), :include_blank => true %></p> <% end %> +<% if @project.safe_attribute?('default_assigned_to_id') && (default_assigned_to_options = project_default_assigned_to_options(@project)).present? %> + <p><%= f.select :default_assigned_to_id, default_assigned_to_options, include_blank: true %></p> +<% end %> + <%= wikitoolbar_for 'project_description' %> <% @project.custom_field_values.each do |value| %> |