about summary refs log tree commit diff
path: root/app/controllers/admin
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2021-04-12 12:37:14 +0200
committerGitHub <noreply@github.com>2021-04-12 12:37:14 +0200
commitf7117646afddb2676e9275d8efe90c3a20c59021 (patch)
treeefb9ba8f7b22d27b0a1ea595cfa30030f5d03b09 /app/controllers/admin
parentad61265268f13d9b2a04e2e176724d8a7376f85a (diff)
Add cold-start follow recommendations (#15945)
Diffstat (limited to 'app/controllers/admin')
-rw-r--r--app/controllers/admin/follow_recommendations_controller.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/app/controllers/admin/follow_recommendations_controller.rb b/app/controllers/admin/follow_recommendations_controller.rb
new file mode 100644
index 000000000..e3eac62b3
--- /dev/null
+++ b/app/controllers/admin/follow_recommendations_controller.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+module Admin
+  class FollowRecommendationsController < BaseController
+    before_action :set_language
+
+    def show
+      authorize :follow_recommendation, :show?
+
+      @form     = Form::AccountBatch.new
+      @accounts = filtered_follow_recommendations
+    end
+
+    def update
+      @form = Form::AccountBatch.new(form_account_batch_params.merge(current_account: current_account, action: action_from_button))
+      @form.save
+    rescue ActionController::ParameterMissing
+      # Do nothing
+    ensure
+      redirect_to admin_follow_recommendations_path(filter_params)
+    end
+
+    private
+
+    def set_language
+      @language = follow_recommendation_filter.language
+    end
+
+    def filtered_follow_recommendations
+      follow_recommendation_filter.results
+    end
+
+    def follow_recommendation_filter
+      @follow_recommendation_filter ||= FollowRecommendationFilter.new(filter_params)
+    end
+
+    def form_account_batch_params
+      params.require(:form_account_batch).permit(:action, account_ids: [])
+    end
+
+    def filter_params
+      params.slice(*FollowRecommendationFilter::KEYS).permit(*FollowRecommendationFilter::KEYS)
+    end
+
+    def action_from_button
+      if params[:suppress]
+        'suppress_follow_recommendation'
+      elsif params[:unsuppress]
+        'unsuppress_follow_recommendation'
+      end
+    end
+  end
+end