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

This commit is contained in:
Eugen Rochko
2019-09-09 12:50:09 +02:00
committed by GitHub
parent 3feacd2b14
commit 261e52268c
7 changed files with 142 additions and 19 deletions

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