mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Phriction - policy front end changes
Summary: Ref T4029. Fixes T6034. Various front-end miscellania here. See D10814#96251. This more or less makes policy work but I am not going to call it "fixed" here since we need D10814 to be deployed too and will do that manually. Test Plan: - changed document policy from web ui and changes persisted - changed document policy from web and had form error and changes persisted - created a structure like users/users/justmyuserpolicy and made sure another user could delete the users/users/ doc - moved a doc from a to b and verified policy persisted - verified stub documents inherited policy of the document that stub them...! - uploaded a file and verified that it 1) had the permissions of the page it was added to and 2) had an "attached" tab linking back to the page on the file page (this means T6034 is fixed with this) Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T6034, T4029 Differential Revision: https://secure.phabricator.com/D10816
This commit is contained in:
parent
8a3b1b9730
commit
c8d20d3c66
9 changed files with 80 additions and 59 deletions
|
@ -2756,7 +2756,6 @@ phutil_register_library_map(array(
|
|||
'PhrequentUserTime' => 'applications/phrequent/storage/PhrequentUserTime.php',
|
||||
'PhrequentUserTimeQuery' => 'applications/phrequent/query/PhrequentUserTimeQuery.php',
|
||||
'PhrictionActionConstants' => 'applications/phriction/constants/PhrictionActionConstants.php',
|
||||
'PhrictionActionMenuEventListener' => 'applications/phriction/event/PhrictionActionMenuEventListener.php',
|
||||
'PhrictionChangeType' => 'applications/phriction/constants/PhrictionChangeType.php',
|
||||
'PhrictionConduitAPIMethod' => 'applications/phriction/conduit/PhrictionConduitAPIMethod.php',
|
||||
'PhrictionConstants' => 'applications/phriction/constants/PhrictionConstants.php',
|
||||
|
@ -5959,7 +5958,6 @@ phutil_register_library_map(array(
|
|||
),
|
||||
'PhrequentUserTimeQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhrictionActionConstants' => 'PhrictionConstants',
|
||||
'PhrictionActionMenuEventListener' => 'PhabricatorEventListener',
|
||||
'PhrictionChangeType' => 'PhrictionConstants',
|
||||
'PhrictionConduitAPIMethod' => 'ConduitAPIMethod',
|
||||
'PhrictionContent' => array(
|
||||
|
|
|
@ -36,12 +36,6 @@ final class PhabricatorPhrictionApplication extends PhabricatorApplication {
|
|||
);
|
||||
}
|
||||
|
||||
public function getEventListeners() {
|
||||
return array(
|
||||
new PhrictionActionMenuEventListener(),
|
||||
);
|
||||
}
|
||||
|
||||
public function getRoutes() {
|
||||
return array(
|
||||
// Match "/w/" with slug "/".
|
||||
|
|
|
@ -4,6 +4,10 @@ final class PhrictionDiffController extends PhrictionController {
|
|||
|
||||
private $id;
|
||||
|
||||
public function shouldAllowPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->id = $data['id'];
|
||||
}
|
||||
|
|
|
@ -5,6 +5,10 @@ final class PhrictionDocumentController
|
|||
|
||||
private $slug;
|
||||
|
||||
public function shouldAllowPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->slug = $data['slug'];
|
||||
}
|
||||
|
|
|
@ -131,6 +131,8 @@ final class PhrictionEditController
|
|||
$content_text = $request->getStr('content');
|
||||
$notes = $request->getStr('description');
|
||||
$current_version = $request->getInt('contentVersion');
|
||||
$v_view = $request->getStr('viewPolicy');
|
||||
$v_edit = $request->getStr('editPolicy');
|
||||
|
||||
$xactions = array();
|
||||
$xactions[] = id(new PhrictionTransaction())
|
||||
|
@ -139,6 +141,12 @@ final class PhrictionEditController
|
|||
$xactions[] = id(new PhrictionTransaction())
|
||||
->setTransactionType(PhrictionTransaction::TYPE_CONTENT)
|
||||
->setNewValue($content_text);
|
||||
$xactions[] = id(new PhrictionTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
|
||||
->setNewValue($v_view);
|
||||
$xactions[] = id(new PhrictionTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)
|
||||
->setNewValue($v_edit);
|
||||
|
||||
$editor = id(new PhrictionTransactionEditor())
|
||||
->setActor($user)
|
||||
|
@ -170,7 +178,8 @@ final class PhrictionEditController
|
|||
$overwrite = true;
|
||||
}
|
||||
|
||||
// TODO - remember to set policy to what the user tried to set it to
|
||||
$document->setViewPolicy($v_view);
|
||||
$document->setEditPolicy($v_edit);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,6 +203,13 @@ final class PhrictionEditController
|
|||
|
||||
$cancel_uri = PhrictionDocument::getSlugURI($document->getSlug());
|
||||
|
||||
$policies = id(new PhabricatorPolicyQuery())
|
||||
->setViewer($user)
|
||||
->setObject($document)
|
||||
->execute();
|
||||
$view_capability = PhabricatorPolicyCapability::CAN_VIEW;
|
||||
$edit_capability = PhabricatorPolicyCapability::CAN_EDIT;
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setUser($user)
|
||||
->addHiddenInput('slug', $document->getSlug())
|
||||
|
@ -219,6 +235,22 @@ final class PhrictionEditController
|
|||
->setName('content')
|
||||
->setID('document-textarea')
|
||||
->setUser($user))
|
||||
->appendChild(
|
||||
id(new AphrontFormPolicyControl())
|
||||
->setName('viewPolicy')
|
||||
->setPolicyObject($document)
|
||||
->setCapability($view_capability)
|
||||
->setPolicies($policies)
|
||||
->setCaption(
|
||||
$document->describeAutomaticCapability($view_capability)))
|
||||
->appendChild(
|
||||
id(new AphrontFormPolicyControl())
|
||||
->setName('editPolicy')
|
||||
->setPolicyObject($document)
|
||||
->setCapability($edit_capability)
|
||||
->setPolicies($policies)
|
||||
->setCaption(
|
||||
$document->describeAutomaticCapability($edit_capability)))
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel(pht('Edit Notes'))
|
||||
|
|
|
@ -5,6 +5,10 @@ final class PhrictionHistoryController
|
|||
|
||||
private $slug;
|
||||
|
||||
public function shouldAllowPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->slug = $data['slug'];
|
||||
}
|
||||
|
|
|
@ -200,8 +200,18 @@ final class PhrictionTransactionEditor
|
|||
->setNewValue(true);
|
||||
}
|
||||
break;
|
||||
case PhrictionTransaction::TYPE_MOVE_TO:
|
||||
$document = $xaction->getNewValue();
|
||||
$xactions[] = id(new PhrictionTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
|
||||
->setNewValue($document->getViewPolicy());
|
||||
$xactions[] = id(new PhrictionTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)
|
||||
->setNewValue($document->getEditPolicy());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return $xactions;
|
||||
|
@ -298,6 +308,12 @@ final class PhrictionTransactionEditor
|
|||
->setTransactionType(PhrictionTransaction::TYPE_CONTENT)
|
||||
->setNewValue('')
|
||||
->setMetadataValue('stub:create:phid', $object->getPHID());
|
||||
$stub_xactions[] = id(new PhrictionTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
|
||||
->setNewValue($object->getViewPolicy());
|
||||
$stub_xactions[] = id(new PhrictionTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)
|
||||
->setNewValue($object->getEditPolicy());
|
||||
$sub_editor = id(new PhrictionTransactionEditor())
|
||||
->setActor($this->getActor())
|
||||
->setContentSource($this->getContentSource())
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class PhrictionActionMenuEventListener extends PhabricatorEventListener {
|
||||
|
||||
public function register() {
|
||||
$this->listen(PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS);
|
||||
}
|
||||
|
||||
public function handleEvent(PhutilEvent $event) {
|
||||
switch ($event->getType()) {
|
||||
case PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS:
|
||||
$this->handleActionsEvent($event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function handleActionsEvent(PhutilEvent $event) {
|
||||
$object = $event->getValue('object');
|
||||
|
||||
$actions = null;
|
||||
if ($object instanceof PhabricatorProject) {
|
||||
$actions = $this->buildProjectActions($event);
|
||||
}
|
||||
|
||||
$this->addActionMenuItems($event, $actions);
|
||||
}
|
||||
|
||||
private function buildProjectActions(PhutilEvent $event) {
|
||||
if (!$this->canUseApplication($event->getUser())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$project = $event->getValue('object');
|
||||
$slug = PhabricatorSlug::normalize($project->getPhrictionSlug());
|
||||
$href = '/w/projects/'.$slug;
|
||||
|
||||
return id(new PhabricatorActionView())
|
||||
->setIcon('fa-book')
|
||||
->setName(pht('View Wiki'))
|
||||
->setHref($href);
|
||||
}
|
||||
|
||||
}
|
|
@ -18,10 +18,7 @@ final class PhrictionDocument extends PhrictionDAO
|
|||
|
||||
private $contentObject = self::ATTACHABLE;
|
||||
private $ancestors = array();
|
||||
|
||||
// TODO: This should be `self::ATTACHABLE`, but there are still a lot of call
|
||||
// sites which load PhrictionDocuments directly.
|
||||
private $project = null;
|
||||
private $project = self::ATTACHABLE;
|
||||
|
||||
public function getConfiguration() {
|
||||
return array(
|
||||
|
@ -68,9 +65,24 @@ final class PhrictionDocument extends PhrictionDAO
|
|||
$content->setTitle($default_title);
|
||||
$document->attachContent($content);
|
||||
|
||||
$default_view_policy = PhabricatorPolicies::getMostOpenPolicy();
|
||||
$document->setViewPolicy($default_view_policy);
|
||||
$document->setEditPolicy(PhabricatorPolicies::POLICY_USER);
|
||||
$parent_doc = null;
|
||||
$ancestral_slugs = PhabricatorSlug::getAncestry($slug);
|
||||
if ($ancestral_slugs) {
|
||||
$parent = end($ancestral_slugs);
|
||||
$parent_doc = id(new PhrictionDocumentQuery())
|
||||
->setViewer($actor)
|
||||
->withSlugs(array($parent))
|
||||
->executeOne();
|
||||
}
|
||||
|
||||
if ($parent_doc) {
|
||||
$document->setViewPolicy($parent_doc->getViewPolicy());
|
||||
$document->setEditPolicy($parent_doc->getEditPolicy());
|
||||
} else {
|
||||
$default_view_policy = PhabricatorPolicies::getMostOpenPolicy();
|
||||
$document->setViewPolicy($default_view_policy);
|
||||
$document->setEditPolicy(PhabricatorPolicies::POLICY_USER);
|
||||
}
|
||||
|
||||
return $document;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue