private function checkCapability(PhabricatorPolicyInterface $object, $capability)
 {
     $policy = $object->getPolicy($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 anything other
         // than "view", restrict the policy to "user".
         if ($capability != PhabricatorPolicyCapability::CAN_VIEW) {
             $policy = PhabricatorPolicies::POLICY_USER;
         }
     }
     $viewer = $this->viewer;
     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:
             throw new Exception("Object has unknown policy '{$policy}'!");
     }
     return false;
 }