Commit 678e5355 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Create events on comments and milestone

parent 190e483f
...@@ -43,6 +43,7 @@ class MilestonesController < ProjectResourceController ...@@ -43,6 +43,7 @@ class MilestonesController < ProjectResourceController
def create def create
@milestone = @project.milestones.new(params[:milestone]) @milestone = @project.milestones.new(params[:milestone])
@milestone.author_id = current_user.id
if @milestone.save if @milestone.save
redirect_to project_milestone_path(@project, @milestone) redirect_to project_milestone_path(@project, @milestone)
...@@ -52,6 +53,7 @@ class MilestonesController < ProjectResourceController ...@@ -52,6 +53,7 @@ class MilestonesController < ProjectResourceController
end end
def update def update
@milestone.author_id = current_user.id
@milestone.update_attributes(params[:milestone]) @milestone.update_attributes(params[:milestone])
respond_to do |format| respond_to do |format|
......
...@@ -63,7 +63,7 @@ class Event < ActiveRecord::Base ...@@ -63,7 +63,7 @@ class Event < ActiveRecord::Base
# - new issue # - new issue
# - merge request # - merge request
def allowed? def allowed?
push? || issue? || merge_request? || membership_changed? push? || issue? || merge_request? || membership_changed? || note? || milestone?
end end
def project_name def project_name
...@@ -94,6 +94,14 @@ class Event < ActiveRecord::Base ...@@ -94,6 +94,14 @@ class Event < ActiveRecord::Base
action == self.class::Reopened action == self.class::Reopened
end end
def milestone?
target_type == "Milestone"
end
def note?
target_type == "Note"
end
def issue? def issue?
target_type == "Issue" target_type == "Issue"
end end
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
class Milestone < ActiveRecord::Base class Milestone < ActiveRecord::Base
attr_accessible :title, :description, :due_date, :closed attr_accessible :title, :description, :due_date, :closed
attr_accessor :author_id
belongs_to :project belongs_to :project
has_many :issues has_many :issues
......
...@@ -121,4 +121,12 @@ class Note < ActiveRecord::Base ...@@ -121,4 +121,12 @@ class Note < ActiveRecord::Base
def downvote? def downvote?
note.start_with?('-1') || note.start_with?(':-1:') note.start_with?('-1') || note.start_with?(':-1:')
end end
def noteable_type_name
if noteable_type.present?
noteable_type.downcase
else
"wall"
end
end
end end
class ActivityObserver < ActiveRecord::Observer class ActivityObserver < ActiveRecord::Observer
observe :issue, :merge_request observe :issue, :merge_request, :note, :milestone
def after_create(record) def after_create(record)
Event.create( Event.create(
...@@ -12,7 +12,7 @@ class ActivityObserver < ActiveRecord::Observer ...@@ -12,7 +12,7 @@ class ActivityObserver < ActiveRecord::Observer
end end
def after_save(record) def after_save(record)
if record.changed.include?("closed") if record.changed.include?("closed")
Event.create( Event.create(
project: record.project, project: record.project,
target_id: record.id, target_id: record.id,
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
- if event.push? - if event.push?
= render "events/event/push", event: event = render "events/event/push", event: event
- if event.note?
= render "events/event/note", event: event
- else - else
= render "events/event/common", event: event = render "events/event/common", event: event
......
.event-title
%span.author_name= link_to_author event
%span.event_label commented on #{event.target.noteable_type_name}
- if event.target and event.target.noteable_id
= link_to [event.project, event.target.noteable] do
%strong= truncate event.target.noteable_id
- else
%strong (deleted)
at
- if event.project
= link_to_project event.project
- else
= event.project_name
.event-body
%p.hint= truncate event.target.note, length: 70
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