Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/controller/PhabricatorProjectController.php
| <?php | <?php | ||||
| abstract class PhabricatorProjectController extends PhabricatorController { | abstract class PhabricatorProjectController extends PhabricatorController { | ||||
| private $project; | private $project; | ||||
| protected function setProject(PhabricatorProject $project) { | protected function setProject(PhabricatorProject $project) { | ||||
| $this->project = $project; | $this->project = $project; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| protected function getProject() { | protected function getProject() { | ||||
| return $this->project; | return $this->project; | ||||
| } | } | ||||
| protected function loadProject() { | |||||
| $viewer = $this->getViewer(); | |||||
| $request = $this->getRequest(); | |||||
| $id = $request->getURIData('id'); | |||||
| $slug = $request->getURIData('slug'); | |||||
| if ($slug) { | |||||
| $normal_slug = PhabricatorSlug::normalizeProjectSlug($slug); | |||||
| $is_abnormal = ($slug !== $normal_slug); | |||||
| $normal_uri = "/tag/{$normal_slug}/"; | |||||
| } else { | |||||
| $is_abnormal = false; | |||||
| } | |||||
| $query = id(new PhabricatorProjectQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->needMembers(true) | |||||
| ->needWatchers(true) | |||||
| ->needImages(true) | |||||
| ->needSlugs(true); | |||||
| if ($slug) { | |||||
| $query->withSlugs(array($slug)); | |||||
| } else { | |||||
| $query->withIDs(array($id)); | |||||
| } | |||||
| $policy_exception = null; | |||||
| try { | |||||
| $project = $query->executeOne(); | |||||
| } catch (PhabricatorPolicyException $ex) { | |||||
| $policy_exception = $ex; | |||||
| $project = null; | |||||
| } | |||||
| if (!$project) { | |||||
| // This project legitimately does not exist, so just 404 the user. | |||||
| if (!$policy_exception) { | |||||
| return new Aphront404Response(); | |||||
| } | |||||
| // Here, the project exists but the user can't see it. If they are | |||||
| // using a non-canonical slug to view the project, redirect to the | |||||
| // canonical slug. If they're already using the canonical slug, rethrow | |||||
| // the exception to give them the policy error. | |||||
| if ($is_abnormal) { | |||||
| return id(new AphrontRedirectResponse())->setURI($normal_uri); | |||||
| } else { | |||||
| throw $policy_exception; | |||||
| } | |||||
| } | |||||
| // The user can view the project, but is using a noncanonical slug. | |||||
| // Redirect to the canonical slug. | |||||
| $primary_slug = $project->getPrimarySlug(); | |||||
| if ($slug && ($slug !== $primary_slug)) { | |||||
| $primary_uri = "/tag/{$primary_slug}/"; | |||||
| return id(new AphrontRedirectResponse())->setURI($primary_uri); | |||||
| } | |||||
| $this->setProject($project); | |||||
| return null; | |||||
| } | |||||
| public function buildApplicationMenu() { | public function buildApplicationMenu() { | ||||
| return $this->buildSideNavView(true)->getMenu(); | return $this->buildSideNavView(true)->getMenu(); | ||||
| } | } | ||||
| public function buildSideNavView($for_app = false) { | public function buildSideNavView($for_app = false) { | ||||
| $project = $this->getProject(); | $project = $this->getProject(); | ||||
| $nav = new AphrontSideNavFilterView(); | $nav = new AphrontSideNavFilterView(); | ||||
| ▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines | |||||