From 8d8086fccf9635484ccb915018a7074f73f7d1d3 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 30 Jul 2018 16:22:46 -0700 Subject: [PATCH] Add Spaces support to Phriction Summary: Ref T13164. See PHI774. Fixes T12435. Since Phriction is hierarchical, there isn't a super strong motivation to support Spaces: you can generally set policies on a small number of documents to get the desired effective policy behavior. However, it still improves consistency and there's no reason //not// to support Spaces. In the case where you have some moderately weird/complex policy on one or more Spaces, using Spaces to define the policy behavior can make things a bit simpler and easier to understand. This probably doesn't actually fix whatever the root problem in T12435 was (complicated, non-hierarchical access policies?). See also a bunch of discussion in T12442. So we might end up going beyond this to address other use cases, but I think this is reasonable regardless. Test Plan: Created and edited Phriction documents and shifted them between Spaces. Searched by Space, etc. Reviewers: amckinley Reviewed By: amckinley Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13164, T12435 Differential Revision: https://secure.phabricator.com/D19553 --- .../20180730.phriction.01.spaces.sql | 2 ++ src/__phutil_library_map__.php | 1 + .../controller/PhrictionEditController.php | 9 +++++++ .../query/PhrictionDocumentSearchEngine.php | 1 + .../phriction/storage/PhrictionDocument.php | 25 +++++++++++++++---- 5 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 resources/sql/autopatches/20180730.phriction.01.spaces.sql diff --git a/resources/sql/autopatches/20180730.phriction.01.spaces.sql b/resources/sql/autopatches/20180730.phriction.01.spaces.sql new file mode 100644 index 0000000000..6d3e007258 --- /dev/null +++ b/resources/sql/autopatches/20180730.phriction.01.spaces.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_phriction.phriction_document + ADD spacePHID VARBINARY(64) DEFAULT NULL; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 981764dc7a..bd4cfef6c2 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -11129,6 +11129,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationTransactionInterface', 'PhabricatorConduitResultInterface', 'PhabricatorPolicyCodexInterface', + 'PhabricatorSpacesInterface', ), 'PhrictionDocumentAuthorHeraldField' => 'PhrictionDocumentHeraldField', 'PhrictionDocumentContentHeraldField' => 'PhrictionDocumentHeraldField', diff --git a/src/applications/phriction/controller/PhrictionEditController.php b/src/applications/phriction/controller/PhrictionEditController.php index 006488b274..ccd473931c 100644 --- a/src/applications/phriction/controller/PhrictionEditController.php +++ b/src/applications/phriction/controller/PhrictionEditController.php @@ -121,6 +121,8 @@ final class PhrictionEditController $v_projects = array_reverse($v_projects); } + $v_space = $document->getSpacePHID(); + if ($request->isFormPost()) { $title = $request->getStr('title'); @@ -131,6 +133,7 @@ final class PhrictionEditController $v_edit = $request->getStr('editPolicy'); $v_cc = $request->getArr('cc'); $v_projects = $request->getArr('projects'); + $v_space = $request->getStr('spacePHID'); $xactions = array(); $xactions[] = id(new PhrictionTransaction()) @@ -146,6 +149,9 @@ final class PhrictionEditController $xactions[] = id(new PhrictionTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY) ->setNewValue($v_edit); + $xactions[] = id(new PhrictionTransaction()) + ->setTransactionType(PhabricatorTransactions::TYPE_SPACE) + ->setNewValue($v_space); $xactions[] = id(new PhrictionTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) ->setNewValue(array('=' => $v_cc)); @@ -192,6 +198,7 @@ final class PhrictionEditController $document->setViewPolicy($v_view); $document->setEditPolicy($v_edit); + $document->setSpacePHID($v_space); } } @@ -267,7 +274,9 @@ final class PhrictionEditController ->setDatasource(new PhabricatorMetaMTAMailableDatasource())) ->appendChild( id(new AphrontFormPolicyControl()) + ->setViewer($viewer) ->setName('viewPolicy') + ->setSpacePHID($v_space) ->setPolicyObject($document) ->setCapability($view_capability) ->setPolicies($policies) diff --git a/src/applications/phriction/query/PhrictionDocumentSearchEngine.php b/src/applications/phriction/query/PhrictionDocumentSearchEngine.php index e3d962146a..49a332268b 100644 --- a/src/applications/phriction/query/PhrictionDocumentSearchEngine.php +++ b/src/applications/phriction/query/PhrictionDocumentSearchEngine.php @@ -131,6 +131,7 @@ final class PhrictionDocumentSearchEngine $item = id(new PHUIObjectItemView()) ->setHeader($content->getTitle()) + ->setObject($document) ->setHref($slug_uri) ->addByline($byline) ->addIcon('none', $updated); diff --git a/src/applications/phriction/storage/PhrictionDocument.php b/src/applications/phriction/storage/PhrictionDocument.php index f482579cea..6edb516e6e 100644 --- a/src/applications/phriction/storage/PhrictionDocument.php +++ b/src/applications/phriction/storage/PhrictionDocument.php @@ -12,7 +12,8 @@ final class PhrictionDocument extends PhrictionDAO PhabricatorProjectInterface, PhabricatorApplicationTransactionInterface, PhabricatorConduitResultInterface, - PhabricatorPolicyCodexInterface { + PhabricatorPolicyCodexInterface, + PhabricatorSpacesInterface { protected $slug; protected $depth; @@ -21,6 +22,7 @@ final class PhrictionDocument extends PhrictionDAO protected $mailKey; protected $viewPolicy; protected $editPolicy; + protected $spacePHID; private $contentObject = self::ATTACHABLE; private $ancestors = array(); @@ -81,12 +83,16 @@ final class PhrictionDocument extends PhrictionDAO } if ($parent_doc) { - $document->setViewPolicy($parent_doc->getViewPolicy()); - $document->setEditPolicy($parent_doc->getEditPolicy()); + $document + ->setViewPolicy($parent_doc->getViewPolicy()) + ->setEditPolicy($parent_doc->getEditPolicy()) + ->setSpacePHID($parent_doc->getSpacePHID()); } else { $default_view_policy = PhabricatorPolicies::getMostOpenPolicy(); - $document->setViewPolicy($default_view_policy); - $document->setEditPolicy(PhabricatorPolicies::POLICY_USER); + $document + ->setViewPolicy($default_view_policy) + ->setEditPolicy(PhabricatorPolicies::POLICY_USER) + ->setSpacePHID($actor->getDefaultSpacePHID()); } return $document; @@ -202,6 +208,15 @@ final class PhrictionDocument extends PhrictionDAO } +/* -( PhabricatorSpacesInterface )----------------------------------------- */ + + + public function getSpacePHID() { + return $this->spacePHID; + } + + + /* -( PhabricatorSubscribableInterface )----------------------------------- */