Phriction - make the check for project sub pages more fine-grained

Summary:
we were just checking if projects/ was in the URI before barfing. Use some more fun utility functions such that we only complain if there is no project.

Fixes T4071.

Test Plan: made a subpage under a project - success! tried to make a project wiki page where there was no project - successful failure! tried to make a project wiki sub page where there was no project - successful failure!

Reviewers: epriestley, chad

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Maniphest Tasks: T4071

Differential Revision: https://secure.phabricator.com/D7527
This commit is contained in:
Bob Trahan 2013-11-07 12:06:42 -08:00
parent 0e65740c2d
commit 9084f1fe8c
4 changed files with 32 additions and 18 deletions

View file

@ -40,9 +40,11 @@ final class PhrictionDocumentController
$document = new PhrictionDocument(); $document = new PhrictionDocument();
if (PhrictionDocument::isProjectSlug($slug)) { if (PhrictionDocument::isProjectSlug($slug)) {
$project = id(new PhabricatorProject())->loadOneWhere( $project = id(new PhabricatorProjectQuery())
'phrictionSlug = %s', ->setViewer($user)
PhrictionDocument::getProjectSlugIdentifier($slug)); ->withPhrictionSlugs(array(
PhrictionDocument::getProjectSlugIdentifier($slug)))
->executeOne();
if (!$project) { if (!$project) {
return new Aphront404Response(); return new Aphront404Response();
} }
@ -214,9 +216,11 @@ final class PhrictionDocumentController
$project_phid = null; $project_phid = null;
if (PhrictionDocument::isProjectSlug($slug)) { if (PhrictionDocument::isProjectSlug($slug)) {
$project = id(new PhabricatorProject())->loadOneWhere( $project = id(new PhabricatorProjectQuery())
'phrictionSlug = %s', ->setViewer($viewer)
PhrictionDocument::getProjectSlugIdentifier($slug)); ->withPhrictionSlugs(array(
PhrictionDocument::getProjectSlugIdentifier($slug)))
->executeOne();
if ($project) { if ($project) {
$project_phid = $project->getPHID(); $project_phid = $project->getPHID();
} }

View file

@ -51,9 +51,11 @@ final class PhrictionEditController
$content = id(new PhrictionContent())->load($document->getContentID()); $content = id(new PhrictionContent())->load($document->getContentID());
} else { } else {
if (PhrictionDocument::isProjectSlug($slug)) { if (PhrictionDocument::isProjectSlug($slug)) {
$project = id(new PhabricatorProject())->loadOneWhere( $project = id(new PhabricatorProjectQuery())
'phrictionSlug = %s', ->setViewer($user)
PhrictionDocument::getProjectSlugIdentifier($slug)); ->withPhrictionSlugs(array(
PhrictionDocument::getProjectSlugIdentifier($slug)))
->executeOne();
if (!$project) { if (!$project) {
return new Aphront404Response(); return new Aphront404Response();
} }

View file

@ -33,7 +33,13 @@ final class PhrictionNewController extends PhrictionController {
->addSubmitButton(pht('Edit Document')); ->addSubmitButton(pht('Edit Document'));
return id(new AphrontDialogResponse())->setDialog($dialog); return id(new AphrontDialogResponse())->setDialog($dialog);
} elseif (substr($slug, 0, 9) == 'projects/') { } else if (PhrictionDocument::isProjectSlug($slug)) {
$project = id(new PhabricatorProjectQuery())
->setViewer($user)
->withPhrictionSlugs(array(
PhrictionDocument::getProjectSlugIdentifier($slug)))
->executeOne();
if (!$project) {
$dialog = new AphrontDialogView(); $dialog = new AphrontDialogView();
$dialog->setSubmitURI('/w/') $dialog->setSubmitURI('/w/')
->setTitle(pht('Oops!')) ->setTitle(pht('Oops!'))
@ -44,12 +50,12 @@ final class PhrictionNewController extends PhrictionController {
Create a new project with this name first.')) Create a new project with this name first.'))
->addCancelButton('/w/', 'Okay'); ->addCancelButton('/w/', 'Okay');
return id(new AphrontDialogResponse())->setDialog($dialog); return id(new AphrontDialogResponse())->setDialog($dialog);
}
} else {
$uri = '/phriction/edit/?slug='.$slug;
return id(new AphrontRedirectResponse())
->setURI($uri);
} }
$uri = '/phriction/edit/?slug='.$slug;
return id(new AphrontRedirectResponse())
->setURI($uri);
} }
if ($slug == '/') { if ($slug == '/') {

View file

@ -240,9 +240,11 @@ final class PhrictionDocumentEditor extends PhabricatorEditor {
$project_phid = null; $project_phid = null;
$slug = $document->getSlug(); $slug = $document->getSlug();
if (PhrictionDocument::isProjectSlug($slug)) { if (PhrictionDocument::isProjectSlug($slug)) {
$project = id(new PhabricatorProject())->loadOneWhere( $project = id(new PhabricatorProjectQuery())
'phrictionSlug = %s', ->setViewer($this->requireActor())
PhrictionDocument::getProjectSlugIdentifier($slug)); ->withPhrictionSlugs(array(
PhrictionDocument::getProjectSlugIdentifier($slug)))
->executeOne();
if ($project) { if ($project) {
$project_phid = $project->getPHID(); $project_phid = $project->getPHID();
} }