1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/models/concerns/openlab_sync.rb

45 lines
964 B
Ruby
Raw Normal View History

# frozen_string_literal: false
# module definition
module OpenlabSync
extend ActiveSupport::Concern
included do
after_create :openlab_create, if: :openlab_sync_active?
2022-11-23 10:01:16 +01:00
after_update :openlab_update, if: :openlab_sync_active?
after_destroy :openlab_destroy, if: :openlab_sync_active?
def openlab_create
OpenlabWorker.perform_in(2.seconds, :create, id) if published?
end
def openlab_update
return unless published?
if state_was == 'draft'
OpenlabWorker.perform_async(:create, id)
else
OpenlabWorker.perform_async(:update, id)
end
end
def openlab_destroy
OpenlabWorker.perform_async(:destroy, id)
end
def openlab_attributes
OpenLabService.to_hash(self)
end
def openlab_sync_active?
self.class.openlab_sync_active?
end
end
class_methods do
def openlab_sync_active?
Setting.get('openlab_app_secret').present?
end
end
end