当前位置: 首页>>代码示例>>PHP>>正文


PHP PhabricatorPolicyQuery::isObjectPolicy方法代码示例

本文整理汇总了PHP中PhabricatorPolicyQuery::isObjectPolicy方法的典型用法代码示例。如果您正苦于以下问题:PHP PhabricatorPolicyQuery::isObjectPolicy方法的具体用法?PHP PhabricatorPolicyQuery::isObjectPolicy怎么用?PHP PhabricatorPolicyQuery::isObjectPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PhabricatorPolicyQuery的用法示例。


在下文中一共展示了PhabricatorPolicyQuery::isObjectPolicy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: checkCapability

 private function checkCapability(PhabricatorPolicyInterface $object, $capability)
 {
     $policy = $this->getObjectPolicy($object, $capability);
     if (!$policy) {
         // TODO: Formalize this somehow?
         $policy = PhabricatorPolicies::POLICY_USER;
     }
     if ($policy == PhabricatorPolicies::POLICY_PUBLIC) {
         // If the object is set to "public" but that policy is disabled for this
         // install, restrict the policy to "user".
         if (!PhabricatorEnv::getEnvConfig('policy.allow-public')) {
             $policy = PhabricatorPolicies::POLICY_USER;
         }
         // If the object is set to "public" but the capability is not a public
         // capability, restrict the policy to "user".
         $capobj = PhabricatorPolicyCapability::getCapabilityByKey($capability);
         if (!$capobj || !$capobj->shouldAllowPublicPolicySetting()) {
             $policy = PhabricatorPolicies::POLICY_USER;
         }
     }
     $viewer = $this->viewer;
     if ($viewer->isOmnipotent()) {
         return true;
     }
     if ($object instanceof PhabricatorSpacesInterface) {
         $space_phid = $object->getSpacePHID();
         if (!$this->canViewerSeeObjectsInSpace($viewer, $space_phid)) {
             $this->rejectObjectFromSpace($object, $space_phid);
             return false;
         }
     }
     if ($object->hasAutomaticCapability($capability, $viewer)) {
         return true;
     }
     switch ($policy) {
         case PhabricatorPolicies::POLICY_PUBLIC:
             return true;
         case PhabricatorPolicies::POLICY_USER:
             if ($viewer->getPHID()) {
                 return true;
             } else {
                 $this->rejectObject($object, $policy, $capability);
             }
             break;
         case PhabricatorPolicies::POLICY_ADMIN:
             if ($viewer->getIsAdmin()) {
                 return true;
             } else {
                 $this->rejectObject($object, $policy, $capability);
             }
             break;
         case PhabricatorPolicies::POLICY_NOONE:
             $this->rejectObject($object, $policy, $capability);
             break;
         default:
             if (PhabricatorPolicyQuery::isObjectPolicy($policy)) {
                 if ($this->checkObjectPolicy($policy, $object)) {
                     return true;
                 } else {
                     $this->rejectObject($object, $policy, $capability);
                     break;
                 }
             }
             $type = phid_get_type($policy);
             if ($type == PhabricatorProjectProjectPHIDType::TYPECONST) {
                 if (!empty($this->userProjects[$viewer->getPHID()][$policy])) {
                     return true;
                 } else {
                     $this->rejectObject($object, $policy, $capability);
                 }
             } else {
                 if ($type == PhabricatorPeopleUserPHIDType::TYPECONST) {
                     if ($viewer->getPHID() == $policy) {
                         return true;
                     } else {
                         $this->rejectObject($object, $policy, $capability);
                     }
                 } else {
                     if ($type == PhabricatorPolicyPHIDTypePolicy::TYPECONST) {
                         if ($this->checkCustomPolicy($policy, $object)) {
                             return true;
                         } else {
                             $this->rejectObject($object, $policy, $capability);
                         }
                     } else {
                         // Reject objects with unknown policies.
                         $this->rejectObject($object, false, $capability);
                     }
                 }
             }
     }
     return false;
 }
开发者ID:patelhardik,项目名称:phabricator,代码行数:93,代码来源:PhabricatorPolicyFilter.php


注:本文中的PhabricatorPolicyQuery::isObjectPolicy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。