mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-15 22:51:41 +00:00
feat: asignar rol a deploys al crear o modificar el sitio
(cherry picked from commit dc82b8cef2
)
This commit is contained in:
parent
6a0ccbd004
commit
cba395473c
1 changed files with 17 additions and 1 deletions
|
@ -26,6 +26,8 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
|
||||||
# que no haya estados intermedios.
|
# que no haya estados intermedios.
|
||||||
site.locales = [usuarie.lang]
|
site.locales = [usuarie.lang]
|
||||||
|
|
||||||
|
add_role_to_deploys!
|
||||||
|
|
||||||
site.save &&
|
site.save &&
|
||||||
site.config.write &&
|
site.config.write &&
|
||||||
commit_config(action: :create) &&
|
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
|
# Actualiza el sitio y guarda los cambios en la configuración
|
||||||
def update
|
def update
|
||||||
I18n.with_locale(usuarie&.lang&.to_sym || I18n.default_locale) do
|
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 &&
|
site.config.write &&
|
||||||
commit_config(action: :update) &&
|
commit_config(action: :update) &&
|
||||||
site.reset.nil? &&
|
site.reset.nil? &&
|
||||||
|
@ -241,6 +246,17 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
|
||||||
|
|
||||||
private
|
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)
|
def with_all_locales(&block)
|
||||||
site.locales.map do |locale|
|
site.locales.map do |locale|
|
||||||
next unless I18n.available_locales.include? locale
|
next unless I18n.available_locales.include? locale
|
||||||
|
|
Loading…
Reference in a new issue