Skip to content

Commit 9084f1f

Browse files
committed
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
1 parent 0e65740 commit 9084f1f

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

src/applications/phriction/controller/PhrictionDocumentController.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ public function processRequest() {
4040
$document = new PhrictionDocument();
4141

4242
if (PhrictionDocument::isProjectSlug($slug)) {
43-
$project = id(new PhabricatorProject())->loadOneWhere(
44-
'phrictionSlug = %s',
45-
PhrictionDocument::getProjectSlugIdentifier($slug));
43+
$project = id(new PhabricatorProjectQuery())
44+
->setViewer($user)
45+
->withPhrictionSlugs(array(
46+
PhrictionDocument::getProjectSlugIdentifier($slug)))
47+
->executeOne();
4648
if (!$project) {
4749
return new Aphront404Response();
4850
}
@@ -214,9 +216,11 @@ private function buildPropertyListView(
214216

215217
$project_phid = null;
216218
if (PhrictionDocument::isProjectSlug($slug)) {
217-
$project = id(new PhabricatorProject())->loadOneWhere(
218-
'phrictionSlug = %s',
219-
PhrictionDocument::getProjectSlugIdentifier($slug));
219+
$project = id(new PhabricatorProjectQuery())
220+
->setViewer($viewer)
221+
->withPhrictionSlugs(array(
222+
PhrictionDocument::getProjectSlugIdentifier($slug)))
223+
->executeOne();
220224
if ($project) {
221225
$project_phid = $project->getPHID();
222226
}

src/applications/phriction/controller/PhrictionEditController.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ public function processRequest() {
5151
$content = id(new PhrictionContent())->load($document->getContentID());
5252
} else {
5353
if (PhrictionDocument::isProjectSlug($slug)) {
54-
$project = id(new PhabricatorProject())->loadOneWhere(
55-
'phrictionSlug = %s',
56-
PhrictionDocument::getProjectSlugIdentifier($slug));
54+
$project = id(new PhabricatorProjectQuery())
55+
->setViewer($user)
56+
->withPhrictionSlugs(array(
57+
PhrictionDocument::getProjectSlugIdentifier($slug)))
58+
->executeOne();
5759
if (!$project) {
5860
return new Aphront404Response();
5961
}

src/applications/phriction/controller/PhrictionNewController.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ public function processRequest() {
3333
->addSubmitButton(pht('Edit Document'));
3434

3535
return id(new AphrontDialogResponse())->setDialog($dialog);
36-
} elseif (substr($slug, 0, 9) == 'projects/') {
36+
} else if (PhrictionDocument::isProjectSlug($slug)) {
37+
$project = id(new PhabricatorProjectQuery())
38+
->setViewer($user)
39+
->withPhrictionSlugs(array(
40+
PhrictionDocument::getProjectSlugIdentifier($slug)))
41+
->executeOne();
42+
if (!$project) {
3743
$dialog = new AphrontDialogView();
3844
$dialog->setSubmitURI('/w/')
3945
->setTitle(pht('Oops!'))
@@ -44,12 +50,12 @@ public function processRequest() {
4450
Create a new project with this name first.'))
4551
->addCancelButton('/w/', 'Okay');
4652
return id(new AphrontDialogResponse())->setDialog($dialog);
47-
48-
} else {
49-
$uri = '/phriction/edit/?slug='.$slug;
50-
return id(new AphrontRedirectResponse())
51-
->setURI($uri);
53+
}
5254
}
55+
56+
$uri = '/phriction/edit/?slug='.$slug;
57+
return id(new AphrontRedirectResponse())
58+
->setURI($uri);
5359
}
5460

5561
if ($slug == '/') {

src/applications/phriction/editor/PhrictionDocumentEditor.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,11 @@ private function updateDocument($document, $content, $new_content) {
240240
$project_phid = null;
241241
$slug = $document->getSlug();
242242
if (PhrictionDocument::isProjectSlug($slug)) {
243-
$project = id(new PhabricatorProject())->loadOneWhere(
244-
'phrictionSlug = %s',
245-
PhrictionDocument::getProjectSlugIdentifier($slug));
243+
$project = id(new PhabricatorProjectQuery())
244+
->setViewer($this->requireActor())
245+
->withPhrictionSlugs(array(
246+
PhrictionDocument::getProjectSlugIdentifier($slug)))
247+
->executeOne();
246248
if ($project) {
247249
$project_phid = $project->getPHID();
248250
}

0 commit comments

Comments
 (0)