From cba395473c28587c7cfcc25c4797eb6084f63173 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 28 Feb 2024 12:05:09 -0300 Subject: [PATCH] feat: asignar rol a deploys al crear o modificar el sitio (cherry picked from commit dc82b8cef2ee014898128a8916b75c5358d9646d) --- app/services/site_service.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/services/site_service.rb b/app/services/site_service.rb index eeef0b3f..d8f1f379 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -26,6 +26,8 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do # que no haya estados intermedios. site.locales = [usuarie.lang] + add_role_to_deploys! + site.save && site.config.write && commit_config(action: :create) && @@ -43,7 +45,10 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do # Actualiza el sitio y guarda los cambios en la configuración def update I18n.with_locale(usuarie&.lang&.to_sym || I18n.default_locale) do - site.update(params) && + site.assign_attributes(params) + add_role_to_deploys! + + site.save && site.config.write && commit_config(action: :update) && site.reset.nil? && @@ -241,6 +246,17 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do private + # Asignar un rol a cada deploy si no lo tenía ya + def add_role_to_deploys! + site.deploys.each do |deploy| + deploy.rol ||= current_role + end + end + + def current_role + @current_role ||= usuarie.rol_for_site(site) + end + def with_all_locales(&block) site.locales.map do |locale| next unless I18n.available_locales.include? locale