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) active

Scoping shortcuts for active/expired/future



23
24
25
# File 'app/models/submission.rb', line 23

def self.active
  joins(:content).merge(Content.active)
end

+ (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.



86
87
88
89
90
91
92
93
94
95
# File 'app/models/submission.rb', line 86

def self.deny_old_expired
  Submission.pending.expired.readonly(false).each do |submission|
    submission.moderation_flag = false
    submission.moderation_reason = I18n.t(:content_expired_mod)
    #Rails.logger.info submission
    #print submission.to_yaml
    #print submission.errors.to_yaml
    submission.save
  end
end

+ (Object) expired



27
28
29
# File 'app/models/submission.rb', line 27

def self.expired
  joins(:content).merge(Content.expired)
end

+ (Object) future



31
32
33
# File 'app/models/submission.rb', line 31

def self.future
  joins(:content).merge(Content.future)
end

Instance Method Details

- (Boolean) is_approved?

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

Returns:

  • (Boolean)


51
52
53
# File 'app/models/submission.rb', line 51

def is_approved?
  moderation_flag ? true : false
end

- (Boolean) is_denied?

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

Returns:

  • (Boolean)


57
58
59
60
# File 'app/models/submission.rb', line 57

def is_denied?
  return false if moderation_flag || moderation_flag == nil
  true
end

- (Boolean) is_pending?

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

Returns:

  • (Boolean)


64
65
66
# File 'app/models/submission.rb', line 64

def is_pending?
  moderation_flag.nil?
end

- (Object) moderation_text



38
39
40
41
42
43
44
45
46
47
# File 'app/models/submission.rb', line 38

def moderation_text
  case self.moderation_flag
    when true
      return I18n.t(:approved)
    when false
      return I18n.t(:rejected)
    else
      return I18n.t(:pending)
  end
end

- (Object) update_child_moderation

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



71
72
73
74
75
76
77
78
79
80
# File 'app/models/submission.rb', line 71

def update_child_moderation
  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