From 368001b341bfa0b6891a15088625c615d6839098 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 22 Mar 2023 19:32:52 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20poder=20encadenar=20licencias=20con=20c?= =?UTF-8?q?=C3=B3digos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/site_service.rb | 46 ++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/app/services/site_service.rb b/app/services/site_service.rb index e4793453..47b532f4 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -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