Skip to content
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

Generates default CLP, freezes objects #1132

Merged
merged 1 commit into from
Mar 22, 2016
Merged
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
36 changes: 19 additions & 17 deletions src/Schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
var Parse = require('parse/node').Parse;
var transform = require('./transform');

var defaultColumns = {
const defaultColumns = Object.freeze({
// Contain the default columns for every parse object type (except _Join collection)
_Default: {
"objectId": {type:'String'},
Expand Down Expand Up @@ -84,14 +84,14 @@ var defaultColumns = {
"sentPerType": {type:'Object'},
"failedPerType":{type:'Object'},
}
};
});

var requiredColumns = {
const requiredColumns = Object.freeze({
_Product: ["productIdentifier", "icon", "order", "title", "subtitle"],
_Role: ["name", "ACL"]
}
});

const systemClasses = ['_User', '_Installation', '_Role', '_Session', '_Product'];
const systemClasses = Object.freeze(['_User', '_Installation', '_Role', '_Session', '_Product']);

// 10 alpha numberic chars + uppercase
const userIdRegex = /^[a-zA-Z0-9]{10}$/;
Expand All @@ -100,7 +100,7 @@ const roleRegex = /^role:.*/;
// * permission
const publicRegex = /^\*$/

const permissionKeyRegex = [userIdRegex, roleRegex, publicRegex];
const permissionKeyRegex = Object.freeze([userIdRegex, roleRegex, publicRegex]);

function verifyPermissionKey(key) {
let result = permissionKeyRegex.reduce((isGood, regEx) => {
Expand All @@ -112,13 +112,15 @@ function verifyPermissionKey(key) {
}
}

let CLPValidKeys = ['find', 'get', 'create', 'update', 'delete', 'addField'];
let DefaultClassLevelPermissions = CLPValidKeys.reduce((perms, key) => {
const CLPValidKeys = Object.freeze(['find', 'get', 'create', 'update', 'delete', 'addField']);
let DefaultClassLevelPermissions = () => {
return CLPValidKeys.reduce((perms, key) => {
perms[key] = {
'*': true
};
return perms;
}, {});
}

function validateCLP(perms) {
if (!perms) {
Expand Down Expand Up @@ -899,21 +901,21 @@ function mongoSchemaToSchemaAPIResponse(schema) {
fields: mongoSchemaAPIResponseFields(schema),
};

let classLevelPermissions = DefaultClassLevelPermissions;
let classLevelPermissions = DefaultClassLevelPermissions();
if (schema._metadata && schema._metadata.class_permissions) {
classLevelPermissions = Object.assign(classLevelPermissions, schema._metadata.class_permissions);
classLevelPermissions = Object.assign({}, classLevelPermissions, schema._metadata.class_permissions);
}
result.classLevelPermissions = classLevelPermissions;
return result;
}

module.exports = {
load: load,
classNameIsValid: classNameIsValid,
invalidClassNameMessage: invalidClassNameMessage,
schemaAPITypeToMongoFieldType: schemaAPITypeToMongoFieldType,
buildMergedSchemaObject: buildMergedSchemaObject,
mongoFieldTypeToSchemaAPIType: mongoFieldTypeToSchemaAPIType,
export {
load,
classNameIsValid,
invalidClassNameMessage,
schemaAPITypeToMongoFieldType,
buildMergedSchemaObject,
mongoFieldTypeToSchemaAPIType,
mongoSchemaToSchemaAPIResponse,
systemClasses,
};