From 9e35bdcaea7c2d459bd3ca91a32674a5a323c9c7 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 7 Jul 2016 09:35:44 +0100 Subject: [PATCH] Refactor: add `?` suffix to truth tests. --- .../Features/User/UserController.coffee | 2 +- .../Features/User/UserSessionsManager.coffee | 26 +++++++++---------- .../app/coffee/infrastructure/Server.coffee | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/services/web/app/coffee/Features/User/UserController.coffee b/services/web/app/coffee/Features/User/UserController.coffee index ce96dd2a2f..546cea035e 100644 --- a/services/web/app/coffee/Features/User/UserController.coffee +++ b/services/web/app/coffee/Features/User/UserController.coffee @@ -122,7 +122,7 @@ module.exports = UserController = AuthenticationManager.setUserPassword user._id, newPassword1, (error) -> return next(error) if error? UserSessionsManager.revokeAllUserSessions user, [req.sessionID], (err) -> - return next(err) if err + return next(err) if err? res.send message: type:'success' diff --git a/services/web/app/coffee/Features/User/UserSessionsManager.coffee b/services/web/app/coffee/Features/User/UserSessionsManager.coffee index cd8407dd40..30a9d7471a 100644 --- a/services/web/app/coffee/Features/User/UserSessionsManager.coffee +++ b/services/web/app/coffee/Features/User/UserSessionsManager.coffee @@ -16,10 +16,10 @@ module.exports = UserSessionsManager = return "sess:#{sessionId}" trackSession: (user, sessionId, callback=(err)-> ) -> - if !user + if !user? logger.log {sessionId}, "no user to track, returning" return callback(null) - if !sessionId + if !sessionId? logger.log {user_id: user._id}, "no sessionId to track, returning" return callback(null) logger.log {user_id: user._id, sessionId}, "onLogin handler" @@ -29,17 +29,17 @@ module.exports = UserSessionsManager = .sadd(sessionSetKey, value) .expire(sessionSetKey, "#{Settings.cookieSessionLength}") .exec (err, response) -> - if err + if err? logger.err {err, user_id: user._id, sessionSetKey}, "error while adding session key to UserSessions set" return callback(err) UserSessionsManager._checkSessions(user, () ->) callback() untrackSession: (user, sessionId, callback=(err)-> ) -> - if !user + if !user? logger.log {sessionId}, "no user to untrack, returning" return callback(null) - if !sessionId + if !sessionId? logger.log {user_id: user._id}, "no sessionId to untrack, returning" return callback(null) logger.log {user_id: user._id, sessionId}, "onLogout handler" @@ -52,7 +52,7 @@ module.exports = UserSessionsManager = .srem(sessionSetKey, value) .expire(sessionSetKey, "#{Settings.cookieSessionLength}") .exec (err, response) -> - if err + if err? logger.err {err, user_id: user._id, sessionSetKey}, "error while removing session key from UserSessions set" return callback(err) UserSessionsManager._checkSessions(user, () ->) @@ -68,7 +68,7 @@ module.exports = UserSessionsManager = logger.log {user_id: user._id}, "revoking all existing sessions for user" sessionSetKey = UserSessionsManager._sessionSetKey(user) rclient.smembers sessionSetKey, (err, sessionKeys) -> - if err + if err? logger.err {err, user_id: user._id, sessionSetKey}, "error getting contents of UserSessions set" return callback(err) keysToDelete = _.filter(sessionKeys, (k) -> k not in retain) @@ -80,7 +80,7 @@ module.exports = UserSessionsManager = .del(keysToDelete) .srem(sessionSetKey, keysToDelete) .exec (err, result) -> - if err + if err? logger.err {err, user_id: user._id, sessionSetKey}, "error revoking all sessions for user" return callback(err) callback(null) @@ -91,7 +91,7 @@ module.exports = UserSessionsManager = return callback(null) sessionSetKey = UserSessionsManager._sessionSetKey(user) rclient.expire sessionSetKey, "#{Settings.cookieSessionLength}", (err, response) -> - if err + if err? logger.err {err, user_id: user._id}, "error while updating ttl on UserSessions set" return callback(err) callback(null) @@ -103,7 +103,7 @@ module.exports = UserSessionsManager = logger.log {user_id: user._id}, "checking sessions for user" sessionSetKey = UserSessionsManager._sessionSetKey(user) rclient.smembers sessionSetKey, (err, sessionKeys) -> - if err + if err? logger.err {err, user_id: user._id, sessionSetKey}, "error getting contents of UserSessions set" return callback(err) logger.log {user_id: user._id, count: sessionKeys.length}, "checking sessions for user" @@ -112,12 +112,12 @@ module.exports = UserSessionsManager = (key) -> (next) -> rclient.get key, (err, val) -> - if err + if err? return next(err) - if val == null + if !val? logger.log {user_id: user._id, key}, ">> removing key from UserSessions set" rclient.srem sessionSetKey, key, (err, result) -> - if err + if err? return next(err) return next(null) else diff --git a/services/web/app/coffee/infrastructure/Server.coffee b/services/web/app/coffee/infrastructure/Server.coffee index b5b49d1329..3b40ff6885 100644 --- a/services/web/app/coffee/infrastructure/Server.coffee +++ b/services/web/app/coffee/infrastructure/Server.coffee @@ -90,7 +90,7 @@ webRouter.use translations.setLangBasedOnDomainMiddlewear # Measure expiry from last request, not last login webRouter.use (req, res, next) -> req.session.touch() - if req?.session?.user + if req?.session?.user? UserSessionsManager.touch(req.session.user, (err)->) next()