<commit_before>module DiscourseAkismet
  class AdminModQueueController < Admin::AdminController
    requires_plugin 'discourse-akismet'

    def index
      render_json_dump({
        posts: serialize_data(DiscourseAkismet.needs_review, PostSerializer),
        enabled: SiteSetting.akismet_enabled?,
        stats: DiscourseAkismet.stats
      })
    end

    def confirm_spam
      post = Post.with_deleted.find(params[:post_id])
      DiscourseAkismet.move_to_state(post, 'confirmed_spam')
      log_confirmation(post, 'confirmed_spam')
      render nothing: true
    end

    def allow
      post = Post.with_deleted.find(params[:post_id])

      Jobs.enqueue(:update_akismet_status, post_id: post.id, status: 'ham')

      PostDestroyer.new(current_user, post).recover
      DiscourseAkismet.move_to_state(post, 'confirmed_ham')
      log_confirmation(post, 'confirmed_ham')

      render nothing: true
    end

    def delete_user
      post = Post.with_deleted.find(params[:post_id])
      user = post.user
      DiscourseAkismet.move_to_state(post, 'confirmed_spam')
      log_confirmation(post, 'confirmed_spam_deleted')
<commit_msg>FIX: If the post was recovered don't try to recover it again.<commit_after>module DiscourseAkismet
  class AdminModQueueController < Admin::AdminController
    requires_plugin 'discourse-akismet'

    def index
      render_json_dump({
        posts: serialize_data(DiscourseAkismet.needs_review, PostSerializer),
        enabled: SiteSetting.akismet_enabled?,
        stats: DiscourseAkismet.stats
      })
    end

    def confirm_spam
      post = Post.with_deleted.find(params[:post_id])
      DiscourseAkismet.move_to_state(post, 'confirmed_spam')
      log_confirmation(post, 'confirmed_spam')
      render nothing: true
    end

    def allow
      post = Post.with_deleted.find(params[:post_id])

      Jobs.enqueue(:update_akismet_status, post_id: post.id, status: 'ham')

      # It's possible the post was recovered already
      if post.deleted_at
        PostDestroyer.new(current_user, post).recover
      end

      DiscourseAkismet.move_to_state(post, 'confirmed_ham')
      log_confirmation(post, 'confirmed_ham')

      render nothing: true
    end

    def delete_user
      post = Post.with_deleted.find(params[:post_id])
      user = post.user
      DiscourseAkismet.move_to_state(post, 'confirmed_spam')
      log_confirmation(post, 'confirmed_spam_deleted')

{'fraction_non_alphanumeric': 0.08666941807676434, 'fraction_numerical': 0.0, 'mean_word_length': 3.539325842696629, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6613668', 'n_tokens_mistral': 791, 'n_tokens_neox': 756, 'n_words': 139}