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)
formatPersonalInfo: (user, callback = (error, info) ->) ->
if !user?
return {}
formatted_user = { id: user._id.toString() }
for key in ["first_name", "last_name", "email", "signUpDate", "role", "institution"]
if user[key]?

View file

@ -373,7 +373,9 @@ define [
return comment
formatUser = (user) ->
if !user?
id = user?._id or user?.id
if !id?
return {
email: null
name: "Anonymous"
@ -381,13 +383,13 @@ define [
hue: ColorManager.ANONYMOUS_HUE
avatar_text: "A"
}
id = user._id or user.id
if id == window.user_id
name = "You"
isSelf = true
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
return {
id: id