Differential D362 Diff 1357 lib/app/base-chips/access-strategy-types/same-as-for-resource-in-field.js
Changeset View
Changeset View
Standalone View
Standalone View
lib/app/base-chips/access-strategy-types/same-as-for-resource-in-field.js
const Query = require("../../../datastore/query.js"); | const Query = require("../../../datastore/query.js"); | ||||
module.exports = app => ({ | module.exports = app => ({ | ||||
name: "same-as-for-resource-in-field", | name: "same-as-for-resource-in-field", | ||||
getRestrictingQuery: async function( | async getRestrictingQuery(context, { action_name, collection, field }) { | ||||
context, | |||||
{ action_name, collection, field } | |||||
) { | |||||
const referenced_collection = get_referenced_collection( | const referenced_collection = get_referenced_collection( | ||||
app, | app, | ||||
collection, | collection, | ||||
field | field | ||||
); | ); | ||||
const referenced_access_strategy = get_referenced_access_strategy( | const referenced_access_strategy = get_referenced_access_strategy( | ||||
app, | app, | ||||
action_name, | action_name, | ||||
Show All 25 Lines | async getRestrictingQuery(context, { action_name, collection, field }) { | ||||
); | ); | ||||
const pipeline = query | const pipeline = query | ||||
.toPipeline() | .toPipeline() | ||||
.concat(referenced_restricting_pipeline); | .concat(referenced_restricting_pipeline); | ||||
return Query.fromCustomPipeline(pipeline); | return Query.fromCustomPipeline(pipeline); | ||||
}, | }, | ||||
checker_function: async function( | async checker_function(context, { action_name, collection, field }, item) { | ||||
context, | |||||
{ action_name, collection, field }, | |||||
item | |||||
) { | |||||
const referenced_collection = get_referenced_collection( | const referenced_collection = get_referenced_collection( | ||||
app, | app, | ||||
collection, | collection, | ||||
field | field | ||||
); | ); | ||||
const referenced_access_strategy = get_referenced_access_strategy( | const referenced_access_strategy = get_referenced_access_strategy( | ||||
app, | app, | ||||
action_name, | action_name, | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | return Object.keys(group).reduce((acc, prop) => { | ||||
if (Array.isArray(group[prop])) { | if (Array.isArray(group[prop])) { | ||||
group[prop] = group[prop].map(subgroup => | group[prop] = group[prop].map(subgroup => | ||||
add_parent_prefix(subgroup, parent_property) | add_parent_prefix(subgroup, parent_property) | ||||
); | ); | ||||
} else if (group[prop] instanceof Object) { | } else if (group[prop] instanceof Object) { | ||||
group[prop] = add_parent_prefix(group[prop], parent_property); | group[prop] = add_parent_prefix(group[prop], parent_property); | ||||
} | } | ||||
const new_prop = prop_regex.test(prop) | const new_prop = prop_regex.test(prop) | ||||
? parent_property + "." + prop | ? `${parent_property}.${prop}` | ||||
: prop; | : prop; | ||||
acc[new_prop] = group[prop]; | acc[new_prop] = group[prop]; | ||||
return acc; | return acc; | ||||
}, {}); | }, {}); | ||||
} | } |