@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Paste: Add edit policy

Summary: T5549

Test Plan: Set edit policy on paste, check that only users meeting the policy requirements can edit it.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Maniphest Tasks: T5549

Differential Revision: https://secure.phabricator.com/D11097

authored by

Alex Monk and committed by
epriestley
a84cd998 debffb1c

+50 -5
+3
resources/sql/autopatches/20141230.pasteeditpolicycolumn.sql
··· 1 + ALTER TABLE `{$NAMESPACE}_pastebin`.`pastebin_paste` 2 + ADD `editPolicy` VARBINARY(64) NOT NULL 3 + AFTER `viewPolicy`;
+2
resources/sql/autopatches/20141230.pasteeditpolicyexisting.sql
··· 1 + UPDATE `{$NAMESPACE}_pastebin`.`pastebin_paste` SET editPolicy = authorPHID 2 + WHERE editPolicy = '';
+2
src/__phutil_library_map__.php
··· 1203 1203 'PasteConduitAPIMethod' => 'applications/paste/conduit/PasteConduitAPIMethod.php', 1204 1204 'PasteCreateConduitAPIMethod' => 'applications/paste/conduit/PasteCreateConduitAPIMethod.php', 1205 1205 'PasteCreateMailReceiver' => 'applications/paste/mail/PasteCreateMailReceiver.php', 1206 + 'PasteDefaultEditCapability' => 'applications/paste/capability/PasteDefaultEditCapability.php', 1206 1207 'PasteDefaultViewCapability' => 'applications/paste/capability/PasteDefaultViewCapability.php', 1207 1208 'PasteEmbedView' => 'applications/paste/view/PasteEmbedView.php', 1208 1209 'PasteInfoConduitAPIMethod' => 'applications/paste/conduit/PasteInfoConduitAPIMethod.php', ··· 4326 4327 'PasteConduitAPIMethod' => 'ConduitAPIMethod', 4327 4328 'PasteCreateConduitAPIMethod' => 'PasteConduitAPIMethod', 4328 4329 'PasteCreateMailReceiver' => 'PhabricatorMailReceiver', 4330 + 'PasteDefaultEditCapability' => 'PhabricatorPolicyCapability', 4329 4331 'PasteDefaultViewCapability' => 'PhabricatorPolicyCapability', 4330 4332 'PasteEmbedView' => 'AphrontView', 4331 4333 'PasteInfoConduitAPIMethod' => 'PasteConduitAPIMethod',
+3
src/applications/paste/application/PhabricatorPasteApplication.php
··· 50 50 PasteDefaultViewCapability::CAPABILITY => array( 51 51 'caption' => pht('Default view policy for newly created pastes.'), 52 52 ), 53 + PasteDefaultEditCapability::CAPABILITY => array( 54 + 'caption' => pht('Default edit policy for newly created pastes.'), 55 + ), 53 56 ); 54 57 } 55 58
+11
src/applications/paste/capability/PasteDefaultEditCapability.php
··· 1 + <?php 2 + 3 + final class PasteDefaultEditCapability extends PhabricatorPolicyCapability { 4 + 5 + const CAPABILITY = 'paste.default.edit'; 6 + 7 + public function getCapabilityName() { 8 + return pht('Default Edit Policy'); 9 + } 10 + 11 + }
+17 -4
src/applications/paste/controller/PhabricatorPasteEditController.php
··· 69 69 $v_language = $paste->getLanguage(); 70 70 $v_text = $paste->getRawContent(); 71 71 } 72 - $v_policy = $paste->getViewPolicy(); 72 + $v_view_policy = $paste->getViewPolicy(); 73 + $v_edit_policy = $paste->getEditPolicy(); 73 74 74 75 if ($is_create) { 75 76 $v_projects = array(); ··· 93 94 94 95 $v_title = $request->getStr('title'); 95 96 $v_language = $request->getStr('language'); 96 - $v_policy = $request->getStr('can_view'); 97 + $v_view_policy = $request->getStr('can_view'); 98 + $v_edit_policy = $request->getStr('can_edit'); 97 99 $v_projects = $request->getArr('projects'); 98 100 99 101 // NOTE: The author is the only editor and can always view the paste, ··· 119 121 ->setNewValue($v_language); 120 122 $xactions[] = id(new PhabricatorPasteTransaction()) 121 123 ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) 122 - ->setNewValue($v_policy); 124 + ->setNewValue($v_view_policy); 125 + $xactions[] = id(new PhabricatorPasteTransaction()) 126 + ->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY) 127 + ->setNewValue($v_edit_policy); 123 128 124 129 $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; 125 130 $xactions[] = id(new PhabricatorPasteTransaction()) ··· 136 141 } else { 137 142 // make sure we update policy so its correctly populated to what 138 143 // the user chose 139 - $paste->setViewPolicy($v_policy); 144 + $paste->setViewPolicy($v_view_policy); 145 + $paste->setEditPolicy($v_edit_policy); 140 146 } 141 147 } 142 148 ··· 174 180 ->setPolicies($policies) 175 181 ->setName('can_view')); 176 182 183 + $form->appendChild( 184 + id(new AphrontFormPolicyControl()) 185 + ->setUser($user) 186 + ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) 187 + ->setPolicyObject($paste) 188 + ->setPolicies($policies) 189 + ->setName('can_edit')); 177 190 178 191 if ($v_projects) { 179 192 $project_handles = $this->loadViewerHandles($v_projects);
+6
src/applications/paste/editor/PhabricatorPasteEditor.php
··· 25 25 'mime-type' => 'text/plain; charset=utf-8', 26 26 'authorPHID' => $actor->getPHID(), 27 27 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, 28 + 'editPolicy' => PhabricatorPolicies::POLICY_NOONE, 28 29 )); 29 30 } 30 31 ··· 35 36 $types[] = PhabricatorPasteTransaction::TYPE_TITLE; 36 37 $types[] = PhabricatorPasteTransaction::TYPE_LANGUAGE; 37 38 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 39 + $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 38 40 $types[] = PhabricatorTransactions::TYPE_COMMENT; 39 41 40 42 return $types; ··· 83 85 case PhabricatorTransactions::TYPE_VIEW_POLICY: 84 86 $object->setViewPolicy($xaction->getNewValue()); 85 87 return; 88 + case PhabricatorTransactions::TYPE_EDIT_POLICY: 89 + $object->setEditPolicy($xaction->getNewValue()); 90 + return; 86 91 case PhabricatorTransactions::TYPE_COMMENT: 87 92 case PhabricatorTransactions::TYPE_SUBSCRIBERS: 88 93 case PhabricatorTransactions::TYPE_EDGE: ··· 101 106 case PhabricatorPasteTransaction::TYPE_TITLE: 102 107 case PhabricatorPasteTransaction::TYPE_LANGUAGE: 103 108 case PhabricatorTransactions::TYPE_VIEW_POLICY: 109 + case PhabricatorTransactions::TYPE_EDIT_POLICY: 104 110 case PhabricatorTransactions::TYPE_COMMENT: 105 111 case PhabricatorTransactions::TYPE_SUBSCRIBERS: 106 112 case PhabricatorTransactions::TYPE_EDGE:
+6 -1
src/applications/paste/storage/PhabricatorPaste.php
··· 17 17 protected $language; 18 18 protected $parentPHID; 19 19 protected $viewPolicy; 20 + protected $editPolicy; 20 21 protected $mailKey; 21 22 22 23 private $content = self::ATTACHABLE; ··· 29 30 ->executeOne(); 30 31 31 32 $view_policy = $app->getPolicy(PasteDefaultViewCapability::CAPABILITY); 33 + $edit_policy = $app->getPolicy(PasteDefaultEditCapability::CAPABILITY); 32 34 33 35 return id(new PhabricatorPaste()) 34 36 ->setTitle('') 35 37 ->setAuthorPHID($actor->getPHID()) 36 - ->setViewPolicy($view_policy); 38 + ->setViewPolicy($view_policy) 39 + ->setEditPolicy($edit_policy); 37 40 } 38 41 39 42 public function getURI() { ··· 146 149 public function getPolicy($capability) { 147 150 if ($capability == PhabricatorPolicyCapability::CAN_VIEW) { 148 151 return $this->viewPolicy; 152 + } else if ($capability == PhabricatorPolicyCapability::CAN_EDIT) { 153 + return $this->editPolicy; 149 154 } 150 155 return PhabricatorPolicies::POLICY_NOONE; 151 156 }