has_publishing.rb 761 B

12345678910111213141516171819202122232425
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module HasPublishing
  3. extend ActiveSupport::Concern
  4. included do
  5. CanBePublished::StateMachine.aasm.events.each do |event|
  6. define_method :"has_publishing_#{event.name}" do
  7. object = klass.find params[:id]
  8. object.can_be_published_aasm.aasm.fire! event.name, current_user
  9. render json: klass.full(params[:id]), status: :ok
  10. end
  11. end
  12. end
  13. def has_publishing_update # rubocop:disable Naming/PredicateName
  14. params_for_update = params
  15. .permit(:id, :internal_at, :published_at, :archived_at)
  16. .to_h
  17. .to_h { |k, v| [k.to_sym, v == '--now--' ? Time.zone.now : v] }
  18. model_update_render(klass, params_for_update)
  19. end
  20. end