From 78820b6faceaec8b33a2a15414709a9c89ec4c48 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 3 Jul 2019 20:25:23 -0300 Subject: [PATCH] sitios a base de datos --- .gitignore | 1 + .rubocop.yml | 20 +++++++ app/controllers/application_controller.rb | 7 +-- app/controllers/i18n_controller.rb | 3 +- app/controllers/invitadxs_controller.rb | 13 +++-- app/controllers/login_controller.rb | 36 ------------ app/controllers/posts_controller.rb | 25 +++++--- app/controllers/sites_controller.rb | 18 +++--- app/lib/warden/email_and_password.rb | 6 -- app/lib/warden/email_and_password/strategy.rb | 34 ----------- app/lib/warden/imap.rb | 6 -- app/lib/warden/imap/strategy.rb | 57 ------------------- app/models/site.rb | 17 +++++- app/policies/i18n_policy.rb | 9 ++- app/policies/invitadx_policy.rb | 8 ++- app/policies/site_policy.rb | 21 ++++--- app/policies/sutty_policy.rb | 22 ------- app/views/layouts/_breadcrumb.haml | 6 +- app/views/login/_logout.haml | 4 -- app/views/login/new.haml | 18 ------ config/environments/production.rb | 54 ++++++++++-------- config/environments/test.rb | 20 ++++--- config/initializers/warden.rb | 19 ------- config/routes.rb | 13 ++--- db/migrate/20190703200455_create_sitios.rb | 10 +++- 25 files changed, 164 insertions(+), 283 deletions(-) delete mode 100644 app/controllers/login_controller.rb delete mode 100644 app/lib/warden/email_and_password.rb delete mode 100644 app/lib/warden/email_and_password/strategy.rb delete mode 100644 app/lib/warden/imap.rb delete mode 100644 app/lib/warden/imap/strategy.rb delete mode 100644 app/policies/sutty_policy.rb delete mode 100644 app/views/login/_logout.haml delete mode 100644 app/views/login/new.haml delete mode 100644 config/initializers/warden.rb diff --git a/.gitignore b/.gitignore index 27918865..483c9162 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ /_deploy/* /_usuarias/* /_invitadxs/* +.env diff --git a/.rubocop.yml b/.rubocop.yml index 5c2335f8..0d3d351a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -15,22 +15,42 @@ Metrics/AbcSize: - 'db/schema.rb' - 'db/migrate/*.rb' - 'app/models/site.rb' + - 'app/controllers/sites_controller.rb' + - 'app/controllers/posts_controller.rb' + - 'app/controllers/invitadxs_controller.rb' Metrics/MethodLength: Exclude: - 'db/schema.rb' - 'db/migrate/*.rb' - 'app/models/site.rb' + - 'app/controllers/sites_controller.rb' + - 'app/controllers/posts_controller.rb' + - 'app/controllers/invitadxs_controller.rb' Metrics/BlockLength: Exclude: + - 'config/environments/production.rb' - 'config/initializers/devise.rb' - 'db/schema.rb' Metrics/ClassLength: Exclude: - 'app/models/site.rb' + - 'app/controllers/posts_controller.rb' Performance/TimesMap: Exclude: - 'app/models/site.rb' + +Lint/HandleExceptions: + Exclude: + - 'app/controllers/posts_controller.rb' + +Style/GuardClause: + Exclude: + - 'app/controllers/posts_controller.rb' + +Metrics/PerceivedComplexity: + Exclude: + - 'app/controllers/posts_controller.rb' diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 804c5193..5266ee0e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -15,14 +15,11 @@ class ApplicationController < ActionController::Base private - # Encontrar un sitio por su ID - # TODO volverlo más natural a rails + # Encontrar un sitio por su nombre def find_site id = params[:site_id] || params[:id] - current_user.sites.find do |s| - s.id == id - end + current_usuarie.sites.find_by_name id end def find_post(site) diff --git a/app/controllers/i18n_controller.rb b/app/controllers/i18n_controller.rb index bb960441..81012b48 100644 --- a/app/controllers/i18n_controller.rb +++ b/app/controllers/i18n_controller.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true +# Controlador de traducciones class I18nController < ApplicationController include Pundit - before_action :authenticate! + before_action :authenticate_usuarie! def index authorize :i18n diff --git a/app/controllers/invitadxs_controller.rb b/app/controllers/invitadxs_controller.rb index d967c436..b6dc81b9 100644 --- a/app/controllers/invitadxs_controller.rb +++ b/app/controllers/invitadxs_controller.rb @@ -1,10 +1,13 @@ # frozen_string_literal: true +# Controlador de Invitadxs +# +# TODO: reemplazar class InvitadxsController < ApplicationController include Pundit def index - authenticate! + authenticate_usuarie! @site = find_site @invitadxs = @site.invitadxs @@ -23,7 +26,8 @@ class InvitadxsController < ApplicationController @invitadx.sites << @site if @invitadx.save - InvitadxMailer.with(site: @site, invitadx: @invitadx).confirmation_required.deliver + InvitadxMailer.with(site: @site, invitadx: @invitadx) + .confirmation_required.deliver redirect_to site_invitadx_path(@site, @invitadx) else render 'new' @@ -42,7 +46,7 @@ class InvitadxsController < ApplicationController site.id == params[:site_id] end - if @invitadx.confirmation_token = params[:confirmation_token] + if (@invitadx.confirmation_token = params[:confirmation_token]) @invitadx.update_attribute :confirmed, true flash[:info] = t('.confirmed') redirect_to site_invitadxs_login_new_path(@site) @@ -55,6 +59,7 @@ class InvitadxsController < ApplicationController def invitadx_params params.require(:invitadx).permit(:email, :password, - :password_confirmation, :acepta_politicas_de_privacidad) + :password_confirmation, + :acepta_politicas_de_privacidad) end end diff --git a/app/controllers/login_controller.rb b/app/controllers/login_controller.rb deleted file mode 100644 index da712471..00000000 --- a/app/controllers/login_controller.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -class LoginController < ApplicationController - protect_from_forgery with: :exception - - def index - redirect_to new_login_path - end - - def new - @has_cover = true - @site = Site.find(params[:site_id]) if params[:site_id].present? - - render 'login/new' - end - - def create - authenticate - session[:lang] = params[:lang] - referer = request.referer unless %r{/login} =~ request.referer - referer = params[:referer] if params[:referer].present? - - if authenticated? - redirect_to referer || sites_path - else - flash[:danger] = t('login.error') - render 'login/new' - end - end - - def delete - warden.logout - - redirect_to login_new_path - end -end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 08cfa32c..4205ecf8 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,15 +1,17 @@ # frozen_string_literal: true +# Controlador para artículos class PostsController < ApplicationController include Pundit - before_action :authenticate! + before_action :authenticate_usuarie! def index authorize Post @site = find_site @lang = find_lang(@site) @category = session[:category] = params.dig(:category) - @posts = policy_scope(@site.posts_for(@lang), policy_scope_class: PostPolicy::Scope) + @posts = policy_scope(@site.posts_for(@lang), + policy_scope_class: PostPolicy::Scope) if params[:sort_by].present? begin @@ -49,7 +51,8 @@ class PostsController < ApplicationController # El post se guarda como incompleto si se envió con "guardar para # después" - @post.update_attributes(incomplete: params[:commit_incomplete].present?) + @post.update_attributes(incomplete: + params[:commit_incomplete].present?) # Las usuarias pueden especificar una autora, de la contrario por # defecto es la usuaria actual @@ -59,7 +62,10 @@ class PostsController < ApplicationController # Todo lo que crean lxs invitadxs es borrador @post.update_attributes(draft: true) end - @post.update_attributes(author: current_user.username) unless @post.author + unless @post.author + @post.update_attributes(author: + current_user.username) + end if @post.save if @post.incomplete? @@ -94,7 +100,9 @@ class PostsController < ApplicationController # Solo las usuarias pueden modificar la autoría if current_user.is_a? Usuaria - @post.update_attributes(author: params[:post][:author]) if params[:post][:author].present? + if params[:post][:author].present? + @post.update_attributes(author: params[:post][:author]) + end @post.update_attributes(draft: false) else # Todo lo que crean lxs invitadxs es borrador @@ -103,7 +111,9 @@ class PostsController < ApplicationController if @post.save flash[:success] = @site.config.dig('thanks') - redirect_to site_posts_path(@site, category: session[:category], lang: @lang) + redirect_to site_posts_path(@site, + category: session[:category], + lang: @lang) else render 'posts/edit' end @@ -119,7 +129,8 @@ class PostsController < ApplicationController @post.destroy - redirect_to site_posts_path(@site, category: session[:category], lang: @lang) + redirect_to site_posts_path(@site, category: session[:category], + lang: @lang) end private diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index f1cf8da6..6ca91f10 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -3,12 +3,12 @@ # Controlador de sitios class SitesController < ApplicationController include Pundit - before_action :authenticate! + before_action :authenticate_usuarie! # Ver un listado de sitios def index authorize Site - @sites = current_user.sites + @sites = current_usuarie.sites end # No tenemos propiedades de un sitio aún, así que vamos al listado de @@ -25,7 +25,8 @@ class SitesController < ApplicationController authorize Site @site = find_site file = [params[:basename], params[:format]].join('.') - path = Pathname.new(File.join(@site.path, 'public', params[:type], file)) + path = File.join(@site.path, 'public', params[:type], file) + path = Pathname.new path # TODO: Verificar que no nos estén sacando archivos del sistema, como # /etc/passwd @@ -63,11 +64,12 @@ class SitesController < ApplicationController authorize @site lang = params.require(:posts).require(:lang) - result = if params[:posts][:force].present? - @site.reorder_collection! lang - else - @site.reorder_collection(lang, params.require(:posts).require(:order)) - end + if params[:posts][:force].present? + result = @site.reorder_collection! lang + else + result = @site + .reorder_collection(lang, params.require(:posts).require(:order)) + end if result flash[:info] = I18n.t('info.posts.reorder') diff --git a/app/lib/warden/email_and_password.rb b/app/lib/warden/email_and_password.rb deleted file mode 100644 index 957770d4..00000000 --- a/app/lib/warden/email_and_password.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true - -module Warden - module EmailAndPassword - end -end diff --git a/app/lib/warden/email_and_password/strategy.rb b/app/lib/warden/email_and_password/strategy.rb deleted file mode 100644 index e32c1f38..00000000 --- a/app/lib/warden/email_and_password/strategy.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -require 'email_address' -module Warden - module EmailAndPassword - class Strategy < Warden::Strategies::Base - def valid? - return false unless params.include? 'username' - return false unless params.include? 'password' - - username = params['username'] - @email = EmailAddress.new(username, host_validation: :a) - - Rails.logger.error [username, @email.error].join(': ') unless @email.valid? - - @email.valid? - end - - # Autentica a una posible invitadx, no fallamos para que haya - # fallback con IMAP - def authenticate! - u = ::Invitadx.find_by_email(params['username']) - - return unless u.try(:authenticate, params['password']) - - if u.confirmed? - success! u - else - fail! 'unconfirmed' - end - end - end - end -end diff --git a/app/lib/warden/imap.rb b/app/lib/warden/imap.rb deleted file mode 100644 index fe435be0..00000000 --- a/app/lib/warden/imap.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true - -module Warden - module IMAP - end -end diff --git a/app/lib/warden/imap/strategy.rb b/app/lib/warden/imap/strategy.rb deleted file mode 100644 index 7e9d6dfc..00000000 --- a/app/lib/warden/imap/strategy.rb +++ /dev/null @@ -1,57 +0,0 @@ -# frozen_string_literal: true - -require 'net/imap' -require 'warden' -require 'email_address' - -module Warden - module IMAP - # Una estrategia de autenticación por IMAP - class Strategy < Warden::Strategies::Base - def valid? - return false unless params.include? 'username' - return false unless params.include? 'password' - - username = params['username'] - - @email = EmailAddress.new(username, host_validation: :a) - - Rails.logger.error [username, @email.error].join(': ') unless @email.valid? - - @email.valid? - end - - def authenticate! - imap_connect - imap_login - end - - private - - def imap_connect - # No vamos a enviar la contraseña en texto plano a ningún lado - @imap = Net::IMAP.new(ENV.fetch('IMAP_SERVER', 'kefir.red'), ssl: true) - # Errores más comunes según - # https://ruby-doc.org/stdlib-2.0.0/libdoc/net/imap/rdoc/Net/IMAP.html - rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, Errno::ENETUNREACH, - SocketError, Net::IMAP::ByeResponseError => e - - Rails.logger.error e.to_s - @imap.disconnect - fail! e.to_s - end - - def imap_login - Rails.logger.info "Autenticando a #{@email.normal}" - @imap.login(@email.normal, params['password']) - @imap.disconnect - - success! ::Usuaria.find(@email.normal) - rescue Net::IMAP::NoResponseError, EOFError => e - @imap.disconnect - Rails.logger.error e.to_s - fail! e.to_s - end - end - end -end diff --git a/app/models/site.rb b/app/models/site.rb index 3e86527d..067f22b0 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -7,8 +7,22 @@ class Site < ApplicationRecord has_and_belongs_to_many :invitades, class_name: 'Usuarie', join_table: 'invitades_sites' + after_initialize :load_jekyll! + attr_accessor :jekyll, :collections - attr_reader :path + + def load_jekyll! + Dir.chdir(path) do + @jekyll ||= Site.load_jekyll(Dir.pwd) + end + end + + # Traer la ruta del sitio + # + # Equivale a _sites + nombre + def path + @path ||= File.join(Site.site_path, name) + end # Este sitio acepta invitadxs? def invitadxs? @@ -121,6 +135,7 @@ class Site < ApplicationRecord # idioma actual collection = default_lang if collection == 'posts' && i18n? + @collections ||= {} c = @collections[collection] return c if c diff --git a/app/policies/i18n_policy.rb b/app/policies/i18n_policy.rb index 899a3ecc..899ece09 100644 --- a/app/policies/i18n_policy.rb +++ b/app/policies/i18n_policy.rb @@ -1,13 +1,16 @@ # frozen_string_literal: true -class I18nPolicy < SuttyPolicy +# Política de acceso a la traducción del sitio. +# +# TODO: Prohibir Invitades +class I18nPolicy def initialize(usuarix, _i18n) @usuarix = usuarix end # Solo las usuarias def index? - usuaria? + true end def edit? @@ -15,6 +18,6 @@ class I18nPolicy < SuttyPolicy end def update? - usuaria? + true end end diff --git a/app/policies/invitadx_policy.rb b/app/policies/invitadx_policy.rb index 6c1a5d95..80fab60b 100644 --- a/app/policies/invitadx_policy.rb +++ b/app/policies/invitadx_policy.rb @@ -1,5 +1,8 @@ # frozen_string_literal: true +# Política de acceso para Invitades +# +# TODO: Incorporar a Usuarie y eliminar class InvitadxPolicy attr_reader :usuarix, :model @@ -14,7 +17,10 @@ class InvitadxPolicy # Al crear, el modelo recibido es un sitio def create? - raise ArgumentError, "#{model.class} must be Site" unless model.class == Site + unless model.class == Site + raise ArgumentError, + "#{model.class} must be Site" + end # El sitio acepta invitadxs model.invitadxs? diff --git a/app/policies/site_policy.rb b/app/policies/site_policy.rb index a243fa66..72fcf855 100644 --- a/app/policies/site_policy.rb +++ b/app/policies/site_policy.rb @@ -1,16 +1,19 @@ # frozen_string_literal: true -class SitePolicy < SuttyPolicy - attr_reader :site +# Política de acceso para sitios +# +# TODO: Distinguir entre Invitades +class SitePolicy + attr_reader :site, :usuarie - def initialize(usuarix, site) - @usuarix = usuarix + def initialize(usuarie, site) + @usuarie = usuarie @site = site end # Solo las usuarias def index? - usuaria? + true end # Todxs lxs usuarixs pueden ver el sitio @@ -20,7 +23,7 @@ class SitePolicy < SuttyPolicy # Solo las usuarias def build? - usuaria? + true end def send_public_file? @@ -28,14 +31,14 @@ class SitePolicy < SuttyPolicy end def enqueue? - usuaria? + true end def build_log? - usuaria? + true end def reorder_posts? - usuaria? + true end end diff --git a/app/policies/sutty_policy.rb b/app/policies/sutty_policy.rb deleted file mode 100644 index 23d71d58..00000000 --- a/app/policies/sutty_policy.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -class SuttyPolicy - attr_reader :usuarix - - def invitadx? - usuarix.is_a? Invitadx - end - - def usuaria? - usuarix.is_a? Usuaria - end - - class Scope < SuttyPolicy - attr_reader :scope - - def initialize(usuarix, scope) - @usuarix = usuarix - @scope = scope - end - end -end diff --git a/app/views/layouts/_breadcrumb.haml b/app/views/layouts/_breadcrumb.haml index 0c928a00..c8793762 100644 --- a/app/views/layouts/_breadcrumb.haml +++ b/app/views/layouts/_breadcrumb.haml @@ -1,6 +1,10 @@ %nav{'aria-label': 'breadcrumb', role: 'navigation'} %ol.breadcrumb - %li.breadcrumb-item= render 'login/logout' + %li.breadcrumb-item + = link_to destroy_usuarie_session_path, method: :delete, + data: { toggle: 'tooltip' }, title: t('help.logout'), + role: 'button', class: 'btn-text' do + = fa_icon 'sign-out', title: t('help.logout') - if help = @site.try(:config).try(:dig, 'help') %li.breadcrumb-item= link_to t('.help'), help, target: '_blank' - crumbs.compact.each do |crumb| diff --git a/app/views/login/_logout.haml b/app/views/login/_logout.haml deleted file mode 100644 index c15d4cff..00000000 --- a/app/views/login/_logout.haml +++ /dev/null @@ -1,4 +0,0 @@ -= form_tag login_logout_path, method: :delete, class: 'form-inline' do - = button_tag type: 'submit', class: 'btn-text', - data: { toggle: 'tooltip' }, title: t('help.logout') do - = fa_icon('sign-out') diff --git a/app/views/login/new.haml b/app/views/login/new.haml deleted file mode 100644 index 504cc613..00000000 --- a/app/views/login/new.haml +++ /dev/null @@ -1,18 +0,0 @@ -.row.align-items-center.justify-content-center.full-height - .col-md-6.align-self-center - = render 'layouts/flash' - - = form_tag login_path do - - if @site - %input{type: 'hidden', name: 'referer', value: site_path(@site)} - .form-group - %input{type: 'email', name: 'username', class: 'form-control', placeholder: t('login.email')} - .form-group - %input{type: 'password', name: 'password', class: 'form-control', placeholder: t('login.password')} - .form-group - %select.form-control{name: 'lang', placeholder: t('login.lang')} - %option{value: 'es'} Castellano - %option{value: 'en'} English - - .form-group - %input{type: 'submit', value: t('login.submit'), class: 'btn btn-lg btn-primary btn-block'} diff --git a/config/environments/production.rb b/config/environments/production.rb index 924b6efc..12687e07 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true Rails.application.configure do - # Settings specified here will take precedence over those in config/application.rb. + # Settings specified here will take precedence over those in + # config/application.rb. # Code is not reloaded between requests. config.cache_classes = true @@ -21,9 +22,10 @@ Rails.application.configure do # `config/secrets.yml.key`. config.read_encrypted_secrets = true - # Disable serving static files from the `/public` folder by default since - # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + # Disable serving static files from the `/public` folder by default + # since Apache or NGINX already handles this. + config.public_file_server + .enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier @@ -32,20 +34,22 @@ Rails.application.configure do # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false - # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + # `config.assets.precompile` and `config.assets.version` have moved to + # config/initializers/assets.rb - # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # Enable serving of images, stylesheets, and JavaScripts from an asset + # server. # config.action_controller.asset_host = 'http://assets.example.com' # Specifies the header that your server uses for sending files. - # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' - # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true + # Force all access to the app over SSL, use Strict-Transport-Security, + # and use secure cookies. + config.force_ssl = true - # Use the lowest log level to ensure availability of diagnostic information - # when problems arise. + # Use the lowest log level to ensure availability of diagnostic + # information when problems arise. config.log_level = :debug # Prepend all log lines with the following tags. @@ -54,28 +58,32 @@ Rails.application.configure do # Use a different cache store in production. # config.cache_store = :mem_cache_store - # Use a real queuing backend for Active Job (and separate queues per environment) + # Use a real queuing backend for Active Job (and separate queues per + # environment) # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "sutty_#{Rails.env}" config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. - # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # Set this to true and configure the email server for immediate + # delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # the I18n.default_locale when a translation cannot be found). + # Enable locale fallbacks for I18n (makes lookups for any locale fall + # back to the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify - # Use default logging formatter so that PID and timestamp are not suppressed. + # Use default logging formatter so that PID and timestamp are not + # suppressed. config.log_formatter = ::Logger::Formatter.new # Use a different logger for distributed setups. - # require 'syslog/logger' - # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + require 'syslog/logger' + config.logger = ActiveSupport::TaggedLogging + .new(Syslog::Logger.new('app-name')) if ENV['RAILS_LOG_TO_STDOUT'].present? logger = ActiveSupport::Logger.new(STDOUT) @@ -87,16 +95,16 @@ Rails.application.configure do config.active_record.dump_schema_after_migration = false # Recibir por mail notificaciones de excepciones - config.action_mailer.default_url_options = { host: 'sutty.kefir.red' } + config.action_mailer.default_url_options = { host: ENV['SUTTY'] } config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :sendmail - config.action_mailer.default_options = { from: ENV.fetch('DEFAULT_FROM', 'sutty@kefir.red') } + config.action_mailer.default_options = { from: ENV['DEFAULT_FROM'] } config.middleware.use ExceptionNotification::Rack, email: { email_prefix: '[ERROR]', - sender_address: %(sutty@kefir.red), - exception_recipients: 'sysadmin@kefir.red' + sender_address: ENV['DEFAULT_FROM'], + exception_recipients: ENV['EXCEPTION_TO'] } end diff --git a/config/environments/test.rb b/config/environments/test.rb index 669350ab..455b905e 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true Rails.application.configure do - # Settings specified here will take precedence over those in config/application.rb. + # Settings specified here will take precedence over those in + # config/application.rb. # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that @@ -9,16 +10,17 @@ Rails.application.configure do # and recreated between test runs. Don't rely on the data there! config.cache_classes = true - # Do not eager load code on boot. This avoids loading your whole application - # just for the purpose of running a single test. If you are using a tool that - # preloads Rails for running tests, you may have to set it to true. + # Do not eager load code on boot. This avoids loading your whole + # application just for the purpose of running a single test. If you + # are using a tool that preloads Rails for running tests, you may have + # to set it to true. config.eager_load = false - # Configure public file server for tests with Cache-Control for performance. + # Configure public file server for tests with Cache-Control for + # performance. config.public_file_server.enabled = true - config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}" - } + config.public_file_server.headers = { 'Cache-Control' => "public, + max-age=#{1.hour.seconds.to_i}" } # Show full error reports and disable caching. config.consider_all_requests_local = true @@ -35,6 +37,8 @@ Rails.application.configure do # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + config.action_mailer.default_url_options = { host: 'localhost', + port: 3000 } # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/config/initializers/warden.rb b/config/initializers/warden.rb deleted file mode 100644 index 9af19d0b..00000000 --- a/config/initializers/warden.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -Rails.configuration.middleware.use RailsWarden::Manager do |manager| - manager.default_strategies :email, :imap - manager.failure_app = ->(env) { LoginController.action(:new).call(env) } -end - -class Warden::SessionSerializer - def serialize(record) - [record.username] - end - - def deserialize(keys) - Invitadx.find_by_email(keys.first) || Usuaria.find(keys.first) - end -end - -Warden::Strategies.add(:imap, Warden::IMAP::Strategy) -Warden::Strategies.add(:email, Warden::EmailAndPassword::Strategy) diff --git a/config/routes.rb b/config/routes.rb index fab13c94..ce11f6df 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,11 +1,9 @@ # frozen_string_literal: true Rails.application.routes.draw do - root 'application#index' + devise_for :usuaries - get 'login/new', to: 'login#new' - post 'login', to: 'login#create' - delete 'login/logout', to: 'login#delete' + root 'application#index' get 'markdown', to: 'application#markdown' @@ -13,15 +11,16 @@ Rails.application.routes.draw do # como un objeto válido resources :invitadxs, only: [:create] - resources :sites, only: %i[index show], constraints: { site_id: %r{[^/]+}, id: %r{[^/]+} } do + resources :sites, only: %i[index show], + constraints: { site_id: %r{[^/]+}, id: %r{[^/]+} } do + get 'public/:type/:basename', to: 'sites#send_public_file' + resources :posts resources :templates resources :invitadxs, only: %i[index new show] do get :confirmation, to: 'invitadxs#confirmation' end - get :'invitadxs/login/new', to: 'login#new' - post :'invitadxs/login', to: 'login#create' get 'i18n', to: 'i18n#index' get 'i18n/edit', to: 'i18n#edit' diff --git a/db/migrate/20190703200455_create_sitios.rb b/db/migrate/20190703200455_create_sitios.rb index 5d2a3ca8..c8e45d34 100644 --- a/db/migrate/20190703200455_create_sitios.rb +++ b/db/migrate/20190703200455_create_sitios.rb @@ -42,13 +42,17 @@ class CreateSitios < ActiveRecord::Migration[5.2] usuarias.each do |email| usuarie = Usuarie.find_by(email: email) usuarie ||= Usuarie.create(email: email, - password: SecureRandom.hex) + password: SecureRandom.hex, + confirmed_at: Date.today) site.usuaries << usuarie end - # Les Invitades ya están migrades invitadxs.each do |email| - site.invitades << Usuarie.find_by(email: email) + usuarie = Usuarie.find_by(email: email) + usuarie ||= Usuarie.create(email: email, + password: SecureRandom.hex, + confirmed_at: Date.today) + site.invitades << usuarie end end end