Centralizes list of system classes into Schema

This commit is contained in:
Florent Vilmart
2016-03-12 13:40:59 -05:00
parent 49531e7efe
commit 308fe1498a
3 changed files with 39 additions and 26 deletions

View File

@@ -1,6 +1,7 @@
// An object that encapsulates everything we need to run a 'find' // An object that encapsulates everything we need to run a 'find'
// operation, encoded in the REST API format. // operation, encoded in the REST API format.
var Schema = require('./Schema');
var Parse = require('parse/node').Parse; var Parse = require('parse/node').Parse;
import { default as FilesController } from './Controllers/FilesController'; import { default as FilesController } from './Controllers/FilesController';
@@ -171,7 +172,7 @@ RestQuery.prototype.redirectClassNameForKey = function() {
// Validates this operation against the allowClientClassCreation config. // Validates this operation against the allowClientClassCreation config.
RestQuery.prototype.validateClientClassCreation = function() { RestQuery.prototype.validateClientClassCreation = function() {
let sysClass = ['_User', '_Installation', '_Role', '_Session', '_Product']; let sysClass = Schema.systemClasses;
if (this.config.allowClientClassCreation === false && !this.auth.isMaster if (this.config.allowClientClassCreation === false && !this.auth.isMaster
&& sysClass.indexOf(this.className) === -1) { && sysClass.indexOf(this.className) === -1) {
return this.config.database.collectionExists(this.className).then((hasClass) => { return this.config.database.collectionExists(this.className).then((hasClass) => {

View File

@@ -3,6 +3,7 @@
// This could be either a "create" or an "update". // This could be either a "create" or an "update".
import cache from './cache'; import cache from './cache';
var Schema = require('./Schema');
var deepcopy = require('deepcopy'); var deepcopy = require('deepcopy');
var Auth = require('./Auth'); var Auth = require('./Auth');
@@ -108,7 +109,7 @@ RestWrite.prototype.getUserAndRoleACL = function() {
// Validates this operation against the allowClientClassCreation config. // Validates this operation against the allowClientClassCreation config.
RestWrite.prototype.validateClientClassCreation = function() { RestWrite.prototype.validateClientClassCreation = function() {
let sysClass = ['_User', '_Installation', '_Role', '_Session', '_Product']; let sysClass = Schema.systemClasses;
if (this.config.allowClientClassCreation === false && !this.auth.isMaster if (this.config.allowClientClassCreation === false && !this.auth.isMaster
&& sysClass.indexOf(this.className) === -1) { && sysClass.indexOf(this.className) === -1) {
return this.config.database.collectionExists(this.className).then((hasClass) => { return this.config.database.collectionExists(this.className).then((hasClass) => {

View File

@@ -67,7 +67,20 @@ var defaultColumns = {
"icon": {type:'File'}, "icon": {type:'File'},
"order": {type:'Number'}, "order": {type:'Number'},
"title": {type:'String'}, "title": {type:'String'},
"subtitle": {type:'String'}, "subtitle": {type:'String'},
},
_PushStatus: {
"pushTime": {type:'String'},
"source": {type:'String'}, // rest or web
"query": {type:'String'}, // the stringified JSON query
"payload": {type:'Object'}, // the JSON payload,
"title": {type:'String'},
"expiry": {type:'Number'},
"status": {type:'String'},
"numSent": {type:'Number'},
"pushHash": {type:'String'},
"errorMessage": {type:'Object'},
"sentPerType": {type:'Object'}
} }
}; };
@@ -76,6 +89,8 @@ var requiredColumns = {
_Role: ["name", "ACL"] _Role: ["name", "ACL"]
} }
const systemClasses = ['_User', '_Installation', '_Role', '_Session', '_Product', '_PushStatus'];
// 10 alpha numberic chars + uppercase // 10 alpha numberic chars + uppercase
const userIdRegex = /^[a-zA-Z0-9]{10}$/; const userIdRegex = /^[a-zA-Z0-9]{10}$/;
// Anything that start with role // Anything that start with role
@@ -127,13 +142,8 @@ function validateCLP(perms) {
var joinClassRegex = /^_Join:[A-Za-z0-9_]+:[A-Za-z0-9_]+/; var joinClassRegex = /^_Join:[A-Za-z0-9_]+:[A-Za-z0-9_]+/;
var classAndFieldRegex = /^[A-Za-z][A-Za-z0-9_]*$/; var classAndFieldRegex = /^[A-Za-z][A-Za-z0-9_]*$/;
function classNameIsValid(className) { function classNameIsValid(className) {
return ( return (systemClasses.indexOf(className) > -1 ||
className === '_User' ||
className === '_Installation' ||
className === '_Session' ||
className === '_SCHEMA' || //TODO: remove this, as _SCHEMA is not a valid class name for storing Parse Objects. className === '_SCHEMA' || //TODO: remove this, as _SCHEMA is not a valid class name for storing Parse Objects.
className === '_Role' ||
className === '_Product' ||
joinClassRegex.test(className) || joinClassRegex.test(className) ||
//Class names have the same constraints as field names, but also allow the previous additional names. //Class names have the same constraints as field names, but also allow the previous additional names.
fieldNameIsValid(className) fieldNameIsValid(className)
@@ -903,4 +913,5 @@ module.exports = {
buildMergedSchemaObject: buildMergedSchemaObject, buildMergedSchemaObject: buildMergedSchemaObject,
mongoFieldTypeToSchemaAPIType: mongoFieldTypeToSchemaAPIType, mongoFieldTypeToSchemaAPIType: mongoFieldTypeToSchemaAPIType,
mongoSchemaToSchemaAPIResponse, mongoSchemaToSchemaAPIResponse,
systemClasses,
}; };