From 5c467e08b88d3c0db22d496fee1c7591adfcd3ec Mon Sep 17 00:00:00 2001 From: f Date: Mon, 24 Apr 2023 17:21:24 -0300 Subject: [PATCH 1/8] =?UTF-8?q?fix:=20aceptar=20la=20invitaci=C3=B3n=20tam?= =?UTF-8?q?bi=C3=A9n=20confirma=20el=20correo=20#13247?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit les usuaries que no confirmaron su correo quedaban en un loop si luego eran invitades a un sitio. --- app/models/usuarie.rb | 6 ++++++ app/views/devise/mailer/invitation_instructions.html.haml | 2 +- app/views/devise/mailer/invitation_instructions.text.haml | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/usuarie.rb b/app/models/usuarie.rb index 0dcf917d..ef13239b 100644 --- a/app/models/usuarie.rb +++ b/app/models/usuarie.rb @@ -50,6 +50,12 @@ class Usuarie < ApplicationRecord end end + # Les usuaries necesitan link de invitación si no tenían cuenta + # o todavía no la confirmaron + def needs_invitation_link? + (created_by_invite? && !invitation_accepted?) || !confirmed? + end + private def lang_from_locale! diff --git a/app/views/devise/mailer/invitation_instructions.html.haml b/app/views/devise/mailer/invitation_instructions.html.haml index b12cef64..1cdcb2a9 100644 --- a/app/views/devise/mailer/invitation_instructions.html.haml +++ b/app/views/devise/mailer/invitation_instructions.html.haml @@ -8,7 +8,7 @@ %h1= site.title %p= site.description -- if @resource.created_by_invite? && !@resource.invitation_accepted? +- if @resource.needs_invitation_link? %p= link_to t('devise.mailer.invitation_instructions.accept'), accept_invitation_url(@resource, invitation_token: @token, change_locale_to: @resource.lang) diff --git a/app/views/devise/mailer/invitation_instructions.text.haml b/app/views/devise/mailer/invitation_instructions.text.haml index bb496733..eab021ef 100644 --- a/app/views/devise/mailer/invitation_instructions.text.haml +++ b/app/views/devise/mailer/invitation_instructions.text.haml @@ -9,7 +9,7 @@ \ = site.description \ -- if @resource.created_by_invite? && !@resource.invitation_accepted? +- if @resource.needs_invitation_link? = accept_invitation_url(@resource, invitation_token: @token, change_locale_to: @resource.lang) \ - if @resource.invitation_due_at From 229914e8493a158192c5ee9bc10ede0516bbe0cc Mon Sep 17 00:00:00 2001 From: f Date: Mon, 24 Apr 2023 17:44:04 -0300 Subject: [PATCH 2/8] =?UTF-8?q?fix:=20confirmar=20usuaries=20en=20la=20inv?= =?UTF-8?q?itaci=C3=B3n=20#13247?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/usuaries_controller.rb | 6 ++++++ app/models/usuarie.rb | 4 ++-- app/views/devise/mailer/invitation_instructions.html.haml | 4 ++++ app/views/devise/mailer/invitation_instructions.text.haml | 4 ++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/controllers/usuaries_controller.rb b/app/controllers/usuaries_controller.rb index 9e9cac71..28513e63 100644 --- a/app/controllers/usuaries_controller.rb +++ b/app/controllers/usuaries_controller.rb @@ -96,6 +96,12 @@ class UsuariesController < ApplicationController # XXX: La invitación tiene que ser enviada luego de crear el rol if role.persisted? + # Si es una cuenta manual que no está confirmada aun, + # aprovechar para reconfirmarla. + if !usuarie.confirmed? && !usuarie.created_by_invite? + usuarie.generate_confirmation_token! + end + usuarie.deliver_invitation else raise ArgumentError, role.errors.full_messages diff --git a/app/models/usuarie.rb b/app/models/usuarie.rb index ef13239b..e25a6785 100644 --- a/app/models/usuarie.rb +++ b/app/models/usuarie.rb @@ -51,9 +51,9 @@ class Usuarie < ApplicationRecord end # Les usuaries necesitan link de invitación si no tenían cuenta - # o todavía no la confirmaron + # y todavía no aceptaron la invitación anterior. def needs_invitation_link? - (created_by_invite? && !invitation_accepted?) || !confirmed? + created_by_invite? && !invitation_accepted? end private diff --git a/app/views/devise/mailer/invitation_instructions.html.haml b/app/views/devise/mailer/invitation_instructions.html.haml index 1cdcb2a9..6370ed1a 100644 --- a/app/views/devise/mailer/invitation_instructions.html.haml +++ b/app/views/devise/mailer/invitation_instructions.html.haml @@ -18,5 +18,9 @@ format: :'devise.mailer.invitation_instructions.accept_until_format')) %p= t('devise.mailer.invitation_instructions.ignore') +- elsif !@resource.confirmed? && @resource.confirmation_token + = confirmation_url(@resource, confirmation_token: @token, change_locale_to: @resource.lang) + \ + = t('devise.mailer.invitation_instructions.ignore') - else %p= link_to t('devise.mailer.invitation_instructions.sign_in'), root_url diff --git a/app/views/devise/mailer/invitation_instructions.text.haml b/app/views/devise/mailer/invitation_instructions.text.haml index eab021ef..719c7cd2 100644 --- a/app/views/devise/mailer/invitation_instructions.text.haml +++ b/app/views/devise/mailer/invitation_instructions.text.haml @@ -18,6 +18,10 @@ format: :'devise.mailer.invitation_instructions.accept_until_format')) \ = t('devise.mailer.invitation_instructions.ignore') +- elsif !@resource.confirmed? && @resource.confirmation_token + = confirmation_url(@resource, confirmation_token: @token, change_locale_to: @resource.lang) + \ + = t('devise.mailer.invitation_instructions.ignore') - else = root_url(change_locale_to: @resource.lang) = t('devise.mailer.invitation_instructions.sign_in') From e35d09e343fa79232edeae617de849e958f64781 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 24 Apr 2023 18:07:57 -0300 Subject: [PATCH 3/8] fix: si le usuarie creo su cuenta manualmente no necesita ser invitade --- app/models/usuarie.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/usuarie.rb b/app/models/usuarie.rb index e25a6785..2bc7a1b5 100644 --- a/app/models/usuarie.rb +++ b/app/models/usuarie.rb @@ -12,6 +12,7 @@ class Usuarie < ApplicationRecord validates_with EmailAddress::ActiveRecordValidator, field: :email before_create :lang_from_locale! + before_update :remove_confirmation_invitation_inconsistencies! before_update :accept_invitation_after_confirmation! has_many :roles @@ -62,6 +63,13 @@ class Usuarie < ApplicationRecord self.lang = I18n.locale.to_s end + # El invitation_token solo es necesario cuando fue creade por otre + # usuarie. De lo contrario lo que queremos es un proceso de + # confirmación. + def remove_confirmation_invitation_inconsistencies! + self.invitation_token = nil unless created_by_invite? + end + # Si le usuarie (re)confirma su cuenta con una invitación pendiente, # considerarla aceptada también. def accept_invitation_after_confirmation! From 3a7c9c6b623f68a445441e58de8b98094401c357 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 24 Apr 2023 18:12:40 -0300 Subject: [PATCH 4/8] =?UTF-8?q?fixup!=20fix:=20confirmar=20usuaries=20en?= =?UTF-8?q?=20la=20invitaci=C3=B3n=20#13247?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/usuaries_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/usuaries_controller.rb b/app/controllers/usuaries_controller.rb index 28513e63..76d17541 100644 --- a/app/controllers/usuaries_controller.rb +++ b/app/controllers/usuaries_controller.rb @@ -99,7 +99,7 @@ class UsuariesController < ApplicationController # Si es una cuenta manual que no está confirmada aun, # aprovechar para reconfirmarla. if !usuarie.confirmed? && !usuarie.created_by_invite? - usuarie.generate_confirmation_token! + usuarie.send :generate_confirmation_token! end usuarie.deliver_invitation From 838b398f289be22158ea81857d664cebc95398b7 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 24 Apr 2023 18:58:05 -0300 Subject: [PATCH 5/8] =?UTF-8?q?fix:=20cambiar=20el=20token=20de=20confirma?= =?UTF-8?q?ci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/usuaries_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/usuaries_controller.rb b/app/controllers/usuaries_controller.rb index 76d17541..6924c860 100644 --- a/app/controllers/usuaries_controller.rb +++ b/app/controllers/usuaries_controller.rb @@ -99,6 +99,7 @@ class UsuariesController < ApplicationController # Si es una cuenta manual que no está confirmada aun, # aprovechar para reconfirmarla. if !usuarie.confirmed? && !usuarie.created_by_invite? + usuarie.confirmation_token = nil usuarie.send :generate_confirmation_token! end From 18de36939f50266ba6b1707c41dc769bd51cd65d Mon Sep 17 00:00:00 2001 From: f Date: Mon, 24 Apr 2023 19:00:23 -0300 Subject: [PATCH 6/8] fix: usar el token correcto --- app/views/devise/mailer/invitation_instructions.html.haml | 2 +- app/views/devise/mailer/invitation_instructions.text.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/devise/mailer/invitation_instructions.html.haml b/app/views/devise/mailer/invitation_instructions.html.haml index 6370ed1a..5c10c433 100644 --- a/app/views/devise/mailer/invitation_instructions.html.haml +++ b/app/views/devise/mailer/invitation_instructions.html.haml @@ -19,7 +19,7 @@ %p= t('devise.mailer.invitation_instructions.ignore') - elsif !@resource.confirmed? && @resource.confirmation_token - = confirmation_url(@resource, confirmation_token: @token, change_locale_to: @resource.lang) + = confirmation_url(@resource, confirmation_token: @resource.confirmation_token, change_locale_to: @resource.lang) \ = t('devise.mailer.invitation_instructions.ignore') - else diff --git a/app/views/devise/mailer/invitation_instructions.text.haml b/app/views/devise/mailer/invitation_instructions.text.haml index 719c7cd2..ee0247a0 100644 --- a/app/views/devise/mailer/invitation_instructions.text.haml +++ b/app/views/devise/mailer/invitation_instructions.text.haml @@ -19,7 +19,7 @@ \ = t('devise.mailer.invitation_instructions.ignore') - elsif !@resource.confirmed? && @resource.confirmation_token - = confirmation_url(@resource, confirmation_token: @token, change_locale_to: @resource.lang) + = confirmation_url(@resource, confirmation_token: @resource.confirmation_token, change_locale_to: @resource.lang) \ = t('devise.mailer.invitation_instructions.ignore') - else From 34947ffd4e9069f787973cfc9fd009ec3f94c394 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 24 Apr 2023 19:01:02 -0300 Subject: [PATCH 7/8] fix: typo --- config/locales/devise_invitable.es.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/devise_invitable.es.yml b/config/locales/devise_invitable.es.yml index e83a703c..860ee4f8 100644 --- a/config/locales/devise_invitable.es.yml +++ b/config/locales/devise_invitable.es.yml @@ -22,7 +22,7 @@ es: someone_invited_you: "Alguien te ha invitado a colaborar en %{url}, podés aceptar la invitación con el enlace a continuación." accept: "Aceptar la invitación" accept_until: "La invitación vencerá el %{due_date}." - ignore: "Si no querés aceptar la invitación, por favor ignora este correo. Tu cuenta no será creada hasta que aceptes la invitación y configures una contraseña." + ignore: "Si no querés aceptar la invitación, por favor ignorá este correo. Tu cuenta no será creada hasta que aceptes la invitación y configures una contraseña." sign_in: "Iniciá sesión con tu cuenta para aceptar o rechazar la invitación." time: formats: From 5c44a4f15ee0a6af0fe14664c1d9f7bfe4a9a41c Mon Sep 17 00:00:00 2001 From: f Date: Mon, 24 Apr 2023 19:01:19 -0300 Subject: [PATCH 8/8] fix: el mensaje de ignorar no es el correcto --- app/views/devise/mailer/invitation_instructions.html.haml | 2 -- app/views/devise/mailer/invitation_instructions.text.haml | 2 -- 2 files changed, 4 deletions(-) diff --git a/app/views/devise/mailer/invitation_instructions.html.haml b/app/views/devise/mailer/invitation_instructions.html.haml index 5c10c433..e87d99d9 100644 --- a/app/views/devise/mailer/invitation_instructions.html.haml +++ b/app/views/devise/mailer/invitation_instructions.html.haml @@ -20,7 +20,5 @@ %p= t('devise.mailer.invitation_instructions.ignore') - elsif !@resource.confirmed? && @resource.confirmation_token = confirmation_url(@resource, confirmation_token: @resource.confirmation_token, change_locale_to: @resource.lang) - \ - = t('devise.mailer.invitation_instructions.ignore') - else %p= link_to t('devise.mailer.invitation_instructions.sign_in'), root_url diff --git a/app/views/devise/mailer/invitation_instructions.text.haml b/app/views/devise/mailer/invitation_instructions.text.haml index ee0247a0..5cb007de 100644 --- a/app/views/devise/mailer/invitation_instructions.text.haml +++ b/app/views/devise/mailer/invitation_instructions.text.haml @@ -20,8 +20,6 @@ = t('devise.mailer.invitation_instructions.ignore') - elsif !@resource.confirmed? && @resource.confirmation_token = confirmation_url(@resource, confirmation_token: @resource.confirmation_token, change_locale_to: @resource.lang) - \ - = t('devise.mailer.invitation_instructions.ignore') - else = root_url(change_locale_to: @resource.lang) = t('devise.mailer.invitation_instructions.sign_in')