mirror of
https://0xacab.org/sutty/sutty
synced 2025-03-14 20:08:19 +00:00
Merge branch 'issue-13244' into 'rails'
Opción Publicar Sitio Automáticamente Closes #17534 and #17533 See merge request sutty/sutty!200
This commit is contained in:
commit
c066ad8ec6
4 changed files with 32 additions and 1 deletions
12
app/lib/concerns/auto_publish_concern.rb
Normal file
12
app/lib/concerns/auto_publish_concern.rb
Normal file
|
@ -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
|
|
@ -3,6 +3,8 @@
|
||||||
# Este servicio se encarga de crear artículos y guardarlos en git,
|
# Este servicio se encarga de crear artículos y guardarlos en git,
|
||||||
# asignándoselos a une usuarie
|
# asignándoselos a une usuarie
|
||||||
PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
||||||
|
include AutoPublishConcern
|
||||||
|
|
||||||
# Crea un artículo nuevo
|
# Crea un artículo nuevo
|
||||||
#
|
#
|
||||||
# @return Post
|
# @return Post
|
||||||
|
@ -22,6 +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
|
# Devolver el post aunque no se haya salvado para poder rescatar los
|
||||||
# errores
|
# errores
|
||||||
|
auto_publish!
|
||||||
post
|
post
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -35,6 +38,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
||||||
params[:draft] = true
|
params[:draft] = true
|
||||||
|
|
||||||
commit(action: :created, add: [post.path.absolute]) if post.update(anon_post_params)
|
commit(action: :created, add: [post.path.absolute]) if post.update(anon_post_params)
|
||||||
|
auto_publish!
|
||||||
post
|
post
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -56,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
|
# Devolver el post aunque no se haya salvado para poder rescatar los
|
||||||
# errores
|
# errores
|
||||||
|
auto_publish!
|
||||||
post
|
post
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
# Se encargar de guardar cambios en sitios
|
# Se encargar de guardar cambios en sitios
|
||||||
# TODO: Implementar rollback en la configuración
|
# TODO: Implementar rollback en la configuración
|
||||||
SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
|
SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
|
||||||
|
include AutoPublishConcern
|
||||||
|
|
||||||
def deploy
|
def deploy
|
||||||
site.enqueue!
|
site.enqueue!
|
||||||
DeployJob.perform_later site
|
DeployJob.perform_later site
|
||||||
|
@ -36,10 +38,14 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
|
||||||
add_licencias &&
|
add_licencias &&
|
||||||
add_code_of_conduct &&
|
add_code_of_conduct &&
|
||||||
add_privacy_policy &&
|
add_privacy_policy &&
|
||||||
site.index_posts! &&
|
|
||||||
deploy
|
deploy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if site.persisted?
|
||||||
|
site.index_posts!
|
||||||
|
auto_publish!
|
||||||
|
end
|
||||||
|
|
||||||
site
|
site
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
8
db/migrate/20230822165038_add_autopublish_to_sites.rb
Normal file
8
db/migrate/20230822165038_add_autopublish_to_sites.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue