Page MenuHomePhabricator

D10978.id26360.diff
No OneTemporary

D10978.id26360.diff

diff --git a/src/applications/phriction/editor/PhrictionTransactionEditor.php b/src/applications/phriction/editor/PhrictionTransactionEditor.php
--- a/src/applications/phriction/editor/PhrictionTransactionEditor.php
+++ b/src/applications/phriction/editor/PhrictionTransactionEditor.php
@@ -519,6 +519,42 @@
$errors[] = $error;
}
}
+
+ if ($this->getIsNewObject()) {
+ // NOTE: We use the ominpotent user for these checks because policy
+ // doesn't matter; existence does.
+ $other_doc_viewer = PhabricatorUser::getOmnipotentUser();
+ $ancestral_slugs = PhabricatorSlug::getAncestry($object->getSlug());
+ if ($ancestral_slugs) {
+ $ancestors = id(new PhrictionDocumentQuery())
+ ->setViewer($other_doc_viewer)
+ ->withSlugs($ancestral_slugs)
+ ->execute();
+ $ancestors = mpull($ancestors, null, 'getSlug');
+ foreach ($ancestral_slugs as $slug) {
+ $ancestor_doc = idx($ancestors, $slug);
+ if (!$ancestor_doc) {
+ $create_uri = '/phriction/edit/?slug='.$slug;
+ $message = pht(
+ 'Can not create document because the parent document with '.
+ 'slug %s does not exist!',
+ phutil_tag(
+ 'a',
+ array(
+ 'href' => $create_uri,
+ ),
+ $slug));
+ $error = new PhabricatorApplicationTransactionValidationError(
+ $type,
+ pht('Missing Ancestor'),
+ $message,
+ $xaction);
+ $errors[] = $error;
+ }
+ }
+ }
+ }
+
break;
case PhrictionTransaction::TYPE_MOVE_TO:
@@ -547,10 +583,41 @@
$errors[] = $error;
}
- // NOTE: We use the ominpotent user because we can't let users
- // overwrite documents even if they can't see them.
+ // NOTE: We use the ominpotent user for these checks because policy
+ // doesn't matter; existence does.
+ $other_doc_viewer = PhabricatorUser::getOmnipotentUser();
+ $ancestral_slugs = PhabricatorSlug::getAncestry($object->getSlug());
+ if ($ancestral_slugs) {
+ $ancestors = id(new PhrictionDocumentQuery())
+ ->setViewer($other_doc_viewer)
+ ->withSlugs($ancestral_slugs)
+ ->execute();
+ $ancestors = mpull($ancestors, null, 'getSlug');
+ foreach ($ancestral_slugs as $slug) {
+ $ancestor_doc = idx($ancestors, $slug);
+ if (!$ancestor_doc) {
+ $create_uri = '/phriction/edit/?slug='.$slug;
+ $message = pht(
+ 'Can not move document because the parent document with '.
+ 'slug %s does not exist!',
+ phutil_tag(
+ 'a',
+ array(
+ 'href' => $create_uri,
+ ),
+ $slug));
+ $error = new PhabricatorApplicationTransactionValidationError(
+ $type,
+ pht('Missing Ancestor'),
+ $message,
+ $xaction);
+ $errors[] = $error;
+ }
+ }
+ }
+
$target_document = id(new PhrictionDocumentQuery())
- ->setViewer(PhabricatorUser::getOmnipotentUser())
+ ->setViewer($other_doc_viewer)
->withSlugs(array($object->getSlug()))
->needContent(true)
->executeOne();

File Metadata

Mime Type
text/plain
Expires
Wed, May 8, 8:04 PM (2 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6272770
Default Alt Text
D10978.id26360.diff (3 KB)

Event Timeline