From c17cd0ac274eac564bb5ee8735cee23dacdf8d34 Mon Sep 17 00:00:00 2001 From: jazzari Date: Fri, 18 Aug 2023 17:37:40 -0300 Subject: [PATCH 01/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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 From cd018385f7c5861b4e425e4d504dd7387d6beade Mon Sep 17 00:00:00 2001 From: jazzari Date: Fri, 3 May 2024 12:43:53 -0300 Subject: [PATCH 11/14] fix: corregidos metodos donde se retorna site o post #13244 --- app/services/post_service.rb | 9 +++------ app/services/site_service.rb | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/services/post_service.rb b/app/services/post_service.rb index 9cc41323..f7da581d 100644 --- a/app/services/post_service.rb +++ b/app/services/post_service.rb @@ -24,8 +24,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! + post.tap(&:auto_publish!) end # Crear un post anónimo, con opciones más limitadas. No usamos post. @@ -38,8 +37,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do params[:draft] = true commit(action: :created, add: [post.path.absolute]) if post.update(anon_post_params) - post - auto_publish! + post.tap(&:auto_publish!) end def update @@ -60,8 +58,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! + post.tap(&:auto_publish!) end def destroy diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 4c83a6dd..1b9ccdb6 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -38,7 +38,7 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do deploy end - site + site.tap(&:auto_publish!) end # Actualiza el sitio y guarda los cambios en la configuración From 1c44c91f76e0b17f72a2ef6fcdbd0b49e4057875 Mon Sep 17 00:00:00 2001 From: jazzari Date: Tue, 7 May 2024 15:54:29 -0300 Subject: [PATCH 12/14] fix: corregido auto_publish! en Site_service y Post_service #13244 --- app/services/post_service.rb | 9 ++++++--- app/services/site_service.rb | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/services/post_service.rb b/app/services/post_service.rb index f7da581d..256a617d 100644 --- a/app/services/post_service.rb +++ b/app/services/post_service.rb @@ -24,7 +24,8 @@ 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.tap(&:auto_publish!) + auto_publish! + post end # Crear un post anónimo, con opciones más limitadas. No usamos post. @@ -37,7 +38,8 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do params[:draft] = true commit(action: :created, add: [post.path.absolute]) if post.update(anon_post_params) - post.tap(&:auto_publish!) + auto_publish! + post end def update @@ -58,7 +60,8 @@ 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.tap(&:auto_publish!) + auto_publish! + post end def destroy diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 1b9ccdb6..0ce09c53 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -38,7 +38,8 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do deploy end - site.tap(&:auto_publish!) + auto_publish! + site end # Actualiza el sitio y guarda los cambios en la configuración From c8b243c655d1eb2a2861567e56b572dcd604e325 Mon Sep 17 00:00:00 2001 From: jazzari Date: Thu, 23 May 2024 14:53:53 -0300 Subject: [PATCH 13/14] fix: movido auto-publish concern a lib/concerns para uso general #13244 --- app/{services => lib}/concerns/auto_publish_concern.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/{services => lib}/concerns/auto_publish_concern.rb (100%) diff --git a/app/services/concerns/auto_publish_concern.rb b/app/lib/concerns/auto_publish_concern.rb similarity index 100% rename from app/services/concerns/auto_publish_concern.rb rename to app/lib/concerns/auto_publish_concern.rb From ce4f9937fba24d14b18060fdc527a343411f2941 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 9 Oct 2024 16:54:46 -0300 Subject: [PATCH 14/14] =?UTF-8?q?fix:=20solo=20indexar=20y=20publicar=20de?= =?UTF-8?q?spu=C3=A9s=20de=20crear?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #17534 closes #17533 --- app/services/site_service.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 64158e4a..68b2a1b4 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -38,11 +38,14 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do add_licencias && add_code_of_conduct && add_privacy_policy && - site.index_posts! && deploy end - auto_publish! + if site.persisted? + site.index_posts! + auto_publish! + end + site end