mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Fix 500 errors coming from Google scripts (#15237)
* fix issue with userFields options * remove only --------- Co-authored-by: Phillip Thelen <phillip@habitica.com>
This commit is contained in:
@@ -40,6 +40,24 @@ describe('GET /user', () => {
|
||||
expect(returnedUser.stats).to.not.exist;
|
||||
});
|
||||
|
||||
it('returns when ALWAYS_LOADED paths are requested', async () => {
|
||||
const returnedUser = await user.get('/user?userFields=_id,notifications,preferences,auth,flags,permissions');
|
||||
|
||||
expect(returnedUser._id).to.equal(user._id);
|
||||
expect(returnedUser.notifications).to.exist;
|
||||
expect(returnedUser.preferences).to.exist;
|
||||
expect(returnedUser.auth).to.exist;
|
||||
expect(returnedUser.flags).to.exist;
|
||||
expect(returnedUser.permissions).to.exist;
|
||||
});
|
||||
|
||||
it('returns when subpaths paths are requested', async () => {
|
||||
const returnedUser = await user.get('/user?userFields=auth.local.username');
|
||||
|
||||
expect(returnedUser._id).to.equal(user._id);
|
||||
expect(returnedUser.auth.local.username).to.exist;
|
||||
});
|
||||
|
||||
it('does not return requested private properties', async () => {
|
||||
const returnedUser = await user.get('/user?userFields=apiToken,secret.text');
|
||||
|
||||
|
||||
@@ -36,9 +36,11 @@ function getUserFields (options, req) {
|
||||
const { userFields } = req.query;
|
||||
if (!userFields || urlPath !== '/user') return '';
|
||||
|
||||
const userFieldOptions = userFields.split(',');
|
||||
let userFieldOptions = userFields.split(',');
|
||||
if (userFieldOptions.length === 0) return '';
|
||||
|
||||
userFieldOptions = userFieldOptions.filter(field => USER_FIELDS_ALWAYS_LOADED.indexOf(field.split('.')[0]) === -1);
|
||||
|
||||
return userFieldOptions.concat(USER_FIELDS_ALWAYS_LOADED).join(' ');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user