Explorar el Código

Add some comment tools

master
Peter J. Jones hace 11 años
padre
commit
3448e939c2

+ 8
- 4
TODO Ver fichero

@@ -4,9 +4,13 @@
* Schema
- [X] Record IP Address and other info
* Comment Listing
- [ ] Correct ordering of replies
- [ ] All replies are approved
- [X] Correct ordering of replies
- [X] All replies are approved
- [X] Render comment for replies
* Banter Mailer
- [ ] Send out approval email
- [ ] Reply emails with URL
- [X] Send out approval email
- [X] Reply emails with URL
- [ ] Script to receive emails
* Misc
- [X] A tool that can approve comments
- [X] A tool to expire comments

+ 10
- 1
app/models/comment.rb Ver fichero

@@ -51,7 +51,8 @@ class Comment < ActiveRecord::Base
end

################################################################################
# Approve the comment with the given ID, or approval code
# Approve the comment with the given ID, or approval code. Returns
# the approved comment if found.
def self.approve! (id)
conditions = ['']
conditions.first << (id.to_s.match(/^\d+$/) ? 'id=?' : 'approval_code=?')
@@ -60,9 +61,17 @@ class Comment < ActiveRecord::Base
if comment = find(:first, :conditions => conditions)
comment.approved = true
comment.save!
comment
end
end
################################################################################
# Expire comments that haven't been approved.
def self.expire! (seconds=14.days)
water_level = Time.now - seconds
delete_all(["approved = ? AND updated_at < ?", false, water_level])
end
################################################################################
# Returns a list of email addresses of people that are monitoring
# the comment with the given ID.

+ 1
- 0
app/views/banter_mailer/moderation_message.rhtml Ver fichero

@@ -1,6 +1,7 @@
A new comment has been posted for:

<%= @comment.parent_description %>
<%= @comment.cached_parent_url %>
You can post the comment by replying to this email. You can also ignore this
message and the comment will be deleted in a few days.

+ 2
- 2
app/views/comments/_comment.html.erb Ver fichero

@@ -1,4 +1,4 @@
<div class="comment">
<div class="comment" id="<%= comment.dom_id %>">
<%= render(:partial => 'comments/attributes', :locals => {:comment => comment}) %>
<div class="replies">
@@ -7,7 +7,7 @@
<% end %>
</div>
<div id="comment-reply-<%= comment.id %>" class="bottom-reply-link">
<div class="bottom-reply-link">
<%= comments_reply_link('Reply', parent, comment) %>
</div>
</div>

+ 20
- 0
script/approve Ver fichero

@@ -0,0 +1,20 @@
#!/usr/bin/env ruby

################################################################################
ENV['RAILS_ENV'] ||= 'production'
require File.dirname(__FILE__) + '/../../../../config/environment'

################################################################################
unless ARGV.length == 1
$stderr.puts("Usage: approve <ID|CODE>")
exit(1)
end

################################################################################
unless comment = Comment.approve!(ARGV.first)
$stderr.puts("Comment not found: #{ARGV.first}")
exit(1)
end

################################################################################
$stdout.puts("Approved comment #{comment.id} for #{comment.parent_description}")

+ 11
- 0
script/expire Ver fichero

@@ -0,0 +1,11 @@
#!/usr/bin/env ruby

################################################################################
ENV['RAILS_ENV'] ||= 'production'
require File.dirname(__FILE__) + '/../../../../config/environment'

################################################################################
seconds = ARGV.empty? ? 14.days : ARGV.first.to_i.days

################################################################################
$stdout.puts(Comment.expire!(seconds).to_s)

Cargando…
Cancelar
Guardar