Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,16 @@ paths:
type: object
projects:
type: object
session:
description: The current session
type: object
properties:
createdAt:
type: string
description: ISO date format
expiresAt:
type: string
description: ISO date format
example:
createdAt: 2018-04-18T23:19:14.802Z
displayName: My Display Name
Expand All @@ -1802,6 +1812,9 @@ paths:
projects:
"1":
formTrashCollapsed: false
session:
createdAt: 2018-05-18T23:42:11.406Z
expiresAt: 2018-06-18T23:42:11.406Z
403:
description: Forbidden
content:
Expand Down
8 changes: 6 additions & 2 deletions lib/resources/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.

const { always } = require('ramda');
const { always, pick } = require('ramda');
const { User } = require('../model/frames');
const { verifyPassword } = require('../util/crypto');
const { success, isTrue } = require('../util/http');
Expand Down Expand Up @@ -116,7 +116,11 @@ module.exports = (service, endpoint, anonymousEndpoint) => {
return user;
}
const [ verbs, preferences ] = await Promise.all([ Auth.verbsOn(user.actorId, '*'), UserPreferences.getForUser(user.actorId) ]);
return Object.assign({ verbs, preferences }, user.forApi());

const session = auth.session
.map(pick(['createdAt', 'expiresAt'])).get();

return Object.assign({ verbs, preferences, session }, user.forApi());
}));

// Gets full details of a user by actor id.
Expand Down
18 changes: 18 additions & 0 deletions test/integration/api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,24 @@ describe('api: /users', () => {
.expect(200)
.then(({ body }) => body.email.should.equal('[email protected]')))));

it('should not return session details if not extended', testService((service) =>
service.login('alice', (asAlice) =>
asAlice.get('/v1/users/current')
.expect(200)
.then(({ body }) => { should.not.exist(body.session); }))));

it('should return session details if extended', testService((service) =>
service.login('alice', (asAlice) =>
asAlice.get('/v1/users/current')
.set('X-Extended-Metadata', 'true')
.expect(200)
.then(({ body }) => {
body.session.should.be.an.Object();
body.session.should.only.have.keys('createdAt', 'expiresAt');
body.session.createdAt.should.be.an.isoDate();
body.session.expiresAt.should.be.an.isoDate();
}))));

it('should not return site-wide verbs if not extended', testService((service) =>
service.login('alice', (asAlice) =>
asAlice.get('/v1/users/current')
Expand Down