summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2015-09-17 08:04:37 +0000
committerStan Hu <stanhu@gmail.com>2015-09-17 08:04:37 +0000
commitf4816372457c3b513f8707efd87ce34c9922177c (patch)
tree534be1d81e56da85514b88dd47fde25a7cf093f1 /app/models
parent2e9a7032cec02588484eb162717298d311770c7d (diff)
parentd3d03d1362e576d194782a655cdfe9bc6ed5c596 (diff)
downloadgitlab-ce-f4816372457c3b513f8707efd87ce34c9922177c.tar.gz
Merge branch 'fix-issue-2382' into 'master'
Create a "destroyed Milestone" event and keep Milestone events around in the DB for posterity Also fix issue where destroying a Milestone would cause odd, transient messages like "created milestone" or "imported milestone". Now if a milestone is destroyed, at least it will indicate in the activity feed even if it's not clear which milestone was destroyed: ![image](https://gitlab.com/gitlab-org/gitlab-ce/uploads/c89cc8a0a9fa549deac433f17b890913/image.png) Closes #2382 See merge request !1227
Diffstat (limited to 'app/models')
-rw-r--r--app/models/event.rb12
-rw-r--r--app/models/milestone.rb2
2 files changed, 11 insertions, 3 deletions
diff --git a/app/models/event.rb b/app/models/event.rb
index 78f16c6304e..47600c57e35 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -27,6 +27,7 @@ class Event < ActiveRecord::Base
MERGED = 7
JOINED = 8 # User joined project
LEFT = 9 # User left project
+ DESTROYED = 10
delegate :name, :email, to: :author, prefix: true, allow_nil: true
delegate :title, to: :issue, prefix: true, allow_nil: true
@@ -48,6 +49,7 @@ class Event < ActiveRecord::Base
scope :code_push, -> { where(action: PUSHED) }
scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent }
scope :with_associations, -> { includes(project: :namespace) }
+ scope :for_milestone_id, ->(milestone_id) { where(target_type: "Milestone", target_id: milestone_id) }
class << self
def reset_event_cache_for(target)
@@ -71,7 +73,7 @@ class Event < ActiveRecord::Base
elsif created_project?
true
else
- (issue? || merge_request? || note? || milestone?) && target
+ ((issue? || merge_request? || note?) && target) || milestone?
end
end
@@ -115,6 +117,10 @@ class Event < ActiveRecord::Base
action == LEFT
end
+ def destroyed?
+ action == DESTROYED
+ end
+
def commented?
action == COMMENTED
end
@@ -124,7 +130,7 @@ class Event < ActiveRecord::Base
end
def created_project?
- created? && !target
+ created? && !target && target_type.nil?
end
def created_target?
@@ -180,6 +186,8 @@ class Event < ActiveRecord::Base
'joined'
elsif left?
'left'
+ elsif destroyed?
+ 'destroyed'
elsif commented?
"commented on"
elsif created_project?
diff --git a/app/models/milestone.rb b/app/models/milestone.rb
index c6aff6f709f..d979a35084b 100644
--- a/app/models/milestone.rb
+++ b/app/models/milestone.rb
@@ -61,7 +61,7 @@ class Milestone < ActiveRecord::Base
false
end
end
-
+
def open_items_count
self.issues.opened.count + self.merge_requests.opened.count
end