Skip to content
Snippets Groups Projects
Unverified Commit 163e9465 authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

gh file unpublish

parent 26ce97b1
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment