Add batch approve/reject for pending hashtags in admin UI (#11791)
This commit is contained in:
		@@ -3,12 +3,33 @@
 | 
			
		||||
module Admin
 | 
			
		||||
  class TagsController < BaseController
 | 
			
		||||
    before_action :set_tags, only: :index
 | 
			
		||||
    before_action :set_tag, except: :index
 | 
			
		||||
    before_action :set_usage_by_domain, except: :index
 | 
			
		||||
    before_action :set_counters, except: :index
 | 
			
		||||
    before_action :set_tag, except: [:index, :batch, :approve_all, :reject_all]
 | 
			
		||||
    before_action :set_usage_by_domain, except: [:index, :batch, :approve_all, :reject_all]
 | 
			
		||||
    before_action :set_counters, except: [:index, :batch, :approve_all, :reject_all]
 | 
			
		||||
 | 
			
		||||
    def index
 | 
			
		||||
      authorize :tag, :index?
 | 
			
		||||
 | 
			
		||||
      @form = Form::TagBatch.new
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def batch
 | 
			
		||||
      @form = Form::TagBatch.new(form_tag_batch_params.merge(current_account: current_account, action: action_from_button))
 | 
			
		||||
      @form.save
 | 
			
		||||
    rescue ActionController::ParameterMissing
 | 
			
		||||
      flash[:alert] = I18n.t('admin.accounts.no_account_selected')
 | 
			
		||||
    ensure
 | 
			
		||||
      redirect_to admin_tags_path(filter_params)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def approve_all
 | 
			
		||||
      Form::TagBatch.new(current_account: current_account, tag_ids: Tag.pending_review.pluck(:id), action: 'approve').save
 | 
			
		||||
      redirect_to admin_tags_path(filter_params)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def reject_all
 | 
			
		||||
      Form::TagBatch.new(current_account: current_account, tag_ids: Tag.pending_review.pluck(:id), action: 'reject').save
 | 
			
		||||
      redirect_to admin_tags_path(filter_params)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def show
 | 
			
		||||
@@ -61,7 +82,7 @@ module Admin
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def filter_params
 | 
			
		||||
      params.slice(:context, :review).permit(:context, :review)
 | 
			
		||||
      params.slice(:context, :review, :page).permit(:context, :review, :page)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def tag_params
 | 
			
		||||
@@ -75,5 +96,17 @@ module Admin
 | 
			
		||||
        date.to_time(:utc).beginning_of_day.to_i
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def form_tag_batch_params
 | 
			
		||||
      params.require(:form_tag_batch).permit(:action, tag_ids: [])
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def action_from_button
 | 
			
		||||
      if params[:approve]
 | 
			
		||||
        'approve'
 | 
			
		||||
      elsif params[:reject]
 | 
			
		||||
        'reject'
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user