From af613c11d6b82ca8efdc2a0d363ba561c0a96226 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Fri, 29 Jun 2018 16:07:18 +1000 Subject: [PATCH] Handle submissions made by deleted users --- config/locales/server.en.yml | 5 +++++ controllers/admin.rb | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 75372a30..8ce4b4bb 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1,4 +1,9 @@ en: + admin: + wizard: + submissions: + no_user: "deleted (id: %{id})" + wizard: custom_title: "Wizard" field: diff --git a/controllers/admin.rb b/controllers/admin.rb index eb30ee30..69941e77 100644 --- a/controllers/admin.rb +++ b/controllers/admin.rb @@ -148,7 +148,13 @@ class CustomWizard::AdminController < ::ApplicationController all_submissions = [*rows].map do |r| submissions = ::JSON.parse(r.value) - username = User.find(r.key).username + + if user = User.find_by(id: r.key) + username = user.username + else + username = I18n.t('admin.wizard.submissions.no_user', id: r.key) + end + submissions.map { |s| { username: username }.merge!(s.except("redirect_to")) } end.flatten