mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-23 04:36:21 +00:00
Merge branch 'issue-2123' into panel.sutty.nl
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
commit
7cc7f2bfb7
3 changed files with 24 additions and 16 deletions
|
@ -81,20 +81,26 @@ class UsuariesController < ApplicationController
|
|||
authorize SiteUsuarie.new(@site, current_usuarie)
|
||||
|
||||
# Enviar la invitación si es necesario y agregar al sitio
|
||||
invitaciones.each do |invitacion|
|
||||
attributes = { email: invitacion.address, skip_invitation: true }
|
||||
invitaciones.each do |address|
|
||||
next if Usuarie.where(id: @site.roles.pluck(:usuarie_id)).find_by_email(address)
|
||||
|
||||
next if Usuarie.where(id: @site.roles.pluck(:usuarie_id)).find_by(attributes)
|
||||
|
||||
usuarie = Usuarie.find_by attributes
|
||||
usuarie ||= Usuarie.invite!(attributes).tap do |u|
|
||||
Usuarie.transaction do
|
||||
usuarie = Usuarie.find_by_email(address)
|
||||
usuarie ||= Usuarie.invite!({ email: address, skip_invitation: true }).tap do |u|
|
||||
u.send :generate_invitation_token!
|
||||
end
|
||||
|
||||
@site.roles.create(usuarie: usuarie, temporal: true, rol: invited_as)
|
||||
role = @site.roles.create(usuarie: usuarie, temporal: true, rol: invited_as)
|
||||
|
||||
# XXX: La invitación tiene que ser enviada luego de crear el rol
|
||||
if role.persisted?
|
||||
usuarie.deliver_invitation
|
||||
else
|
||||
raise ArgumentError, role.errors.full_messages
|
||||
end
|
||||
rescue ArgumentError => e
|
||||
ExceptionNotifier.notify_exception(e, data: { site: @site.name, address: address })
|
||||
end
|
||||
end
|
||||
|
||||
redirect_to site_usuaries_path(@site)
|
||||
|
@ -135,6 +141,8 @@ class UsuariesController < ApplicationController
|
|||
private
|
||||
|
||||
# Traer todas las invitaciones que al menos tengan usuarie y dominio
|
||||
#
|
||||
# @return [Array]
|
||||
def invitaciones
|
||||
# XXX: Podríamos usar EmailAddress pero hace chequeos más lentos
|
||||
params[:invitaciones]&.tr("\r", '')&.split("\n")&.map do |m|
|
||||
|
@ -143,7 +151,7 @@ class UsuariesController < ApplicationController
|
|||
nil
|
||||
end.compact.select do |m|
|
||||
m.local && m.domain
|
||||
end
|
||||
end.map(&:address)
|
||||
end
|
||||
|
||||
# El tipo de invitación que tenemos que enviar, si alguien mandó
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
- site = @resource.sites.last
|
||||
- site = @resource.roles.where(temporal: true).last&.site
|
||||
|
||||
%p= t('devise.mailer.invitation_instructions.hello',
|
||||
email: @resource.email)
|
||||
|
@ -8,7 +8,7 @@
|
|||
%h1= site.title
|
||||
%p= site.description
|
||||
|
||||
- if @resource.created_by_invite?
|
||||
- if @resource.created_by_invite? && !@resource.invitation_accepted?
|
||||
%p= link_to t('devise.mailer.invitation_instructions.accept'),
|
||||
accept_invitation_url(@resource, invitation_token: @token, change_locale_to: @resource.lang)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
- site = @resource.sites.last
|
||||
- site = @resource.roles.where(temporal: true).last&.site
|
||||
|
||||
= t('devise.mailer.invitation_instructions.hello', email: @resource.email)
|
||||
\
|
||||
|
@ -9,7 +9,7 @@
|
|||
\
|
||||
= site.description
|
||||
\
|
||||
- if @resource.created_by_invite?
|
||||
- if @resource.created_by_invite? && !@resource.invitation_accepted?
|
||||
= accept_invitation_url(@resource, invitation_token: @token, change_locale_to: @resource.lang)
|
||||
\
|
||||
- if @resource.invitation_due_at
|
||||
|
|
Loading…
Reference in a new issue