From 28a40aeee41918f808c33b696b3c15a85d02d9e0 Mon Sep 17 00:00:00 2001 From: albert Date: Sun, 17 Mar 2013 20:33:25 -0400 Subject: [PATCH] fixes #925 --- app/assets/stylesheets/specific/comments.css.scss | 5 +++++ app/models/comment.rb | 12 +++++++++++- app/views/comments/partials/show/_comment.html.erb | 4 ++++ .../20130318002652_add_updater_info_to_comments.rb | 6 ++++++ db/structure.sql | 8 ++++++-- script/fixes/007.rb | 6 ++++++ 6 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20130318002652_add_updater_info_to_comments.rb create mode 100644 script/fixes/007.rb diff --git a/app/assets/stylesheets/specific/comments.css.scss b/app/assets/stylesheets/specific/comments.css.scss index e6a1e85ea..90a59d3e1 100644 --- a/app/assets/stylesheets/specific/comments.css.scss +++ b/app/assets/stylesheets/specific/comments.css.scss @@ -4,6 +4,11 @@ div.comments-for-post { div.notices { margin: 1em 0; } + + .info { + color: #AAA; + font-style: italic; + } div.list-of-comments { article.comment { diff --git a/app/models/comment.rb b/app/models/comment.rb index ce1e9dfa5..42b3b7577 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -5,6 +5,7 @@ class Comment < ActiveRecord::Base belongs_to :creator, :class_name => "User" has_many :votes, :class_name => "CommentVote", :dependent => :destroy before_validation :initialize_creator, :on => :create + before_validation :initialize_updater after_save :update_last_commented_at after_destroy :update_last_commented_at attr_accessible :body, :post_id, :do_not_bump_post @@ -70,9 +71,18 @@ class Comment < ActiveRecord::Base self.ip_addr = CurrentUser.ip_addr end + def initialize_updater + self.updater_id = CurrentUser.user.id + self.updater_ip_addr = CurrentUser.ip_addr + end + def creator_name User.id_to_name(creator_id) end + + def updater_name + User.id_to_name(updater_id) + end def validate_creator_is_not_limited if creator.can_comment? @@ -111,7 +121,7 @@ class Comment < ActiveRecord::Base end def editable_by?(user) - creator_id == user.id || user.is_moderator? + creator_id == user.id || user.is_janitor? end end diff --git a/app/views/comments/partials/show/_comment.html.erb b/app/views/comments/partials/show/_comment.html.erb index 3e7e45e54..039dfcf45 100644 --- a/app/views/comments/partials/show/_comment.html.erb +++ b/app/views/comments/partials/show/_comment.html.erb @@ -8,6 +8,10 @@
<%= format_text(comment.body) %> + + <% if comment.updater_id.present? && (comment.updater_id != comment.creator_id || comment.created_at != comment.updated_at) %> +

Updated by <%= link_to comment.updater_name, user_path(comment.updater_id) %> <%= time_ago_in_words_tagged(comment.updated_at) %>.

+ <% end %>
<% if @post || @posts %> diff --git a/db/migrate/20130318002652_add_updater_info_to_comments.rb b/db/migrate/20130318002652_add_updater_info_to_comments.rb new file mode 100644 index 000000000..d8815fead --- /dev/null +++ b/db/migrate/20130318002652_add_updater_info_to_comments.rb @@ -0,0 +1,6 @@ +class AddUpdaterInfoToComments < ActiveRecord::Migration + def change + add_column :comments, :updater_id, :integer + add_column :comments, :updater_ip_addr, "inet" + end +end diff --git a/db/structure.sql b/db/structure.sql index 39c2b1380..bdf91e29f 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -684,7 +684,9 @@ CREATE TABLE comments ( body_index tsvector NOT NULL, score integer DEFAULT 0 NOT NULL, created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + updated_at timestamp without time zone NOT NULL, + updater_id integer, + updater_ip_addr inet ); @@ -6240,4 +6242,6 @@ INSERT INTO schema_migrations (version) VALUES ('20130305005138'); INSERT INTO schema_migrations (version) VALUES ('20130307225324'); -INSERT INTO schema_migrations (version) VALUES ('20130308204213'); \ No newline at end of file +INSERT INTO schema_migrations (version) VALUES ('20130308204213'); + +INSERT INTO schema_migrations (version) VALUES ('20130318002652'); \ No newline at end of file diff --git a/script/fixes/007.rb b/script/fixes/007.rb new file mode 100644 index 000000000..617ee3126 --- /dev/null +++ b/script/fixes/007.rb @@ -0,0 +1,6 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')) + +ActiveRecord::Base.connection.execute("set statement_timeout = 0") +ActiveRecord::Base.connection.execute("update comments set updater_id = creator_id")