5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-23 04:06:21 +00:00

hostname en los formularios de contacto

This commit is contained in:
f 2020-03-25 15:49:36 -03:00
parent eb2bdacd5c
commit 29947b4ed5
No known key found for this signature in database
GPG key ID: 2AE5A13E321F953D
3 changed files with 44 additions and 11 deletions

View file

@ -64,8 +64,13 @@ module Api
render html: body(:gave_consent), status: status render html: body(:gave_consent), status: status
end end
# Realiza la inversa de Site#hostname
def site_id def site_id
@site_id ||= if params[:site_id].end_with? Site.domain
params[:site_id].gsub(/\.#{Site.domain}\z/, '') params[:site_id].gsub(/\.#{Site.domain}\z/, '')
else
"#{params[:site_id]}."
end
end end
# Encuentra el sitio # Encuentra el sitio

View file

@ -68,10 +68,9 @@ class Site < ApplicationRecord
end end
def hostname def hostname
return @hostname unless name_changed? || @hostname.blank?
sub = name || I18n.t('deploys.deploy_local.ejemplo') sub = name || I18n.t('deploys.deploy_local.ejemplo')
@hostname = if sub.ends_with? '.'
if sub.ends_with? '.'
sub.gsub(/\.\Z/, '') sub.gsub(/\.\Z/, '')
else else
"#{sub}.#{Site.domain}" "#{sub}.#{Site.domain}"

View file

@ -18,7 +18,7 @@ module Api
test 'el sitio tiene que existir' do test 'el sitio tiene que existir' do
@site.destroy @site.destroy
post v1_site_contact_url(@site), post v1_site_contact_url(site_id: @site.hostname),
params: { params: {
name: SecureRandom.hex, name: SecureRandom.hex,
pronouns: SecureRandom.hex, pronouns: SecureRandom.hex,
@ -33,7 +33,7 @@ module Api
end end
test 'hay que enviar desde el sitio principal' do test 'hay que enviar desde el sitio principal' do
post v1_site_contact_url(@site), post v1_site_contact_url(site_id: @site.hostname),
params: { params: {
name: SecureRandom.hex, name: SecureRandom.hex,
pronouns: SecureRandom.hex, pronouns: SecureRandom.hex,
@ -48,7 +48,7 @@ module Api
end end
test 'hay que dar consentimiento' do test 'hay que dar consentimiento' do
post v1_site_contact_url(@site), post v1_site_contact_url(site_id: @site.hostname),
headers: { headers: {
Origin: @site.url Origin: @site.url
}, },
@ -90,6 +90,35 @@ module Api
assert_equal redirect, response.headers['Location'] assert_equal redirect, response.headers['Location']
assert_equal 2, ActionMailer::Base.deliveries.size assert_equal 2, ActionMailer::Base.deliveries.size
end end
test 'se puede enviar mensajes a dominios propios' do
ActionMailer::Base.deliveries.clear
@site.update name: 'example.org.'
redirect = "#{@site.url}?thanks"
10.times do
create :rol, site: @site
end
post v1_site_contact_url(site_id: @site.hostname),
headers: {
Origin: @site.url
},
params: {
name: SecureRandom.hex,
pronouns: SecureRandom.hex,
contact: SecureRandom.hex,
from: "#{SecureRandom.hex}@sutty.nl",
body: SecureRandom.hex,
gdpr: true,
redirect: redirect
}
assert_equal redirect, response.headers['Location']
assert_equal 2, ActionMailer::Base.deliveries.size
end
end end
end end
end end