Handle legacy _client_permissions key in _SCHEMA. Fixes #888.

This commit is contained in:
Drew Gross
2016-03-07 13:44:45 -08:00
parent 75ae95815d
commit 963811d022
3 changed files with 56 additions and 25 deletions

View File

@@ -4,7 +4,7 @@ var express = require('express'),
Parse = require('parse/node').Parse,
Schema = require('../Schema');
import PromiseRouter from '../PromiseRouter';
import PromiseRouter from '../PromiseRouter';
import * as middleware from "../middlewares";
function classNameMismatchResponse(bodyClass, pathClass) {
@@ -14,30 +14,10 @@ function classNameMismatchResponse(bodyClass, pathClass) {
);
}
function mongoSchemaAPIResponseFields(schema) {
var fieldNames = Object.keys(schema).filter(key => key !== '_id' && key !== '_metadata');
var response = fieldNames.reduce((obj, fieldName) => {
obj[fieldName] = Schema.mongoFieldTypeToSchemaAPIType(schema[fieldName])
return obj;
}, {});
response.ACL = {type: 'ACL'};
response.createdAt = {type: 'Date'};
response.updatedAt = {type: 'Date'};
response.objectId = {type: 'String'};
return response;
}
function mongoSchemaToSchemaAPIResponse(schema) {
return {
className: schema._id,
fields: mongoSchemaAPIResponseFields(schema),
};
}
function getAllSchemas(req) {
return req.config.database.adaptiveCollection('_SCHEMA')
.then(collection => collection.find({}))
.then(schemas => schemas.map(mongoSchemaToSchemaAPIResponse))
.then(schemas => schemas.map(Schema.mongoSchemaToSchemaAPIResponse))
.then(schemas => ({ response: { results: schemas }}));
}
@@ -51,7 +31,7 @@ function getOneSchema(req) {
}
return results[0];
})
.then(schema => ({ response: mongoSchemaToSchemaAPIResponse(schema) }));
.then(schema => ({ response: Schema.mongoSchemaToSchemaAPIResponse(schema) }));
}
function createSchema(req) {
@@ -68,7 +48,7 @@ function createSchema(req) {
return req.config.database.loadSchema()
.then(schema => schema.addClassIfNotExists(className, req.body.fields))
.then(result => ({ response: mongoSchemaToSchemaAPIResponse(result) }));
.then(result => ({ response: Schema.mongoSchemaToSchemaAPIResponse(result) }));
}
function modifySchema(req) {
@@ -118,7 +98,7 @@ function modifySchema(req) {
if (err) {
reject(err);
}
resolve({ response: mongoSchemaToSchemaAPIResponse(mongoObject.result)});
resolve({ response: Schema.mongoSchemaToSchemaAPIResponse(mongoObject.result)});
})
}));
});

View File

@@ -760,6 +760,27 @@ function getObjectType(obj) {
return 'object';
}
const nonFieldSchemaKeys = ['_id', '_metadata', '_client_permissions'];
function mongoSchemaAPIResponseFields(schema) {
var fieldNames = Object.keys(schema).filter(key => nonFieldSchemaKeys.indexOf(key) === -1);
var response = fieldNames.reduce((obj, fieldName) => {
obj[fieldName] = mongoFieldTypeToSchemaAPIType(schema[fieldName])
return obj;
}, {});
response.ACL = {type: 'ACL'};
response.createdAt = {type: 'Date'};
response.updatedAt = {type: 'Date'};
response.objectId = {type: 'String'};
return response;
}
function mongoSchemaToSchemaAPIResponse(schema) {
return {
className: schema._id,
fields: mongoSchemaAPIResponseFields(schema),
};
}
module.exports = {
load: load,
classNameIsValid: classNameIsValid,
@@ -768,4 +789,5 @@ module.exports = {
schemaAPITypeToMongoFieldType: schemaAPITypeToMongoFieldType,
buildMergedSchemaObject: buildMergedSchemaObject,
mongoFieldTypeToSchemaAPIType: mongoFieldTypeToSchemaAPIType,
mongoSchemaToSchemaAPIResponse,
};