fix(profile): prevent crashing on renew token action

This commit is contained in:
Paul Chavard 2021-11-16 16:54:09 +03:00
parent ea15c94e2d
commit 716a859c93
2 changed files with 9 additions and 5 deletions

View file

@ -1,10 +1,9 @@
module Users module Users
class ProfilController < UserController class ProfilController < UserController
before_action :ensure_update_email_is_authorized, only: :update_email before_action :ensure_update_email_is_authorized, only: :update_email
before_action :find_transfers, only: [:show, :renew_api_token]
def show def show
@waiting_merge_emails = waiting_merge_emails
@waiting_transfers = current_user.dossiers.joins(:transfer).group('dossier_transfers.email').count.to_a
end end
def renew_api_token def renew_api_token
@ -56,6 +55,11 @@ module Users
private private
def find_transfers
@waiting_merge_emails = waiting_merge_emails
@waiting_transfers = current_user.dossiers.joins(:transfer).group('dossier_transfers.email').count.to_a
end
def waiting_merge_emails def waiting_merge_emails
users_requesting_merge.pluck(:email) users_requesting_merge.pluck(:email)
end end

View file

@ -5,7 +5,7 @@
#profil-page.container #profil-page.container
%h1 Profil %h1 Profil
- if @waiting_merge_emails&.any? - if @waiting_merge_emails.present?
.card .card
.card-title Demande de fusion de comptes .card-title Demande de fusion de comptes
%p %p
@ -37,7 +37,7 @@
application_name: APPLICATION_NAME, application_name: APPLICATION_NAME,
legit_admin_domains: LEGIT_ADMIN_DOMAINS.join(', ')) legit_admin_domains: LEGIT_ADMIN_DOMAINS.join(', '))
= form_for @current_user, url: update_email_path, method: :patch, html: { class: 'form' } do |f| = form_for current_user, url: update_email_path, method: :patch, html: { class: 'form' } do |f|
= f.email_field :email, value: nil, placeholder: 'Nouvelle adresse email', required: true = f.email_field :email, value: nil, placeholder: 'Nouvelle adresse email', required: true
= f.submit "Changer mon adresse", class: 'button primary' = f.submit "Changer mon adresse", class: 'button primary'
@ -50,7 +50,7 @@
= email_field_tag :next_owner, nil, required: true = email_field_tag :next_owner, nil, required: true
= submit_tag "Transférer tous mes dossiers", class: 'button primary', data: { confirm: t('.transfer_confirmation') } = submit_tag "Transférer tous mes dossiers", class: 'button primary', data: { confirm: t('.transfer_confirmation') }
- if @waiting_transfers.any? - if @waiting_transfers.present?
.card.warning .card.warning
.card-title= t('.waiting_transfers') .card-title= t('.waiting_transfers')
%ul %ul