Page MenuHomePhabricator

D11097.id26649.diff
No OneTemporary

D11097.id26649.diff

diff --git a/resources/sql/autopatches/20141230.pasteeditpolicycolumn.sql b/resources/sql/autopatches/20141230.pasteeditpolicycolumn.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20141230.pasteeditpolicycolumn.sql
@@ -0,0 +1,3 @@
+ALTER TABLE `{$NAMESPACE}_pastebin`.`pastebin_paste`
+ ADD `editPolicy` VARBINARY(64) NOT NULL
+ AFTER `viewPolicy`;
diff --git a/resources/sql/autopatches/20141230.pasteeditpolicyexisting.sql b/resources/sql/autopatches/20141230.pasteeditpolicyexisting.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20141230.pasteeditpolicyexisting.sql
@@ -0,0 +1,2 @@
+UPDATE `{$NAMESPACE}_pastebin`.`pastebin_paste` SET editPolicy = authorPHID
+ WHERE editPolicy = '';
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1203,6 +1203,7 @@
'PasteConduitAPIMethod' => 'applications/paste/conduit/PasteConduitAPIMethod.php',
'PasteCreateConduitAPIMethod' => 'applications/paste/conduit/PasteCreateConduitAPIMethod.php',
'PasteCreateMailReceiver' => 'applications/paste/mail/PasteCreateMailReceiver.php',
+ 'PasteDefaultEditCapability' => 'applications/paste/capability/PasteDefaultEditCapability.php',
'PasteDefaultViewCapability' => 'applications/paste/capability/PasteDefaultViewCapability.php',
'PasteEmbedView' => 'applications/paste/view/PasteEmbedView.php',
'PasteInfoConduitAPIMethod' => 'applications/paste/conduit/PasteInfoConduitAPIMethod.php',
@@ -4326,6 +4327,7 @@
'PasteConduitAPIMethod' => 'ConduitAPIMethod',
'PasteCreateConduitAPIMethod' => 'PasteConduitAPIMethod',
'PasteCreateMailReceiver' => 'PhabricatorMailReceiver',
+ 'PasteDefaultEditCapability' => 'PhabricatorPolicyCapability',
'PasteDefaultViewCapability' => 'PhabricatorPolicyCapability',
'PasteEmbedView' => 'AphrontView',
'PasteInfoConduitAPIMethod' => 'PasteConduitAPIMethod',
diff --git a/src/applications/paste/application/PhabricatorPasteApplication.php b/src/applications/paste/application/PhabricatorPasteApplication.php
--- a/src/applications/paste/application/PhabricatorPasteApplication.php
+++ b/src/applications/paste/application/PhabricatorPasteApplication.php
@@ -50,6 +50,9 @@
PasteDefaultViewCapability::CAPABILITY => array(
'caption' => pht('Default view policy for newly created pastes.'),
),
+ PasteDefaultEditCapability::CAPABILITY => array(
+ 'caption' => pht('Default edit policy for newly created pastes.'),
+ ),
);
}
diff --git a/src/applications/paste/capability/PasteDefaultEditCapability.php b/src/applications/paste/capability/PasteDefaultEditCapability.php
new file mode 100644
--- /dev/null
+++ b/src/applications/paste/capability/PasteDefaultEditCapability.php
@@ -0,0 +1,11 @@
+<?php
+
+final class PasteDefaultEditCapability extends PhabricatorPolicyCapability {
+
+ const CAPABILITY = 'paste.default.edit';
+
+ public function getCapabilityName() {
+ return pht('Default Edit Policy');
+ }
+
+}
diff --git a/src/applications/paste/controller/PhabricatorPasteEditController.php b/src/applications/paste/controller/PhabricatorPasteEditController.php
--- a/src/applications/paste/controller/PhabricatorPasteEditController.php
+++ b/src/applications/paste/controller/PhabricatorPasteEditController.php
@@ -69,7 +69,8 @@
$v_language = $paste->getLanguage();
$v_text = $paste->getRawContent();
}
- $v_policy = $paste->getViewPolicy();
+ $v_view_policy = $paste->getViewPolicy();
+ $v_edit_policy = $paste->getEditPolicy();
if ($is_create) {
$v_projects = array();
@@ -93,7 +94,8 @@
$v_title = $request->getStr('title');
$v_language = $request->getStr('language');
- $v_policy = $request->getStr('can_view');
+ $v_view_policy = $request->getStr('can_view');
+ $v_edit_policy = $request->getStr('can_edit');
$v_projects = $request->getArr('projects');
// NOTE: The author is the only editor and can always view the paste,
@@ -119,7 +121,10 @@
->setNewValue($v_language);
$xactions[] = id(new PhabricatorPasteTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
- ->setNewValue($v_policy);
+ ->setNewValue($v_view_policy);
+ $xactions[] = id(new PhabricatorPasteTransaction())
+ ->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)
+ ->setNewValue($v_edit_policy);
$proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
$xactions[] = id(new PhabricatorPasteTransaction())
@@ -136,7 +141,8 @@
} else {
// make sure we update policy so its correctly populated to what
// the user chose
- $paste->setViewPolicy($v_policy);
+ $paste->setViewPolicy($v_view_policy);
+ $paste->setEditPolicy($v_edit_policy);
}
}
@@ -174,6 +180,13 @@
->setPolicies($policies)
->setName('can_view'));
+ $form->appendChild(
+ id(new AphrontFormPolicyControl())
+ ->setUser($user)
+ ->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
+ ->setPolicyObject($paste)
+ ->setPolicies($policies)
+ ->setName('can_edit'));
if ($v_projects) {
$project_handles = $this->loadViewerHandles($v_projects);
diff --git a/src/applications/paste/editor/PhabricatorPasteEditor.php b/src/applications/paste/editor/PhabricatorPasteEditor.php
--- a/src/applications/paste/editor/PhabricatorPasteEditor.php
+++ b/src/applications/paste/editor/PhabricatorPasteEditor.php
@@ -25,6 +25,7 @@
'mime-type' => 'text/plain; charset=utf-8',
'authorPHID' => $actor->getPHID(),
'viewPolicy' => PhabricatorPolicies::POLICY_NOONE,
+ 'editPolicy' => PhabricatorPolicies::POLICY_NOONE,
));
}
@@ -35,6 +36,7 @@
$types[] = PhabricatorPasteTransaction::TYPE_TITLE;
$types[] = PhabricatorPasteTransaction::TYPE_LANGUAGE;
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
+ $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
$types[] = PhabricatorTransactions::TYPE_COMMENT;
return $types;
@@ -83,6 +85,9 @@
case PhabricatorTransactions::TYPE_VIEW_POLICY:
$object->setViewPolicy($xaction->getNewValue());
return;
+ case PhabricatorTransactions::TYPE_EDIT_POLICY:
+ $object->setEditPolicy($xaction->getNewValue());
+ return;
case PhabricatorTransactions::TYPE_COMMENT:
case PhabricatorTransactions::TYPE_SUBSCRIBERS:
case PhabricatorTransactions::TYPE_EDGE:
@@ -101,6 +106,7 @@
case PhabricatorPasteTransaction::TYPE_TITLE:
case PhabricatorPasteTransaction::TYPE_LANGUAGE:
case PhabricatorTransactions::TYPE_VIEW_POLICY:
+ case PhabricatorTransactions::TYPE_EDIT_POLICY:
case PhabricatorTransactions::TYPE_COMMENT:
case PhabricatorTransactions::TYPE_SUBSCRIBERS:
case PhabricatorTransactions::TYPE_EDGE:
diff --git a/src/applications/paste/storage/PhabricatorPaste.php b/src/applications/paste/storage/PhabricatorPaste.php
--- a/src/applications/paste/storage/PhabricatorPaste.php
+++ b/src/applications/paste/storage/PhabricatorPaste.php
@@ -17,6 +17,7 @@
protected $language;
protected $parentPHID;
protected $viewPolicy;
+ protected $editPolicy;
protected $mailKey;
private $content = self::ATTACHABLE;
@@ -29,11 +30,13 @@
->executeOne();
$view_policy = $app->getPolicy(PasteDefaultViewCapability::CAPABILITY);
+ $edit_policy = $app->getPolicy(PasteDefaultEditCapability::CAPABILITY);
return id(new PhabricatorPaste())
->setTitle('')
->setAuthorPHID($actor->getPHID())
- ->setViewPolicy($view_policy);
+ ->setViewPolicy($view_policy)
+ ->setEditPolicy($edit_policy);
}
public function getURI() {
@@ -146,6 +149,8 @@
public function getPolicy($capability) {
if ($capability == PhabricatorPolicyCapability::CAN_VIEW) {
return $this->viewPolicy;
+ } else if ($capability == PhabricatorPolicyCapability::CAN_EDIT) {
+ return $this->editPolicy;
}
return PhabricatorPolicies::POLICY_NOONE;
}

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 28, 6:14 PM (3 h, 6 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6940678
Default Alt Text
D11097.id26649.diff (8 KB)

Event Timeline