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

Create events on comments and milestone

parent 523b49c5d124
......@@ -43,6 +43,7 @@ def show
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 @@ def create
end
def update
@milestone.author_id = current_user.id
@milestone.update_attributes(params[:milestone])
respond_to do |format|
......
......@@ -63,7 +63,7 @@ def determine_action(record)
# - 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 @@ def reopened?
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 @@ def upvote?
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(
......@@ -12,7 +12,7 @@ def after_create(record)
end
def after_save(record)
if record.changed.include?("closed")
if record.changed.include?("closed")
Event.create(
project: record.project,
target_id: record.id,
......
......@@ -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