From c17cd0ac274eac564bb5ee8735cee23dacdf8d34 Mon Sep 17 00:00:00 2001 From: jazzari Date: Fri, 18 Aug 2023 17:37:40 -0300 Subject: [PATCH 01/10] feat: add boolean method for automatic publications #13244 --- app/models/site.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/site.rb b/app/models/site.rb index 24644b9c..d5b4c6cb 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -2,7 +2,9 @@ # Un sitio es un directorio dentro del directorio de sitios de cada # Usuaria -class Site < ApplicationRecord +class def create_njalla_records? + !site.name.end_with?('.') +end < ApplicationRecord include FriendlyId include Site::Forms include Site::FindAndReplace @@ -461,6 +463,11 @@ class Site < ApplicationRecord @docs = nil end + # @return [Boolean] + def automatic_publication? + @auto_publ = false + end + private # Asegurarse que el sitio tenga una llave privada From 8d736f8ac31420293857f6ed81fe17290476686a Mon Sep 17 00:00:00 2001 From: jazzari Date: Tue, 22 Aug 2023 12:41:02 -0300 Subject: [PATCH 02/10] Revert "feat: add boolean method for automatic publications #13244" This reverts commit c17cd0ac274eac564bb5ee8735cee23dacdf8d34. --- app/models/site.rb | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/models/site.rb b/app/models/site.rb index d5b4c6cb..24644b9c 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -2,9 +2,7 @@ # Un sitio es un directorio dentro del directorio de sitios de cada # Usuaria -class def create_njalla_records? - !site.name.end_with?('.') -end < ApplicationRecord +class Site < ApplicationRecord include FriendlyId include Site::Forms include Site::FindAndReplace @@ -463,11 +461,6 @@ end < ApplicationRecord @docs = nil end - # @return [Boolean] - def automatic_publication? - @auto_publ = false - end - private # Asegurarse que el sitio tenga una llave privada From 1ec4740b89c94558a22302bd6474638f39913a7b Mon Sep 17 00:00:00 2001 From: jazzari Date: Tue, 22 Aug 2023 13:58:10 -0300 Subject: [PATCH 03/10] feat: add boolean autopublish to sites model #13244 --- db/migrate/20230822165038_add_autopublish_to_sites.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 db/migrate/20230822165038_add_autopublish_to_sites.rb 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..dc68025e --- /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, :autopublish, :boolean, default: false + end +end From fa7689a53123d9e4d93cdebd1306f9b0b4426dd9 Mon Sep 17 00:00:00 2001 From: jazzari Date: Tue, 22 Aug 2023 18:20:46 -0300 Subject: [PATCH 04/10] fix: fix auto_publish name in site #13244 --- db/migrate/20230822165038_add_autopublish_to_sites.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20230822165038_add_autopublish_to_sites.rb b/db/migrate/20230822165038_add_autopublish_to_sites.rb index dc68025e..2f89e9d2 100644 --- a/db/migrate/20230822165038_add_autopublish_to_sites.rb +++ b/db/migrate/20230822165038_add_autopublish_to_sites.rb @@ -3,6 +3,6 @@ # Agrega posibilidad de autopublicación del sitio class AddAutopublishToSites < ActiveRecord::Migration[6.1] def change - add_column :sites, :autopublish, :boolean, default: false + add_column :sites, :auto_publish, :boolean, default: false end end From 331dc7f60760c16246e1885aefdb9dc4b950c965 Mon Sep 17 00:00:00 2001 From: jazzari Date: Mon, 2 Oct 2023 15:40:44 -0300 Subject: [PATCH 05/10] feat: creado modulo BaseService para opcion de auto_publicacion #13244 --- app/services/base_service.rb | 5 +++++ app/services/post_service.rb | 2 ++ app/services/site_service.rb | 2 ++ 3 files changed, 9 insertions(+) create mode 100644 app/services/base_service.rb diff --git a/app/services/base_service.rb b/app/services/base_service.rb new file mode 100644 index 00000000..2b46c415 --- /dev/null +++ b/app/services/base_service.rb @@ -0,0 +1,5 @@ +module BaseService + def auto_publish! + DeployJob.perform_later site if site.auto_publish? + end +end diff --git a/app/services/post_service.rb b/app/services/post_service.rb index dda7992d..b1863fbe 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 BaseService + # Crea un artículo nuevo # # @return Post diff --git a/app/services/site_service.rb b/app/services/site_service.rb index b1df3d10..b446e527 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 BaseService + def deploy site.enqueue! DeployJob.perform_later site.id From e175863081b8c9be8b869340152f931c419298c4 Mon Sep 17 00:00:00 2001 From: jazzari Date: Mon, 2 Oct 2023 15:51:35 -0300 Subject: [PATCH 06/10] fix: agregado parentesis en parametro DeployJob #13244 --- app/services/base_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/base_service.rb b/app/services/base_service.rb index 2b46c415..a7aed5f4 100644 --- a/app/services/base_service.rb +++ b/app/services/base_service.rb @@ -1,5 +1,5 @@ module BaseService def auto_publish! - DeployJob.perform_later site if site.auto_publish? + DeployJob.perform_later(site.id) if site.auto_publish? end end From 919b015daf355a572d0824bc7132dde1ed1e1536 Mon Sep 17 00:00:00 2001 From: jazzari Date: Thu, 12 Oct 2023 18:23:10 -0300 Subject: [PATCH 07/10] fix: modificado base_service a autopublishconcern #13244 --- app/services/base_service.rb | 5 ----- app/services/concerns/autopublish.rb | 10 ++++++++++ app/services/post_service.rb | 8 +++++--- 3 files changed, 15 insertions(+), 8 deletions(-) delete mode 100644 app/services/base_service.rb create mode 100644 app/services/concerns/autopublish.rb diff --git a/app/services/base_service.rb b/app/services/base_service.rb deleted file mode 100644 index a7aed5f4..00000000 --- a/app/services/base_service.rb +++ /dev/null @@ -1,5 +0,0 @@ -module BaseService - def auto_publish! - DeployJob.perform_later(site.id) if site.auto_publish? - end -end diff --git a/app/services/concerns/autopublish.rb b/app/services/concerns/autopublish.rb new file mode 100644 index 00000000..6b5a8cd3 --- /dev/null +++ b/app/services/concerns/autopublish.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + + +module AutoPublishConcern + extend ActiveSupport::Concern + + def auto_publish! + DeployJob.perform_later(site.id) if site.auto_publish? + end +end diff --git a/app/services/post_service.rb b/app/services/post_service.rb index b1863fbe..5f7167ea 100644 --- a/app/services/post_service.rb +++ b/app/services/post_service.rb @@ -3,8 +3,7 @@ # 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 BaseService - + # Crea un artículo nuevo # # @return Post @@ -25,12 +24,13 @@ 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 + include AutoPublishConcern end # Crear un post anónimo, con opciones más limitadas. No usamos post. def create_anonymous # XXX: Confiamos en el parámetro de idioma porque estamos - # verificándolos en Site#posts + # verificándolos extend ActiveSupport::Concernn Site#posts self.post = site.posts(lang: locale) .build(layout: layout) # Los artículos anónimos siempre son borradores @@ -38,6 +38,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do commit(action: :created, add: [post.path.absolute]) if post.update(anon_post_params) post + include AutoPublishConcern end def update @@ -59,6 +60,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 + include AutoPublishConcern end def destroy From 0ab0b143f39ebe324a7369b923aea02531455a0c Mon Sep 17 00:00:00 2001 From: jazzari Date: Tue, 17 Oct 2023 15:30:37 -0300 Subject: [PATCH 08/10] fix: corregida llamada a auto_publish! #13244 --- app/services/concerns/autopublish.rb | 6 ++++-- app/services/post_service.rb | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/services/concerns/autopublish.rb b/app/services/concerns/autopublish.rb index 6b5a8cd3..81f81aad 100644 --- a/app/services/concerns/autopublish.rb +++ b/app/services/concerns/autopublish.rb @@ -4,7 +4,9 @@ module AutoPublishConcern extend ActiveSupport::Concern - def auto_publish! - DeployJob.perform_later(site.id) if site.auto_publish? + included do + def auto_publish! + DeployJob.perform_later(site.id) if site.auto_publish? + end end end diff --git a/app/services/post_service.rb b/app/services/post_service.rb index 5f7167ea..e9305c34 100644 --- a/app/services/post_service.rb +++ b/app/services/post_service.rb @@ -3,6 +3,7 @@ # 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 # @@ -24,7 +25,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 - include AutoPublishConcern + auto_publish! end # Crear un post anónimo, con opciones más limitadas. No usamos post. @@ -38,7 +39,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do commit(action: :created, add: [post.path.absolute]) if post.update(anon_post_params) post - include AutoPublishConcern + auto_publish! end def update @@ -60,7 +61,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 - include AutoPublishConcern + auto_publish! end def destroy From d3e5324687056aaf781994a84d5dba90c9748e98 Mon Sep 17 00:00:00 2001 From: jazzari Date: Wed, 10 Jan 2024 15:40:40 -0300 Subject: [PATCH 09/10] fix: corregido nombre de archivo auto_publish_concern.rb #13244 --- .../concerns/{autopublish.rb => auto_publish_concern.rb} | 0 app/services/site_service.rb | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename app/services/concerns/{autopublish.rb => auto_publish_concern.rb} (100%) diff --git a/app/services/concerns/autopublish.rb b/app/services/concerns/auto_publish_concern.rb similarity index 100% rename from app/services/concerns/autopublish.rb rename to app/services/concerns/auto_publish_concern.rb diff --git a/app/services/site_service.rb b/app/services/site_service.rb index b446e527..4c83a6dd 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -3,7 +3,7 @@ # 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 BaseService + include AutoPublishConcern def deploy site.enqueue! From ecc4224d0a0c7befc5b979be96cc62df3941e62e Mon Sep 17 00:00:00 2001 From: jazzari Date: Tue, 23 Apr 2024 12:45:52 -0300 Subject: [PATCH 10/10] fix: corregido parametro de job #13244 --- app/services/concerns/auto_publish_concern.rb | 2 +- app/services/post_service.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/concerns/auto_publish_concern.rb b/app/services/concerns/auto_publish_concern.rb index 81f81aad..19160f02 100644 --- a/app/services/concerns/auto_publish_concern.rb +++ b/app/services/concerns/auto_publish_concern.rb @@ -6,7 +6,7 @@ module AutoPublishConcern included do def auto_publish! - DeployJob.perform_later(site.id) if site.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 e9305c34..9cc41323 100644 --- a/app/services/post_service.rb +++ b/app/services/post_service.rb @@ -31,7 +31,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do # Crear un post anónimo, con opciones más limitadas. No usamos post. def create_anonymous # XXX: Confiamos en el parámetro de idioma porque estamos - # verificándolos extend ActiveSupport::Concernn Site#posts + # verificándolos en Site#posts self.post = site.posts(lang: locale) .build(layout: layout) # Los artículos anónimos siempre son borradores