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

Add application and object level policy controls to Countdown

Summary: Ref T603. Give countdowns proper UI-level policy controls, and an application-level default policy. Put policy information in the header.

Test Plan:
- Adjusted default policy.
- Created new countdowns.
- Edited countdowns.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603

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

+77 -25
+5
resources/sql/patches/20131015.cpolicy.sql
··· 1 + ALTER TABLE {$NAMESPACE}_countdown.countdown 2 + ADD viewPolicy VARCHAR(64) NOT NULL; 3 + 4 + UPDATE {$NAMESPACE}_countdown.countdown 5 + SET viewPolicy = 'users' WHERE viewPolicy = '';
+2
src/__phutil_library_map__.php
··· 1068 1068 'PhabricatorController' => 'applications/base/controller/PhabricatorController.php', 1069 1069 'PhabricatorCoreConfigOptions' => 'applications/config/option/PhabricatorCoreConfigOptions.php', 1070 1070 'PhabricatorCountdown' => 'applications/countdown/storage/PhabricatorCountdown.php', 1071 + 'PhabricatorCountdownCapabilityDefaultView' => 'applications/countdown/capability/PhabricatorCountdownCapabilityDefaultView.php', 1071 1072 'PhabricatorCountdownController' => 'applications/countdown/controller/PhabricatorCountdownController.php', 1072 1073 'PhabricatorCountdownDAO' => 'applications/countdown/storage/PhabricatorCountdownDAO.php', 1073 1074 'PhabricatorCountdownDeleteController' => 'applications/countdown/controller/PhabricatorCountdownDeleteController.php', ··· 3244 3245 0 => 'PhabricatorCountdownDAO', 3245 3246 1 => 'PhabricatorPolicyInterface', 3246 3247 ), 3248 + 'PhabricatorCountdownCapabilityDefaultView' => 'PhabricatorPolicyCapability', 3247 3249 'PhabricatorCountdownController' => 'PhabricatorController', 3248 3250 'PhabricatorCountdownDAO' => 'PhabricatorLiskDAO', 3249 3251 'PhabricatorCountdownDeleteController' => 'PhabricatorCountdownController',
+8 -3
src/applications/countdown/application/PhabricatorApplicationCountdown.php
··· 1 1 <?php 2 2 3 - /** 4 - * @group countdown 5 - */ 6 3 final class PhabricatorApplicationCountdown extends PhabricatorApplication { 7 4 8 5 public function getBaseURI() { ··· 46 43 => 'PhabricatorCountdownEditController', 47 44 'delete/(?P<id>[1-9]\d*)/' 48 45 => 'PhabricatorCountdownDeleteController' 46 + ), 47 + ); 48 + } 49 + 50 + public function getCustomCapabilities() { 51 + return array( 52 + PhabricatorCountdownCapabilityDefaultView::CAPABILITY => array( 53 + 'caption' => pht('Default view policy for new countdowns.'), 49 54 ), 50 55 ); 51 56 }
+20
src/applications/countdown/capability/PhabricatorCountdownCapabilityDefaultView.php
··· 1 + <?php 2 + 3 + final class PhabricatorCountdownCapabilityDefaultView 4 + extends PhabricatorPolicyCapability { 5 + 6 + const CAPABILITY = 'countdown.default.view'; 7 + 8 + public function getCapabilityKey() { 9 + return self::CAPABILITY; 10 + } 11 + 12 + public function getCapabilityName() { 13 + return pht('Default View Policy'); 14 + } 15 + 16 + public function shouldAllowPublicPolicySetting() { 17 + return true; 18 + } 19 + 20 + }
-5
src/applications/countdown/controller/PhabricatorCountdownDeleteController.php
··· 31 31 return new Aphront404Response(); 32 32 } 33 33 34 - if (($countdown->getAuthorPHID() !== $user->getPHID()) 35 - && $user->getIsAdmin() === false) { 36 - return new Aphront403Response(); 37 - } 38 - 39 34 if ($request->isFormPost()) { 40 35 $countdown->delete(); 41 36 return id(new AphrontRedirectResponse())
+19 -7
src/applications/countdown/controller/PhabricatorCountdownEditController.php
··· 27 27 PhabricatorPolicyCapability::CAN_EDIT, 28 28 )) 29 29 ->executeOne(); 30 - 31 - // If no countdown is found 32 30 if (!$countdown) { 33 31 return new Aphront404Response(); 34 32 } 35 33 } else { 36 34 $page_title = pht('Create Countdown'); 37 - $countdown = new PhabricatorCountdown(); 38 - $countdown->setEpoch(time()); 35 + $countdown = PhabricatorCountdown::initializeNewCountdown($user); 39 36 } 40 37 41 38 $error_view = null; 42 - $e_text = null; 39 + $e_text = true; 40 + $e_epoch = null; 43 41 44 42 if ($request->isFormPost()) { 45 43 $errors = array(); 46 44 $title = $request->getStr('title'); 47 45 $epoch = $request->getStr('epoch'); 46 + $view_policy = $request->getStr('viewPolicy'); 48 47 49 48 $e_text = null; 50 49 if (!strlen($title)) { ··· 68 67 if (!count($errors)) { 69 68 $countdown->setTitle($title); 70 69 $countdown->setEpoch($timestamp); 71 - $countdown->setAuthorPHID($user->getPHID()); 70 + $countdown->setViewPolicy($view_policy); 72 71 $countdown->save(); 73 72 return id(new AphrontRedirectResponse()) 74 73 ->setURI('/countdown/'.$countdown->getID().'/'); ··· 106 105 $submit_label = pht('Create Countdown'); 107 106 } 108 107 108 + $policies = id(new PhabricatorPolicyQuery()) 109 + ->setViewer($user) 110 + ->setObject($countdown) 111 + ->execute(); 109 112 110 113 $form = id(new AphrontFormView()) 111 114 ->setUser($user) ··· 114 117 id(new AphrontFormTextControl()) 115 118 ->setLabel(pht('Title')) 116 119 ->setValue($countdown->getTitle()) 117 - ->setName('title')) 120 + ->setName('title') 121 + ->setError($e_text)) 118 122 ->appendChild( 119 123 id(new AphrontFormTextControl()) 120 124 ->setLabel(pht('End Date')) 121 125 ->setValue($display_epoch) 122 126 ->setName('epoch') 127 + ->setError($e_epoch) 123 128 ->setCaption(pht('Examples: '. 124 129 '2011-12-25 or 3 hours or '. 125 130 'June 8 2011, 5 PM.'))) 131 + ->appendChild( 132 + id(new AphrontFormPolicyControl()) 133 + ->setUser($user) 134 + ->setName('viewPolicy') 135 + ->setPolicyObject($countdown) 136 + ->setPolicies($policies) 137 + ->setCapability(PhabricatorPolicyCapability::CAN_VIEW)) 126 138 ->appendChild( 127 139 id(new AphrontFormSubmitControl()) 128 140 ->addCancelButton($cancel_uri)
+3 -2
src/applications/countdown/controller/PhabricatorCountdownViewController.php
··· 22 22 ->setViewer($user) 23 23 ->withIDs(array($this->id)) 24 24 ->executeOne(); 25 - 26 25 if (!$countdown) { 27 26 return new Aphront404Response(); 28 27 } ··· 42 41 ->setName("C{$id}")); 43 42 44 43 $header = id(new PHUIHeaderView()) 45 - ->setHeader($title); 44 + ->setHeader($title) 45 + ->setUser($user) 46 + ->setPolicyObject($countdown); 46 47 47 48 $actions = $this->buildActionListView($countdown); 48 49 $properties = $this->buildPropertyListView($countdown, $actions);
+16 -8
src/applications/countdown/storage/PhabricatorCountdown.php
··· 1 1 <?php 2 2 3 - /** 4 - * @group countdown 5 - */ 6 3 final class PhabricatorCountdown 7 4 extends PhabricatorCountdownDAO 8 5 implements PhabricatorPolicyInterface { ··· 10 7 protected $title; 11 8 protected $authorPHID; 12 9 protected $epoch; 13 - // protected $viewPolicy; //commented out till we have it on countdown table 10 + protected $viewPolicy; 11 + 12 + public static function initializeNewCountdown(PhabricatorUser $actor) { 13 + $app = id(new PhabricatorApplicationQuery()) 14 + ->setViewer($actor) 15 + ->withClasses(array('PhabricatorApplicationCountdown')) 16 + ->executeOne(); 17 + 18 + $view_policy = $app->getPolicy( 19 + PhabricatorCountdownCapabilityDefaultView::CAPABILITY); 20 + 21 + return id(new PhabricatorCountdown()) 22 + ->setAuthorPHID($actor->getPHID()) 23 + ->setViewPolicy($view_policy) 24 + ->setEpoch(PhabricatorTime::getNow()); 25 + } 14 26 15 27 public function getConfiguration() { 16 28 return array( ··· 21 33 public function generatePHID() { 22 34 return PhabricatorPHID::generateNewPHID( 23 35 PhabricatorCountdownPHIDTypeCountdown::TYPECONST); 24 - } 25 - 26 - public function getViewPolicy() { 27 - return PhabricatorPolicies::POLICY_USER; 28 36 } 29 37 30 38
+4
src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
··· 1672 1672 'type' => 'sql', 1673 1673 'name' => $this->getPatchPath('20131010.pstorage.sql'), 1674 1674 ), 1675 + '20131015.cpolicy.sql' => array( 1676 + 'type' => 'sql', 1677 + 'name' => $this->getPatchPath('20131015.cpolicy.sql'), 1678 + ), 1675 1679 ); 1676 1680 } 1677 1681 }