diff --git a/app/services/post_service.rb b/app/services/post_service.rb index 84f58dad..4f5427ca 100644 --- a/app/services/post_service.rb +++ b/app/services/post_service.rb @@ -13,7 +13,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do post.draft.value = true if site.invitade? usuarie post.assign_attributes(post_params) - params.require(:post).permit(:slug).tap do |p| + params.require(base).permit(:slug).tap do |p| post.slug.value = p[:slug] if p[:slug].present? end @@ -82,7 +82,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do # # { uuid => 2, uuid => 1, uuid => 0 } def reorder - reorder = params.require(:post).permit(reorder: {})&.dig(:reorder)&.transform_values(&:to_i) + reorder = params.require(base).permit(reorder: {})&.dig(:reorder)&.transform_values(&:to_i) posts = site.posts(lang: locale).where(uuid: reorder.keys) files = posts.map do |post| @@ -105,6 +105,13 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do private + # La base donde buscar los parĂ¡metros + # + # @return [Symbol] + def base + @base ||= params.permit(:base).try(:[], :base).try(:to_sym) || :post + end + # Una lista de archivos a modificar # # @return [Set] @@ -126,7 +133,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do # Solo permitir cambiar estos atributos de cada articulo def post_params - @post_params ||= params.require(:post).permit(post.params).to_h + @post_params ||= params.require(base).permit(post.params).to_h end # Eliminar metadatos internos