From b7a27a87dd2879622f89d4102f4a4346aa7c17ac Mon Sep 17 00:00:00 2001 From: f Date: Mon, 3 Apr 2023 16:58:22 -0300 Subject: [PATCH] feat: cuando se modifica la licencia, considerarla personalizada --- app/models/licencia.rb | 4 ++++ app/services/post_service.rb | 12 ++++++++++++ app/views/sites/_form.haml | 1 + db/seeds/licencias.yml | 6 ++++++ 4 files changed, 23 insertions(+) diff --git a/app/models/licencia.rb b/app/models/licencia.rb index f0a542ef..351a8ae5 100644 --- a/app/models/licencia.rb +++ b/app/models/licencia.rb @@ -17,4 +17,8 @@ class Licencia < ApplicationRecord validates :description, presence: true validates :short_description, presence: true validates :deed, presence: true + + def custom? + url == 'custom' + end end diff --git a/app/services/post_service.rb b/app/services/post_service.rb index 81ebe4a1..f1b9f7c3 100644 --- a/app/services/post_service.rb +++ b/app/services/post_service.rb @@ -18,6 +18,8 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do commit(action: :created, file: update_related_posts) if post.update(post_params) + update_site_license! + # Devolver el post aunque no se haya salvado para poder rescatar los # errores post @@ -44,6 +46,8 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do # relacionados. commit(action: :updated, file: update_related_posts) if post.update(post_params) + update_site_license! + # Devolver el post aunque no se haya salvado para poder rescatar los # errores post @@ -137,4 +141,12 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do p.path.absolute if p.save(validate: false) end.compact << post.path.absolute end + + # Si les usuaries modifican o crean una licencia, considerarla + # personalizada en el panel. + def update_site_license! + if site.usuarie?(usuarie) && post.layout.name == :license + site.update licencia: Licencia.find_by_url('custom') + end + end end diff --git a/app/views/sites/_form.haml b/app/views/sites/_form.haml index 9a044c7f..10f158c8 100644 --- a/app/views/sites/_form.haml +++ b/app/views/sites/_form.haml @@ -79,6 +79,7 @@ %h2= t('.licencia.title') %p.lead= t('.help.licencia') - Licencia.all.find_each do |licencia| + - next if licencia.custom? && site.licencia != licencia .row.license .col .media.mt-1 diff --git a/db/seeds/licencias.yml b/db/seeds/licencias.yml index c5e2886a..402e5d8b 100644 --- a/db/seeds/licencias.yml +++ b/db/seeds/licencias.yml @@ -1,4 +1,10 @@ --- +- name_en: "Custom license" + name_es: "Licencia personalizada" + url_en: "custom" + url_es: "custom" + description_en: "The license terms are provided by you." + description_es: "Los términos de la licencia fueron provistos por vos." - name_en: 'Peer Production License' name_es: 'Licencia de Producción de Pares' short_description_en: "This work is licensed under a Peer Production License"