summaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/issue.rb10
-rw-r--r--app/models/member.rb9
-rw-r--r--app/models/principal.rb5
-rw-r--r--app/models/project.rb4
4 files changed, 23 insertions, 5 deletions
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|