Commit fe17af9a authored by jplang's avatar jplang

Option to set a default assignee on each project (#482).

Patch by Felix Schäfer.

git-svn-id: https://svn.redmine.org/redmine/trunk@16525 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent bd65eb82
......@@ -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}")
......
......@@ -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
......
......@@ -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
......
......@@ -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)
......
......@@ -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|
......
......@@ -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| %>
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment