當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Tyr.byUids方法代碼示例

本文整理匯總了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);
      })
開發者ID:CrossLead,項目名稱:tyranid-gracl,代碼行數:9,代碼來源:PermissionsModel.ts

示例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,
//.........這裏部分代碼省略.........
開發者ID:CrossLead,項目名稱:tyranid-gracl,代碼行數:101,代碼來源:PermissionsModel.ts


注:本文中的tyranid.Tyr.byUids方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。