Class: SuggestedEdit

Inherits:
ApplicationRecord show all
Includes:
EditsValidations, PostRelated, PostValidations, Timestamped
Defined in:
/var/apps/qpixel/app/models/suggested_edit.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EditsValidations

#max_edit_comment_length

Methods included from PostValidations

#check_required_tags, #maximum_tag_length, #maximum_tags, #maximum_title_length, #no_spaces_in_tags, #stripped_minimum_body, #stripped_minimum_title, #tags_in_tag_set

Methods inherited from ApplicationRecord

#attributes_print, fuzzy_search, match_search, #match_search, sanitize_for_search, sanitize_name, sanitize_sql_in, useful_err_msg, with_lax_group_rules

Class Method Details

.accessible_to(user, category) ⇒ ActiveRecord::Relation<SuggestedEdit>

Gets suggested edits scoped for a given user and category

Parameters:

  • user (User)

    user to check

  • category (Category)

    category to check

Returns:



29
30
31
32
# File '/var/apps/qpixel/app/models/suggested_edit.rb', line 29

def self.accessible_to(user, category)
  posts = user&.can_see_deleted_posts? ? Post.in(category) : Post.undeleted.in(category)
  SuggestedEdit.where(post: posts)
end

Instance Method Details

#approved?Boolean

Returns:

  • (Boolean)


43
44
45
# File '/var/apps/qpixel/app/models/suggested_edit.rb', line 43

def approved?
  !active && accepted
end

#clear_pending_cacheObject



34
35
36
37
# File '/var/apps/qpixel/app/models/suggested_edit.rb', line 34

def clear_pending_cache
  Rails.cache.delete "pending_suggestions/#{post.category_id}"
  Rails.cache.delete "pending_suggestions_with_deleted/#{post.category_id}"
end

#on_article?Boolean

Returns:

  • (Boolean)


55
56
57
# File '/var/apps/qpixel/app/models/suggested_edit.rb', line 55

def on_article?
  post.article?
end

#on_question?Boolean

Returns:

  • (Boolean)


51
52
53
# File '/var/apps/qpixel/app/models/suggested_edit.rb', line 51

def on_question?
  post.question?
end

#pending?Boolean

Returns:

  • (Boolean)


39
40
41
# File '/var/apps/qpixel/app/models/suggested_edit.rb', line 39

def pending?
  active
end

#rejected?Boolean

Returns:

  • (Boolean)


47
48
49
# File '/var/apps/qpixel/app/models/suggested_edit.rb', line 47

def rejected?
  !active && !accepted
end

#update_tag_associationsObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File '/var/apps/qpixel/app/models/suggested_edit.rb', line 61

def update_tag_associations
  return if tags_cache.nil? # Don't update if this doesn't affect tags

  tags_cache.each do |tag_name|
    tag = Tag.find_or_create_by name: tag_name, tag_set: post.category.tag_set
    unless tags.include? tag
      tags << tag
    end
  end

  tags.each do |tag|
    unless tags_cache.include? tag.name
      tags.delete tag
    end
  end
end