DEV: Remove code deprecated by the new Reviewable API (#8023)

DEV: Remove code deprecated by the new Reviewable API (#8023)

  • Remove flag hooks and endpoints

  • Remove #reject_bulk for users

  • Remove code for quued_posts_controller

diff --git a/app/controllers/admin/flagged_topics_controller.rb b/app/controllers/admin/flagged_topics_controller.rb
deleted file mode 100644
index 10680b9..0000000
--- a/app/controllers/admin/flagged_topics_controller.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-require_dependency 'flag_query'
-
-class Admin::FlaggedTopicsController < Admin::AdminController
-
-  def index
-    result = FlagQuery.flagged_topics
-
-    render_json_dump(
-      {
-        flagged_topics: serialize_data(result[:flagged_topics], FlaggedTopicSummarySerializer),
-        users: serialize_data(result[:users], BasicUserSerializer),
-      },
-      rest_serializer: true
-    )
-  end
-
-end
diff --git a/app/controllers/admin/flags_controller.rb b/app/controllers/admin/flags_controller.rb
deleted file mode 100644
index 9ede2f7..0000000
--- a/app/controllers/admin/flags_controller.rb
+++ /dev/null
@@ -1,146 +0,0 @@
-# frozen_string_literal: true
-
-require 'flag_query'
-
-class Admin::FlagsController < Admin::AdminController
-
-  def self.flags_per_page
-    10
-  end
-
-  def index
-    Discourse.deprecate("FlagsController#index has been deprecated, please use the Reviewable API instead", since: "2.3.0beta5", drop_from: "2.4")
-
-    offset = params[:offset].to_i
-    per_page = Admin::FlagsController.flags_per_page
-
-    posts, topics, users, post_actions, total_rows = FlagQuery.flagged_posts_report(
-      current_user,
-      filter: params[:filter],
-      user_id: params[:user_id],
-      offset: offset,
-      topic_id: params[:topic_id],
-      per_page: per_page
-    )
-
-    meta = {
-      types: {
-        disposed_by: 'user'
-      }
-    }
-
-    next_segment = offset + per_page
-    if (total_rows || 0) > next_segment
-      meta[:total_rows_flagged_posts] = total_rows
-      meta[:load_more_flagged_posts] = admin_flags_filtered_path(
-        filter: params[:filter],
-        offset: next_segment,
-        topic_id: params[:topic_id]
-      )
-    end
-
-    render_json_dump(
-      {
-        flagged_posts: posts,
-        topics: serialize_data(topics, FlaggedTopicSerializer),
-        users: serialize_data(users, FlaggedUserSerializer),
-        post_actions: post_actions
-      },
-      rest_serializer: true,
-      meta: meta
-    )
-  end
-
-  def agree
-    Discourse.deprecate("FlagsController#agree has been deprecated, please use the Reviewable API instead", since: "2.3.0beta5", drop_from: "2.4")
-
-    params.permit(:id, :action_on_post)
-    post = Post.find(params[:id])
-
-    DiscourseEvent.trigger(
-      :before_staff_flag_action,
-      type: 'agree',
-      post: post,
-      action_on_post: params[:action_on_post],
-      user: current_user
-    )
-
-    reviewable = post.reviewable_flag
-    return render_json_error(I18n.t("flags.errors.already_handled"), status: 409) if reviewable.blank?
-
-    keep_post = ['silenced', 'suspended', 'keep'].include?(params[:action_on_post])
-    delete_post = params[:action_on_post] == "delete"
-    restore_post = params[:action_on_post] == "restore"
-
-    if delete_post
-      # PostDestroy automatically agrees with flags
-      destroy_post(post)
-    elsif restore_post
-      reviewable.perform(current_user, :agree_and_restore)
-    else
-      reviewable.perform(
-        current_user,
-        :agree_and_keep,
-        post_was_deleted: delete_post,
-        hide_post: !keep_post
-      )
-    end
-
-    render body: nil
-  end
-
-  def disagree
-    Discourse.deprecate("FlagsController#disagree has been deprecated, please use the Reviewable API instead", since: "2.3.0beta5", drop_from: "2.4")
-    params.permit(:id)
-    post = Post.find(params[:id])
-
-    if reviewable = post.reviewable_flag
-      DiscourseEvent.trigger(
-        :before_staff_flag_action,
-        type: 'disagree',
-        post: post,
-        user: current_user
-      )
-
-      if post.hidden?
-        reviewable.perform(current_user, :disagree_and_restore)
-      else
-        reviewable.perform(current_user, :disagree)
-      end
-    end
-
-    render body: nil
-  end
-
-  def defer
-    Discourse.deprecate("FlagsController#defer has been deprecated, please use the Reviewable API instead", since: "2.3.0beta5", drop_from: "2.4")
-
-    params.permit(:id, :delete_post)
-    post = Post.find(params[:id])
-
-    if reviewable = post.reviewable_flag
-      DiscourseEvent.trigger(
-        :before_staff_flag_action,
-        type: 'defer',
-        post: post,
-        user: current_user
-      )
-
-      reviewable.perform(current_user, :ignore, post_was_deleted: params[:delete_post])
-      destroy_post(post) if params[:delete_post]
-    end
-
-    render body: nil
-  end
-
-  private
-
-  def destroy_post(post)
-    if post.is_first_post?
-      topic = Topic.find_by(id: post.topic_id)
-      guardian.ensure_can_delete!(topic) if topic.present?
-    end
-
-    PostDestroyer.new(current_user, post).destroy
-  end
-end
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index 3d4d0c2..59b9f03 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -370,23 +370,6 @@ class Admin::UsersController < Admin::AdminController
     )
   end
 
-  # Kept for backwards compatibility, but is replaced by the Reviewable Queue
-  def reject_bulk
-    Discourse.deprecate("AdminUsersController#reject_bulk is deprecated. Please use the Reviewable API instead.", since: "2.3.0beta5", drop_from: "2.4")
-
-    success_count = 0
-    d = UserDestroyer.new(current_user)
-
-    User.where(id: params[:users]).each do |u|
-      success_count += 1 if guardian.can_delete_user?(u) && d.destroy(u, params.slice(:context)) rescue UserDestroyer::PostsExistError
-    end
-
-    render json: {
-      success: success_count,
-      failed: (params[:users].try(:size) || 0) - success_count
-    }
-  end
-
   def disable_second_factor
     guardian.ensure_can_disable_second_factor!(@user)
     user_second_factor = @user.user_second_factors
diff --git a/app/controllers/queued_posts_controller.rb b/app/controllers/queued_posts_controller.rb
deleted file mode 100644
index 0220790..0000000
--- a/app/controllers/queued_posts_controller.rb
+++ /dev/null
@@ -1,72 +0,0 @@
-# frozen_string_literal: true
-
-require_dependency 'queued_post_serializer'
-
-class QueuedPostsController < ApplicationController
-
-  before_action :ensure_staff
-
-  def index
-    Discourse.deprecate("QueuedPostController#index is deprecated. Please use the Reviewable API instead.", since: "2.3.0beta5", drop_from: "2.4")
-
-    status = params[:state] || 'pending'
-    status = 'pending' if status == 'new'
-
-    reviewables = Reviewable.list_for(current_user, status: status.to_sym, type: ReviewableQueuedPost.name)
-    render_serialized(reviewables,
-                      QueuedPostSerializer,
-                      root: :queued_posts,
-                      rest_serializer: true,
-                      refresh_queued_posts: "/queued_posts?status=new")
-  end
-
-  def update
-    Discourse.deprecate("QueuedPostController#update is deprecated. Please use the Reviewable API instead.", since: "2.3.0beta5", drop_from: "2.4")
-    reviewable = Reviewable.find_by(id: params[:id])
-    raise Discourse::NotFound if reviewable.blank?
-
-    update_params = params[:queued_post]
-
-    reviewable.payload['raw'] = update_params[:raw] if update_params[:raw].present?
-    if reviewable.topic_id.blank? && update_params[:state].blank?
-      reviewable.payload['title'] = update_params[:title] if update_params[:title].present?
-      reviewable.payload['tags'] = update_params[:tags]
-      reviewable.category_id = update_params[:category_id].to_i if update_params[:category_id].present?
-    end
-
-    reviewable.save(validate: false)
-
-    state = update_params[:state]
-    begin
-      if state == 'approved'
-        reviewable.perform(current_user, :approve_post)
-      elsif state == 'rejected'
-        reviewable.perform(current_user, :reject_post)

[... diff too long, it was truncated ...]

GitHub sha: 3259ea60

1 Like