Commit 7ad5a1b3 authored by blackst0ne's avatar blackst0ne

Add last_edited_at and last_edited_by attributes

parent b82870af
......@@ -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
......
......@@ -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?
......
......@@ -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
......
......@@ -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'
......
......@@ -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')
......
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddLastEditedAtAndLastEditedByIdToIssues < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
def change
add_column :issues, :last_edited_at, :timestamp
add_column :issues, :last_edited_by_id, :integer
end
end
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddLastEditedAtAndLastEditedByIdToNotes < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
def change
add_column :notes, :last_edited_at, :timestamp
add_column :notes, :last_edited_by_id, :integer
end
end
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddLastEditedAtAndLastEditedByIdToMergeRequests < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
def change
add_column :merge_requests, :last_edited_at, :timestamp
add_column :merge_requests, :last_edited_by_id, :integer
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170426181740) do
ActiveRecord::Schema.define(version: 20170503022548) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -488,6 +488,8 @@ ActiveRecord::Schema.define(version: 20170426181740) do
t.integer "relative_position"
t.datetime "closed_at"
t.integer "cached_markdown_version"
t.datetime "last_edited_at"
t.integer "last_edited_by_id"
end
add_index "issues", ["assignee_id"], name: "index_issues_on_assignee_id", using: :btree
......@@ -674,6 +676,8 @@ ActiveRecord::Schema.define(version: 20170426181740) do
t.text "description_html"
t.integer "time_estimate"
t.integer "cached_markdown_version"
t.datetime "last_edited_at"
t.integer "last_edited_by_id"
end
add_index "merge_requests", ["assignee_id"], name: "index_merge_requests_on_assignee_id", using: :btree
......@@ -774,6 +778,8 @@ ActiveRecord::Schema.define(version: 20170426181740) do
t.string "discussion_id"
t.text "note_html"
t.integer "cached_markdown_version"
t.datetime "last_edited_at"
t.integer "last_edited_by_id"
end
add_index "notes", ["author_id"], name: "index_notes_on_author_id", using: :btree
......
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