本文整理汇总了TypeScript中tyranid.Tyr.byUids方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Tyr.byUids方法的具体用法?TypeScript Tyr.byUids怎么用?TypeScript Tyr.byUids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tyranid.Tyr
的用法示例。
在下文中一共展示了Tyr.byUids方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
_.map(permissionsToCheck, perm => {
const tyranidOpts = {
auth: subject,
perm,
fields: { _id: 1 }
};
return Tyr.byUids(uidsToCheck, tyranidOpts);
})
示例2: findEntitiesWithPermissionAccessToResource
public static async findEntitiesWithPermissionAccessToResource(
accessType: 'allow' | 'deny',
permissions: string[],
doc: Tyr.Document
) {
const plugin = PermissionsModel.getGraclPlugin();
validateAsResource(plugin, doc.$model);
if (!permissions.length) {
plugin.error(
`No permissions provided to findEntitiesWithPermissionAccessToResource()!`
);
}
/**
* Get hierarchy of permissions stemming from provided list
*/
const permHierarchy = permissions.map(p => {
const components = parsePermissionString(plugin, p);
const formatted = formatPermissionType(plugin, {
action: components.action,
collection:
components.collection ||
(isCrudPermission(plugin, p) && doc.$model.def.name) ||
undefined
});
validatePermissionExists(plugin, formatted);
return [formatted, ...getPermissionParents(plugin, formatted)];
});
const permissionsAsResource = (await plugin.permissionsModel.findAll({
query: {
$and: [
// for the given resource...
{ resourceId: doc.$uid },
// get any permission docs with any of the possible permTypes
{
$or: permHierarchy.map(list => ({
$or: list.map(permission => ({
[`access.${permission}`]: { $exists: true }
}))
}))
}
]
}
})) as Permission[];
// get all subjects with direct permissions set for this resource,
// does not yet include _all_ subjects down the heirarchy
const subjectDocuments = await Tyr.byUids(permissionsAsResource.map(
p => p.subjectId
) as string[]);
const subjectsByCollection: Hash<Tyr.Document[]> = {};
_.each(subjectDocuments, subject => {
const colName = subject.$model.def.name;
if (!subjectsByCollection[colName]) {
subjectsByCollection[colName] = [];
}
subjectsByCollection[colName].push(subject);
});
const permsBySubjectId: Hash<Permission> = {};
_.each(permissionsAsResource, perm => {
permsBySubjectId[perm.subjectId] = perm;
});
// test if a given subject satisfies all required permissions
const accessCache: Hash<boolean> = {};
function filterAccess(subject: Tyr.Document, explicit = false) {
const uid = subject.$uid;
const hashKey = `${uid}-${explicit}`;
if (hashKey in accessCache) {
return accessCache[hashKey];
}
const perm = permsBySubjectId[uid] || { access: {} };
return (accessCache[hashKey] = _.every(permHierarchy, list => {
// check for explicit denies
if (explicit) {
const access = accessType === 'allow' ? false : true;
return _.every(list, p => _.get(perm, `access.${p}`) !== access);
} else {
const access = accessType === 'allow' ? true : false;
return _.some(list, p => _.get(perm, `access.${p}`) === access);
}
}));
}
interface Hierarchy {
[key: string]: Hierarchy;
}
async function traverse(
hierarchy: Hierarchy,
//.........这里部分代码省略.........