1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 21:40:55 +01:00

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
This commit is contained in:
epriestley 2018-07-30 16:22:46 -07:00
parent 8374201620
commit 8d8086fccf
5 changed files with 33 additions and 5 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_phriction.phriction_document
ADD spacePHID VARBINARY(64) DEFAULT NULL;

View file

@ -11129,6 +11129,7 @@ phutil_register_library_map(array(
'PhabricatorApplicationTransactionInterface',
'PhabricatorConduitResultInterface',
'PhabricatorPolicyCodexInterface',
'PhabricatorSpacesInterface',
),
'PhrictionDocumentAuthorHeraldField' => 'PhrictionDocumentHeraldField',
'PhrictionDocumentContentHeraldField' => 'PhrictionDocumentHeraldField',

View file

@ -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)

View file

@ -131,6 +131,7 @@ final class PhrictionDocumentSearchEngine
$item = id(new PHUIObjectItemView())
->setHeader($content->getTitle())
->setObject($document)
->setHref($slug_uri)
->addByline($byline)
->addIcon('none', $updated);

View file

@ -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 )----------------------------------- */