Skip to content

Commit 9761b18

Browse files
author
Tom Kirkpatrick
committed
Fix lint issues
1 parent d33d777 commit 9761b18

File tree

4 files changed

+39
-40
lines changed

4 files changed

+39
-40
lines changed

lib/middleware/user-context.js

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,37 @@ module.exports = function userContextMiddleware() {
88
return function userContext(req, res, next) {
99
const loopbackContext = loopback.getCurrentContext();
1010

11-
if (loopbackContext) {
12-
if (!req.accessToken) {
13-
debug('No user context (access token not found)');
14-
return next();
15-
}
16-
17-
loopbackContext.set('accessToken', req.accessToken.id);
18-
const app = req.app;
19-
const UserModel = app.accessUtils.options.userModel || 'User';
20-
21-
Promise.join(
22-
app.models[UserModel].findById(req.accessToken.userId),
23-
app.models.Team.find({
24-
where: {
25-
userId: req.accessToken.userId
26-
}
27-
}),
28-
(user, groups) => {
29-
if (!user) {
30-
return next(new Error('No user with this access token was found.'));
31-
}
32-
loopbackContext.set('currentUser', user);
33-
loopbackContext.set('currentUserGroups', groups);
34-
debug('currentUser', user);
35-
debug('currentUserGroups', groups);
36-
return next();
37-
})
38-
.catch(next);
39-
}
40-
else {
11+
if (!loopbackContext) {
4112
debug('No user context (loopback current context not found)');
4213
return next();
4314
}
15+
16+
if (!req.accessToken) {
17+
debug('No user context (access token not found)');
18+
return next();
19+
}
20+
21+
loopbackContext.set('accessToken', req.accessToken.id);
22+
const app = req.app;
23+
const UserModel = app.accessUtils.options.userModel || 'User';
24+
25+
return Promise.join(
26+
app.models[UserModel].findById(req.accessToken.userId),
27+
app.models.Team.find({
28+
where: {
29+
userId: req.accessToken.userId
30+
}
31+
}),
32+
(user, groups) => {
33+
if (!user) {
34+
return next(new Error('No user with this access token was found.'));
35+
}
36+
loopbackContext.set('currentUser', user);
37+
loopbackContext.set('currentUserGroups', groups);
38+
debug('currentUser', user);
39+
debug('currentUserGroups', groups);
40+
return next();
41+
})
42+
.catch(next);
4443
};
4544
};

lib/utils.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module.exports = class AccessUtils {
7171
debug('%s observe access: query=%s, options=%o, hookState=%o',
7272
Model.modelName, JSON.stringify(ctx.query, null, 4), ctx.options, ctx.hookState);
7373

74-
this.buildFilter(currentUser.getId())
74+
return this.buildFilter(currentUser.getId())
7575
.then(filter => {
7676
debug('filter: %o', filter);
7777
const where = ctx.query.where ? {
@@ -80,12 +80,9 @@ module.exports = class AccessUtils {
8080

8181
ctx.query.where = where;
8282
debug('where query modified to: %s', JSON.stringify(ctx.query, null, 4));
83-
next();
8483
});
8584
}
86-
else {
87-
return next();
88-
}
85+
return next();
8986
});
9087
}
9188
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"esformatter-use-strict": "2.0.2",
7272
"eslint": "2.0.0-rc.0",
7373
"eslint-config-fullcube": "https://github.com/fullcube/eslint-config-fullcube/tarball/master",
74-
"eslint-config-strict": "https://github.com/fullcube/eslint-config-strict/tarball/84cf461e49efa918558d69aaa99733b65c606c2d",
74+
"eslint-config-strict": "https://github.com/fullcube/eslint-config-strict/tarball/f235fa38289b17e305a65be38ff9cfdf4c1eb31c",
7575
"isparta": "4.0.0",
7676
"leasot": "3.1.2",
7777
"loopback-boot": "2.16.0",

test/rest-test.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ describe('REST API', function() {
496496
if (invoiceId) {
497497
return app.models.Invoice.destroyById(invoiceId);
498498
}
499+
return null;
499500
});
500501
});
501502
// end create
@@ -589,10 +590,12 @@ describe('REST API', function() {
589590
});
590591
}
591592
else {
592-
return logInAs(user.username)
593-
.then(res => json('put', `/api/invoices/1?access_token=${res.body.id}`)
594-
.send({ someprop: 'someval' })
595-
.expect(401));
593+
it('should update a teams invoice attributes', function() {
594+
return logInAs(user.username)
595+
.then(res => json('put', `/api/invoices/1?access_token=${res.body.id}`)
596+
.send({ someprop: 'someval' })
597+
.expect(401));
598+
});
596599
}
597600

598601
it('should not update another teams invoice attributes', function() {

0 commit comments

Comments
 (0)