Changeset View
Changeset View
Standalone View
Standalone View
src/applications/spaces/query/PhabricatorSpacesNamespaceQuery.php
| <?php | <?php | ||||
| final class PhabricatorSpacesNamespaceQuery | final class PhabricatorSpacesNamespaceQuery | ||||
| extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
| const KEY_ALL = 'spaces.all'; | const KEY_ALL = 'spaces.all'; | ||||
| const KEY_DEFAULT = 'spaces.default'; | const KEY_DEFAULT = 'spaces.default'; | ||||
| const KEY_VIEWER = 'spaces.viewer'; | |||||
| private $ids; | private $ids; | ||||
| private $phids; | private $phids; | ||||
| private $isDefaultNamespace; | private $isDefaultNamespace; | ||||
| private $isArchived; | private $isArchived; | ||||
| public function withIDs(array $ids) { | public function withIDs(array $ids) { | ||||
| $this->ids = $ids; | $this->ids = $ids; | ||||
| ▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | if ($default_space === false) { | ||||
| $cache->setKey($cache_key, $default_space); | $cache->setKey($cache_key, $default_space); | ||||
| } | } | ||||
| return $default_space; | return $default_space; | ||||
| } | } | ||||
| public static function getViewerSpaces(PhabricatorUser $viewer) { | public static function getViewerSpaces(PhabricatorUser $viewer) { | ||||
| $cache = PhabricatorCaches::getRequestCache(); | |||||
| $cache_key = self::KEY_VIEWER.'('.$viewer->getPHID().')'; | |||||
| $result = $cache->getKey($cache_key); | |||||
| if ($result === null) { | |||||
| $spaces = self::getAllSpaces(); | $spaces = self::getAllSpaces(); | ||||
| $result = array(); | $result = array(); | ||||
| foreach ($spaces as $key => $space) { | foreach ($spaces as $key => $space) { | ||||
| $can_see = PhabricatorPolicyFilter::hasCapability( | $can_see = PhabricatorPolicyFilter::hasCapability( | ||||
| $viewer, | $viewer, | ||||
| $space, | $space, | ||||
| PhabricatorPolicyCapability::CAN_VIEW); | PhabricatorPolicyCapability::CAN_VIEW); | ||||
| if ($can_see) { | if ($can_see) { | ||||
| $result[$key] = $space; | $result[$key] = $space; | ||||
| } | } | ||||
| } | } | ||||
| $cache->setKey($cache_key, $result); | |||||
| } | |||||
| return $result; | return $result; | ||||
| } | } | ||||
| public static function getViewerActiveSpaces(PhabricatorUser $viewer) { | public static function getViewerActiveSpaces(PhabricatorUser $viewer) { | ||||
| $spaces = self::getViewerSpaces($viewer); | $spaces = self::getViewerSpaces($viewer); | ||||
| foreach ($spaces as $key => $space) { | foreach ($spaces as $key => $space) { | ||||
| ▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines | |||||