has_collection_update.rb 819 B

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. module HasCollectionUpdate
  3. extend ActiveSupport::Concern
  4. included do
  5. after_commit :push_collection_to_clients
  6. end
  7. # methods defined here are going to extend the class, not the instance of it
  8. class_methods do
  9. =begin
  10. define required permissions to push collection to web app
  11. class Model < ApplicationModel
  12. include HasCollectionUpdate
  13. collection_push_permission('some_permission')
  14. end
  15. =end
  16. attr_accessor :collection_push_permission_value
  17. def collection_push_permission(*permission)
  18. @collection_push_permission_value = permission
  19. end
  20. end
  21. def push_collection_to_clients
  22. return if Setting.get('import_mode')
  23. CollectionUpdateJob.set(wait: 10.seconds).perform_later(self.class.name)
  24. end
  25. end