diff --git a/CHANGELOG.md b/CHANGELOG.md index 929e0b718..0d25f3ac5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Next release +## v6.3.41 2025 February 26 + +- Fix a bug: unable to sync projects with openprojects +- [TODO DEPLOY] `rails fablab:openlab:bulk_export` +- [TODO DEPLOY] `rails fablab:openlab:bulk_update` + ## v6.3.40 2025 February 24 - Fix a bug: machine reservation time in my reservations is incorrect diff --git a/app/models/concerns/openlab_sync.rb b/app/models/concerns/openlab_sync.rb index 49daddf42..d496c8069 100644 --- a/app/models/concerns/openlab_sync.rb +++ b/app/models/concerns/openlab_sync.rb @@ -1,25 +1,29 @@ -# frozen_string_literal: false +# frozen_string_literal: true -# module definition +# Module for synchronizing objects with OpenLab platform module OpenlabSync extend ActiveSupport::Concern included do - after_save :openlab_create_or_update, if: :openlab_sync_active? - after_destroy :openlab_destroy, if: :openlab_sync_active? + after_save :openlab_sync_after_save, if: :should_sync_with_openlab? + after_destroy :openlab_destroy, if: :should_sync_with_openlab? - def openlab_create - OpenlabWorker.perform_in(2.seconds, :create, id) if published? + def openlab_sync_after_save + if saved_change_to_state? && published? + # New publication - create in OpenLab + openlab_create + elsif published? + # Update existing publication + openlab_update + end end - def openlab_create_or_update - return unless published? + def openlab_create + OpenlabWorker.perform_async(:create, id) + end - if state_was == 'draft' || state_was.nil? - OpenlabWorker.perform_async(:create, id) - else - OpenlabWorker.perform_async(:update, id) - end + def openlab_update + OpenlabWorker.perform_async(:update, id) end def openlab_destroy @@ -30,6 +34,11 @@ module OpenlabSync OpenLabService.to_hash(self) end + # Determines if the object should be synced with OpenLab + def should_sync_with_openlab? + openlab_sync_active? && published? + end + def openlab_sync_active? self.class.openlab_sync_active? end diff --git a/package.json b/package.json index 8f7a49b6c..56453185b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fab-manager", - "version": "6.3.40", + "version": "6.3.41", "description": "Fab-manager is the FabLab management solution. It provides a comprehensive, web-based, open-source tool to simplify your administrative tasks and your marker's projects.", "keywords": [ "fablab",