diff --git a/app/models/communication/website/github_file.rb b/app/models/communication/website/github_file.rb index e596d5839eb3a343d7f9151e5f72b913a301fcce..0fd31d1599478b6a1aab10a107aec0fe624510c2 100644 --- a/app/models/communication/website/github_file.rb +++ b/app/models/communication/website/github_file.rb @@ -35,6 +35,11 @@ class Communication::Website::GithubFile < ApplicationRecord end handle_asynchronously :publish, queue: 'default' + def unpublish + remove_from_github + end + handle_asynchronously :unpublish, queue: 'default' + def add_to_batch(github) return unless valid_for_publication? github.add_to_batch github_params diff --git a/app/models/concerns/with_github_files.rb b/app/models/concerns/with_github_files.rb index 750f34cddd40750cfba405c8217af21ccabea1ba..ddc2b863efc2af23c0238ddd6571035fbe86b515 100644 --- a/app/models/concerns/with_github_files.rb +++ b/app/models/concerns/with_github_files.rb @@ -6,6 +6,7 @@ module WithGithubFiles after_save :create_github_files after_save_commit :publish_github_files + after_save_commit :unpublish_github_files, if: :should_unpublish_github_files? end def force_publish! @@ -54,6 +55,18 @@ module WithGithubFiles end end + def unpublish_github_files + list_of_websites.each do |website| + github_manifest.each do |manifest_item| + github_files.find_by(website: website, manifest_identifier: manifest_item[:identifier])&.unpublish + end + end + end + + def should_unpublish_github_files? + respond_to?(:published?) && saved_change_to_published? && !published? + end + def list_of_websites respond_to?(:websites) ? websites : [website] end