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
def create
@milestone = @project.milestones.new(params[:milestone])
@milestone.author_id = current_user.id
if @milestone.save
redirect_to project_milestone_path(@project, @milestone)
......@@ -52,6 +53,7 @@ class MilestonesController < ProjectResourceController
end
def update
@milestone.author_id = current_user.id
@milestone.update_attributes(params[:milestone])
respond_to do |format|
......
......@@ -63,7 +63,7 @@ class Event < ActiveRecord::Base
# - new issue
# - merge request
def allowed?
push? || issue? || merge_request? || membership_changed?
push? || issue? || merge_request? || membership_changed? || note? || milestone?
end
def project_name
......@@ -94,6 +94,14 @@ class Event < ActiveRecord::Base
action == self.class::Reopened
end
def milestone?
target_type == "Milestone"
end
def note?
target_type == "Note"
end
def issue?
target_type == "Issue"
end
......
......@@ -14,6 +14,7 @@
class Milestone < ActiveRecord::Base
attr_accessible :title, :description, :due_date, :closed
attr_accessor :author_id
belongs_to :project
has_many :issues
......
......@@ -121,4 +121,12 @@ class Note < ActiveRecord::Base
def downvote?
note.start_with?('-1') || note.start_with?(':-1:')
end
def noteable_type_name
if noteable_type.present?
noteable_type.downcase
else
"wall"
end
end
end
class ActivityObserver < ActiveRecord::Observer
observe :issue, :merge_request
observe :issue, :merge_request, :note, :milestone
def after_create(record)
Event.create(
......
......@@ -5,6 +5,8 @@
- if event.push?
= render "events/event/push", event: event
- if event.note?
= render "events/event/note", event: event
- else
= 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