1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 12:00:55 +01:00

Project - use hashtag as a way to access project profile in URI, e.g. /project/hashtag/

Summary: Fixes T4022. Hooks up the project profile controller to understanding URIs like /project/hashtag/ Also, makes handles have the new /project/hashtag/ URI by default, thus upselling that feature super duper heavily.

Test Plan: clicked some project links, noted pretty uri and page working nicely.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: chad, epriestley, Korvin

Maniphest Tasks: T4022

Differential Revision: https://secure.phabricator.com/D9260
This commit is contained in:
Bob Trahan 2014-05-22 15:16:16 -07:00
parent a76f61f7e1
commit c39f302c04
3 changed files with 23 additions and 6 deletions

View file

@ -67,6 +67,10 @@ final class PhabricatorApplicationProject extends PhabricatorApplication {
'history/(?P<id>[1-9]\d*)/' => 'PhabricatorProjectHistoryController', 'history/(?P<id>[1-9]\d*)/' => 'PhabricatorProjectHistoryController',
'(?P<action>watch|unwatch)/(?P<id>[1-9]\d*)/' '(?P<action>watch|unwatch)/(?P<id>[1-9]\d*)/'
=> 'PhabricatorProjectWatchController', => 'PhabricatorProjectWatchController',
),
'/tag/' => array(
'(?P<slug>[^/]+)/' => 'PhabricatorProjectProfileController',
), ),
); );
} }

View file

@ -4,29 +4,41 @@ final class PhabricatorProjectProfileController
extends PhabricatorProjectController { extends PhabricatorProjectController {
private $id; private $id;
private $slug;
public function shouldAllowPublic() { public function shouldAllowPublic() {
return true; return true;
} }
public function willProcessRequest(array $data) { public function willProcessRequest(array $data) {
// via /project/view/$id/
$this->id = idx($data, 'id'); $this->id = idx($data, 'id');
// via /tag/$slug/
$this->slug = idx($data, 'slug');
} }
public function processRequest() { public function processRequest() {
$request = $this->getRequest(); $request = $this->getRequest();
$user = $request->getUser(); $user = $request->getUser();
$project = id(new PhabricatorProjectQuery()) $query = id(new PhabricatorProjectQuery())
->setViewer($user) ->setViewer($user)
->withIDs(array($this->id))
->needMembers(true) ->needMembers(true)
->needWatchers(true) ->needWatchers(true)
->needImages(true) ->needImages(true);
->executeOne(); if ($this->slug) {
$query->withSlugs(array($this->slug));
} else {
$query->withIDs(array($this->id));
}
$project = $query->executeOne();
if (!$project) { if (!$project) {
return new Aphront404Response(); return new Aphront404Response();
} }
if ($this->slug && $this->slug != $project->getPrimarySlug()) {
return id(new AphrontRedirectResponse())
->setURI('/tag/'.$project->getPrimarySlug().'/');
}
$picture = $project->getProfileImageURI(); $picture = $project->getProfileImageURI();

View file

@ -43,10 +43,11 @@ final class PhabricatorProjectPHIDTypeProject extends PhabricatorPHIDType {
$name = $project->getName(); $name = $project->getName();
$id = $project->getID(); $id = $project->getID();
$slug = $project->getPrimarySlug();
$handle->setName($name); $handle->setName($name);
$handle->setObjectName('#'.rtrim($project->getPhrictionSlug(), '/')); $handle->setObjectName('#'.$slug);
$handle->setURI("/project/view/{$id}/"); $handle->setURI("/tag/{$slug}/");
$handle->setImageURI($project->getProfileImageURI()); $handle->setImageURI($project->getProfileImageURI());
if ($project->isArchived()) { if ($project->isArchived()) {