Class: ReviewableFlaggedPost
- Inherits:
-
Reviewable
- Object
- ActiveRecord::Base
- Reviewable
- ReviewableFlaggedPost
- Defined in:
- app/models/reviewable_flagged_post.rb
Constant Summary
Constants inherited from Reviewable
Reviewable::TYPE_TO_BASIC_SERIALIZER
Instance Attribute Summary
Attributes inherited from Reviewable
Class Method Summary collapse
-
.action_aliases ⇒ Object
Penalties are handled by the modal after the action is performed.
- .counts_for(posts) ⇒ Object
Instance Method Summary collapse
- #build_actions(actions, guardian, args) ⇒ Object
- #perform_agree_and_hide(performed_by, args) ⇒ Object
- #perform_agree_and_keep(performed_by, args) ⇒ Object
- #perform_agree_and_restore(performed_by, args) ⇒ Object
- #perform_delete_and_agree(performed_by, args) ⇒ Object
- #perform_delete_and_agree_replies(performed_by, args) ⇒ Object
- #perform_delete_and_ignore(performed_by, args) ⇒ Object
- #perform_delete_and_ignore_replies(performed_by, args) ⇒ Object
- #perform_delete_user(performed_by, args) ⇒ Object
- #perform_delete_user_block(performed_by, args) ⇒ Object
- #perform_disagree(performed_by, args) ⇒ Object
- #perform_ignore(performed_by, args) ⇒ Object
- #perform_ignore_and_do_nothing(performed_by, args) ⇒ Object
- #post ⇒ Object
- #post_action_type_view ⇒ Object
Methods inherited from Reviewable
#actions_for, add_custom_filter, #add_score, #basic_serializer, basic_serializers_for_list, #build_editable_fields, bulk_perform_targets, clear_custom_filters!, count_by_date, #create_result, #created_new!, custom_filters, default_visible, #delete_user_actions, #editable_for, #explain_score, #history, list_for, #log_history, lookup_serializer_for, min_score_for_priority, needs_review!, pending_count, #perform, #recalculate_score, score_required_to_hide_post, score_to_auto_close_topic, scores_with_topics, sensitivity_score, sensitivity_score_value, #serializer, serializer_for, set_priorities, spam_score_to_silence_new_user, #transition_to, #type_class, types, typical_sensitivity, unseen_list_for, unseen_reviewable_count, #updatable_reviewable_scores, #update_fields, user_menu_list_for, valid_type?, viewable_by
Class Method Details
.action_aliases ⇒ Object
Penalties are handled by the modal after the action is performed
7 8 9 10 11 12 13 14 15 16 |
# File 'app/models/reviewable_flagged_post.rb', line 7 def self.action_aliases { agree_and_keep_hidden: :agree_and_keep, agree_and_silence: :agree_and_keep, agree_and_suspend: :agree_and_keep, agree_and_edit: :agree_and_keep, disagree_and_restore: :disagree, ignore_and_do_nothing: :ignore, } end |
.counts_for(posts) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/reviewable_flagged_post.rb', line 18 def self.counts_for(posts) result = {} counts = DB.query(<<~SQL, pending: statuses[:pending]) SELECT r.target_id AS post_id, rs.reviewable_score_type, count(*) as total FROM reviewables AS r INNER JOIN reviewable_scores AS rs ON rs.reviewable_id = r.id WHERE r.type = 'ReviewableFlaggedPost' AND r.status = :pending GROUP BY r.target_id, rs.reviewable_score_type SQL counts.each do |c| result[c.post_id] ||= {} result[c.post_id][c.reviewable_score_type] = c.total end result end |
Instance Method Details
#build_actions(actions, guardian, args) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/models/reviewable_flagged_post.rb', line 44 def build_actions(actions, guardian, args) return unless pending? return if post.blank? agree_bundle = actions.add_bundle("#{id}-agree", icon: "thumbs-up", label: "reviewables.actions.agree.title") if !post.user_deleted? && !post.hidden? build_action(actions, :agree_and_hide, icon: "far-eye-slash", bundle: agree_bundle) end if post.hidden? build_action(actions, :agree_and_keep_hidden, icon: "thumbs-up", bundle: agree_bundle) else build_action(actions, :agree_and_keep, icon: "thumbs-up", bundle: agree_bundle) build_action( actions, :agree_and_edit, icon: "pencil", bundle: agree_bundle, client_action: "edit", ) end if guardian.can_delete_post_or_topic?(post) build_action(actions, :delete_and_agree, icon: "trash-can", bundle: agree_bundle) if post.reply_count > 0 build_action( actions, :delete_and_agree_replies, icon: "trash-can", bundle: agree_bundle, confirm: true, ) end end if (potential_spam? || potentially_illegal?) && guardian.can_delete_user?(target_created_by) delete_user_actions(actions, agree_bundle) end if guardian.can_suspend?(target_created_by) build_action( actions, :agree_and_suspend, icon: "ban", bundle: agree_bundle, client_action: "suspend", ) build_action( actions, :agree_and_silence, icon: "microphone-slash", bundle: agree_bundle, client_action: "silence", ) end if post.user_deleted? build_action(actions, :agree_and_restore, icon: "far-eye", bundle: agree_bundle) end if post.hidden? build_action(actions, :disagree_and_restore, icon: "thumbs-down") else build_action(actions, :disagree, icon: "thumbs-down") end post_visible_or_system_user = !post.hidden? || guardian.user.is_system_user? can_delete_post_or_topic = guardian.can_delete_post_or_topic?(post) # We must return early in this case otherwise we can end up with a bundle # with no associated actions, which is not valid on the client. return if !can_delete_post_or_topic && !post_visible_or_system_user ignore = actions.add_bundle( "#{id}-ignore", icon: "thumbs-up", label: "reviewables.actions.ignore.title", ) if post_visible_or_system_user build_action(actions, :ignore_and_do_nothing, icon: "up-right-from-square", bundle: ignore) end if can_delete_post_or_topic build_action(actions, :delete_and_ignore, icon: "trash-can", bundle: ignore) if post.reply_count > 0 build_action( actions, :delete_and_ignore_replies, icon: "trash-can", confirm: true, bundle: ignore, ) end end end |
#perform_agree_and_hide(performed_by, args) ⇒ Object
201 202 203 |
# File 'app/models/reviewable_flagged_post.rb', line 201 def perform_agree_and_hide(performed_by, args) agree(performed_by, args) { |pa| post.hide!(pa.post_action_type_id) } end |
#perform_agree_and_keep(performed_by, args) ⇒ Object
179 180 181 |
# File 'app/models/reviewable_flagged_post.rb', line 179 def perform_agree_and_keep(performed_by, args) agree(performed_by, args) end |
#perform_agree_and_restore(performed_by, args) ⇒ Object
205 206 207 |
# File 'app/models/reviewable_flagged_post.rb', line 205 def perform_agree_and_restore(performed_by, args) agree(performed_by, args) { PostDestroyer.new(performed_by, post).recover } end |
#perform_delete_and_agree(performed_by, args) ⇒ Object
269 270 271 272 273 |
# File 'app/models/reviewable_flagged_post.rb', line 269 def perform_delete_and_agree(performed_by, args) result = agree(performed_by, args) destroyer(performed_by, post).destroy result end |
#perform_delete_and_agree_replies(performed_by, args) ⇒ Object
275 276 277 278 279 |
# File 'app/models/reviewable_flagged_post.rb', line 275 def perform_delete_and_agree_replies(performed_by, args) result = agree(performed_by, args) PostDestroyer.delete_with_replies(performed_by, post, self) result end |
#perform_delete_and_ignore(performed_by, args) ⇒ Object
256 257 258 259 260 |
# File 'app/models/reviewable_flagged_post.rb', line 256 def perform_delete_and_ignore(performed_by, args) result = perform_ignore_and_do_nothing(performed_by, args) destroyer(performed_by, post).destroy result end |
#perform_delete_and_ignore_replies(performed_by, args) ⇒ Object
262 263 264 265 266 267 |
# File 'app/models/reviewable_flagged_post.rb', line 262 def perform_delete_and_ignore_replies(performed_by, args) result = perform_ignore_and_do_nothing(performed_by, args) PostDestroyer.delete_with_replies(performed_by, post, self) result end |
#perform_delete_user(performed_by, args) ⇒ Object
183 184 185 186 187 188 189 |
# File 'app/models/reviewable_flagged_post.rb', line 183 def perform_delete_user(performed_by, args) = delete_opts UserDestroyer.new(performed_by).destroy(post.user, ) agree(performed_by, args) end |
#perform_delete_user_block(performed_by, args) ⇒ Object
191 192 193 194 195 196 197 198 199 |
# File 'app/models/reviewable_flagged_post.rb', line 191 def perform_delete_user_block(performed_by, args) = delete_opts .merge!(block_email: true, block_ip: true) if Rails.env.production? UserDestroyer.new(performed_by).destroy(post.user, ) agree(performed_by, args) end |
#perform_disagree(performed_by, args) ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'app/models/reviewable_flagged_post.rb', line 209 def perform_disagree(performed_by, args) # -1 is the automatic system clear action_type_ids = if performed_by.id == Discourse::SYSTEM_USER_ID post_action_type_view.auto_action_flag_types.values else post_action_type_view.notify_flag_type_ids end actions = PostAction.active.where(post_id: target_id).where(post_action_type_id: action_type_ids) actions.each do |action| action.disagreed_at = Time.zone.now action.disagreed_by_id = performed_by.id # so callback is called action.save action.add_moderator_post_if_needed(performed_by, :disagreed) end # reset all cached counters cached = {} action_type_ids.each do |atid| column = "#{post_action_type_view.types[atid]}_count" cached[column] = 0 if ActiveRecord::Base.connection.column_exists?(:posts, column) end Post.with_deleted.where(id: target_id).update_all(cached) if actions.first.present? unassign_topic performed_by, post DiscourseEvent.trigger(:flag_reviewed, post) DiscourseEvent.trigger(:flag_disagreed, actions.first) end # Undo hide/silence if applicable if post&.hidden? notify_poster(performed_by) post.unhide! UserSilencer.unsilence(post.user) if UserSilencer.was_silenced_for?(post) end create_result(:success, :rejected) do |result| result.update_flag_stats = { status: :disagreed, user_ids: actions.map(&:user_id) } end end |
#perform_ignore(performed_by, args) ⇒ Object
143 144 145 |
# File 'app/models/reviewable_flagged_post.rb', line 143 def perform_ignore(performed_by, args) perform_ignore_and_do_nothing(performed_by, args) end |
#perform_ignore_and_do_nothing(performed_by, args) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'app/models/reviewable_flagged_post.rb', line 151 def perform_ignore_and_do_nothing(performed_by, args) actions = PostAction .active .where(post_id: target_id) .where(post_action_type_id: post_action_type_view.notify_flag_type_ids) actions.each do |action| action.deferred_at = Time.zone.now action.deferred_by_id = performed_by.id # so callback is called action.save unless args[:expired] action.add_moderator_post_if_needed(performed_by, :ignored, args[:post_was_deleted]) end end if actions.first.present? unassign_topic performed_by, post DiscourseEvent.trigger(:flag_reviewed, post) DiscourseEvent.trigger(:flag_deferred, actions.first) end create_result(:success, :ignored) do |result| result.update_flag_stats = { status: :ignored, user_ids: actions.map(&:user_id) } end end |
#post ⇒ Object
40 41 42 |
# File 'app/models/reviewable_flagged_post.rb', line 40 def post @post ||= (target || Post.with_deleted.find_by(id: target_id)) end |
#post_action_type_view ⇒ Object
147 148 149 |
# File 'app/models/reviewable_flagged_post.rb', line 147 def post_action_type_view @post_action_type_view ||= PostActionTypeView.new end |