Added array support for pointer-permissions (#5921)
* added array support for pointer permissions * added tests for array support for pointer permissions * Postgres fix * simplify PG, no idea why this works
This commit is contained in:
committed by
Diamond Lewis
parent
4f8da12674
commit
0fa315fc5b
File diff suppressed because it is too large
Load Diff
@@ -268,7 +268,7 @@ const buildWhereClause = ({ schema, query, index }): WhereClause => {
|
|||||||
const initialPatternsLength = patterns.length;
|
const initialPatternsLength = patterns.length;
|
||||||
const fieldValue = query[fieldName];
|
const fieldValue = query[fieldName];
|
||||||
|
|
||||||
// nothingin the schema, it's gonna blow up
|
// nothing in the schema, it's gonna blow up
|
||||||
if (!schema.fields[fieldName]) {
|
if (!schema.fields[fieldName]) {
|
||||||
// as it won't exist
|
// as it won't exist
|
||||||
if (fieldValue && fieldValue.$exists === false) {
|
if (fieldValue && fieldValue.$exists === false) {
|
||||||
@@ -498,6 +498,12 @@ const buildWhereClause = ({ schema, query, index }): WhereClause => {
|
|||||||
}
|
}
|
||||||
values.push(fieldName, JSON.stringify(fieldValue.$all));
|
values.push(fieldName, JSON.stringify(fieldValue.$all));
|
||||||
index += 2;
|
index += 2;
|
||||||
|
} else if (Array.isArray(fieldValue.$all)) {
|
||||||
|
if (fieldValue.$all.length === 1) {
|
||||||
|
patterns.push(`$${index}:name = $${index + 1}`);
|
||||||
|
values.push(fieldName, fieldValue.$all[0].objectId);
|
||||||
|
index += 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof fieldValue.$exists !== 'undefined') {
|
if (typeof fieldValue.$exists !== 'undefined') {
|
||||||
|
|||||||
@@ -1482,23 +1482,23 @@ class DatabaseController {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const permFields = perms[field];
|
const permFields = perms[field];
|
||||||
const ors = permFields.map(key => {
|
const ors = permFields.flatMap(key => {
|
||||||
|
// constraint for single pointer setup
|
||||||
const q = {
|
const q = {
|
||||||
[key]: userPointer,
|
[key]: userPointer,
|
||||||
};
|
};
|
||||||
|
// constraint for users-array setup
|
||||||
|
const qa = {
|
||||||
|
[key]: { $all: [userPointer] },
|
||||||
|
};
|
||||||
// if we already have a constraint on the key, use the $and
|
// if we already have a constraint on the key, use the $and
|
||||||
if (Object.prototype.hasOwnProperty.call(query, key)) {
|
if (Object.prototype.hasOwnProperty.call(query, key)) {
|
||||||
return { $and: [q, query] };
|
return [{ $and: [q, query] }, { $and: [qa, query] }];
|
||||||
}
|
}
|
||||||
// otherwise just add the constaint
|
// otherwise just add the constaint
|
||||||
return Object.assign({}, query, {
|
return [Object.assign({}, query, q), Object.assign({}, query, qa)];
|
||||||
[`${key}`]: userPointer,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
if (ors.length > 1) {
|
return { $or: ors };
|
||||||
return { $or: ors };
|
|
||||||
}
|
|
||||||
return ors[0];
|
|
||||||
} else {
|
} else {
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -238,9 +238,12 @@ function validateCLP(perms: ClassLevelPermissions, fields: SchemaFields) {
|
|||||||
} else {
|
} else {
|
||||||
perms[operation].forEach(key => {
|
perms[operation].forEach(key => {
|
||||||
if (
|
if (
|
||||||
!fields[key] ||
|
!(
|
||||||
fields[key].type != 'Pointer' ||
|
fields[key] &&
|
||||||
fields[key].targetClass != '_User'
|
((fields[key].type == 'Pointer' &&
|
||||||
|
fields[key].targetClass == '_User') ||
|
||||||
|
fields[key].type == 'Array')
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
throw new Parse.Error(
|
throw new Parse.Error(
|
||||||
Parse.Error.INVALID_JSON,
|
Parse.Error.INVALID_JSON,
|
||||||
|
|||||||
Reference in New Issue
Block a user