Enable prefer-const lint rule (#3202)
This commit is contained in:
committed by
Florent Vilmart
parent
a6c988176e
commit
ca286b7108
@@ -42,14 +42,14 @@ export class AdaptableController {
|
||||
throw new Error(this.constructor.name+" requires an adapter");
|
||||
}
|
||||
|
||||
let Type = this.expectedAdapterType();
|
||||
const Type = this.expectedAdapterType();
|
||||
// Allow skipping for testing
|
||||
if (!Type) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Makes sure the prototype matches
|
||||
let mismatches = Object.getOwnPropertyNames(Type.prototype).reduce((obj, key) => {
|
||||
const mismatches = Object.getOwnPropertyNames(Type.prototype).reduce((obj, key) => {
|
||||
const adapterType = typeof adapter[key];
|
||||
const expectedType = typeof Type.prototype[key];
|
||||
if (adapterType !== expectedType) {
|
||||
|
||||
@@ -20,17 +20,17 @@ export class SubCache {
|
||||
}
|
||||
|
||||
get(key) {
|
||||
let cacheKey = joinKeys(this.prefix, key);
|
||||
const cacheKey = joinKeys(this.prefix, key);
|
||||
return this.cache.get(cacheKey);
|
||||
}
|
||||
|
||||
put(key, value, ttl) {
|
||||
let cacheKey = joinKeys(this.prefix, key);
|
||||
const cacheKey = joinKeys(this.prefix, key);
|
||||
return this.cache.put(cacheKey, value, ttl);
|
||||
}
|
||||
|
||||
del(key) {
|
||||
let cacheKey = joinKeys(this.prefix, key);
|
||||
const cacheKey = joinKeys(this.prefix, key);
|
||||
return this.cache.del(cacheKey);
|
||||
}
|
||||
|
||||
@@ -50,17 +50,17 @@ export class CacheController extends AdaptableController {
|
||||
}
|
||||
|
||||
get(key) {
|
||||
let cacheKey = joinKeys(this.appId, key);
|
||||
const cacheKey = joinKeys(this.appId, key);
|
||||
return this.adapter.get(cacheKey).then(null, () => Promise.resolve(null));
|
||||
}
|
||||
|
||||
put(key, value, ttl) {
|
||||
let cacheKey = joinKeys(this.appId, key);
|
||||
const cacheKey = joinKeys(this.appId, key);
|
||||
return this.adapter.put(cacheKey, value, ttl);
|
||||
}
|
||||
|
||||
del(key) {
|
||||
let cacheKey = joinKeys(this.appId, key);
|
||||
const cacheKey = joinKeys(this.appId, key);
|
||||
return this.adapter.del(cacheKey);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,14 +9,14 @@ import logger from '../logger';
|
||||
import * as SchemaController from './SchemaController';
|
||||
|
||||
function addWriteACL(query, acl) {
|
||||
let newQuery = _.cloneDeep(query);
|
||||
const newQuery = _.cloneDeep(query);
|
||||
//Can't be any existing '_wperm' query, we don't allow client queries on that, no need to $and
|
||||
newQuery._wperm = { "$in" : [null, ...acl]};
|
||||
return newQuery;
|
||||
}
|
||||
|
||||
function addReadACL(query, acl) {
|
||||
let newQuery = _.cloneDeep(query);
|
||||
const newQuery = _.cloneDeep(query);
|
||||
//Can't be any existing '_rperm' query, we don't allow client queries on that, no need to $and
|
||||
newQuery._rperm = { "$in" : [null, "*", ...acl]};
|
||||
return newQuery;
|
||||
@@ -31,7 +31,7 @@ const transformObjectACL = ({ ACL, ...result }) => {
|
||||
result._wperm = [];
|
||||
result._rperm = [];
|
||||
|
||||
for (let entry in ACL) {
|
||||
for (const entry in ACL) {
|
||||
if (ACL[entry].read) {
|
||||
result._rperm.push(entry);
|
||||
}
|
||||
@@ -139,7 +139,7 @@ DatabaseController.prototype.redirectClassNameForKey = function(className, key)
|
||||
// batch request, that could confuse other users of the schema.
|
||||
DatabaseController.prototype.validateObject = function(className, object, query, { acl }) {
|
||||
let schema;
|
||||
let isMaster = acl === undefined;
|
||||
const isMaster = acl === undefined;
|
||||
var aclGroup = acl || [];
|
||||
return this.loadSchema().then(s => {
|
||||
schema = s;
|
||||
@@ -241,7 +241,7 @@ DatabaseController.prototype.update = function(className, query, update, {
|
||||
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid field name for update: ${fieldName}`);
|
||||
}
|
||||
});
|
||||
for (let updateOperation in update) {
|
||||
for (const updateOperation in update) {
|
||||
if (Object.keys(updateOperation).some(innerKey => innerKey.includes('$') || innerKey.includes('.'))) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_NESTED_KEY, "Nested keys should not contain the '$' or '.' characters");
|
||||
}
|
||||
@@ -270,12 +270,12 @@ DatabaseController.prototype.update = function(className, query, update, {
|
||||
};
|
||||
|
||||
function sanitizeDatabaseResult(originalObject, result) {
|
||||
let response = {};
|
||||
const response = {};
|
||||
if (!result) {
|
||||
return Promise.resolve(response);
|
||||
}
|
||||
Object.keys(originalObject).forEach(key => {
|
||||
let keyUpdate = originalObject[key];
|
||||
const keyUpdate = originalObject[key];
|
||||
// determine if that was an op
|
||||
if (keyUpdate && typeof keyUpdate === 'object' && keyUpdate.__op
|
||||
&& ['Add', 'AddUnique', 'Remove', 'Increment'].indexOf(keyUpdate.__op) > -1) {
|
||||
@@ -300,7 +300,7 @@ DatabaseController.prototype.handleRelationUpdates = function(className, objectI
|
||||
return;
|
||||
}
|
||||
if (op.__op == 'AddRelation') {
|
||||
for (let object of op.objects) {
|
||||
for (const object of op.objects) {
|
||||
pending.push(this.addRelation(key, className,
|
||||
objectId,
|
||||
object.objectId));
|
||||
@@ -309,7 +309,7 @@ DatabaseController.prototype.handleRelationUpdates = function(className, objectI
|
||||
}
|
||||
|
||||
if (op.__op == 'RemoveRelation') {
|
||||
for (let object of op.objects) {
|
||||
for (const object of op.objects) {
|
||||
pending.push(this.removeRelation(key, className,
|
||||
objectId,
|
||||
object.objectId));
|
||||
@@ -324,10 +324,10 @@ DatabaseController.prototype.handleRelationUpdates = function(className, objectI
|
||||
}
|
||||
};
|
||||
|
||||
for (let key in update) {
|
||||
for (const key in update) {
|
||||
process(update[key], key);
|
||||
}
|
||||
for (let key of deleteMe) {
|
||||
for (const key of deleteMe) {
|
||||
delete update[key];
|
||||
}
|
||||
return Promise.all(pending);
|
||||
@@ -337,7 +337,7 @@ DatabaseController.prototype.handleRelationUpdates = function(className, objectI
|
||||
// Returns a promise that resolves successfully iff the add was successful.
|
||||
const relationSchema = { fields: { relatedId: { type: 'String' }, owningId: { type: 'String' } } };
|
||||
DatabaseController.prototype.addRelation = function(key, fromClassName, fromId, toId) {
|
||||
let doc = {
|
||||
const doc = {
|
||||
relatedId: toId,
|
||||
owningId : fromId
|
||||
};
|
||||
@@ -410,7 +410,7 @@ DatabaseController.prototype.destroy = function(className, query, { acl } = {})
|
||||
};
|
||||
|
||||
const flattenUpdateOperatorsForCreate = object => {
|
||||
for (let key in object) {
|
||||
for (const key in object) {
|
||||
if (object[key] && object[key].__op) {
|
||||
switch (object[key].__op) {
|
||||
case 'Increment':
|
||||
@@ -469,7 +469,7 @@ const transformAuthData = (className, object, schema) => {
|
||||
// Returns a promise that resolves successfully iff the object saved.
|
||||
DatabaseController.prototype.create = function(className, object, { acl } = {}) {
|
||||
// Make a copy of the object, so we don't mutate the incoming data.
|
||||
let originalObject = object;
|
||||
const originalObject = object;
|
||||
object = transformObjectACL(object);
|
||||
|
||||
object.createdAt = { iso: object.createdAt, __type: 'Date' };
|
||||
@@ -496,13 +496,13 @@ DatabaseController.prototype.create = function(className, object, { acl } = {})
|
||||
};
|
||||
|
||||
DatabaseController.prototype.canAddField = function(schema, className, object, aclGroup) {
|
||||
let classSchema = schema.data[className];
|
||||
const classSchema = schema.data[className];
|
||||
if (!classSchema) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
let fields = Object.keys(object);
|
||||
let schemaFields = Object.keys(classSchema);
|
||||
let newKeys = fields.filter((field) => {
|
||||
const fields = Object.keys(object);
|
||||
const schemaFields = Object.keys(classSchema);
|
||||
const newKeys = fields.filter((field) => {
|
||||
return schemaFields.indexOf(field) < 0;
|
||||
})
|
||||
if (newKeys.length > 0) {
|
||||
@@ -543,7 +543,7 @@ DatabaseController.prototype.reduceInRelation = function(className, query, schem
|
||||
// Search for an in-relation or equal-to-relation
|
||||
// Make it sequential for now, not sure of paralleization side effects
|
||||
if (query['$or']) {
|
||||
let ors = query['$or'];
|
||||
const ors = query['$or'];
|
||||
return Promise.all(ors.map((aQuery, index) => {
|
||||
return this.reduceInRelation(className, aQuery, schema).then((aQuery) => {
|
||||
query['$or'][index] = aQuery;
|
||||
@@ -553,14 +553,14 @@ DatabaseController.prototype.reduceInRelation = function(className, query, schem
|
||||
});
|
||||
}
|
||||
|
||||
let promises = Object.keys(query).map((key) => {
|
||||
const promises = Object.keys(query).map((key) => {
|
||||
if (query[key] && (query[key]['$in'] || query[key]['$ne'] || query[key]['$nin'] || query[key].__type == 'Pointer')) {
|
||||
let t = schema.getExpectedType(className, key);
|
||||
const t = schema.getExpectedType(className, key);
|
||||
if (!t || t.type !== 'Relation') {
|
||||
return Promise.resolve(query);
|
||||
}
|
||||
// Build the list of queries
|
||||
let queries = Object.keys(query[key]).map((constraintKey) => {
|
||||
const queries = Object.keys(query[key]).map((constraintKey) => {
|
||||
let relatedIds;
|
||||
let isNegation = false;
|
||||
if (constraintKey === 'objectId') {
|
||||
@@ -586,7 +586,7 @@ DatabaseController.prototype.reduceInRelation = function(className, query, schem
|
||||
delete query[key];
|
||||
// execute each query independnently to build the list of
|
||||
// $in / $nin
|
||||
let promises = queries.map((q) => {
|
||||
const promises = queries.map((q) => {
|
||||
if (!q) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
@@ -637,12 +637,12 @@ DatabaseController.prototype.reduceRelationKeys = function(className, query) {
|
||||
};
|
||||
|
||||
DatabaseController.prototype.addInObjectIdsIds = function(ids = null, query) {
|
||||
let idsFromString = typeof query.objectId === 'string' ? [query.objectId] : null;
|
||||
let idsFromEq = query.objectId && query.objectId['$eq'] ? [query.objectId['$eq']] : null;
|
||||
let idsFromIn = query.objectId && query.objectId['$in'] ? query.objectId['$in'] : null;
|
||||
const idsFromString = typeof query.objectId === 'string' ? [query.objectId] : null;
|
||||
const idsFromEq = query.objectId && query.objectId['$eq'] ? [query.objectId['$eq']] : null;
|
||||
const idsFromIn = query.objectId && query.objectId['$in'] ? query.objectId['$in'] : null;
|
||||
|
||||
let allIds = [idsFromString, idsFromEq, idsFromIn, ids].filter(list => list !== null);
|
||||
let totalLength = allIds.reduce((memo, list) => memo + list.length, 0);
|
||||
const allIds = [idsFromString, idsFromEq, idsFromIn, ids].filter(list => list !== null);
|
||||
const totalLength = allIds.reduce((memo, list) => memo + list.length, 0);
|
||||
|
||||
let idsIntersection = [];
|
||||
if (totalLength > 125) {
|
||||
@@ -665,7 +665,7 @@ DatabaseController.prototype.addInObjectIdsIds = function(ids = null, query) {
|
||||
}
|
||||
|
||||
DatabaseController.prototype.addNotInObjectIdsIds = function(ids = [], query) {
|
||||
let idsFromNin = query.objectId && query.objectId['$nin'] ? query.objectId['$nin'] : [];
|
||||
const idsFromNin = query.objectId && query.objectId['$nin'] ? query.objectId['$nin'] : [];
|
||||
let allIds = [...idsFromNin,...ids].filter(list => list !== null);
|
||||
|
||||
// make a set and spread to remove duplicates
|
||||
@@ -707,8 +707,8 @@ DatabaseController.prototype.find = function(className, query, {
|
||||
keys,
|
||||
op
|
||||
} = {}) {
|
||||
let isMaster = acl === undefined;
|
||||
let aclGroup = acl || [];
|
||||
const isMaster = acl === undefined;
|
||||
const aclGroup = acl || [];
|
||||
op = op || (typeof query.objectId == 'string' && Object.keys(query).length === 1 ? 'get' : 'find');
|
||||
let classExists = true;
|
||||
return this.loadSchema()
|
||||
@@ -846,9 +846,9 @@ DatabaseController.prototype.addPointerPermissions = function(schema, className,
|
||||
if (schema.testBaseCLP(className, aclGroup, operation)) {
|
||||
return query;
|
||||
}
|
||||
let perms = schema.perms[className];
|
||||
let field = ['get', 'find'].indexOf(operation) > -1 ? 'readUserFields' : 'writeUserFields';
|
||||
let userACL = aclGroup.filter((acl) => {
|
||||
const perms = schema.perms[className];
|
||||
const field = ['get', 'find'].indexOf(operation) > -1 ? 'readUserFields' : 'writeUserFields';
|
||||
const userACL = aclGroup.filter((acl) => {
|
||||
return acl.indexOf('role:') != 0 && acl != '*';
|
||||
});
|
||||
// the ACL should have exactly 1 user
|
||||
@@ -858,16 +858,16 @@ DatabaseController.prototype.addPointerPermissions = function(schema, className,
|
||||
if (userACL.length != 1) {
|
||||
return;
|
||||
}
|
||||
let userId = userACL[0];
|
||||
let userPointer = {
|
||||
const userId = userACL[0];
|
||||
const userPointer = {
|
||||
"__type": "Pointer",
|
||||
"className": "_User",
|
||||
"objectId": userId
|
||||
};
|
||||
|
||||
let permFields = perms[field];
|
||||
let ors = permFields.map((key) => {
|
||||
let q = {
|
||||
const permFields = perms[field];
|
||||
const ors = permFields.map((key) => {
|
||||
const q = {
|
||||
[key]: userPointer
|
||||
};
|
||||
return {'$and': [q, query]};
|
||||
@@ -886,17 +886,17 @@ DatabaseController.prototype.addPointerPermissions = function(schema, className,
|
||||
DatabaseController.prototype.performInitialization = function() {
|
||||
const requiredUserFields = { fields: { ...SchemaController.defaultColumns._Default, ...SchemaController.defaultColumns._User } };
|
||||
|
||||
let userClassPromise = this.loadSchema()
|
||||
const userClassPromise = this.loadSchema()
|
||||
.then(schema => schema.enforceClassExists('_User'))
|
||||
|
||||
let usernameUniqueness = userClassPromise
|
||||
const usernameUniqueness = userClassPromise
|
||||
.then(() => this.adapter.ensureUniqueness('_User', requiredUserFields, ['username']))
|
||||
.catch(error => {
|
||||
logger.warn('Unable to ensure uniqueness for usernames: ', error);
|
||||
return Promise.reject(error);
|
||||
});
|
||||
|
||||
let emailUniqueness = userClassPromise
|
||||
const emailUniqueness = userClassPromise
|
||||
.then(() => this.adapter.ensureUniqueness('_User', requiredUserFields, ['email']))
|
||||
.catch(error => {
|
||||
logger.warn('Unable to ensure uniqueness for user email addresses: ', error);
|
||||
@@ -904,7 +904,7 @@ DatabaseController.prototype.performInitialization = function() {
|
||||
});
|
||||
|
||||
// Create tables for volatile classes
|
||||
let adapterInit = this.adapter.performInitialization({ VolatileClassesSchemas: SchemaController.VolatileClassesSchemas });
|
||||
const adapterInit = this.adapter.performInitialization({ VolatileClassesSchemas: SchemaController.VolatileClassesSchemas });
|
||||
return Promise.all([usernameUniqueness, emailUniqueness, adapterInit]);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ export class FilesController extends AdaptableController {
|
||||
|
||||
createFile(config, filename, data, contentType) {
|
||||
|
||||
let extname = path.extname(filename);
|
||||
const extname = path.extname(filename);
|
||||
|
||||
const hasExtension = extname.length > 0;
|
||||
|
||||
@@ -53,13 +53,13 @@ export class FilesController extends AdaptableController {
|
||||
if (typeof object !== 'object') {
|
||||
return;
|
||||
}
|
||||
for (let key in object) {
|
||||
let fileObject = object[key];
|
||||
for (const key in object) {
|
||||
const fileObject = object[key];
|
||||
if (fileObject && fileObject['__type'] === 'File') {
|
||||
if (fileObject['url']) {
|
||||
continue;
|
||||
}
|
||||
let filename = fileObject['name'];
|
||||
const filename = fileObject['name'];
|
||||
// all filenames starting with "tfss-" should be from files.parsetfss.com
|
||||
// all filenames starting with a "-" seperated UUID should be from files.parse.com
|
||||
// all other filenames have been migrated or created from Parse Server
|
||||
|
||||
@@ -157,7 +157,7 @@ export class HooksController {
|
||||
|
||||
function wrapToHTTPRequest(hook, key) {
|
||||
return (req, res) => {
|
||||
let jsonBody = {};
|
||||
const jsonBody = {};
|
||||
for (var i in req) {
|
||||
jsonBody[i] = req[i];
|
||||
}
|
||||
@@ -169,7 +169,7 @@ function wrapToHTTPRequest(hook, key) {
|
||||
jsonBody.original = req.original.toJSON();
|
||||
jsonBody.original.className = req.original.className;
|
||||
}
|
||||
let jsonRequest: any = {
|
||||
const jsonRequest: any = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
|
||||
@@ -20,7 +20,7 @@ export class LiveQueryController {
|
||||
if (!this.hasLiveQuery(className)) {
|
||||
return;
|
||||
}
|
||||
let req = this._makePublisherRequest(currentObject, originalObject);
|
||||
const req = this._makePublisherRequest(currentObject, originalObject);
|
||||
this.liveQueryPublisher.onCloudCodeAfterSave(req);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ export class LiveQueryController {
|
||||
if (!this.hasLiveQuery(className)) {
|
||||
return;
|
||||
}
|
||||
let req = this._makePublisherRequest(currentObject, originalObject);
|
||||
const req = this._makePublisherRequest(currentObject, originalObject);
|
||||
this.liveQueryPublisher.onCloudCodeAfterDelete(req);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ export class LiveQueryController {
|
||||
}
|
||||
|
||||
_makePublisherRequest(currentObject: any, originalObject: any): any {
|
||||
let req = {
|
||||
const req = {
|
||||
object: currentObject
|
||||
};
|
||||
if (currentObject) {
|
||||
|
||||
@@ -45,7 +45,7 @@ export class LoggerController extends AdaptableController {
|
||||
}
|
||||
|
||||
if (e.body) {
|
||||
for (let key of Object.keys(e.body)) {
|
||||
for (const key of Object.keys(e.body)) {
|
||||
if (key === 'password') {
|
||||
e.body[key] = '********';
|
||||
break;
|
||||
@@ -111,12 +111,12 @@ export class LoggerController extends AdaptableController {
|
||||
}
|
||||
|
||||
static parseOptions(options = {}) {
|
||||
let from = LoggerController.validDateTime(options.from) ||
|
||||
const from = LoggerController.validDateTime(options.from) ||
|
||||
new Date(Date.now() - 7 * MILLISECONDS_IN_A_DAY);
|
||||
let until = LoggerController.validDateTime(options.until) || new Date();
|
||||
let size = Number(options.size) || 10;
|
||||
let order = options.order || LogOrder.DESCENDING;
|
||||
let level = options.level || LogLevel.INFO;
|
||||
const until = LoggerController.validDateTime(options.until) || new Date();
|
||||
const size = Number(options.size) || 10;
|
||||
const order = options.order || LogOrder.DESCENDING;
|
||||
const level = options.level || LogLevel.INFO;
|
||||
|
||||
return {
|
||||
from,
|
||||
|
||||
@@ -57,7 +57,7 @@ export class PushController extends AdaptableController {
|
||||
return Promise.resolve();
|
||||
}
|
||||
if (body.data && body.data.badge) {
|
||||
let badge = body.data.badge;
|
||||
const badge = body.data.badge;
|
||||
let restUpdate = {};
|
||||
if (typeof badge == 'string' && badge.toLowerCase() === 'increment') {
|
||||
restUpdate = { badge: { __op: 'Increment', amount: 1 } }
|
||||
@@ -66,20 +66,20 @@ export class PushController extends AdaptableController {
|
||||
} else {
|
||||
throw "Invalid value for badge, expected number or 'Increment'";
|
||||
}
|
||||
let updateWhere = deepcopy(where);
|
||||
const updateWhere = deepcopy(where);
|
||||
|
||||
badgeUpdate = () => {
|
||||
updateWhere.deviceType = 'ios';
|
||||
// Build a real RestQuery so we can use it in RestWrite
|
||||
let restQuery = new RestQuery(config, master(config), '_Installation', updateWhere);
|
||||
const restQuery = new RestQuery(config, master(config), '_Installation', updateWhere);
|
||||
return restQuery.buildRestWhere().then(() => {
|
||||
let write = new RestWrite(config, master(config), '_Installation', restQuery.restWhere, restUpdate);
|
||||
const write = new RestWrite(config, master(config), '_Installation', restQuery.restWhere, restUpdate);
|
||||
write.runOptions.many = true;
|
||||
return write.execute();
|
||||
});
|
||||
}
|
||||
}
|
||||
let pushStatus = pushStatusHandler(config);
|
||||
const pushStatus = pushStatusHandler(config);
|
||||
return Promise.resolve().then(() => {
|
||||
return pushStatus.setInitial(body, where);
|
||||
}).then(() => {
|
||||
@@ -105,7 +105,7 @@ export class PushController extends AdaptableController {
|
||||
sendToAdapter(body, installations, pushStatus) {
|
||||
if (body.data && body.data.badge && typeof body.data.badge == 'string' && body.data.badge.toLowerCase() == "increment") {
|
||||
// Collect the badges to reduce the # of calls
|
||||
let badgeInstallationsMap = installations.reduce((map, installation) => {
|
||||
const badgeInstallationsMap = installations.reduce((map, installation) => {
|
||||
let badge = installation.badge;
|
||||
if (installation.deviceType != "ios") {
|
||||
badge = UNSUPPORTED_BADGE_KEY;
|
||||
@@ -116,8 +116,8 @@ export class PushController extends AdaptableController {
|
||||
}, {});
|
||||
|
||||
// Map the on the badges count and return the send result
|
||||
let promises = Object.keys(badgeInstallationsMap).map((badge) => {
|
||||
let payload = deepcopy(body);
|
||||
const promises = Object.keys(badgeInstallationsMap).map((badge) => {
|
||||
const payload = deepcopy(body);
|
||||
if (badge == UNSUPPORTED_BADGE_KEY) {
|
||||
delete payload.data.badge;
|
||||
} else {
|
||||
|
||||
@@ -76,7 +76,7 @@ export default class SchemaCache {
|
||||
if (!allKeys) {
|
||||
return;
|
||||
}
|
||||
let promises = Object.keys(allKeys).map((key) => {
|
||||
const promises = Object.keys(allKeys).map((key) => {
|
||||
return this.cache.del(key);
|
||||
});
|
||||
return Promise.all(promises);
|
||||
|
||||
@@ -128,7 +128,7 @@ const requireAuthenticationRegex = /^requiresAuthentication$/
|
||||
const permissionKeyRegex = Object.freeze([userIdRegex, roleRegex, publicRegex, requireAuthenticationRegex]);
|
||||
|
||||
function verifyPermissionKey(key) {
|
||||
let result = permissionKeyRegex.reduce((isGood, regEx) => {
|
||||
const result = permissionKeyRegex.reduce((isGood, regEx) => {
|
||||
isGood = isGood || key.match(regEx) != null;
|
||||
return isGood;
|
||||
}, false);
|
||||
@@ -162,7 +162,7 @@ function validateCLP(perms, fields) {
|
||||
|
||||
Object.keys(perms[operation]).forEach((key) => {
|
||||
verifyPermissionKey(key);
|
||||
let perm = perms[operation][key];
|
||||
const perm = perms[operation][key];
|
||||
if (perm !== true) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, `'${perm}' is not a valid value for class level permissions ${operation}:${key}:${perm}`);
|
||||
}
|
||||
@@ -346,7 +346,7 @@ export default class SchemaController {
|
||||
|
||||
// Inject the in-memory classes
|
||||
volatileClasses.forEach(className => {
|
||||
let schema = injectDefaultSchema({ className });
|
||||
const schema = injectDefaultSchema({ className });
|
||||
this.data[className] = schema.fields;
|
||||
this.perms[className] = schema.classLevelPermissions;
|
||||
});
|
||||
@@ -439,9 +439,9 @@ export default class SchemaController {
|
||||
updateClass(className, submittedFields, classLevelPermissions, database) {
|
||||
return this.getOneSchema(className)
|
||||
.then(schema => {
|
||||
let existingFields = schema.fields;
|
||||
const existingFields = schema.fields;
|
||||
Object.keys(submittedFields).forEach(name => {
|
||||
let field = submittedFields[name];
|
||||
const field = submittedFields[name];
|
||||
if (existingFields[name] && field.__op !== 'Delete') {
|
||||
throw new Parse.Error(255, `Field ${name} exists, cannot update.`);
|
||||
}
|
||||
@@ -452,16 +452,16 @@ export default class SchemaController {
|
||||
|
||||
delete existingFields._rperm;
|
||||
delete existingFields._wperm;
|
||||
let newSchema = buildMergedSchemaObject(existingFields, submittedFields);
|
||||
let validationError = this.validateSchemaData(className, newSchema, classLevelPermissions, Object.keys(existingFields));
|
||||
const newSchema = buildMergedSchemaObject(existingFields, submittedFields);
|
||||
const validationError = this.validateSchemaData(className, newSchema, classLevelPermissions, Object.keys(existingFields));
|
||||
if (validationError) {
|
||||
throw new Parse.Error(validationError.code, validationError.error);
|
||||
}
|
||||
|
||||
// Finally we have checked to make sure the request is valid and we can start deleting fields.
|
||||
// Do all deletions first, then a single save to _SCHEMA collection to handle all additions.
|
||||
let deletePromises = [];
|
||||
let insertedFields = [];
|
||||
const deletePromises = [];
|
||||
const insertedFields = [];
|
||||
Object.keys(submittedFields).forEach(fieldName => {
|
||||
if (submittedFields[fieldName].__op === 'Delete') {
|
||||
const promise = this.deleteField(fieldName, className, database);
|
||||
@@ -474,7 +474,7 @@ export default class SchemaController {
|
||||
return Promise.all(deletePromises) // Delete Everything
|
||||
.then(() => this.reloadData({ clearCache: true })) // Reload our Schema, so we have all the new values
|
||||
.then(() => {
|
||||
let promises = insertedFields.map(fieldName => {
|
||||
const promises = insertedFields.map(fieldName => {
|
||||
const type = submittedFields[fieldName];
|
||||
return this.enforceFieldExists(className, fieldName, type);
|
||||
});
|
||||
@@ -542,7 +542,7 @@ export default class SchemaController {
|
||||
}
|
||||
|
||||
validateSchemaData(className, fields, classLevelPermissions, existingFieldNames) {
|
||||
for (let fieldName in fields) {
|
||||
for (const fieldName in fields) {
|
||||
if (existingFieldNames.indexOf(fieldName) < 0) {
|
||||
if (!fieldNameIsValid(fieldName)) {
|
||||
return {
|
||||
@@ -561,11 +561,11 @@ export default class SchemaController {
|
||||
}
|
||||
}
|
||||
|
||||
for (let fieldName in defaultColumns[className]) {
|
||||
for (const fieldName in defaultColumns[className]) {
|
||||
fields[fieldName] = defaultColumns[className][fieldName];
|
||||
}
|
||||
|
||||
let geoPoints = Object.keys(fields).filter(key => fields[key] && fields[key].type === 'GeoPoint');
|
||||
const geoPoints = Object.keys(fields).filter(key => fields[key] && fields[key].type === 'GeoPoint');
|
||||
if (geoPoints.length > 1) {
|
||||
return {
|
||||
code: Parse.Error.INCORRECT_TYPE,
|
||||
@@ -605,7 +605,7 @@ export default class SchemaController {
|
||||
}
|
||||
|
||||
return this.reloadData().then(() => {
|
||||
let expectedType = this.getExpectedType(className, fieldName);
|
||||
const expectedType = this.getExpectedType(className, fieldName);
|
||||
if (typeof type === 'string') {
|
||||
type = { type };
|
||||
}
|
||||
@@ -690,11 +690,11 @@ export default class SchemaController {
|
||||
validateObject(className, object, query) {
|
||||
let geocount = 0;
|
||||
let promise = this.enforceClassExists(className);
|
||||
for (let fieldName in object) {
|
||||
for (const fieldName in object) {
|
||||
if (object[fieldName] === undefined) {
|
||||
continue;
|
||||
}
|
||||
let expected = getType(object[fieldName]);
|
||||
const expected = getType(object[fieldName]);
|
||||
if (expected === 'GeoPoint') {
|
||||
geocount++;
|
||||
}
|
||||
@@ -722,12 +722,12 @@ export default class SchemaController {
|
||||
|
||||
// Validates that all the properties are set for the object
|
||||
validateRequiredColumns(className, object, query) {
|
||||
let columns = requiredColumns[className];
|
||||
const columns = requiredColumns[className];
|
||||
if (!columns || columns.length == 0) {
|
||||
return Promise.resolve(this);
|
||||
}
|
||||
|
||||
let missingColumns = columns.filter(function(column){
|
||||
const missingColumns = columns.filter(function(column){
|
||||
if (query && query.objectId) {
|
||||
if (object[column] && typeof object[column] === "object") {
|
||||
// Trying to delete a required column
|
||||
@@ -752,8 +752,8 @@ export default class SchemaController {
|
||||
if (!this.perms[className] || !this.perms[className][operation]) {
|
||||
return true;
|
||||
}
|
||||
let classPerms = this.perms[className];
|
||||
let perms = classPerms[operation];
|
||||
const classPerms = this.perms[className];
|
||||
const perms = classPerms[operation];
|
||||
// Handle the public scenario quickly
|
||||
if (perms['*']) {
|
||||
return true;
|
||||
@@ -774,8 +774,8 @@ export default class SchemaController {
|
||||
if (!this.perms[className] || !this.perms[className][operation]) {
|
||||
return true;
|
||||
}
|
||||
let classPerms = this.perms[className];
|
||||
let perms = classPerms[operation];
|
||||
const classPerms = this.perms[className];
|
||||
const perms = classPerms[operation];
|
||||
|
||||
// If only for authenticated users
|
||||
// make sure we have an aclGroup
|
||||
@@ -797,7 +797,7 @@ export default class SchemaController {
|
||||
|
||||
// No matching CLP, let's check the Pointer permissions
|
||||
// And handle those later
|
||||
let permissionField = ['get', 'find'].indexOf(operation) > -1 ? 'readUserFields' : 'writeUserFields';
|
||||
const permissionField = ['get', 'find'].indexOf(operation) > -1 ? 'readUserFields' : 'writeUserFields';
|
||||
|
||||
// Reject create when write lockdown
|
||||
if (permissionField == 'writeUserFields' && operation == 'create') {
|
||||
@@ -831,7 +831,7 @@ export default class SchemaController {
|
||||
|
||||
// Returns a promise for a new Schema.
|
||||
const load = (dbAdapter, schemaCache, options) => {
|
||||
let schema = new SchemaController(dbAdapter, schemaCache);
|
||||
const schema = new SchemaController(dbAdapter, schemaCache);
|
||||
return schema.reloadData(options).then(() => schema);
|
||||
}
|
||||
|
||||
@@ -841,20 +841,20 @@ const load = (dbAdapter, schemaCache, options) => {
|
||||
// to mongoSchemaFromFieldsAndClassName. No validation is done here, it
|
||||
// is done in mongoSchemaFromFieldsAndClassName.
|
||||
function buildMergedSchemaObject(existingFields, putRequest) {
|
||||
let newSchema = {};
|
||||
let sysSchemaField = Object.keys(defaultColumns).indexOf(existingFields._id) === -1 ? [] : Object.keys(defaultColumns[existingFields._id]);
|
||||
for (let oldField in existingFields) {
|
||||
const newSchema = {};
|
||||
const sysSchemaField = Object.keys(defaultColumns).indexOf(existingFields._id) === -1 ? [] : Object.keys(defaultColumns[existingFields._id]);
|
||||
for (const oldField in existingFields) {
|
||||
if (oldField !== '_id' && oldField !== 'ACL' && oldField !== 'updatedAt' && oldField !== 'createdAt' && oldField !== 'objectId') {
|
||||
if (sysSchemaField.length > 0 && sysSchemaField.indexOf(oldField) !== -1) {
|
||||
continue;
|
||||
}
|
||||
let fieldIsDeleted = putRequest[oldField] && putRequest[oldField].__op === 'Delete'
|
||||
const fieldIsDeleted = putRequest[oldField] && putRequest[oldField].__op === 'Delete'
|
||||
if (!fieldIsDeleted) {
|
||||
newSchema[oldField] = existingFields[oldField];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let newField in putRequest) {
|
||||
for (const newField in putRequest) {
|
||||
if (newField !== 'objectId' && putRequest[newField].__op !== 'Delete') {
|
||||
if (sysSchemaField.length > 0 && sysSchemaField.indexOf(newField) !== -1) {
|
||||
continue;
|
||||
@@ -879,7 +879,7 @@ function thenValidateRequiredColumns(schemaPromise, className, object, query) {
|
||||
// The output should be a valid schema value.
|
||||
// TODO: ensure that this is compatible with the format used in Open DB
|
||||
function getType(obj) {
|
||||
let type = typeof obj;
|
||||
const type = typeof obj;
|
||||
switch(type) {
|
||||
case 'boolean':
|
||||
return 'Boolean';
|
||||
|
||||
@@ -48,8 +48,8 @@ export class UserController extends AdaptableController {
|
||||
throw undefined;
|
||||
}
|
||||
|
||||
let query = {username: username, _email_verify_token: token};
|
||||
let updateFields = { emailVerified: true, _email_verify_token: {__op: 'Delete'}};
|
||||
const query = {username: username, _email_verify_token: token};
|
||||
const updateFields = { emailVerified: true, _email_verify_token: {__op: 'Delete'}};
|
||||
|
||||
// if the email verify token needs to be validated then
|
||||
// add additional query params and additional fields that need to be updated
|
||||
@@ -119,8 +119,8 @@ export class UserController extends AdaptableController {
|
||||
// We may need to fetch the user in case of update email
|
||||
this.getUserIfNeeded(user).then((user) => {
|
||||
const username = encodeURIComponent(user.username);
|
||||
let link = `${this.config.verifyEmailURL}?token=${token}&username=${username}`;
|
||||
let options = {
|
||||
const link = `${this.config.verifyEmailURL}?token=${token}&username=${username}`;
|
||||
const options = {
|
||||
appName: this.config.appName,
|
||||
link: link,
|
||||
user: inflate('_User', user),
|
||||
@@ -153,9 +153,9 @@ export class UserController extends AdaptableController {
|
||||
.then(user => {
|
||||
const token = encodeURIComponent(user._perishable_token);
|
||||
const username = encodeURIComponent(user.username);
|
||||
let link = `${this.config.requestResetPasswordURL}?token=${token}&username=${username}`
|
||||
const link = `${this.config.requestResetPasswordURL}?token=${token}&username=${username}`
|
||||
|
||||
let options = {
|
||||
const options = {
|
||||
appName: this.config.appName,
|
||||
link: link,
|
||||
user: inflate('_User', user),
|
||||
@@ -188,22 +188,22 @@ export class UserController extends AdaptableController {
|
||||
}
|
||||
|
||||
defaultVerificationEmail({link, user, appName, }) {
|
||||
let text = "Hi,\n\n" +
|
||||
const text = "Hi,\n\n" +
|
||||
"You are being asked to confirm the e-mail address " + user.get("email") + " with " + appName + "\n\n" +
|
||||
"" +
|
||||
"Click here to confirm it:\n" + link;
|
||||
let to = user.get("email");
|
||||
let subject = 'Please verify your e-mail for ' + appName;
|
||||
const to = user.get("email");
|
||||
const subject = 'Please verify your e-mail for ' + appName;
|
||||
return { text, to, subject };
|
||||
}
|
||||
|
||||
defaultResetPasswordEmail({link, user, appName, }) {
|
||||
let text = "Hi,\n\n" +
|
||||
const text = "Hi,\n\n" +
|
||||
"You requested to reset your password for " + appName + ".\n\n" +
|
||||
"" +
|
||||
"Click here to reset it:\n" + link;
|
||||
let to = user.get("email") || user.get('username');
|
||||
let subject = 'Password Reset for ' + appName;
|
||||
const to = user.get("email") || user.get('username');
|
||||
const subject = 'Password Reset for ' + appName;
|
||||
return { text, to, subject };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user