This commit is contained in:
albert 2013-03-17 20:33:25 -04:00
parent 9210a72c4c
commit 28a40aeee4
6 changed files with 38 additions and 3 deletions

View File

@ -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 {

View File

@ -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

View File

@ -8,6 +8,10 @@
<div class="content">
<div class="body prose">
<%= format_text(comment.body) %>
<% if comment.updater_id.present? && (comment.updater_id != comment.creator_id || comment.created_at != comment.updated_at) %>
<p class="info">Updated by <%= link_to comment.updater_name, user_path(comment.updater_id) %> <%= time_ago_in_words_tagged(comment.updated_at) %>.</p>
<% end %>
</div>
<menu>
<% if @post || @posts %>

View File

@ -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

View File

@ -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');
INSERT INTO schema_migrations (version) VALUES ('20130308204213');
INSERT INTO schema_migrations (version) VALUES ('20130318002652');

6
script/fixes/007.rb Normal file
View File

@ -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")