diff options
author | blackst0ne <blackst0ne.ru@gmail.com> | 2017-05-03 08:32:21 +0300 |
---|---|---|
committer | blackst0ne <blackst0ne.ru@gmail.com> | 2017-05-04 04:58:41 +0300 |
commit | 7ad5a1b371f5d319369a6b9d6609c40dea6292c2 (patch) | |
tree | 2df1a0335961fde770dd4e8594a60d8d6841123f /app | |
parent | b82870afc0031cb830976fb36cd1237c6059397f (diff) |
Add last_edited_at and last_edited_by attributes
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/application_helper.rb | 14 | ||||
-rw-r--r-- | app/models/concerns/issuable.rb | 1 | ||||
-rw-r--r-- | app/models/note.rb | 1 | ||||
-rw-r--r-- | app/services/issuable_base_service.rb | 11 | ||||
-rw-r--r-- | app/services/notes/update_service.rb | 4 |
5 files changed, 24 insertions, 7 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b9d375d9b64..0ff6ab48808 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -181,15 +181,15 @@ module ApplicationHelper end def edited_time_ago_with_tooltip(object, placement: 'top', html_class: 'time_ago', include_author: false) - return if object.updated_at == object.created_at + return if object.last_edited_at == object.created_at || object.last_edited_at.blank? - content_tag :small, class: "edited-text" do - output = content_tag(:span, "Edited ") - output << time_ago_with_tooltip(object.updated_at, placement: placement, html_class: html_class) + content_tag :small, class: 'edited-text' do + output = content_tag(:span, 'Edited ') + output << time_ago_with_tooltip(object.last_edited_at, placement: placement, html_class: html_class) - if include_author && object.updated_by - output << content_tag(:span, " by ") - output << link_to_member(object.project, object.updated_by, avatar: false, author_class: nil) + if include_author && object.last_edited_by + output << content_tag(:span, ' by ') + output << link_to_member(object.project, object.last_edited_by, avatar: false, author_class: nil) end output diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 26dbf4d9570..de1ad840daa 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -28,6 +28,7 @@ module Issuable belongs_to :author, class_name: "User" belongs_to :assignee, class_name: "User" belongs_to :updated_by, class_name: "User" + belongs_to :last_edited_by, class_name: 'User' belongs_to :milestone has_many :notes, as: :noteable, inverse_of: :noteable, dependent: :destroy do def authors_loaded? diff --git a/app/models/note.rb b/app/models/note.rb index b06985b4a6f..943211ca991 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -38,6 +38,7 @@ class Note < ActiveRecord::Base belongs_to :noteable, polymorphic: true, touch: true belongs_to :author, class_name: "User" belongs_to :updated_by, class_name: "User" + belongs_to :last_edited_by, class_name: 'User' has_many :todos, dependent: :destroy has_many :events, as: :target, dependent: :destroy diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb index 7072d78b28d..889e4508758 100644 --- a/app/services/issuable_base_service.rb +++ b/app/services/issuable_base_service.rb @@ -218,6 +218,13 @@ class IssuableBaseService < BaseService if issuable.changed? || params.present? issuable.assign_attributes(params.merge(updated_by: current_user)) + if has_title_or_description_changed?(issuable) + issuable.assign_attributes(params.merge( + last_edited_at: Time.now, + last_edited_by: current_user + )) + end + before_update(issuable) if issuable.with_transaction_returning_status { issuable.save } @@ -240,6 +247,10 @@ class IssuableBaseService < BaseService old_label_ids.sort != new_label_ids.sort end + def has_title_or_description_changed?(issuable) + issuable.title_changed? || issuable.description_changed? + end + def change_state(issuable) case params.delete(:state_event) when 'reopen' diff --git a/app/services/notes/update_service.rb b/app/services/notes/update_service.rb index 75fd08ea0a9..4b4f383abf2 100644 --- a/app/services/notes/update_service.rb +++ b/app/services/notes/update_service.rb @@ -5,7 +5,11 @@ module Notes old_mentioned_users = note.mentioned_users.to_a + note.assign_attributes(params) + params.merge!(last_edited_at: Time.now, last_edited_by: current_user) if note.note_changed? + note.update_attributes(params.merge(updated_by: current_user)) + note.create_new_cross_references!(current_user) if note.previous_changes.include?('note') |