5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 19:16:23 +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
end
# Realiza la inversa de Site#hostname
def site_id
params[:site_id].gsub(/\.#{Site.domain}\z/, '')
@site_id ||= if params[:site_id].end_with? Site.domain
params[:site_id].gsub(/\.#{Site.domain}\z/, '')
else
"#{params[:site_id]}."
end
end
# Encuentra el sitio

View file

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

View file

@ -18,7 +18,7 @@ module Api
test 'el sitio tiene que existir' do
@site.destroy
post v1_site_contact_url(@site),
post v1_site_contact_url(site_id: @site.hostname),
params: {
name: SecureRandom.hex,
pronouns: SecureRandom.hex,
@ -33,7 +33,7 @@ module Api
end
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: {
name: SecureRandom.hex,
pronouns: SecureRandom.hex,
@ -48,7 +48,7 @@ module Api
end
test 'hay que dar consentimiento' do
post v1_site_contact_url(@site),
post v1_site_contact_url(site_id: @site.hostname),
headers: {
Origin: @site.url
},
@ -90,6 +90,35 @@ module Api
assert_equal redirect, response.headers['Location']
assert_equal 2, ActionMailer::Base.deliveries.size
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