From e4e8508e57edadd9eaa7737d752b79c5076c6845 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 11 Nov 2020 18:15:58 -0300 Subject: [PATCH] =?UTF-8?q?integraci=C3=B3n=20con=20tienda?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 2 ++ app/controllers/sites_controller.rb | 1 + app/models/concerns/tienda.rb | 23 +++++++++++++++++++ app/models/deploy_local.rb | 2 ++ app/models/site.rb | 1 + app/views/layouts/_breadcrumb.haml | 5 ++++ app/views/sites/_form.haml | 20 ++++++++++++++++ config/locales/es.yml | 6 +++++ .../20201111203031_add_tienda_to_site.rb | 6 +++++ 9 files changed, 66 insertions(+) create mode 100644 app/models/concerns/tienda.rb create mode 100644 db/migrate/20201111203031_add_tienda_to_site.rb diff --git a/.env.example b/.env.example index f02a3a8..9d40394 100644 --- a/.env.example +++ b/.env.example @@ -20,3 +20,5 @@ DEBUG_FORMS= # Duración de la Cookie de invitade # @see Api::V1::ProtectedController COOKIE_DURATION=30 +# Dominio de la tienda +TIENDA=tienda.sutty.local diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index dcb2953..d7d2f9f 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -137,6 +137,7 @@ class SitesController < ApplicationController params.require(:site) .permit(:name, :design_id, :licencia_id, :description, :title, :colaboracion_anonima, :contact, :acepta_invitades, + :tienda_api_key, :tienda_url, deploys_attributes: %i[type id _destroy]) end end diff --git a/app/models/concerns/tienda.rb b/app/models/concerns/tienda.rb new file mode 100644 index 0000000..cd09358 --- /dev/null +++ b/app/models/concerns/tienda.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +# Integración con la tienda +module Tienda + extend ActiveSupport::Concern + + included do + encrypts :tienda_api_key + + def tienda? + tienda_api_key.present? && tienda_url.present? + end + + # Sugerir una dirección al configurar por primera vez + def tienda_url + t = read_attribute(:tienda_url) + + return t if new_record? + + t.blank? ? 'https://' + name + '.' + ENV.fetch('TIENDA', 'tienda.sutty.nl') : t + end + end +end diff --git a/app/models/deploy_local.rb b/app/models/deploy_local.rb index 3e1b823..67323a4 100644 --- a/app/models/deploy_local.rb +++ b/app/models/deploy_local.rb @@ -57,6 +57,8 @@ class DeployLocal < Deploy { 'HOME' => home_dir, 'PATH' => paths.join(':'), + 'SPREE_API_KEY' => site.tienda_api_key, + 'SPREE_URL' => site.tienda_url, 'JEKYLL_ENV' => Rails.env, 'LANG' => ENV['LANG'] } diff --git a/app/models/site.rb b/app/models/site.rb index 38645a3..0e8db8c 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -6,6 +6,7 @@ class Site < ApplicationRecord include FriendlyId include Site::Forms include Site::FindAndReplace + include Tienda # Cifrar la llave privada que cifra y decifra campos ocultos. Sutty # tiene acceso pero los datos se guardan cifrados en el sitio. Esto diff --git a/app/views/layouts/_breadcrumb.haml b/app/views/layouts/_breadcrumb.haml index 3551153..01765d0 100644 --- a/app/views/layouts/_breadcrumb.haml +++ b/app/views/layouts/_breadcrumb.haml @@ -21,6 +21,11 @@ - if current_usuarie %ul.navbar-nav + - if @site&.tienda? + %li.nav-item + = link_to t('.tienda'), @site.tienda_url, + role: 'button', class: 'btn' + %li.nav-item = link_to t('.logout'), destroy_usuarie_session_path, method: :delete, role: 'button', class: 'btn' diff --git a/app/views/sites/_form.haml b/app/views/sites/_form.haml index 9e61786..d26eeeb 100644 --- a/app/views/sites/_form.haml +++ b/app/views/sites/_form.haml @@ -104,6 +104,26 @@ %hr/ + .form-group#tienda + %h2= t('.tienda.title') + %p.lead + - if site.tienda? + = t('.tienda.help') + - else + = t('.tienda.first_time_html') + + .row + .col + .form-group + = f.label :tienda_url + = f.url_field :tienda_url, class: 'form-control' + .col + .form-group + = f.label :tienda_api_key + = f.text_field :tienda_api_key, class: 'form-control' + + %hr/ + - if site.persisted? .form-group#contact %h2= t('.contact.title') diff --git a/config/locales/es.yml b/config/locales/es.yml index b4e445d..677c267 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -126,6 +126,8 @@ es: acepta_invitades: Habilitar colaboración de otres usuaries colaboracion_anonima: Habilitar colaboración anónima contact: Habilitar formularios de contacto + tienda_url: Dirección de la tienda + tienda_api_key: Clave de acceso errors: models: site: @@ -418,6 +420,10 @@ es: contact: title: 'Habilitar formularios de contacto' help: 'Si tu sitio tiene formularios de contacto, con esta opción habilitas su funcionamiento. Si tu sitio está bajo ataque de spam o trolls, puedes deshabilitarlos temporalmente aquí.' + tienda: + title: Tienda + first_time_html: 'Para configurar tu tienda, ponte en contacto con nosotres :)' + help: 'Puedes configurar tu tienda aquí.' fetch: title: 'Actualizar el sitio' help: diff --git a/db/migrate/20201111203031_add_tienda_to_site.rb b/db/migrate/20201111203031_add_tienda_to_site.rb new file mode 100644 index 0000000..86554da --- /dev/null +++ b/db/migrate/20201111203031_add_tienda_to_site.rb @@ -0,0 +1,6 @@ +class AddTiendaToSite < ActiveRecord::Migration[6.0] + def change + add_column :sites, :tienda_api_key_ciphertext, :string, default: '' + add_column :sites, :tienda_url, :string, default: '' + end +end