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
This commit is contained in:
parent
aae04f3739
commit
dc82b8cef2
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.
|
||||
site.locales = [usuarie.lang] + I18n.available_locales
|
||||
|
||||
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? &&
|
||||
|
@ -224,6 +229,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
|
||||
|
|
Loading…
Reference in a new issue