Page MenuHomePhabricator

D19584.id46838.diff
No OneTemporary

D19584.id46838.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
@@ -516,58 +516,6 @@
}
return $error;
}
- protected function requireCapabilities(
- PhabricatorLiskDAO $object,
- PhabricatorApplicationTransaction $xaction) {
-
- /*
- * New objects have a special case. If a user can't see
- * x/y
- * then definitely don't let them make some
- * x/y/z
- * We need to load the direct parent to handle this case.
- */
- if ($this->getIsNewObject()) {
- $actor = $this->requireActor();
- $parent_doc = null;
- $ancestral_slugs = PhabricatorSlug::getAncestry($object->getSlug());
- // No ancestral slugs is "/"; the first person gets to play with "/".
- if ($ancestral_slugs) {
- $parent = end($ancestral_slugs);
- $parent_doc = id(new PhrictionDocumentQuery())
- ->setViewer($actor)
- ->withSlugs(array($parent))
- ->executeOne();
- // If the $actor can't see the $parent_doc then they can't create
- // the child $object; throw a policy exception.
- if (!$parent_doc) {
- id(new PhabricatorPolicyFilter())
- ->setViewer($actor)
- ->raisePolicyExceptions(true)
- ->rejectObject(
- $object,
- $object->getEditPolicy(),
- PhabricatorPolicyCapability::CAN_EDIT);
- }
-
- // If the $actor can't edit the $parent_doc then they can't create
- // the child $object; throw a policy exception.
- if (!PhabricatorPolicyFilter::hasCapability(
- $actor,
- $parent_doc,
- PhabricatorPolicyCapability::CAN_EDIT)) {
- id(new PhabricatorPolicyFilter())
- ->setViewer($actor)
- ->raisePolicyExceptions(true)
- ->rejectObject(
- $object,
- $object->getEditPolicy(),
- PhabricatorPolicyCapability::CAN_EDIT);
- }
- }
- }
- return parent::requireCapabilities($object, $xaction);
- }
protected function supportsSearch() {
return true;
diff --git a/src/applications/phriction/xaction/PhrictionDocumentTitleTransaction.php b/src/applications/phriction/xaction/PhrictionDocumentTitleTransaction.php
--- a/src/applications/phriction/xaction/PhrictionDocumentTitleTransaction.php
+++ b/src/applications/phriction/xaction/PhrictionDocumentTitleTransaction.php
@@ -91,6 +91,29 @@
pht('Documents must have a title.'));
}
+ if ($this->isNewObject()) {
+ // No ancestral slugs is "/". No ancestry checks apply when creating the
+ // root document.
+ $ancestral_slugs = PhabricatorSlug::getAncestry($object->getSlug());
+ if ($ancestral_slugs) {
+ // You must be able to view and edit the parent document to create a new
+ // child.
+ $parent_document = id(new PhrictionDocumentQuery())
+ ->setViewer($this->getActor())
+ ->withSlugs(array(last($ancestral_slugs)))
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ PhabricatorPolicyCapability::CAN_EDIT,
+ ))
+ ->executeOne();
+ if (!$parent_document) {
+ $errors[] = $this->newInvalidError(
+ pht('You can not create a document which does not have a parent.'));
+ }
+ }
+ }
+
return $errors;
}

File Metadata

Mime Type
text/plain
Expires
Fri, Apr 4, 12:42 AM (2 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7418707
Default Alt Text
D19584.id46838.diff (3 KB)

Event Timeline