mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 23:46:22 +00:00
hostname en los formularios de contacto
This commit is contained in:
parent
eb2bdacd5c
commit
29947b4ed5
3 changed files with 44 additions and 11 deletions
|
@ -64,8 +64,13 @@ module Api
|
|||
render html: body(:gave_consent), status: status
|
||||
end
|
||||
|
||||
# Realiza la inversa de Site#hostname
|
||||
def site_id
|
||||
@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
|
||||
|
|
|
@ -68,10 +68,9 @@ 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? '.'
|
||||
|
||||
if sub.ends_with? '.'
|
||||
sub.gsub(/\.\Z/, '')
|
||||
else
|
||||
"#{sub}.#{Site.domain}"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue