5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 13:06:22 +00:00

sitios a base de datos

This commit is contained in:
f 2019-07-03 20:25:23 -03:00
parent ba6688430a
commit 78820b6fac
No known key found for this signature in database
GPG key ID: 2AE5A13E321F953D
25 changed files with 164 additions and 283 deletions

1
.gitignore vendored
View file

@ -26,3 +26,4 @@
/_deploy/* /_deploy/*
/_usuarias/* /_usuarias/*
/_invitadxs/* /_invitadxs/*
.env

View file

@ -15,22 +15,42 @@ Metrics/AbcSize:
- 'db/schema.rb' - 'db/schema.rb'
- 'db/migrate/*.rb' - 'db/migrate/*.rb'
- 'app/models/site.rb' - 'app/models/site.rb'
- 'app/controllers/sites_controller.rb'
- 'app/controllers/posts_controller.rb'
- 'app/controllers/invitadxs_controller.rb'
Metrics/MethodLength: Metrics/MethodLength:
Exclude: Exclude:
- 'db/schema.rb' - 'db/schema.rb'
- 'db/migrate/*.rb' - 'db/migrate/*.rb'
- 'app/models/site.rb' - 'app/models/site.rb'
- 'app/controllers/sites_controller.rb'
- 'app/controllers/posts_controller.rb'
- 'app/controllers/invitadxs_controller.rb'
Metrics/BlockLength: Metrics/BlockLength:
Exclude: Exclude:
- 'config/environments/production.rb'
- 'config/initializers/devise.rb' - 'config/initializers/devise.rb'
- 'db/schema.rb' - 'db/schema.rb'
Metrics/ClassLength: Metrics/ClassLength:
Exclude: Exclude:
- 'app/models/site.rb' - 'app/models/site.rb'
- 'app/controllers/posts_controller.rb'
Performance/TimesMap: Performance/TimesMap:
Exclude: Exclude:
- 'app/models/site.rb' - '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'

View file

@ -15,14 +15,11 @@ class ApplicationController < ActionController::Base
private private
# Encontrar un sitio por su ID # Encontrar un sitio por su nombre
# TODO volverlo más natural a rails
def find_site def find_site
id = params[:site_id] || params[:id] id = params[:site_id] || params[:id]
current_user.sites.find do |s| current_usuarie.sites.find_by_name id
s.id == id
end
end end
def find_post(site) def find_post(site)

View file

@ -1,8 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
# Controlador de traducciones
class I18nController < ApplicationController class I18nController < ApplicationController
include Pundit include Pundit
before_action :authenticate! before_action :authenticate_usuarie!
def index def index
authorize :i18n authorize :i18n

View file

@ -1,10 +1,13 @@
# frozen_string_literal: true # frozen_string_literal: true
# Controlador de Invitadxs
#
# TODO: reemplazar
class InvitadxsController < ApplicationController class InvitadxsController < ApplicationController
include Pundit include Pundit
def index def index
authenticate! authenticate_usuarie!
@site = find_site @site = find_site
@invitadxs = @site.invitadxs @invitadxs = @site.invitadxs
@ -23,7 +26,8 @@ class InvitadxsController < ApplicationController
@invitadx.sites << @site @invitadx.sites << @site
if @invitadx.save 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) redirect_to site_invitadx_path(@site, @invitadx)
else else
render 'new' render 'new'
@ -42,7 +46,7 @@ class InvitadxsController < ApplicationController
site.id == params[:site_id] site.id == params[:site_id]
end end
if @invitadx.confirmation_token = params[:confirmation_token] if (@invitadx.confirmation_token = params[:confirmation_token])
@invitadx.update_attribute :confirmed, true @invitadx.update_attribute :confirmed, true
flash[:info] = t('.confirmed') flash[:info] = t('.confirmed')
redirect_to site_invitadxs_login_new_path(@site) redirect_to site_invitadxs_login_new_path(@site)
@ -55,6 +59,7 @@ class InvitadxsController < ApplicationController
def invitadx_params def invitadx_params
params.require(:invitadx).permit(:email, :password, params.require(:invitadx).permit(:email, :password,
:password_confirmation, :acepta_politicas_de_privacidad) :password_confirmation,
:acepta_politicas_de_privacidad)
end end
end end

View file

@ -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

View file

@ -1,15 +1,17 @@
# frozen_string_literal: true # frozen_string_literal: true
# Controlador para artículos
class PostsController < ApplicationController class PostsController < ApplicationController
include Pundit include Pundit
before_action :authenticate! before_action :authenticate_usuarie!
def index def index
authorize Post authorize Post
@site = find_site @site = find_site
@lang = find_lang(@site) @lang = find_lang(@site)
@category = session[:category] = params.dig(:category) @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? if params[:sort_by].present?
begin begin
@ -49,7 +51,8 @@ class PostsController < ApplicationController
# El post se guarda como incompleto si se envió con "guardar para # El post se guarda como incompleto si se envió con "guardar para
# después" # 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 # Las usuarias pueden especificar una autora, de la contrario por
# defecto es la usuaria actual # defecto es la usuaria actual
@ -59,7 +62,10 @@ class PostsController < ApplicationController
# Todo lo que crean lxs invitadxs es borrador # Todo lo que crean lxs invitadxs es borrador
@post.update_attributes(draft: true) @post.update_attributes(draft: true)
end 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.save
if @post.incomplete? if @post.incomplete?
@ -94,7 +100,9 @@ class PostsController < ApplicationController
# Solo las usuarias pueden modificar la autoría # Solo las usuarias pueden modificar la autoría
if current_user.is_a? Usuaria 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) @post.update_attributes(draft: false)
else else
# Todo lo que crean lxs invitadxs es borrador # Todo lo que crean lxs invitadxs es borrador
@ -103,7 +111,9 @@ class PostsController < ApplicationController
if @post.save if @post.save
flash[:success] = @site.config.dig('thanks') 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 else
render 'posts/edit' render 'posts/edit'
end end
@ -119,7 +129,8 @@ class PostsController < ApplicationController
@post.destroy @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 end
private private

View file

@ -3,12 +3,12 @@
# Controlador de sitios # Controlador de sitios
class SitesController < ApplicationController class SitesController < ApplicationController
include Pundit include Pundit
before_action :authenticate! before_action :authenticate_usuarie!
# Ver un listado de sitios # Ver un listado de sitios
def index def index
authorize Site authorize Site
@sites = current_user.sites @sites = current_usuarie.sites
end end
# No tenemos propiedades de un sitio aún, así que vamos al listado de # No tenemos propiedades de un sitio aún, así que vamos al listado de
@ -25,7 +25,8 @@ class SitesController < ApplicationController
authorize Site authorize Site
@site = find_site @site = find_site
file = [params[:basename], params[:format]].join('.') 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 # TODO: Verificar que no nos estén sacando archivos del sistema, como
# /etc/passwd # /etc/passwd
@ -63,10 +64,11 @@ class SitesController < ApplicationController
authorize @site authorize @site
lang = params.require(:posts).require(:lang) lang = params.require(:posts).require(:lang)
result = if params[:posts][:force].present? if params[:posts][:force].present?
@site.reorder_collection! lang result = @site.reorder_collection! lang
else else
@site.reorder_collection(lang, params.require(:posts).require(:order)) result = @site
.reorder_collection(lang, params.require(:posts).require(:order))
end end
if result if result

View file

@ -1,6 +0,0 @@
# frozen_string_literal: true
module Warden
module EmailAndPassword
end
end

View file

@ -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

View file

@ -1,6 +0,0 @@
# frozen_string_literal: true
module Warden
module IMAP
end
end

View file

@ -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

View file

@ -7,8 +7,22 @@ class Site < ApplicationRecord
has_and_belongs_to_many :invitades, class_name: 'Usuarie', has_and_belongs_to_many :invitades, class_name: 'Usuarie',
join_table: 'invitades_sites' join_table: 'invitades_sites'
after_initialize :load_jekyll!
attr_accessor :jekyll, :collections 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? # Este sitio acepta invitadxs?
def invitadxs? def invitadxs?
@ -121,6 +135,7 @@ class Site < ApplicationRecord
# idioma actual # idioma actual
collection = default_lang if collection == 'posts' && i18n? collection = default_lang if collection == 'posts' && i18n?
@collections ||= {}
c = @collections[collection] c = @collections[collection]
return c if c return c if c

View file

@ -1,13 +1,16 @@
# frozen_string_literal: true # 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) def initialize(usuarix, _i18n)
@usuarix = usuarix @usuarix = usuarix
end end
# Solo las usuarias # Solo las usuarias
def index? def index?
usuaria? true
end end
def edit? def edit?
@ -15,6 +18,6 @@ class I18nPolicy < SuttyPolicy
end end
def update? def update?
usuaria? true
end end
end end

View file

@ -1,5 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
# Política de acceso para Invitades
#
# TODO: Incorporar a Usuarie y eliminar
class InvitadxPolicy class InvitadxPolicy
attr_reader :usuarix, :model attr_reader :usuarix, :model
@ -14,7 +17,10 @@ class InvitadxPolicy
# Al crear, el modelo recibido es un sitio # Al crear, el modelo recibido es un sitio
def create? 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 # El sitio acepta invitadxs
model.invitadxs? model.invitadxs?

View file

@ -1,16 +1,19 @@
# frozen_string_literal: true # frozen_string_literal: true
class SitePolicy < SuttyPolicy # Política de acceso para sitios
attr_reader :site #
# TODO: Distinguir entre Invitades
class SitePolicy
attr_reader :site, :usuarie
def initialize(usuarix, site) def initialize(usuarie, site)
@usuarix = usuarix @usuarie = usuarie
@site = site @site = site
end end
# Solo las usuarias # Solo las usuarias
def index? def index?
usuaria? true
end end
# Todxs lxs usuarixs pueden ver el sitio # Todxs lxs usuarixs pueden ver el sitio
@ -20,7 +23,7 @@ class SitePolicy < SuttyPolicy
# Solo las usuarias # Solo las usuarias
def build? def build?
usuaria? true
end end
def send_public_file? def send_public_file?
@ -28,14 +31,14 @@ class SitePolicy < SuttyPolicy
end end
def enqueue? def enqueue?
usuaria? true
end end
def build_log? def build_log?
usuaria? true
end end
def reorder_posts? def reorder_posts?
usuaria? true
end end
end end

View file

@ -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

View file

@ -1,6 +1,10 @@
%nav{'aria-label': 'breadcrumb', role: 'navigation'} %nav{'aria-label': 'breadcrumb', role: 'navigation'}
%ol.breadcrumb %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') - if help = @site.try(:config).try(:dig, 'help')
%li.breadcrumb-item= link_to t('.help'), help, target: '_blank' %li.breadcrumb-item= link_to t('.help'), help, target: '_blank'
- crumbs.compact.each do |crumb| - crumbs.compact.each do |crumb|

View file

@ -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')

View file

@ -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'}

View file

@ -1,7 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
Rails.application.configure do 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. # Code is not reloaded between requests.
config.cache_classes = true config.cache_classes = true
@ -21,9 +22,10 @@ Rails.application.configure do
# `config/secrets.yml.key`. # `config/secrets.yml.key`.
config.read_encrypted_secrets = true config.read_encrypted_secrets = true
# Disable serving static files from the `/public` folder by default since # Disable serving static files from the `/public` folder by default
# Apache or NGINX already handles this. # since Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? config.public_file_server
.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS. # Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier 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. # Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false 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' # config.action_controller.asset_host = 'http://assets.example.com'
# Specifies the header that your server uses for sending files. # 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'
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # Force all access to the app over SSL, use Strict-Transport-Security,
# config.force_ssl = true # and use secure cookies.
config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information # Use the lowest log level to ensure availability of diagnostic
# when problems arise. # information when problems arise.
config.log_level = :debug config.log_level = :debug
# Prepend all log lines with the following tags. # Prepend all log lines with the following tags.
@ -54,28 +58,32 @@ Rails.application.configure do
# Use a different cache store in production. # Use a different cache store in production.
# config.cache_store = :mem_cache_store # 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_adapter = :resque
# config.active_job.queue_name_prefix = "sutty_#{Rails.env}" # config.active_job.queue_name_prefix = "sutty_#{Rails.env}"
config.action_mailer.perform_caching = false config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors. # 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 # config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to # Enable locale fallbacks for I18n (makes lookups for any locale fall
# the I18n.default_locale when a translation cannot be found). # back to the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true config.i18n.fallbacks = true
# Send deprecation notices to registered listeners. # Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify 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 config.log_formatter = ::Logger::Formatter.new
# Use a different logger for distributed setups. # Use a different logger for distributed setups.
# require 'syslog/logger' require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') config.logger = ActiveSupport::TaggedLogging
.new(Syslog::Logger.new('app-name'))
if ENV['RAILS_LOG_TO_STDOUT'].present? if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new(STDOUT) logger = ActiveSupport::Logger.new(STDOUT)
@ -87,16 +95,16 @@ Rails.application.configure do
config.active_record.dump_schema_after_migration = false config.active_record.dump_schema_after_migration = false
# Recibir por mail notificaciones de excepciones # 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.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :sendmail 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, config.middleware.use ExceptionNotification::Rack,
email: { email: {
email_prefix: '[ERROR]', email_prefix: '[ERROR]',
sender_address: %(sutty@kefir.red), sender_address: ENV['DEFAULT_FROM'],
exception_recipients: 'sysadmin@kefir.red' exception_recipients: ENV['EXCEPTION_TO']
} }
end end

View file

@ -1,7 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
Rails.application.configure do 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 # The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that # 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! # and recreated between test runs. Don't rely on the data there!
config.cache_classes = true config.cache_classes = true
# Do not eager load code on boot. This avoids loading your whole application # Do not eager load code on boot. This avoids loading your whole
# just for the purpose of running a single test. If you are using a tool that # application just for the purpose of running a single test. If you
# preloads Rails for running tests, you may have to set it to true. # are using a tool that preloads Rails for running tests, you may have
# to set it to true.
config.eager_load = false 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.enabled = true
config.public_file_server.headers = { config.public_file_server.headers = { 'Cache-Control' => "public,
'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}" max-age=#{1.hour.seconds.to_i}" }
}
# Show full error reports and disable caching. # Show full error reports and disable caching.
config.consider_all_requests_local = true config.consider_all_requests_local = true
@ -35,6 +37,8 @@ Rails.application.configure do
# The :test delivery method accumulates sent emails in the # The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array. # ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test config.action_mailer.delivery_method = :test
config.action_mailer.default_url_options = { host: 'localhost',
port: 3000 }
# Print deprecation notices to the stderr. # Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr config.active_support.deprecation = :stderr

View file

@ -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)

View file

@ -1,11 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
Rails.application.routes.draw do Rails.application.routes.draw do
root 'application#index' devise_for :usuaries
get 'login/new', to: 'login#new' root 'application#index'
post 'login', to: 'login#create'
delete 'login/logout', to: 'login#delete'
get 'markdown', to: 'application#markdown' get 'markdown', to: 'application#markdown'
@ -13,15 +11,16 @@ Rails.application.routes.draw do
# como un objeto válido # como un objeto válido
resources :invitadxs, only: [:create] 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' get 'public/:type/:basename', to: 'sites#send_public_file'
resources :posts resources :posts
resources :templates resources :templates
resources :invitadxs, only: %i[index new show] do resources :invitadxs, only: %i[index new show] do
get :confirmation, to: 'invitadxs#confirmation' get :confirmation, to: 'invitadxs#confirmation'
end end
get :'invitadxs/login/new', to: 'login#new'
post :'invitadxs/login', to: 'login#create'
get 'i18n', to: 'i18n#index' get 'i18n', to: 'i18n#index'
get 'i18n/edit', to: 'i18n#edit' get 'i18n/edit', to: 'i18n#edit'

View file

@ -42,13 +42,17 @@ class CreateSitios < ActiveRecord::Migration[5.2]
usuarias.each do |email| usuarias.each do |email|
usuarie = Usuarie.find_by(email: email) usuarie = Usuarie.find_by(email: email)
usuarie ||= Usuarie.create(email: email, usuarie ||= Usuarie.create(email: email,
password: SecureRandom.hex) password: SecureRandom.hex,
confirmed_at: Date.today)
site.usuaries << usuarie site.usuaries << usuarie
end end
# Les Invitades ya están migrades
invitadxs.each do |email| 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 end
end end