Skip to content

Remove Stage name check on aggregate pipelines #7237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 3, 2021
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ___
- NEW: Supporting patterns in LiveQuery server's config parameter `classNames` [#7131](https://github.com/parse-community/parse-server/pull/7131). Thanks to [Nes-si](https://github.com/Nes-si)
- NEW: `requireAnyUserRoles` and `requireAllUserRoles` for Parse Cloud validator. [#7097](https://github.com/parse-community/parse-server/pull/7097). Thanks to [dblythy](https://github.com/dblythy)
- NEW: Support Facebook Limited Login [#7219](https://github.com/parse-community/parse-server/pull/7219). Thanks to [miguel-s](https://github.com/miguel-s)
- IMPROVE: Removed Stage name check on aggregate pipelines [#7237](https://github.com/parse-community/parse-server/pull/7237). Thanks to [BRETT71](https://github.com/BRETT71)
- IMPROVE: Retry transactions on MongoDB when it fails due to transient error [#7187](https://github.com/parse-community/parse-server/pull/7187). Thanks to [Antonio Davi Macedo Coelho de Castro](https://github.com/davimacedo).
- IMPROVE: Bump tests to use Mongo 4.4.4 [#7184](https://github.com/parse-community/parse-server/pull/7184). Thanks to [Antonio Davi Macedo Coelho de Castro](https://github.com/davimacedo).
- IMPROVE: Added new account lockout policy option `accountLockout.unlockOnPasswordReset` to automatically unlock account on password reset. [#7146](https://github.com/parse-community/parse-server/pull/7146). Thanks to [Manuel Trezza](https://github.com/mtrezza).
Expand Down
11 changes: 11 additions & 0 deletions spec/AggregateRouter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,15 @@ describe('AggregateRouter', () => {
expect(e.message).toBe('Pipeline stages should only have one key found group, match');
}
});

it('get search pipeline from Pipeline Operator (Array)', () => {
const body = {
pipeline: {
search: {},
},
};
const expected = [{ $search: {} }];
const result = AggregateRouter.getPipeline(body);
expect(result).toEqual(expected);
});
});
12 changes: 0 additions & 12 deletions spec/ParseQuery.Aggregate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,6 @@ describe('Parse.Query Aggregate testing', () => {
);
});

it('invalid query invalid key', done => {
const options = Object.assign({}, masterKeyOptions, {
body: {
unknown: {},
},
});
get(Parse.serverURL + '/aggregate/TestObject', options).catch(error => {
expect(error.error.code).toEqual(Parse.Error.INVALID_QUERY);
done();
});
});

it('invalid query group _id', done => {
const options = Object.assign({}, masterKeyOptions, {
body: {
Expand Down
35 changes: 0 additions & 35 deletions src/Routers/AggregateRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,6 @@ import * as middleware from '../middlewares';
import Parse from 'parse/node';
import UsersRouter from './UsersRouter';

const BASE_KEYS = ['where', 'distinct', 'pipeline', 'hint', 'explain'];

const PIPELINE_KEYS = [
'addFields',
'bucket',
'bucketAuto',
'collStats',
'count',
'currentOp',
'facet',
'geoNear',
'graphLookup',
'group',
'indexStats',
'limit',
'listLocalSessions',
'listSessions',
'lookup',
'match',
'out',
'project',
'redact',
'replaceRoot',
'sample',
'skip',
'sort',
'sortByCount',
'unwind',
];

const ALLOWED_KEYS = [...BASE_KEYS, ...PIPELINE_KEYS];

export class AggregateRouter extends ClassesRouter {
handleFind(req) {
const body = Object.assign(req.body, ClassesRouter.JSONFromQuery(req.query));
Expand Down Expand Up @@ -122,9 +90,6 @@ export class AggregateRouter extends ClassesRouter {
}

static transformStage(stageName, stage) {
if (ALLOWED_KEYS.indexOf(stageName) === -1) {
throw new Parse.Error(Parse.Error.INVALID_QUERY, `Invalid parameter for query: ${stageName}`);
}
if (stageName === 'group') {
if (Object.prototype.hasOwnProperty.call(stage[stageName], '_id')) {
throw new Parse.Error(
Expand Down