Module: Thredded::ModeratePost

Defined in:
app/commands/thredded/moderate_post.rb

Class Method Summary collapse

Class Method Details

.run!(post:, moderation_state:, moderator:) ⇒ Thredded::PostModerationRecord

Parameters:

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/commands/thredded/moderate_post.rb', line 11

def run!(post:, moderation_state:, moderator:)
  Thredded::Post.transaction do
    post_moderation_record = Thredded::PostModerationRecord.record!(
      moderator: moderator,
      post: post,
      previous_moderation_state: post.moderation_state,
      moderation_state: moderation_state,
    )
    if post.user_id && post.user_detail.pending_moderation?
      update_without_timestamping!(post.user_detail, moderation_state: moderation_state)
    end
    if post.postable.first_post == post
      update_without_timestamping!(post.postable, moderation_state: moderation_state)
      if moderation_state == :blocked
        # When blocking the first post of a topic, also block all the other posts in the topic by this user.
        post.postable.posts.where(user_id: post.user.id).where.not(id: post.id).each do |a_post|
          update_without_timestamping!(a_post, moderation_state: moderation_state)
        end
      end
    end
    update_without_timestamping!(post, moderation_state: moderation_state)
    post_moderation_record
  end
end

.update_without_timestamping!(record, *attr) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • record (ActiveRecord)


38
39
40
41
42
43
44
45
46
# File 'app/commands/thredded/moderate_post.rb', line 38

def update_without_timestamping!(record, *attr)
  record_timestamps_was = record.record_timestamps
  begin
    record.record_timestamps = false
    record.update!(*attr)
  ensure
    record.record_timestamps = record_timestamps_was
  end
end