fix(prettier): Properly handle lint-stage files (#6970)
Now handles top level files and recursive files in folders. Set max line length to be 100
This commit is contained in:
@@ -38,10 +38,7 @@ const ALLOWED_KEYS = [...BASE_KEYS, ...PIPELINE_KEYS];
|
||||
|
||||
export class AggregateRouter extends ClassesRouter {
|
||||
handleFind(req) {
|
||||
const body = Object.assign(
|
||||
req.body,
|
||||
ClassesRouter.JSONFromQuery(req.query)
|
||||
);
|
||||
const body = Object.assign(req.body, ClassesRouter.JSONFromQuery(req.query));
|
||||
const options = {};
|
||||
if (body.distinct) {
|
||||
options.distinct = String(body.distinct);
|
||||
@@ -118,9 +115,7 @@ export class AggregateRouter extends ClassesRouter {
|
||||
return pipeline.map(stage => {
|
||||
const keys = Object.keys(stage);
|
||||
if (keys.length != 1) {
|
||||
throw new Error(
|
||||
`Pipeline stages should only have one key found ${keys.join(', ')}`
|
||||
);
|
||||
throw new Error(`Pipeline stages should only have one key found ${keys.join(', ')}`);
|
||||
}
|
||||
return AggregateRouter.transformStage(keys[0], stage);
|
||||
});
|
||||
@@ -128,10 +123,7 @@ 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}`
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, `Invalid parameter for query: ${stageName}`);
|
||||
}
|
||||
if (stageName === 'group') {
|
||||
if (Object.prototype.hasOwnProperty.call(stage[stageName], '_id')) {
|
||||
@@ -153,14 +145,9 @@ export class AggregateRouter extends ClassesRouter {
|
||||
}
|
||||
|
||||
mountRoutes() {
|
||||
this.route(
|
||||
'GET',
|
||||
'/aggregate/:className',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
req => {
|
||||
return this.handleFind(req);
|
||||
}
|
||||
);
|
||||
this.route('GET', '/aggregate/:className', middleware.promiseEnforceMasterKeyAccess, req => {
|
||||
return this.handleFind(req);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,7 @@ export class AudiencesRouter extends ClassesRouter {
|
||||
}
|
||||
|
||||
handleFind(req) {
|
||||
const body = Object.assign(
|
||||
req.body,
|
||||
ClassesRouter.JSONFromQuery(req.query)
|
||||
);
|
||||
const body = Object.assign(req.body, ClassesRouter.JSONFromQuery(req.query));
|
||||
const options = ClassesRouter.optionsFromBody(body);
|
||||
|
||||
return rest
|
||||
@@ -42,14 +39,9 @@ export class AudiencesRouter extends ClassesRouter {
|
||||
}
|
||||
|
||||
mountRoutes() {
|
||||
this.route(
|
||||
'GET',
|
||||
'/push_audiences',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
req => {
|
||||
return this.handleFind(req);
|
||||
}
|
||||
);
|
||||
this.route('GET', '/push_audiences', middleware.promiseEnforceMasterKeyAccess, req => {
|
||||
return this.handleFind(req);
|
||||
});
|
||||
this.route(
|
||||
'GET',
|
||||
'/push_audiences/:objectId',
|
||||
@@ -58,14 +50,9 @@ export class AudiencesRouter extends ClassesRouter {
|
||||
return this.handleGet(req);
|
||||
}
|
||||
);
|
||||
this.route(
|
||||
'POST',
|
||||
'/push_audiences',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
req => {
|
||||
return this.handleCreate(req);
|
||||
}
|
||||
);
|
||||
this.route('POST', '/push_audiences', middleware.promiseEnforceMasterKeyAccess, req => {
|
||||
return this.handleCreate(req);
|
||||
});
|
||||
this.route(
|
||||
'PUT',
|
||||
'/push_audiences/:objectId',
|
||||
|
||||
@@ -19,10 +19,7 @@ export class ClassesRouter extends PromiseRouter {
|
||||
}
|
||||
|
||||
handleFind(req) {
|
||||
const body = Object.assign(
|
||||
req.body,
|
||||
ClassesRouter.JSONFromQuery(req.query)
|
||||
);
|
||||
const body = Object.assign(req.body, ClassesRouter.JSONFromQuery(req.query));
|
||||
const options = ClassesRouter.optionsFromBody(body);
|
||||
if (req.config.maxLimit && body.limit > req.config.maxLimit) {
|
||||
// Silently replace the limit on the query with the max configured
|
||||
@@ -51,18 +48,12 @@ export class ClassesRouter extends PromiseRouter {
|
||||
|
||||
// Returns a promise for a {response} object.
|
||||
handleGet(req) {
|
||||
const body = Object.assign(
|
||||
req.body,
|
||||
ClassesRouter.JSONFromQuery(req.query)
|
||||
);
|
||||
const body = Object.assign(req.body, ClassesRouter.JSONFromQuery(req.query));
|
||||
const options = {};
|
||||
|
||||
for (const key of Object.keys(body)) {
|
||||
if (ALLOWED_GET_QUERY_KEYS.indexOf(key) === -1) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_QUERY,
|
||||
'Improper encode of parameter'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Improper encode of parameter');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,10 +87,7 @@ export class ClassesRouter extends PromiseRouter {
|
||||
)
|
||||
.then(response => {
|
||||
if (!response.results || response.results.length == 0) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Object not found.'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Object not found.');
|
||||
}
|
||||
|
||||
if (this.className(req) === '_User') {
|
||||
@@ -142,13 +130,7 @@ export class ClassesRouter extends PromiseRouter {
|
||||
|
||||
handleDelete(req) {
|
||||
return rest
|
||||
.del(
|
||||
req.config,
|
||||
req.auth,
|
||||
this.className(req),
|
||||
req.params.objectId,
|
||||
req.info.context
|
||||
)
|
||||
.del(req.config, req.auth, this.className(req), req.params.objectId, req.info.context)
|
||||
.then(() => {
|
||||
return { response: {} };
|
||||
});
|
||||
@@ -187,10 +169,7 @@ export class ClassesRouter extends PromiseRouter {
|
||||
|
||||
for (const key of Object.keys(body)) {
|
||||
if (allowConstraints.indexOf(key) === -1) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_QUERY,
|
||||
`Invalid parameter for query: ${key}`
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, `Invalid parameter for query: ${key}`);
|
||||
}
|
||||
}
|
||||
const options = {};
|
||||
@@ -229,10 +208,7 @@ export class ClassesRouter extends PromiseRouter {
|
||||
if (typeof body.subqueryReadPreference === 'string') {
|
||||
options.subqueryReadPreference = body.subqueryReadPreference;
|
||||
}
|
||||
if (
|
||||
body.hint &&
|
||||
(typeof body.hint === 'string' || typeof body.hint === 'object')
|
||||
) {
|
||||
if (body.hint && (typeof body.hint === 'string' || typeof body.hint === 'object')) {
|
||||
options.hint = body.hint;
|
||||
}
|
||||
if (body.explain) {
|
||||
@@ -251,14 +227,9 @@ export class ClassesRouter extends PromiseRouter {
|
||||
this.route('POST', '/classes/:className', promiseEnsureIdempotency, req => {
|
||||
return this.handleCreate(req);
|
||||
});
|
||||
this.route(
|
||||
'PUT',
|
||||
'/classes/:className/:objectId',
|
||||
promiseEnsureIdempotency,
|
||||
req => {
|
||||
return this.handleUpdate(req);
|
||||
}
|
||||
);
|
||||
this.route('PUT', '/classes/:className/:objectId', promiseEnsureIdempotency, req => {
|
||||
return this.handleUpdate(req);
|
||||
});
|
||||
this.route('DELETE', '/classes/:className/:objectId', req => {
|
||||
return this.handleDelete(req);
|
||||
});
|
||||
|
||||
@@ -56,28 +56,24 @@ export class CloudCodeRouter extends PromiseRouter {
|
||||
}
|
||||
|
||||
static getJobs(req) {
|
||||
return rest
|
||||
.find(req.config, req.auth, '_JobSchedule', {}, {})
|
||||
.then(scheduledJobs => {
|
||||
return {
|
||||
response: scheduledJobs.results,
|
||||
};
|
||||
});
|
||||
return rest.find(req.config, req.auth, '_JobSchedule', {}, {}).then(scheduledJobs => {
|
||||
return {
|
||||
response: scheduledJobs.results,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
static getJobsData(req) {
|
||||
const config = req.config;
|
||||
const jobs = triggers.getJobs(config.applicationId) || {};
|
||||
return rest
|
||||
.find(req.config, req.auth, '_JobSchedule', {}, {})
|
||||
.then(scheduledJobs => {
|
||||
return {
|
||||
response: {
|
||||
in_use: scheduledJobs.results.map(job => job.jobName),
|
||||
jobs: Object.keys(jobs),
|
||||
},
|
||||
};
|
||||
});
|
||||
return rest.find(req.config, req.auth, '_JobSchedule', {}, {}).then(scheduledJobs => {
|
||||
return {
|
||||
response: {
|
||||
in_use: scheduledJobs.results.map(job => job.jobName),
|
||||
jobs: Object.keys(jobs),
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
static createJob(req) {
|
||||
|
||||
@@ -4,61 +4,56 @@ import * as middleware from '../middlewares';
|
||||
|
||||
export class FeaturesRouter extends PromiseRouter {
|
||||
mountRoutes() {
|
||||
this.route(
|
||||
'GET',
|
||||
'/serverInfo',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
req => {
|
||||
const { config } = req;
|
||||
const features = {
|
||||
globalConfig: {
|
||||
create: true,
|
||||
read: true,
|
||||
update: true,
|
||||
delete: true,
|
||||
},
|
||||
hooks: {
|
||||
create: true,
|
||||
read: true,
|
||||
update: true,
|
||||
delete: true,
|
||||
},
|
||||
cloudCode: {
|
||||
jobs: true,
|
||||
},
|
||||
logs: {
|
||||
level: true,
|
||||
size: true,
|
||||
order: true,
|
||||
until: true,
|
||||
from: true,
|
||||
},
|
||||
push: {
|
||||
immediatePush: config.hasPushSupport,
|
||||
scheduledPush: config.hasPushScheduledSupport,
|
||||
storedPushData: config.hasPushSupport,
|
||||
pushAudiences: true,
|
||||
localization: true,
|
||||
},
|
||||
schemas: {
|
||||
addField: true,
|
||||
removeField: true,
|
||||
addClass: true,
|
||||
removeClass: true,
|
||||
clearAllDataFromClass: true,
|
||||
exportClass: false,
|
||||
editClassLevelPermissions: true,
|
||||
editPointerPermissions: true,
|
||||
},
|
||||
};
|
||||
this.route('GET', '/serverInfo', middleware.promiseEnforceMasterKeyAccess, req => {
|
||||
const { config } = req;
|
||||
const features = {
|
||||
globalConfig: {
|
||||
create: true,
|
||||
read: true,
|
||||
update: true,
|
||||
delete: true,
|
||||
},
|
||||
hooks: {
|
||||
create: true,
|
||||
read: true,
|
||||
update: true,
|
||||
delete: true,
|
||||
},
|
||||
cloudCode: {
|
||||
jobs: true,
|
||||
},
|
||||
logs: {
|
||||
level: true,
|
||||
size: true,
|
||||
order: true,
|
||||
until: true,
|
||||
from: true,
|
||||
},
|
||||
push: {
|
||||
immediatePush: config.hasPushSupport,
|
||||
scheduledPush: config.hasPushScheduledSupport,
|
||||
storedPushData: config.hasPushSupport,
|
||||
pushAudiences: true,
|
||||
localization: true,
|
||||
},
|
||||
schemas: {
|
||||
addField: true,
|
||||
removeField: true,
|
||||
addClass: true,
|
||||
removeClass: true,
|
||||
clearAllDataFromClass: true,
|
||||
exportClass: false,
|
||||
editClassLevelPermissions: true,
|
||||
editPointerPermissions: true,
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
response: {
|
||||
features: features,
|
||||
parseServerVersion: version,
|
||||
},
|
||||
};
|
||||
}
|
||||
);
|
||||
return {
|
||||
response: {
|
||||
features: features,
|
||||
parseServerVersion: version,
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,9 +40,7 @@ export class FilesRouter {
|
||||
router.get('/files/:appId/metadata/:filename', this.metadataHandler);
|
||||
|
||||
router.post('/files', function (req, res, next) {
|
||||
next(
|
||||
new Parse.Error(Parse.Error.INVALID_FILE_NAME, 'Filename not provided.')
|
||||
);
|
||||
next(new Parse.Error(Parse.Error.INVALID_FILE_NAME, 'Filename not provided.'));
|
||||
});
|
||||
|
||||
router.post(
|
||||
@@ -72,13 +70,11 @@ export class FilesRouter {
|
||||
const filename = req.params.filename;
|
||||
const contentType = mime.getType(filename);
|
||||
if (isFileStreamable(req, filesController)) {
|
||||
filesController
|
||||
.handleFileStream(config, filename, req, res, contentType)
|
||||
.catch(() => {
|
||||
res.status(404);
|
||||
res.set('Content-Type', 'text/plain');
|
||||
res.end('File not found.');
|
||||
});
|
||||
filesController.handleFileStream(config, filename, req, res, contentType).catch(() => {
|
||||
res.status(404);
|
||||
res.set('Content-Type', 'text/plain');
|
||||
res.end('File not found.');
|
||||
});
|
||||
} else {
|
||||
filesController
|
||||
.getFileData(config, filename)
|
||||
@@ -103,9 +99,7 @@ export class FilesRouter {
|
||||
const contentType = req.get('Content-type');
|
||||
|
||||
if (!req.body || !req.body.length) {
|
||||
next(
|
||||
new Parse.Error(Parse.Error.FILE_SAVE_ERROR, 'Invalid file upload.')
|
||||
);
|
||||
next(new Parse.Error(Parse.Error.FILE_SAVE_ERROR, 'Invalid file upload.'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -243,8 +237,5 @@ export class FilesRouter {
|
||||
}
|
||||
|
||||
function isFileStreamable(req, filesController) {
|
||||
return (
|
||||
req.get('Range') &&
|
||||
typeof filesController.adapter.handleFileStream === 'function'
|
||||
);
|
||||
return req.get('Range') && typeof filesController.adapter.handleFileStream === 'function';
|
||||
}
|
||||
|
||||
@@ -4,10 +4,7 @@ var Parse = require('parse/node').Parse,
|
||||
triggers = require('../triggers');
|
||||
|
||||
import PromiseRouter from '../PromiseRouter';
|
||||
import {
|
||||
promiseEnforceMasterKeyAccess,
|
||||
promiseEnsureIdempotency,
|
||||
} from '../middlewares';
|
||||
import { promiseEnforceMasterKeyAccess, promiseEnsureIdempotency } from '../middlewares';
|
||||
import { jobStatusHandler } from '../StatusHandler';
|
||||
import _ from 'lodash';
|
||||
import { logger } from '../logger';
|
||||
@@ -121,10 +118,7 @@ export class FunctionsRouter extends PromiseRouter {
|
||||
const theFunction = triggers.getFunction(functionName, applicationId);
|
||||
|
||||
if (!theFunction) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.SCRIPT_FAILED,
|
||||
`Invalid function: "${functionName}"`
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.SCRIPT_FAILED, `Invalid function: "${functionName}"`);
|
||||
}
|
||||
let params = Object.assign({}, req.body, req.query);
|
||||
params = parseParams(params);
|
||||
@@ -141,15 +135,12 @@ export class FunctionsRouter extends PromiseRouter {
|
||||
};
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
const userString =
|
||||
req.auth && req.auth.user ? req.auth.user.id : undefined;
|
||||
const userString = req.auth && req.auth.user ? req.auth.user.id : undefined;
|
||||
const cleanInput = logger.truncateLogMessage(JSON.stringify(params));
|
||||
const { success, error, message } = FunctionsRouter.createResponseObject(
|
||||
result => {
|
||||
try {
|
||||
const cleanResult = logger.truncateLogMessage(
|
||||
JSON.stringify(result.response.result)
|
||||
);
|
||||
const cleanResult = logger.truncateLogMessage(JSON.stringify(result.response.result));
|
||||
logger.info(
|
||||
`Ran cloud function ${functionName} for user ${userString} with:\n Input: ${cleanInput}\n Result: ${cleanResult}`,
|
||||
{
|
||||
|
||||
@@ -54,14 +54,9 @@ export class GlobalConfigRouter extends PromiseRouter {
|
||||
this.route('GET', '/config', req => {
|
||||
return this.getGlobalConfig(req);
|
||||
});
|
||||
this.route(
|
||||
'PUT',
|
||||
'/config',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
req => {
|
||||
return this.updateGlobalConfig(req);
|
||||
}
|
||||
);
|
||||
this.route('PUT', '/config', middleware.promiseEnforceMasterKeyAccess, req => {
|
||||
return this.updateGlobalConfig(req);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,31 +19,19 @@ export class GraphQLRouter extends PromiseRouter {
|
||||
"read-only masterKey isn't allowed to update the GraphQL config."
|
||||
);
|
||||
}
|
||||
const data = await req.config.parseGraphQLController.updateGraphQLConfig(
|
||||
req.body.params
|
||||
);
|
||||
const data = await req.config.parseGraphQLController.updateGraphQLConfig(req.body.params);
|
||||
return {
|
||||
response: data,
|
||||
};
|
||||
}
|
||||
|
||||
mountRoutes() {
|
||||
this.route(
|
||||
'GET',
|
||||
GraphQLConfigPath,
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
req => {
|
||||
return this.getGraphQLConfig(req);
|
||||
}
|
||||
);
|
||||
this.route(
|
||||
'PUT',
|
||||
GraphQLConfigPath,
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
req => {
|
||||
return this.updateGraphQLConfig(req);
|
||||
}
|
||||
);
|
||||
this.route('GET', GraphQLConfigPath, middleware.promiseEnforceMasterKeyAccess, req => {
|
||||
return this.getGraphQLConfig(req);
|
||||
});
|
||||
this.route('PUT', GraphQLConfigPath, middleware.promiseEnforceMasterKeyAccess, req => {
|
||||
return this.updateGraphQLConfig(req);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,15 +4,11 @@ import * as middleware from '../middlewares';
|
||||
|
||||
export class HooksRouter extends PromiseRouter {
|
||||
createHook(aHook, config) {
|
||||
return config.hooksController
|
||||
.createHook(aHook)
|
||||
.then(hook => ({ response: hook }));
|
||||
return config.hooksController.createHook(aHook).then(hook => ({ response: hook }));
|
||||
}
|
||||
|
||||
updateHook(aHook, config) {
|
||||
return config.hooksController
|
||||
.updateHook(aHook)
|
||||
.then(hook => ({ response: hook }));
|
||||
return config.hooksController.updateHook(aHook).then(hook => ({ response: hook }));
|
||||
}
|
||||
|
||||
handlePost(req) {
|
||||
@@ -22,17 +18,12 @@ export class HooksRouter extends PromiseRouter {
|
||||
handleGetFunctions(req) {
|
||||
var hooksController = req.config.hooksController;
|
||||
if (req.params.functionName) {
|
||||
return hooksController
|
||||
.getFunction(req.params.functionName)
|
||||
.then(foundFunction => {
|
||||
if (!foundFunction) {
|
||||
throw new Parse.Error(
|
||||
143,
|
||||
`no function named: ${req.params.functionName} is defined`
|
||||
);
|
||||
}
|
||||
return Promise.resolve({ response: foundFunction });
|
||||
});
|
||||
return hooksController.getFunction(req.params.functionName).then(foundFunction => {
|
||||
if (!foundFunction) {
|
||||
throw new Parse.Error(143, `no function named: ${req.params.functionName} is defined`);
|
||||
}
|
||||
return Promise.resolve({ response: foundFunction });
|
||||
});
|
||||
}
|
||||
|
||||
return hooksController.getFunctions().then(
|
||||
@@ -52,26 +43,19 @@ export class HooksRouter extends PromiseRouter {
|
||||
.getTrigger(req.params.className, req.params.triggerName)
|
||||
.then(foundTrigger => {
|
||||
if (!foundTrigger) {
|
||||
throw new Parse.Error(
|
||||
143,
|
||||
`class ${req.params.className} does not exist`
|
||||
);
|
||||
throw new Parse.Error(143, `class ${req.params.className} does not exist`);
|
||||
}
|
||||
return Promise.resolve({ response: foundTrigger });
|
||||
});
|
||||
}
|
||||
|
||||
return hooksController
|
||||
.getTriggers()
|
||||
.then(triggers => ({ response: triggers || [] }));
|
||||
return hooksController.getTriggers().then(triggers => ({ response: triggers || [] }));
|
||||
}
|
||||
|
||||
handleDelete(req) {
|
||||
var hooksController = req.config.hooksController;
|
||||
if (req.params.functionName) {
|
||||
return hooksController
|
||||
.deleteFunction(req.params.functionName)
|
||||
.then(() => ({ response: {} }));
|
||||
return hooksController.deleteFunction(req.params.functionName).then(() => ({ response: {} }));
|
||||
} else if (req.params.className && req.params.triggerName) {
|
||||
return hooksController
|
||||
.deleteTrigger(req.params.className, req.params.triggerName)
|
||||
|
||||
@@ -58,10 +58,7 @@ function getFileForProductIdentifier(productIdentifier, req) {
|
||||
const products = result.results;
|
||||
if (!products || products.length != 1) {
|
||||
// Error not found or too many
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Object not found.'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Object not found.');
|
||||
}
|
||||
|
||||
var download = products[0].download;
|
||||
@@ -76,10 +73,7 @@ export class IAPValidationRouter extends PromiseRouter {
|
||||
|
||||
if (!receipt || !productIdentifier) {
|
||||
// TODO: Error, malformed request
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_JSON,
|
||||
'missing receipt or productIdentifier'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, 'missing receipt or productIdentifier');
|
||||
}
|
||||
|
||||
// Transform the object if there
|
||||
|
||||
@@ -10,10 +10,7 @@ export class InstallationsRouter extends ClassesRouter {
|
||||
}
|
||||
|
||||
handleFind(req) {
|
||||
const body = Object.assign(
|
||||
req.body,
|
||||
ClassesRouter.JSONFromQuery(req.query)
|
||||
);
|
||||
const body = Object.assign(req.body, ClassesRouter.JSONFromQuery(req.query));
|
||||
const options = ClassesRouter.optionsFromBody(body);
|
||||
return rest
|
||||
.find(
|
||||
@@ -40,14 +37,9 @@ export class InstallationsRouter extends ClassesRouter {
|
||||
this.route('POST', '/installations', promiseEnsureIdempotency, req => {
|
||||
return this.handleCreate(req);
|
||||
});
|
||||
this.route(
|
||||
'PUT',
|
||||
'/installations/:objectId',
|
||||
promiseEnsureIdempotency,
|
||||
req => {
|
||||
return this.handleUpdate(req);
|
||||
}
|
||||
);
|
||||
this.route('PUT', '/installations/:objectId', promiseEnsureIdempotency, req => {
|
||||
return this.handleUpdate(req);
|
||||
});
|
||||
this.route('DELETE', '/installations/:objectId', req => {
|
||||
return this.handleDelete(req);
|
||||
});
|
||||
|
||||
@@ -17,10 +17,7 @@ export class LogsRouter extends PromiseRouter {
|
||||
|
||||
validateRequest(req) {
|
||||
if (!req.config || !req.config.loggerController) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.PUSH_MISCONFIGURED,
|
||||
'Logger adapter is not available'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED, 'Logger adapter is not available');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,7 @@ const views = path.resolve(__dirname, '../../views');
|
||||
export class PublicAPIRouter extends PromiseRouter {
|
||||
verifyEmail(req) {
|
||||
const { username, token: rawToken } = req.query;
|
||||
const token =
|
||||
rawToken && typeof rawToken !== 'string' ? rawToken.toString() : rawToken;
|
||||
const token = rawToken && typeof rawToken !== 'string' ? rawToken.toString() : rawToken;
|
||||
|
||||
const appId = req.params.appId;
|
||||
const config = Config.get(appId);
|
||||
@@ -95,22 +94,15 @@ export class PublicAPIRouter extends PromiseRouter {
|
||||
});
|
||||
}
|
||||
// Should we keep the file in memory or leave like that?
|
||||
fs.readFile(
|
||||
path.resolve(views, 'choose_password'),
|
||||
'utf-8',
|
||||
(err, data) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
data = data.replace(
|
||||
'PARSE_SERVER_URL',
|
||||
`'${config.publicServerURL}'`
|
||||
);
|
||||
resolve({
|
||||
text: data,
|
||||
});
|
||||
fs.readFile(path.resolve(views, 'choose_password'), 'utf-8', (err, data) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
);
|
||||
data = data.replace('PARSE_SERVER_URL', `'${config.publicServerURL}'`);
|
||||
resolve({
|
||||
text: data,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -126,8 +118,7 @@ export class PublicAPIRouter extends PromiseRouter {
|
||||
}
|
||||
|
||||
const { username, token: rawToken } = req.query;
|
||||
const token =
|
||||
rawToken && typeof rawToken !== 'string' ? rawToken.toString() : rawToken;
|
||||
const token = rawToken && typeof rawToken !== 'string' ? rawToken.toString() : rawToken;
|
||||
|
||||
if (!username || !token) {
|
||||
return this.invalidLink(req);
|
||||
@@ -164,8 +155,7 @@ export class PublicAPIRouter extends PromiseRouter {
|
||||
}
|
||||
|
||||
const { username, new_password, token: rawToken } = req.body;
|
||||
const token =
|
||||
rawToken && typeof rawToken !== 'string' ? rawToken.toString() : rawToken;
|
||||
const token = rawToken && typeof rawToken !== 'string' ? rawToken.toString() : rawToken;
|
||||
|
||||
if ((!username || !token || !new_password) && req.xhr === false) {
|
||||
return this.invalidLink(req);
|
||||
|
||||
@@ -30,14 +30,9 @@ export class PurgeRouter extends PromiseRouter {
|
||||
}
|
||||
|
||||
mountRoutes() {
|
||||
this.route(
|
||||
'DELETE',
|
||||
'/purge/:className',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
req => {
|
||||
return this.handlePurge(req);
|
||||
}
|
||||
);
|
||||
this.route('DELETE', '/purge/:className', middleware.promiseEnforceMasterKeyAccess, req => {
|
||||
return this.handlePurge(req);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,7 @@ import { Parse } from 'parse/node';
|
||||
|
||||
export class PushRouter extends PromiseRouter {
|
||||
mountRoutes() {
|
||||
this.route(
|
||||
'POST',
|
||||
'/push',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
PushRouter.handlePOST
|
||||
);
|
||||
this.route('POST', '/push', middleware.promiseEnforceMasterKeyAccess, PushRouter.handlePOST);
|
||||
}
|
||||
|
||||
static handlePOST(req) {
|
||||
@@ -21,10 +16,7 @@ export class PushRouter extends PromiseRouter {
|
||||
}
|
||||
const pushController = req.config.pushController;
|
||||
if (!pushController) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.PUSH_MISCONFIGURED,
|
||||
'Push controller is not set'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED, 'Push controller is not set');
|
||||
}
|
||||
|
||||
const where = PushRouter.getQueryCondition(req);
|
||||
|
||||
@@ -28,15 +28,9 @@ function getOneSchema(req) {
|
||||
.then(schema => ({ response: schema }))
|
||||
.catch(error => {
|
||||
if (error === undefined) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_CLASS_NAME,
|
||||
`Class ${className} does not exist.`
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, `Class ${className} does not exist.`);
|
||||
} else {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INTERNAL_SERVER_ERROR,
|
||||
'Database adapter error.'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'Database adapter error.');
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -50,10 +44,7 @@ function createSchema(req) {
|
||||
}
|
||||
if (req.params.className && req.body.className) {
|
||||
if (req.params.className != req.body.className) {
|
||||
return classNameMismatchResponse(
|
||||
req.body.className,
|
||||
req.params.className
|
||||
);
|
||||
return classNameMismatchResponse(req.body.className, req.params.className);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,31 +107,19 @@ const deleteSchema = req => {
|
||||
SchemaController.invalidClassNameMessage(req.params.className)
|
||||
);
|
||||
}
|
||||
return req.config.database
|
||||
.deleteSchema(req.params.className)
|
||||
.then(() => ({ response: {} }));
|
||||
return req.config.database.deleteSchema(req.params.className).then(() => ({ response: {} }));
|
||||
};
|
||||
|
||||
export class SchemasRouter extends PromiseRouter {
|
||||
mountRoutes() {
|
||||
this.route(
|
||||
'GET',
|
||||
'/schemas',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
getAllSchemas
|
||||
);
|
||||
this.route('GET', '/schemas', middleware.promiseEnforceMasterKeyAccess, getAllSchemas);
|
||||
this.route(
|
||||
'GET',
|
||||
'/schemas/:className',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
getOneSchema
|
||||
);
|
||||
this.route(
|
||||
'POST',
|
||||
'/schemas',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
createSchema
|
||||
);
|
||||
this.route('POST', '/schemas', middleware.promiseEnforceMasterKeyAccess, createSchema);
|
||||
this.route(
|
||||
'POST',
|
||||
'/schemas/:className',
|
||||
|
||||
@@ -11,10 +11,7 @@ export class SessionsRouter extends ClassesRouter {
|
||||
handleMe(req) {
|
||||
// TODO: Verify correct behavior
|
||||
if (!req.info || !req.info.sessionToken) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_SESSION_TOKEN,
|
||||
'Session token required.'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'Session token required.');
|
||||
}
|
||||
return rest
|
||||
.find(
|
||||
@@ -28,10 +25,7 @@ export class SessionsRouter extends ClassesRouter {
|
||||
)
|
||||
.then(response => {
|
||||
if (!response.results || response.results.length == 0) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_SESSION_TOKEN,
|
||||
'Session token not found.'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'Session token not found.');
|
||||
}
|
||||
return {
|
||||
response: response.results[0],
|
||||
|
||||
@@ -50,26 +50,17 @@ export class UsersRouter extends ClassesRouter {
|
||||
|
||||
// TODO: use the right error codes / descriptions.
|
||||
if (!username && !email) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.USERNAME_MISSING,
|
||||
'username/email is required.'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.USERNAME_MISSING, 'username/email is required.');
|
||||
}
|
||||
if (!password) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.PASSWORD_MISSING,
|
||||
'password is required.'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.PASSWORD_MISSING, 'password is required.');
|
||||
}
|
||||
if (
|
||||
typeof password !== 'string' ||
|
||||
(email && typeof email !== 'string') ||
|
||||
(username && typeof username !== 'string')
|
||||
) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Invalid username/password.'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Invalid username/password.');
|
||||
}
|
||||
|
||||
let user;
|
||||
@@ -86,10 +77,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
.find('_User', query)
|
||||
.then(results => {
|
||||
if (!results.length) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Invalid username/password.'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Invalid username/password.');
|
||||
}
|
||||
|
||||
if (results.length > 1) {
|
||||
@@ -111,34 +99,21 @@ export class UsersRouter extends ClassesRouter {
|
||||
})
|
||||
.then(() => {
|
||||
if (!isValidPassword) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Invalid username/password.'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Invalid username/password.');
|
||||
}
|
||||
// Ensure the user isn't locked out
|
||||
// A locked out user won't be able to login
|
||||
// To lock a user out, just set the ACL to `masterKey` only ({}).
|
||||
// Empty ACL is OK
|
||||
if (
|
||||
!req.auth.isMaster &&
|
||||
user.ACL &&
|
||||
Object.keys(user.ACL).length == 0
|
||||
) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Invalid username/password.'
|
||||
);
|
||||
if (!req.auth.isMaster && user.ACL && Object.keys(user.ACL).length == 0) {
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Invalid username/password.');
|
||||
}
|
||||
if (
|
||||
req.config.verifyUserEmails &&
|
||||
req.config.preventLoginWithUnverifiedEmail &&
|
||||
!user.emailVerified
|
||||
) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.EMAIL_NOT_FOUND,
|
||||
'User email is not verified.'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.EMAIL_NOT_FOUND, 'User email is not verified.');
|
||||
}
|
||||
|
||||
delete user.password;
|
||||
@@ -166,10 +141,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
|
||||
handleMe(req) {
|
||||
if (!req.info || !req.info.sessionToken) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_SESSION_TOKEN,
|
||||
'Invalid session token'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'Invalid session token');
|
||||
}
|
||||
const sessionToken = req.info.sessionToken;
|
||||
return rest
|
||||
@@ -183,15 +155,8 @@ export class UsersRouter extends ClassesRouter {
|
||||
req.info.context
|
||||
)
|
||||
.then(response => {
|
||||
if (
|
||||
!response.results ||
|
||||
response.results.length == 0 ||
|
||||
!response.results[0].user
|
||||
) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_SESSION_TOKEN,
|
||||
'Invalid session token'
|
||||
);
|
||||
if (!response.results || response.results.length == 0 || !response.results[0].user) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'Invalid session token');
|
||||
} else {
|
||||
const user = response.results[0].user;
|
||||
// Send token back on the login, because SDKs expect that.
|
||||
@@ -228,8 +193,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
}
|
||||
// Calculate the expiry time.
|
||||
const expiresAt = new Date(
|
||||
changedAt.getTime() +
|
||||
86400000 * req.config.passwordPolicy.maxPasswordAge
|
||||
changedAt.getTime() + 86400000 * req.config.passwordPolicy.maxPasswordAge
|
||||
);
|
||||
if (expiresAt < new Date())
|
||||
// fail of current time is past password expiry time
|
||||
@@ -267,9 +231,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
|
||||
await createSession();
|
||||
|
||||
const afterLoginUser = Parse.User.fromJSON(
|
||||
Object.assign({ className: '_User' }, user)
|
||||
);
|
||||
const afterLoginUser = Parse.User.fromJSON(Object.assign({ className: '_User' }, user));
|
||||
maybeRunTrigger(
|
||||
TriggerTypes.afterLogin,
|
||||
{ ...req.auth, user: afterLoginUser },
|
||||
@@ -345,8 +307,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
emailAdapter: req.config.userController.adapter,
|
||||
appName: req.config.appName,
|
||||
publicServerURL: req.config.publicServerURL,
|
||||
emailVerifyTokenValidityDuration:
|
||||
req.config.emailVerifyTokenValidityDuration,
|
||||
emailVerifyTokenValidityDuration: req.config.emailVerifyTokenValidityDuration,
|
||||
});
|
||||
} catch (e) {
|
||||
if (typeof e === 'string') {
|
||||
@@ -366,10 +327,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
|
||||
const { email } = req.body;
|
||||
if (!email) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.EMAIL_MISSING,
|
||||
'you must provide an email'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.EMAIL_MISSING, 'you must provide an email');
|
||||
}
|
||||
if (typeof email !== 'string') {
|
||||
throw new Parse.Error(
|
||||
@@ -403,10 +361,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
|
||||
const { email } = req.body;
|
||||
if (!email) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.EMAIL_MISSING,
|
||||
'you must provide an email'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.EMAIL_MISSING, 'you must provide an email');
|
||||
}
|
||||
if (typeof email !== 'string') {
|
||||
throw new Parse.Error(
|
||||
@@ -417,10 +372,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
|
||||
return req.config.database.find('_User', { email: email }).then(results => {
|
||||
if (!results.length || results.length < 1) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.EMAIL_NOT_FOUND,
|
||||
`No user found with email ${email}`
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.EMAIL_NOT_FOUND, `No user found with email ${email}`);
|
||||
}
|
||||
const user = results[0];
|
||||
|
||||
@@ -428,10 +380,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
delete user.password;
|
||||
|
||||
if (user.emailVerified) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OTHER_CAUSE,
|
||||
`Email ${email} is already verified.`
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.OTHER_CAUSE, `Email ${email} is already verified.`);
|
||||
}
|
||||
|
||||
const userController = req.config.userController;
|
||||
|
||||
Reference in New Issue
Block a user