Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
feat(devices): return OS from user agent os (#1848) r=philbooth
Browse files Browse the repository at this point in the history
Fixes #1829
  • Loading branch information
vladikoff committed Apr 25, 2017
1 parent a5ff7ca commit 3fd0418
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/api.md
Expand Up @@ -533,6 +533,7 @@ with an array of device details in the JSON body:
"isCurrentDevice": true,
"isDevice": true,
"userAgent": "Firefox 50",
"os": "Windows",
"lastAccessTime": 1449235471335,
"lastAccessTimeFormatted": "a few seconds ago",
"deviceId": "0f7aa00356e5416e82b3bef7bc409eef",
Expand All @@ -547,6 +548,7 @@ with an array of device details in the JSON body:
"isCurrentDevice": false,
"isDevice": false,
"userAgent": "Chrome 50",
"os": "Windows",
"lastAccessTime": 1449235471337,
"lastAccessTimeFormatted": "a few seconds ago",
"deviceId": null,
Expand Down
3 changes: 3 additions & 0 deletions lib/routes/account.js
Expand Up @@ -1433,6 +1433,7 @@ module.exports = (
lastAccessTime: isA.number().min(0).required().allow(null),
lastAccessTimeFormatted: isA.string().optional().allow(''),
userAgent: isA.string().max(255).required().allow(''),
os: isA.string().max(255).allow('').allow(null),
deviceId: isA.string().regex(HEX_STRING).allow(null),
deviceName: isA.string().max(255).required().allow('').allow(null),
deviceType: isA.string().max(16).required().allow(null),
Expand Down Expand Up @@ -1471,6 +1472,8 @@ module.exports = (
session.lastAccessTimeFormatted = localizeTimestamp.format(session.lastAccessTime,
request.headers['accept-language'])

session.os = session.uaOS

delete session.tokenId
delete session.uid
delete session.createdAt
Expand Down
3 changes: 2 additions & 1 deletion test/local/routes/account.js
Expand Up @@ -1217,7 +1217,7 @@ describe('/account/sessions', function () {

return runTest(route, mockRequest, function (res) {
assert.equal(res.length, 1)
assert.equal(Object.keys(res[0]).length, 12)
assert.equal(Object.keys(res[0]).length, 13)
var s = res[0]
assert.equal(s.id, testSession.tokenId)
assert.equal(s.deviceName, testSession.deviceName)
Expand All @@ -1230,6 +1230,7 @@ describe('/account/sessions', function () {
assert.equal(s.isDevice, true)
assert.equal(s.lastAccessTimeFormatted, 'a few seconds ago')
assert.equal(s.userAgent, 'Firefox 50')
assert.equal(s.os, 'Windows')
})

})
Expand Down

0 comments on commit 3fd0418

Please sign in to comment.