diff --git a/app/services/concerns/auto_publish_concern.rb b/app/services/concerns/auto_publish_concern.rb new file mode 100644 index 00000000..19160f02 --- /dev/null +++ b/app/services/concerns/auto_publish_concern.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + + +module AutoPublishConcern + extend ActiveSupport::Concern + + included do + def auto_publish! + DeployJob.perform_later(site) if site.auto_publish? + end + end +end diff --git a/app/services/post_service.rb b/app/services/post_service.rb index 84f58dad..ce6b1b26 100644 --- a/app/services/post_service.rb +++ b/app/services/post_service.rb @@ -3,6 +3,8 @@ # Este servicio se encarga de crear artículos y guardarlos en git, # asignándoselos a une usuarie PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do + include AutoPublishConcern + # Crea un artículo nuevo # # @return Post @@ -29,6 +31,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do # Devolver el post aunque no se haya salvado para poder rescatar los # errores post + auto_publish! end # Crear un post anónimo, con opciones más limitadas. No usamos post. @@ -42,6 +45,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do commit(action: :created, add: files) if post.update(anon_post_params) post + auto_publish! end def update @@ -66,6 +70,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do # Devolver el post aunque no se haya salvado para poder rescatar los # errores post + auto_publish! end def destroy diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 448e9f2c..a77c7627 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -3,6 +3,8 @@ # Se encargar de guardar cambios en sitios # TODO: Implementar rollback en la configuración SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do + include AutoPublishConcern + def deploy site.enqueue! DeployJob.perform_later site diff --git a/db/migrate/20230822165038_add_autopublish_to_sites.rb b/db/migrate/20230822165038_add_autopublish_to_sites.rb new file mode 100644 index 00000000..2f89e9d2 --- /dev/null +++ b/db/migrate/20230822165038_add_autopublish_to_sites.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +# Agrega posibilidad de autopublicación del sitio +class AddAutopublishToSites < ActiveRecord::Migration[6.1] + def change + add_column :sites, :auto_publish, :boolean, default: false + end +end