implemented javascripts for approval/disapproval/unapproval from post/show page

This commit is contained in:
albert
2011-02-10 19:08:23 -05:00
parent 00ea319743
commit 33f5350677
19 changed files with 234 additions and 17 deletions

View File

@@ -1,5 +1,6 @@
class Post < ActiveRecord::Base
class ApprovalError < Exception ; end
class DisapprovalError < Exception ; end
attr_accessor :old_tag_string, :old_parent_id
after_destroy :delete_files
@@ -203,6 +204,10 @@ class Post < ActiveRecord::Base
is_pending == false && is_flagged == false && unapproval.nil?
end
def is_approvable?
(is_pending? || is_flagged?) && approver_string != "approver:#{CurrentUser.name}"
end
def unapprove!(reason)
raise Unapproval::Error.new("This post is still pending approval") if is_pending?
raise Unapproval::Error.new("This post has already been flagged") if is_flagged?
@@ -222,7 +227,7 @@ class Post < ActiveRecord::Base
end
def approve!
raise ApprovalError.new("You have already approved this post previously") if approver_string == "approver:#{CurrentUser.name}"
raise ApprovalError.new("You have previously approved this post and cannot approve it again") if approver_string == "approver:#{CurrentUser.name}"
self.is_flagged = false
self.is_pending = false

View File

@@ -4,7 +4,22 @@ class Unapproval < ActiveRecord::Base
belongs_to :unapprover, :class_name => "User"
belongs_to :post
validates_presence_of :reason, :unapprover_id, :unapprover_ip_addr
validate :validate_post_is_active
before_validation :initialize_unapprover, :on => :create
before_save :flag_post
def validate_post_is_active
if post.is_pending? || post.is_flagged? || post.is_removed?
errors[:post] << "is inactive"
false
else
true
end
end
def flag_post
post.update_attribute(:is_flagged, true)
end
def initialize_unapprover
self.unapprover_id = CurrentUser.id