Class: Submission

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveModel::ForbiddenAttributesProtection, PublicActivity::Common
Defined in:
app/models/submission.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) deny_old_expired

Deny content which has previously expired. Any submission belonging to content which has expired but has not yet been reviewed is denied here. We made a special exception to validations to allow submissions to not have a moderator_id if the content has expired.



77
78
79
80
81
82
83
84
85
86
# File 'app/models/submission.rb', line 77

def self.deny_old_expired
  Submission.pending.expired.readonly(false).each do |submission|
    submission.moderation_flag = false
    submission.moderation_reason = 'Content expired before moderation could occur'
    #Rails.logger.info submission
    #print submission.to_yaml
    #print submission.errors.to_yaml
    submission.save
  end    
end

Instance Method Details

- (Boolean) is_approved?

Test if the submission has been approved. (moderation flag is true)

Returns:

  • (Boolean)


43
44
45
# File 'app/models/submission.rb', line 43

def is_approved?
  moderation_flag ? true : false
end

- (Boolean) is_denied?

Test if the submission has been denied. (moderation flag is false)

Returns:

  • (Boolean)


49
50
51
# File 'app/models/submission.rb', line 49

def is_denied?
  (moderation_flag == false) ? true : false
end

- (Boolean) is_pending?

Test if the submission has not yet been moderated. (moderation flag is nil)

Returns:

  • (Boolean)


55
56
57
# File 'app/models/submission.rb', line 55

def is_pending?
  moderation_flag.nil?
end

- (Object) moderation_text



30
31
32
33
34
35
36
37
38
39
# File 'app/models/submission.rb', line 30

def moderation_text
  case self.moderation_flag
    when true
      return "Approved"
    when false
      return "Rejected"
    when nil
      return "Pending"                
    end  
end

- (Object) update_children_moderation_flag

Cascade moderation to children submissions as well. Child content submitted to the same feed will recieve the same moderation as a parent content.



62
63
64
65
66
67
68
69
70
71
# File 'app/models/submission.rb', line 62

def update_children_moderation_flag
  if self.changed.include?('moderation_flag') and self.content.has_children?
    self.content.children.each do |child|
      similiar_submissions = Submission.where(:content_id => child.id, :feed_id => self.feed_id, :moderation_flag => self.moderation_flag_was)
      similiar_submissions.each do |child_submission|
        child_submission.update_attributes({:moderation_flag => self.moderation_flag, :moderator_id => self.moderator_id})
      end
    end
  end
end