5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-07-05 22:45:45 +00:00

fix: poder encadenar licencias con códigos

This commit is contained in:
f 2023-03-22 19:32:52 -03:00
parent e25b4858a0
commit 368001b341

View file

@ -90,18 +90,19 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
end
# Crea la licencia del sitio para cada locale disponible en el sitio
#
# @return [Boolean]
def add_licencias
return unless site.layout? :license
return true unless site.layout? :license
site.locales.each do |locale|
next unless I18n.available_locales.include? locale
Mobility.with_locale(locale) do
add_licencia lang: locale
end
end
with_all_locales do |locale|
add_licencia lang: locale
end.compact.map(&:valid?).all?
end
# Crea una licencia
#
# @return [Post]
def add_licencia(lang:)
params = ActionController::Parameters.new(
post: {
@ -119,20 +120,22 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
# Encuentra la licencia a partir de su enlace permanente y le cambia
# el contenido
#
# @return [Boolean]
def change_licencias
return unless site.layout? :license
return true unless site.layout? :license
site.locales.each do |locale|
next unless I18n.available_locales.include? locale
with_all_locales do |locale|
post = site.posts(lang: locale).find_by(layout: 'license')
Mobility.with_locale(locale) do
post = site.posts(lang: locale).find_by(layout: 'license')
change_licencia(post: post) if post
end
end
change_licencia(post: post) if post
end.compact.map(&:valid?).all?
end
# Cambia una licencia
#
# @param :post [Post]
# @return [Post]
def change_licencia(post:)
params = ActionController::Parameters.new(
post: {
@ -145,8 +148,11 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
params: params).update
end
# Agrega un código de conducta
#
# @return [Boolean]
def add_code_of_conduct
return unless site.layout?(:code_of_conduct) || site.layout?(:page)
return true unless site.layout?(:code_of_conduct) || site.layout?(:page)
# TODO: soportar más códigos de conducta
coc = CodeOfConduct.first
@ -163,7 +169,7 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
)
PostService.new(site: site, usuarie: usuarie, params: params).create
end
end.compact.map(&:valid?).all?
end
# Crea los deploys necesarios para sincronizar a otros nodos de Sutty
@ -176,7 +182,7 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
private
def with_all_locales(&block)
site.locales.each do |locale|
site.locales.map do |locale|
next unless I18n.available_locales.include? locale
Mobility.with_locale(locale) do