about summary refs log tree commit diff
path: root/app/models/form
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-09-09 12:50:09 +0200
committerGitHub <noreply@github.com>2019-09-09 12:50:09 +0200
commit261e52268c05d2da4459a23e2898555dd5db5771 (patch)
tree51ff3e61b3de236a88953e660b3d57d39e78e976 /app/models/form
parent3feacd2b14aeb60999c9ee83422c6c8090ed3ac2 (diff)
Add batch approve/reject for pending hashtags in admin UI (#11791)
Diffstat (limited to 'app/models/form')
-rw-r--r--app/models/form/tag_batch.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/app/models/form/tag_batch.rb b/app/models/form/tag_batch.rb
new file mode 100644
index 000000000..fd517a1a6
--- /dev/null
+++ b/app/models/form/tag_batch.rb
@@ -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