Handle deleted users in comments gracefully

This commit is contained in:
James Allen 2017-01-12 12:31:01 +01:00
parent 9a867438b2
commit 64b9fe52dd
2 changed files with 8 additions and 4 deletions

View file

@ -30,6 +30,8 @@ module.exports = UserController =
res.send JSON.stringify(info) res.send JSON.stringify(info)
formatPersonalInfo: (user, callback = (error, info) ->) -> formatPersonalInfo: (user, callback = (error, info) ->) ->
if !user?
return {}
formatted_user = { id: user._id.toString() } formatted_user = { id: user._id.toString() }
for key in ["first_name", "last_name", "email", "signUpDate", "role", "institution"] for key in ["first_name", "last_name", "email", "signUpDate", "role", "institution"]
if user[key]? if user[key]?

View file

@ -373,7 +373,9 @@ define [
return comment return comment
formatUser = (user) -> formatUser = (user) ->
if !user? id = user?._id or user?.id
if !id?
return { return {
email: null email: null
name: "Anonymous" name: "Anonymous"
@ -381,13 +383,13 @@ define [
hue: ColorManager.ANONYMOUS_HUE hue: ColorManager.ANONYMOUS_HUE
avatar_text: "A" avatar_text: "A"
} }
id = user._id or user.id
if id == window.user_id if id == window.user_id
name = "You" name = "You"
isSelf = true isSelf = true
else else
name = "#{user.first_name} #{user.last_name}" name = [user.first_name, user.last_name].filter((n) -> n?).join(" ")
if name == ""
name = "Unknown"
isSelf = false isSelf = false
return { return {
id: id id: id