Commit 9084f1fe authored by Bob Trahan's avatar Bob Trahan
Browse files

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
parent 0e65740c
......@@ -40,9 +40,11 @@ final class PhrictionDocumentController
$document = new PhrictionDocument();
if (PhrictionDocument::isProjectSlug($slug)) {
$project = id(new PhabricatorProject())->loadOneWhere(
'phrictionSlug = %s',
PhrictionDocument::getProjectSlugIdentifier($slug));
$project = id(new PhabricatorProjectQuery())
->setViewer($user)
->withPhrictionSlugs(array(
PhrictionDocument::getProjectSlugIdentifier($slug)))
->executeOne();
if (!$project) {
return new Aphront404Response();
}
......@@ -214,9 +216,11 @@ final class PhrictionDocumentController
$project_phid = null;
if (PhrictionDocument::isProjectSlug($slug)) {
$project = id(new PhabricatorProject())->loadOneWhere(
'phrictionSlug = %s',
PhrictionDocument::getProjectSlugIdentifier($slug));
$project = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withPhrictionSlugs(array(
PhrictionDocument::getProjectSlugIdentifier($slug)))
->executeOne();
if ($project) {
$project_phid = $project->getPHID();
}
......
......@@ -51,9 +51,11 @@ final class PhrictionEditController
$content = id(new PhrictionContent())->load($document->getContentID());
} else {
if (PhrictionDocument::isProjectSlug($slug)) {
$project = id(new PhabricatorProject())->loadOneWhere(
'phrictionSlug = %s',
PhrictionDocument::getProjectSlugIdentifier($slug));
$project = id(new PhabricatorProjectQuery())
->setViewer($user)
->withPhrictionSlugs(array(
PhrictionDocument::getProjectSlugIdentifier($slug)))
->executeOne();
if (!$project) {
return new Aphront404Response();
}
......
......@@ -33,7 +33,13 @@ final class PhrictionNewController extends PhrictionController {
->addSubmitButton(pht('Edit Document'));
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->setSubmitURI('/w/')
->setTitle(pht('Oops!'))
......@@ -44,12 +50,12 @@ final class PhrictionNewController extends PhrictionController {
Create a new project with this name first.'))
->addCancelButton('/w/', 'Okay');
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 == '/') {
......
......@@ -240,9 +240,11 @@ final class PhrictionDocumentEditor extends PhabricatorEditor {
$project_phid = null;
$slug = $document->getSlug();
if (PhrictionDocument::isProjectSlug($slug)) {
$project = id(new PhabricatorProject())->loadOneWhere(
'phrictionSlug = %s',
PhrictionDocument::getProjectSlugIdentifier($slug));
$project = id(new PhabricatorProjectQuery())
->setViewer($this->requireActor())
->withPhrictionSlugs(array(
PhrictionDocument::getProjectSlugIdentifier($slug)))
->executeOne();
if ($project) {
$project_phid = $project->getPHID();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment