You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
596 B

  1. # frozen_string_literal: true
  2. class Form::TagBatch
  3. include ActiveModel::Model
  4. include Authorization
  5. attr_accessor :tag_ids, :action, :current_account
  6. def save
  7. case action
  8. when 'approve'
  9. approve!
  10. when 'reject'
  11. reject!
  12. end
  13. end
  14. private
  15. def tags
  16. Tag.where(id: tag_ids)
  17. end
  18. def approve!
  19. tags.each { |tag| authorize(tag, :update?) }
  20. tags.update_all(trendable: true, reviewed_at: Time.now.utc)
  21. end
  22. def reject!
  23. tags.each { |tag| authorize(tag, :update?) }
  24. tags.update_all(trendable: false, reviewed_at: Time.now.utc)
  25. end
  26. end