gearheads
/
mastodon
Archived
2
0
Fork 0

Add batch approve/reject for pending hashtags in admin UI (#11791)

gh/stable
Eugen Rochko 2019-09-09 12:50:09 +02:00 committed by GitHub
parent 3feacd2b14
commit 261e52268c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 142 additions and 19 deletions

View File

@ -3,12 +3,33 @@
module Admin module Admin
class TagsController < BaseController class TagsController < BaseController
before_action :set_tags, only: :index before_action :set_tags, only: :index
before_action :set_tag, except: :index before_action :set_tag, except: [:index, :batch, :approve_all, :reject_all]
before_action :set_usage_by_domain, except: :index before_action :set_usage_by_domain, except: [:index, :batch, :approve_all, :reject_all]
before_action :set_counters, except: :index before_action :set_counters, except: [:index, :batch, :approve_all, :reject_all]
def index def index
authorize :tag, :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 end
def show def show
@ -61,7 +82,7 @@ module Admin
end end
def filter_params def filter_params
params.slice(:context, :review).permit(:context, :review) params.slice(:context, :review, :page).permit(:context, :review, :page)
end end
def tag_params def tag_params
@ -75,5 +96,17 @@ module Admin
date.to_time(:utc).beginning_of_day.to_i date.to_time(:utc).beginning_of_day.to_i
end end
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
end end

View File

@ -211,6 +211,16 @@ a.table-action-link {
padding: 0; padding: 0;
} }
} }
.directory__tag {
margin: 0;
width: 100%;
a {
background: transparent;
border-radius: 0;
}
}
} }
.status__content { .status__content {

View File

@ -0,0 +1,33 @@
# frozen_string_literal: true
class Form::TagBatch
include ActiveModel::Model
include Authorization
attr_accessor :tag_ids, :action, :current_account
def save
case action
when 'approve'
approve!
when 'reject'
reject!
end
end
private
def tags
Tag.where(id: tag_ids)
end
def approve!
tags.each { |tag| authorize(tag, :update?) }
tags.update_all(trendable: true, reviewed_at: Time.now.utc)
end
def reject!
tags.each { |tag| authorize(tag, :update?) }
tags.update_all(trendable: false, reviewed_at: Time.now.utc)
end
end

View File

@ -1,16 +1,20 @@
.directory__tag .batch-table__row
= link_to admin_tag_path(tag.id) do %label.batch-table__row__select.batch-table__row__select--aligned.batch-checkbox
%h4 = f.check_box :tag_ids, { multiple: true, include_hidden: false }, tag.id
= fa_icon 'hashtag'
= tag.name
%small .directory__tag
= t('admin.tags.in_directory', count: tag.accounts_count) = link_to admin_tag_path(tag.id) do
&bull; %h4
= t('admin.tags.unique_uses_today', count: tag.history.first[:accounts]) = fa_icon 'hashtag'
= tag.name
- if tag.trending? %small
= fa_icon 'fire fw' = t('admin.tags.in_directory', count: tag.accounts_count)
= t('admin.tags.trending_right_now') &bull;
= t('admin.tags.unique_uses_today', count: tag.history.first[:accounts])
.trends__item__current= number_to_human tag.history.first[:uses], strip_insignificant_zeros: true - if tag.trending?
= fa_icon 'fire fw'
= t('admin.tags.trending_right_now')
.trends__item__current= number_to_human tag.history.first[:uses], strip_insignificant_zeros: true

View File

@ -1,6 +1,9 @@
- content_for :page_title do - content_for :page_title do
= t('admin.tags.title') = t('admin.tags.title')
- content_for :header_tags do
= javascript_pack_tag 'admin', integrity: true, async: true, crossorigin: 'anonymous'
.filters .filters
.filter-subset .filter-subset
%strong= t('admin.tags.context') %strong= t('admin.tags.context')
@ -18,5 +21,37 @@
%hr.spacer/ %hr.spacer/
= render @tags = form_for(@form, url: batch_admin_tags_path) do |f|
= hidden_field_tag :page, params[:page] || 1
= hidden_field_tag :context, params[:context]
= hidden_field_tag :review, params[:review]
.batch-table
.batch-table__toolbar
%label.batch-table__toolbar__select.batch-checkbox-all
= check_box_tag :batch_checkbox_all, nil, false
.batch-table__toolbar__actions
- if params[:review] == 'pending_review'
= f.button safe_join([fa_icon('check'), t('admin.accounts.approve')]), name: :approve, class: 'table-action-link', type: :submit, data: { confirm: t('admin.reports.are_you_sure') }
= f.button safe_join([fa_icon('times'), t('admin.accounts.reject')]), name: :reject, class: 'table-action-link', type: :submit, data: { confirm: t('admin.reports.are_you_sure') }
- else
%span.neutral-hint= t('generic.no_batch_actions_available')
.batch-table__body
- if @tags.empty?
= nothing_here 'nothing-here--under-tabs'
- else
= render partial: 'tag', collection: @tags, locals: { f: f }
= paginate @tags = paginate @tags
- if params[:review] == 'pending_review'
%hr.spacer/
%div{ style: 'overflow: hidden' }
%div{ style: 'float: right' }
= link_to t('admin.accounts.reject_all'), reject_all_admin_tags_path, method: :post, data: { confirm: t('admin.accounts.are_you_sure') }, class: 'button button--destructive'
%div
= link_to t('admin.accounts.approve_all'), approve_all_admin_tags_path, method: :post, data: { confirm: t('admin.accounts.are_you_sure') }, class: 'button'

View File

@ -727,6 +727,7 @@ en:
all: All all: All
changes_saved_msg: Changes successfully saved! changes_saved_msg: Changes successfully saved!
copy: Copy copy: Copy
no_batch_actions_available: No batch actions available on this page
order_by: Order by order_by: Order by
save_changes: Save changes save_changes: Save changes
validation_errors: validation_errors:

View File

@ -251,7 +251,14 @@ Rails.application.routes.draw do
end end
resources :account_moderation_notes, only: [:create, :destroy] resources :account_moderation_notes, only: [:create, :destroy]
resources :tags, only: [:index, :show, :update]
resources :tags, only: [:index, :show, :update] do
collection do
post :approve_all
post :reject_all
post :batch
end
end
end end
get '/admin', to: redirect('/admin/dashboard', status: 302) get '/admin', to: redirect('/admin/dashboard', status: 302)