Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15195249
D10978.id26361.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D10978.id26361.diff
View Options
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,18 @@
$errors[] = $error;
}
}
+
+ if ($this->getIsNewObject()) {
+ $ancestry_errors = $this->validateAncestry(
+ $object,
+ $type,
+ $xaction,
+ pht('create'));
+ if ($ancestry_errors) {
+ $errors = array_merge($errors, $ancestry_errors);
+ }
+ }
+
break;
case PhrictionTransaction::TYPE_MOVE_TO:
@@ -547,8 +559,15 @@
$errors[] = $error;
}
- // NOTE: We use the ominpotent user because we can't let users
- // overwrite documents even if they can't see them.
+ $ancestry_errors = $this->validateAncestry(
+ $object,
+ $type,
+ $xaction,
+ pht('move'));
+ if ($ancestry_errors) {
+ $errors = array_merge($errors, $ancestry_errors);
+ }
+
$target_document = id(new PhrictionDocumentQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withSlugs(array($object->getSlug()))
@@ -606,6 +625,49 @@
return $errors;
}
+ private function validateAncestry(
+ PhabricatorLiskDAO $object,
+ $type,
+ PhabricatorApplicationTransaction $xaction,
+ $verb) {
+
+ $errors = array();
+ // 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 %s document because the parent document with '.
+ 'slug %s does not exist!',
+ $verb,
+ phutil_tag(
+ 'a',
+ array(
+ 'href' => $create_uri,
+ ),
+ $slug));
+ $error = new PhabricatorApplicationTransactionValidationError(
+ $type,
+ pht('Missing Ancestor'),
+ $message,
+ $xaction);
+ $errors[] = $error;
+ }
+ }
+ }
+ return $errors;
+ }
+
private function validateContentVersion(
PhabricatorLiskDAO $object,
$type,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Feb 23, 12:40 PM (10 h, 39 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7186289
Default Alt Text
D10978.id26361.diff (2 KB)
Attached To
Mode
D10978: Phriction - validateTransactions that need parent ancestry to complete successfully
Attached
Detach File
Event Timeline
Log In to Comment